py_eddy_tracker.dataset.grid.RegularGridDataset¶
- class py_eddy_tracker.dataset.grid.RegularGridDataset(*args, **kwargs)[source]¶
Bases:
GridDatasetClass only for regular grid
- Parameters:
filename (str) – Filename to load
x_name (str) – Name of longitude coordinates
y_name (str) – Name of latitude coordinates
centered (bool,None) – Allow to know how coordinates could be used with pixel
indexs (dict) – A dictionary that sets indexes to use for non-coordinate dimensions
unset (bool) – Set to True to create an empty grid object without file
nan_masking (bool) – Set to True to replace data.mask with isnan method result
Methods
add_gridAdd a grid in handler
Compute a u and v grid
At each call it will update position in place with u & v field
c_to_boundsCentered coordinates to bounds coordinates
cleanFunction to remove all land pixel
Give a series of indexes describing the path between two positions
Apply stencil ponderation on field.
copyDuplicate the variable from grid_in in grid_out
eddy_identificationCompute eddy identification on the specified grid
Produce filament with concatenation of advection
get_amplitudeget_maskGet indexes of pixels in contour.
get_uavgCompute geostrophic speed around successive contours Returns the average
gridGive the grid required
grid_tilesGive the grid tiles required, without buffer system
high_filterReturn the high-pass filtered grid, by substracting to the initial grid the low-pass filtered grid (default: order=1)
Draft
Compute z over lons, lats
Check if the grid is circular
wave_length in km order must be int
Not really operational wave_length in km order must be int
loadLoad variable (data).
load_general_featuresLoad attrs to be stored in object
low_filterReturn the low-pass filtered grid (default: order=1)
populateInterpolate another grid at the current grid position
Some nan can be computed over contour if we are near borders, something to explore
unitsGet unit from variable
Get U,V to be used in degrees with precomputed time step
Geo matrix data must be ordered like this (X,Y) and masked with numpy.ma.array
writeWrite dataset output with same format as input
Attributes
EARTH_RADIUSGRAVITYNboundsGive bounds
centeredcontourscoordinatesdimensionsfilenameglobal_attrsindexsis_centeredGive True if pixel is described with its center's position or a corner
nan_maskvariablesvariables_descriptionvarsx_boundsx_cx_dimOnly for regular grid with no step variation
y_boundsy_cy_dimOnly for regular grid with no step variation
- add_uv(grid_height, uname='u', vname='v', stencil_halfwidth=4)[source]¶
Compute a u and v grid
- Parameters:
\[ \begin{align}\begin{aligned}u = \frac{g}{f} \frac{dh}{dy}\\v = -\frac{g}{f} \frac{dh}{dx}\end{aligned}\end{align} \]where
\[ \begin{align}\begin{aligned}g = gravity\\f = 2 \Omega sin(\phi)\end{aligned}\end{align} \]
- advect(x, y, u_name, v_name, nb_step=10, rk4=True, **kw)[source]¶
At each call it will update position in place with u & v field
It’s a dummy advection using only one layer of current
- Parameters:
- bessel_high_filter(grid_name, wave_length, order=1, lat_max=85, **kwargs)[source]¶
- Parameters:
grid_name (str) – grid to filter, data will replace original one
wave_length (float) – in km
order (int) – order to use, if > 1 negative values of the cardinal sinus are present in kernel
lat_max (float) – absolute latitude, no filtering above
kwargs (dict) – look at
RegularGridDataset.convolve_filter_with_dynamic_kernel()
- compute_pixel_path(x0, y0, x1, y1)[source]¶
Give a series of indexes describing the path between two positions
- compute_stencil(data, stencil_halfwidth=4, mode='reflect', vertical=False)[source]¶
Apply stencil ponderation on field.
- Parameters:
- Returns:
gradient array from stencil application
- Return type:
array
Short story, how to get stencil coefficient for stencil (3 points, 5 points and 7 points)
Taylor’s theorem:
\[f(x \pm h) = f(x) \pm f'(x)h + \frac{f''(x)h^2}{2!} \pm \frac{f^{(3)}(x)h^3}{3!} + \frac{f^{(4)}(x)h^4}{4!} \pm \frac{f^{(5)}(x)h^5}{5!} + O(h^6)\]If we stop at O(h^2), we get classic differenciation (stencil 3 points):
\[f(x+h) - f(x-h) = f(x) - f(x) + 2 f'(x)h + O(h^2)\]\[f'(x) = \frac{f(x+h) - f(x-h)}{2h} + O(h^2)\]If we stop at O(h^4), we will get stencil 5 points:
(1)¶\[f(x+h) - f(x-h) = 2 f'(x)h + 2 \frac{f^{(3)}(x)h^3}{3!} + O(h^4)\](2)¶\[f(x+2h) - f(x-2h) = 4 f'(x)h + 16 \frac{f^{(3)}(x)h^3}{3!} + O(h^4)\]If we multiply equation (1) by 8 and substract equation (2), we get:
\[8(f(x+h) - f(x-h)) - (f(x+2h) - f(x-2h)) = 16 f'(x)h - 4 f'(x)h + O(h^4)\]\[f'(x) = \frac{f(x-2h) - 8f(x-h) + 8f(x+h) - f(x+2h)}{12h} + O(h^4)\]If we stop at O(h^6), we will get stencil 7 points:
(3)¶\[f(x+h) - f(x-h) = 2 f'(x)h + 2 \frac{f^{(3)}(x)h^3}{3!} + 2 \frac{f^{(5)}(x)h^5}{5!} + O(h^6)\](4)¶\[f(x+2h) - f(x-2h) = 4 f'(x)h + 16 \frac{f^{(3)}(x)h^3}{3!} + 64 \frac{f^{(5)}(x)h^5}{5!} + O(h^6)\](5)¶\[f(x+3h) - f(x-3h) = 6 f'(x)h + 54 \frac{f^{(3)}(x)h^3}{3!} + 486 \frac{f^{(5)}(x)h^5}{5!} + O(h^6)\]If we multiply equation (3) by 45 and substract equation (4) multiply by 9 and add equation (5), we get:
\[45(f(x+h) - f(x-h)) - 9(f(x+2h) - f(x-2h)) + (f(x+3h) - f(x-3h)) = 90 f'(x)h - 36 f'(x)h + 6 f'(x)h + O(h^6)\]\[f'(x) = \frac{-f(x-3h) + 9f(x-2h) - 45f(x-h) + 45f(x+h) - 9f(x+2h) +f(x+3h)}{60h} + O(h^6)\]…
- contour(ax, name, factor=1, ref=None, **kwargs)[source]¶
- Parameters:
ax (matplotlib.axes.Axes) – matplotlib axes used to draw
name (str,array) – variable to display, could be an array
factor (float) – multiply grid by
ref (float,None) – if defined, all coordinates are wrapped with ref as western boundary
kwargs (dict) – look at
matplotlib.axes.Axes.contour()
- convolve_filter_with_dynamic_kernel(grid, kernel_func, lat_max=85, extend=False, **kwargs_func)[source]¶
- Parameters:
- Returns:
filtered value
- Return type:
array
- display(ax, name, factor=1, ref=None, **kwargs)[source]¶
- Parameters:
ax (matplotlib.axes.Axes) – matplotlib axes used to draw
name (str,array) – variable to display, could be an array
factor (float) – multiply grid by
ref (float,None) – if defined, all coordinates are wrapped with ref as western boundary
kwargs (dict) – look at
matplotlib.axes.Axes.pcolormesh()
- filament(x, y, u_name, v_name, nb_step=10, filament_size=6, rk4=True, **kw)[source]¶
Produce filament with concatenation of advection
It’s a dummy advection using only one layer of current
- Parameters:
- Returns:
x,y for a line
- kernel_lanczos(lat, wave_length, order=1)[source]¶
Not really operational wave_length in km order must be int
- regrid(other, grid_name, new_name=None)[source]¶
Interpolate another grid at the current grid position
- Parameters:
other (RegularGridDataset)
grid_name (str) – variable name to interpolate
new_name (str) – name used to store, if None method will use current ont
- speed_coef_mean(contour)[source]¶
Some nan can be computed over contour if we are near borders, something to explore
- uv_for_advection(u_name=None, v_name=None, time_step=600, h_name=None, backward=False, factor=1)[source]¶
Get U,V to be used in degrees with precomputed time step
- classmethod with_array(coordinates, datas, variables_description=None, **kwargs)[source]¶
Geo matrix data must be ordered like this (X,Y) and masked with numpy.ma.array
- x_size¶
- property xstep¶
Only for regular grid with no step variation
- property ystep¶
Only for regular grid with no step variation