dX {cyclones} | R Documentation

## First derivatives from harmonic fits.

### Description

`dX` calculates the x-derivatives for gridded data in longitude-latitude coordinates. Is based on the equations by Stephenson (1961) p. 162

dA/dx = 1/(r cos(PHI)) * d/dTHETA

where PHI is the latitude in radians and THETA the longitude.

`dY` calculates the y-derivatives for gridded data in longitude-latitude coordinates.

dA/dy= 1/r d/dPHI

.

`dT` calculates the e.g. time derivatives of a time series.

All functions solve for the gradients by fitting coeffiecients to a Fourier approximation

p(x) = a0 + sum(a[i] cos(w[i]*x) + b[i]sin(w[i]*x))

and dp(x)/dx is

dp(x)/dx = sum(w[i](-a[i] sin(w[i]*x) + b[i]cos(w[i]*x)))

Also see `derivFFT`.

Version 1.1-6:

(i) Correction to the wave number in `dX` and `dY` - previously wave number was scaled as 1/[number of points] and gave incorrect magnitudes for the derivatives, but now the wave number is 1/distance.

(ii) Included a simple confidence check (chk.conf) to set coefficients to zero when +- 1 sd includes zero. This check can be disabled. Note, it is recommended to use the minimum value for maxhar.

(iii) Included new test routines to test the magnitudes of the gradients.

### Usage

    dX(lon,lat,Z,r=6.378e06,maxhar=NULL,mask.bad=TRUE,plot=FALSE,chk.conf=1)
    dY(lon,lat,Z,r=6.378e06,maxhar=NULL,mask.bad=TRUE,plot=FALSE,chk.conf=1)
    dT(y,maxhar=NULL,plot=FALSE,chk.conf=1)
    test.dX(field=NULL,maxhar=7)
    test.dY(field=NULL,maxhar=5)
    test.dT(y=NULL,maxhar=15)

### Arguments

`lon` | Longitudes
`lat` | Latitude
`Z` | Field values of which the gradients are sought
`r` | mean radius of Earth
`maxhar` | Number of harmonics to include. If NULL, `maxhar` is set to the length of the series.
`mask.bad` |
`y` | a time series (vector).
`plot` | plot data and fit
`field` | Field to which the test is applied (default: DNMI.slp)
`chk.conf` | If not NULL, test whether conf. int. (+- chk.conf * sd) includes zero - if so, set coefficient to zero.

### Value

A list: list(Z=Z,a=a,b=b,c=c,dZ=dZ,Z.fit=Z.fit,lon=lon,lat=lat) of class "map"

### Author(s)

R.E. Benestad

### Examples

    # Construct a test series:
    t <- seq(-3,3,by=0.1)
    nt <- length(t)
    y <- 2*rnorm(nt) + 10*sin(t/4) - 7*sin(t/3) + 4*cos(t) - sin(2*t) + 2*cos(3*t) + 0.5*sin(4*t)
    plot(y)

    dydt <- dT(y)
    lines(dydt$y.fit,col="red")
    dydt.2 <- dT(y,maxhar=3)
    lines(dydt.2$y.fit,col="blue",lty=2)

    # First derivative
    plot(dydt$dy,type="l")
    lines(dydt.2$dy,col="blue",lty=2)

    # Second derivative
    dy2dt2<-dT(dydt$dy)
    dy2dt2.2<-dT(dydt.2$dy)
    plot(dy2dt2$dy,type="l")
    lines(dy2dt2.2$dy,col="blue",lty=2)

[Package cyclones version 1.1-6 Index]