epygram.geometries.UnstructuredGeometry
— Unstructured Geometry class¶
Contains the classes for 3D geometries of fields.
- class epygram.geometries.UnstructuredGeometry.UnstructuredGeometry(name, grid, dimensions, vcoordinate, position_on_horizontal_grid='center', geoid=None)[source]¶
Bases:
epygram.geometries.AbstractGeometry.RectangularGridGeometry
Handles the geometry for an unstructured 3-Dimensions Field.
- Parameters
name – Name of geometrical type of representation of points on the Globe. Name must be ‘unstructured’
grid – Handles description of the horizontal grid.
dimensions – Handles grid dimensions.
vcoordinate – Handles vertical geometry parameters.
position_on_horizontal_grid –
Position of points w/r to the horizontal. among: [‘upper-right’, ‘upper-left’,
’lower-left’, ‘lower-right’, ‘center-left’, ‘center-right’, ‘lower-center’, ‘upper-center’, ‘center’, ‘__unknown__’]
geoid – To specify geoid shape.
- get_lonlat_grid(subzone=None, position=None, d4=False, nb_validities=0, force_longitudes=None)[source]¶
Returns a tuple of two tables containing one the longitude of each point, the other the latitude, with 2D shape.
- Parameters
subzone –
optional, among (‘C’, ‘CI’), for LAM grids only, returns the grid resp. for the C or C+I zone off the C+I+E zone.
Default is no subzone, i.e. the whole field.
position – position of lonlat grid with respect to the model cell. Defaults to self.position_on_horizontal_grid.
d4 –
if True, returned values are shaped in a 4 dimensions array
- if False, shape of returned values is determined with respect to geometry.
d4=True requires nb_validities > 0
nb_validities – number of validities represented in data values
force_longitudes – if ‘positive’, the longitudes will be forced positive if ‘]-180,180]’, the longitudes will be in the ]-180, 180] interval
Shape of 2D data on Rectangular grids:
grid[0,0] is SW, grid[-1,-1] is NE
grid[0,-1] is SE, grid[-1,0] is NW
- getcenter(position=None)[source]¶
Returns the coordinate of the grid center as a tuple of Angles (center_lon, center_lat).
Caution: this is computed as the raw average of all grid points. A barycentric computation would be more adequate.
- ij2ll(i, j, position=None)[source]¶
Return the (lon, lat) coordinates of point (i,j), in degrees.
- Parameters
i – X index of point in the 2D matrix of gridpoints
j – Y index of point in the 2D matrix of gridpoints
position – lat lon position to return with respect to the model cell. Defaults to self.position_on_horizontal_grid.
- ll2ij(lon, lat, position=None)[source]¶
Return the (i, j) indexes of point (lon, lat) in degrees, in the 2D matrix of gridpoints.
- Parameters
lon – longitude of point in degrees
lat – latitude of point in degrees
position – lat lon position to return with respect to the model cell. Defaults to self.position_on_horizontal_grid.
Caution: the returned (i,j) are float.
- nearest_points(lon, lat, request, position=None, external_distance=None, squeeze=True)[source]¶
Returns the (i, j) position of the points needed to perform an interpolation. This is a list of (lon, lat) tuples.
- Parameters
lon – longitude of point in degrees.
lat – latitude of point in degrees.
request – criteria for selecting the points, among: * {‘n’:’1’} - the nearest point
position – position in the model cell of the lat lon position. Defaults to self.position_on_horizontal_grid.
external_distance – can be a dict containing the target point value and an external field on the same grid as self, to which the distance is computed within the 4 horizontally nearest points; e.g. {‘target_value’:4810, ‘external_field’:a_3DField_with_same_geometry}. If so, the nearest point is selected with distance = |target_value - external_field.data|
squeeze – True to suppress useless dimensions
- Return type
general output form is [list, list, …, list] with as many list items as the length of lon/lat. Each list item is of the form [tuple, tuple, …, tuple] with as many tuples as the request implies. A tuple represents one of the nearest points associated with one value taken from lon/lat. Each tuple as the form (i, j).
Dimensions with a length of one are removed except if squeeze is False. If squeeze is True and if request implies only one nearest point, the list item of the general output form is replaced by the tuple item; if length of lon/lat is one, the output is directly the list item of the general output form. Hence, if length of lon/lat is one and the request implies only one point, the output is a tuple.
In case of a simple square request, output is actually an array. Otherwise, the output is as described (it cannot be an array because the number of nearest points can vary with the entry point).