Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing Field.gradient() function #633

Merged
merged 3 commits into from
Aug 23, 2019
Merged

Removing Field.gradient() function #633

merged 3 commits into from
Aug 23, 2019

Conversation

delandmeterp
Copy link
Contributor

The former Field.gradient() function was based on np.gradient() function, building central difference scheme within the domain and forward or backward scheme on the field boundaries.
While this function could be useful for different applications, it was facing many limitations:

  • This function was not valid for curvilinear schemes
  • For C-grids, the effective resolution was twice as coarse as it could be if computed properly
  • Close to masked areas (coast), spurious gradients could be computed
  • It required to use np.array data for the Field objects, which is not the case anymore in Chunked fields operational #632

The Field.gradient function is then removed from Parcels. Obtaining the gradient of the field can still be achieved easily within a kernel, as it is done in some diffusion kernels:

    dx = .01  # for spherical coords, dx is in degrees
    Fp1 = fieldset.F[time, particle.depth, particle.lat+dx, particle.lon]
    Fm1 = fieldset.F[time, particle.depth, particle.lat-dx, particle.lon]
    dFdx = (Fp1-Fm1) / (2*dx)

Note in such configuration, the gradient on a spherical mesh is computed as [F]/degree.
If the gradient is needed in [F]/m, it is necessary to rescale it, by multiplying it by a factor
f = 1852*60 in the meridional direction or f=1852*60*cos(lat*pi/180) in the zonal direction.

@delandmeterp delandmeterp merged commit e8da625 into master Aug 23, 2019
@delandmeterp delandmeterp deleted the no_field_gradient branch August 23, 2019 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants