epygram.geometries.D3Geometry — 3-D Geometry class

Contains the classes for 3D geometries of fields.


class epygram.geometries.D3Geometry.D3Geometry(*args, **kwargs)[source]

Bases: epygram.util.RecursiveObject, footprints.FootprintBase

Handles the geometry for a 3-Dimensions Field. Abstract mother class.

Note

This class is managed by footprint.

  • info: Not documented
  • priority: PriorityLevel::DEFAULT (rank=1)

Automatic parameters from the footprint:

  • dimensions (footprints.stdtypes.FPDict) - rxx - Handles grid dimensions.
  • geoid (footprints.stdtypes.FPDict) - rxx - To specify geoid shape; actually used in projected geometries only.
    • Optional. Default is FPDict::<<as_dict:: dict()>>.
  • grid (footprints.stdtypes.FPDict) - rxx - Handles description of the horizontal grid.
  • name (str) - rxx - Name of geometrical type of representation of points on the Globe.
    • Values: set([‘reduced_gauss’, ‘regular_lonlat’, ‘lambert’, ‘rotated_reduced_gauss’, ‘unstructured’, ‘regular_gauss’, ‘mercator’, ‘polar_stereographic’])
  • position_on_horizontal_grid (str) - rwx - Position of points w/r to the horizontal.
    • Optional. Default is ‘__unknown__’.
    • Values: set([‘center-left’, ‘lower-right’, ‘upper-right’, ‘lower-center’, ‘lower-left’, ‘center-right’, ‘upper-left’, ‘__unknown__’, ‘upper-center’, ‘center’])
  • structure (str) - rxx - Type of geometry.
    • Values: set([‘3D’])
  • vcoordinate (epygram.geometries.VGeometry.VGeometry) - rwx - Handles vertical geometry parameters.
azimuth(end1, end2)[source]

Initial bearing from end1 to end2 points following a Great Circle.

Parameters:
  • end1 – must be a tuple (lon, lat) in degrees.
  • end2 – must be a tuple (lon, lat) in degrees.

Warning: requires the pyproj module.

datashape

Returns the data shape requested by this geometry.

distance(end1, end2)[source]

Computes the distance between two points along a Great Circle.

Parameters:
  • end1 – first point, must be a tuple (lon, lat) in degrees.
  • end2 – second point, must be a tuple (lon, lat) in degrees.

Warning: requires the pyproj module.

get_levels(d4=False, nb_validities=0, subzone=None)[source]

Returns an array containing the level for each data point.

Parameters:
  • 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 – the number of validities represented in data values
  • subzone – optional, among (‘C’, ‘CI’), for LAM grids only, extracts the levels resp. from the C or C+I zone off the C+I(+E) zone.

Levels are internally stored with the vertical dimension first whereas this method puts the time in first dimension.

linspace(end1, end2, num)[source]

Returns evenly spaced points over the specified interval. Points are lined up along a Great Circle.

Parameters:
  • end1 – must be a tuple (lon, lat) in degrees.
  • end2 – must be a tuple (lon, lat) in degrees.
  • num – the number of points, including point1 and point2.

Warning: requires the pyproj module.

make_point_geometry(lon, lat)[source]

Returns a PointGeometry at coordinates (lon,lat) in degrees.

make_profile_geometry(lon, lat)[source]

Returns a V1DGeometry at coordinates (lon,lat) in degrees.

make_section_geometry(end1, end2, points_number=None, resolution=None, position=None)[source]

Returns a V2DGeometry.

Parameters:
  • end1 – must be a tuple (lon, lat) in degrees.
  • end2 – must be a tuple (lon, lat) in degrees.
  • points_number – defines the total number of horizontal points of the section (including ends). If None, defaults to a number computed from the ends and the resolution.
  • resolution – defines the horizontal resolution to be given to the field. If None, defaults to the horizontal resolution of the field.
  • position – defines the position of data in the grid (for projected grids only)
plotgeometry(color=u'blue', borderonly=True, **kwargs)[source]

Makes a simple plot of the geometry, with a number of options.

Parameters:
  • color – color of the plotting.
  • borderonly – if True, only plot the border of the grid, else the whole grid. Ignored for global geometries.

For other options, cf. plotfield() method of epygram.fields.H2DField.

This method uses (hence requires) ‘matplotlib’ and ‘basemap’ libraries.

projected_geometry

Is the geometry a projection ?

rectangular_grid

Is the grid rectangular ?

what(out=<open file '<stdout>', mode 'w'>, vertical_geometry=True, arpifs_var_names=False, spectral_geometry=None)[source]

Writes in file a summary of the geometry.

Parameters:
  • out – the output open file-like object (duck-typing: out.write() only is needed).
  • vertical_geometry – if True, writes the vertical geometry of the field.
  • arpifs_var_names – if True, prints the equivalent ‘arpifs’ variable names.
  • spectral_geometry – an optional dict containing the spectral truncatures {‘in_X’:, ‘in_Y’:} (LAM) or {‘max’:} (global).

class epygram.geometries.D3Geometry.D3RectangularGridGeometry(*args, **kwargs)[source]

Bases: epygram.geometries.D3Geometry.D3Geometry

Handles the geometry for a rectangular 3-Dimensions Field. Abstract.

Note

This class is managed by footprint.

  • info: Not documented
  • priority: PriorityLevel::DEFAULT (rank=1)

Automatic parameters from the footprint:

  • dimensions (footprints.stdtypes.FPDict) - rxx - Handles grid dimensions.
  • geoid (footprints.stdtypes.FPDict) - rxx - To specify geoid shape; actually used in projected geometries only.
    • Optional. Default is FPDict::<<as_dict:: dict()>>.
  • grid (footprints.stdtypes.FPDict) - rxx - Handles description of the horizontal grid.
  • name (str) - rxx - Name of geometrical type of representation of points on the Globe.
    • Values: set([‘unstructured’, ‘academic’, ‘regular_lonlat’, ‘mercator’, ‘lambert’, ‘polar_stereographic’])
  • position_on_horizontal_grid (str) - rwx - Position of points w/r to the horizontal.
    • Optional. Default is ‘__unknown__’.
    • Values: set([‘center-left’, ‘lower-right’, ‘upper-right’, ‘lower-center’, ‘lower-left’, ‘center-right’, ‘upper-left’, ‘__unknown__’, ‘upper-center’, ‘center’])
  • structure (str) - rxx - Type of geometry.
    • Values: set([‘3D’])
  • vcoordinate (epygram.geometries.VGeometry.VGeometry) - rwx - Handles vertical geometry parameters.
extract_subzone(data, subzone)[source]

Extracts the subzone C or CI from a LAM field.

Parameters:
  • data – the data values with shape concording with geometry.
  • subzone – optional, among (‘C’, ‘CI’), for LAM grids only, extracts the data resp. from the C or C+I zone off the C+I(+E) zone.
fill_maskedvalues(data, fill_value=None)[source]

Returns a copy of data with masked values filled with fill_value.

get_datashape(dimT=1, force_dimZ=None, d4=False, subzone=None)[source]

Returns the data shape according to the geometry.

Parameters:
  • force_dimZ – if supplied, force the Z dimension instead of that of the vertical geometry
  • dimT – if supplied, is the time dimension to be added to the data shape
  • d4
    • if True, shape is 4D
    • if False, shape has only those > 1
  • subzone – optional, among (‘C’, ‘CI’), for LAM grids only, informes that data is resp. on the C or C+I zone off the C+I(+E) zone.
get_lonlat_grid(subzone=None, position=None, d4=False, nb_validities=0)[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

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
gimme_corners_ij(subzone=None)[source]

Returns the indices (i, j) of the four corners of a rectangular grid, as a dict(corner=(i, j)) with corner in:

ll = lower-left / lr = lower-right / ur = upper-right / ul = upper-left.

(0, 0) is always the lower-left corner of the grid.

Parameters:subzone – for LAM fields, returns the corners of the subzone.
gimme_corners_ll(subzone=None, position=None)[source]

Returns the lon/lat of the four corners of a rectangular grid, as a dict(corner=(lon, lat)) with corner in:

ll = lower-left / lr = lower-right / ur = upper-right / ul = upper-left.

Parameters:
  • subzone – for LAM grids, returns the corners of the subzone.
  • position – position of corners with respect to the model cell. Defaults to self.position_on_horizontal_grid.
gridpoints_number

Returns the number of gridpoints of the grid.

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.

horizontally_flattened(data)[source]

Returns a copy of data with horizontal dimensions flattened. data must be 4D for simplicity reasons.

make_subarray_geometry(first_i, last_i, first_j, last_j)[source]

Make a modified geometry consisting in a subarray of the grid, defined by the indexes given as argument.

nearest_points(lon, lat, request, position=None, external_distance=None)[source]

Returns the (i, j) positions of the nearest points.

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 * {‘n’:‘2*2’} - the 2*2 square points around the position * {‘n’:‘4*4’} - the 4*4 square points around the position * {‘n’:’N*N’} - the N*N square points around the position: N must be even * {‘radius’:xxxx, ‘shape’:’square’} - the points which are xxxx metres

    around the position in X or Y direction
    • {‘radius’:xxxx, ‘shape’:’circle’} - the points within xxxx metres around the position. (default shape == circle)
  • 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| Only valid with request={‘n’:‘1’}
Return type:

list of (lon, lat) tuples, or (lon, lat) if one only point.

point_is_inside_domain_ij(i=None, j=None, margin=-0.1, subzone=None)[source]

Returns True if the point(s) of i/j coordinates is(are) inside the field.

Parameters:
  • i – X index of point
  • j – Y index of point.
  • margin – considers the point inside if at least ‘margin’ points far from the border. The -0.1 default is a safety for precision errors.
  • subzone – considers only a subzone among (‘C’, ‘CI’) of the domain.
point_is_inside_domain_ll(lon, lat, margin=-0.1, subzone=None, position=None)[source]

Returns True if the point(s) of lon/lat coordinates is(are) inside the field.

Parameters:
  • lon – longitude of point(s) in degrees.
  • lat – latitude of point(s) in degrees.
  • margin – considers the point inside if at least ‘margin’ points far from the border. The -0.1 default is a safety for precision errors.
  • subzone – considers only a subzone among (‘C’, ‘CI’) of the domain.
  • position – position of the grid with respect to the model cell. Defaults to self.position_on_horizontal_grid.
reshape_data(data, first_dimension=None, d4=False, subzone=None)[source]

Returns a 2D data (horizontal dimensions) reshaped from 1D, according to geometry.

Parameters:
  • data – the 1D data (or 3D with a T and Z dimensions, or 2D with either a T/Z dimension, to be specified), of dimension concording with geometry. In case data is 3D, T must be first dimension and Z the second.
  • first_dimension – in case data is 2D, specify what is the first dimension of data among (‘T’, ‘Z’)
  • subzone – optional, among (‘C’, ‘CI’), for LAM grids only, informes that data is resp. on the C or C+I zone off the C+I(+E) zone.
  • d4
    • if True, returned values are shaped in a 4 dimensions array
    • if False, shape of returned values is determined with respect to geometry

class epygram.geometries.D3Geometry.D3UnstructuredGeometry(*args, **kwargs)[source]

Bases: epygram.geometries.D3Geometry.D3RectangularGridGeometry

Handles the geometry for an unstructured 3-Dimensions Field.

Note

This class is managed by footprint.

  • info: Not documented
  • priority: PriorityLevel::DEFAULT (rank=1)

Automatic parameters from the footprint:

  • dimensions (footprints.stdtypes.FPDict) - rxx - Handles grid dimensions.
  • geoid (footprints.stdtypes.FPDict) - rxx - To specify geoid shape; actually used in projected geometries only.
    • Optional. Default is FPDict::<<as_dict:: dict()>>.
  • grid (footprints.stdtypes.FPDict) - rxx - Handles description of the horizontal grid.
  • name (str) - rxx - Name of geometrical type of representation of points on the Globe.
    • Values: set([‘unstructured’])
  • position_on_horizontal_grid (str) - rwx - Position of points w/r to the horizontal.
    • Optional. Default is ‘__unknown__’.
    • Values: set([‘center-left’, ‘lower-right’, ‘upper-right’, ‘lower-center’, ‘lower-left’, ‘center-right’, ‘upper-left’, ‘__unknown__’, ‘upper-center’, ‘center’])
  • structure (str) - rxx - Type of geometry.
    • Values: set([‘3D’])
  • vcoordinate (epygram.geometries.VGeometry.VGeometry) - rwx - Handles vertical geometry parameters.
get_lonlat_grid(subzone=None, position=None, d4=False, nb_validities=0)[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

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
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.

make_basemap(gisquality=u'i', specificproj=None, zoom=None, ax=None, **_)[source]

Returns a matplotlib.basemap.Basemap object of the ‘ad hoc’ projection (if available). This is designed to avoid explicit handling of deep horizontal geometry attributes.

Parameters:
  • gisquality

    defines the quality of GIS contours, cf. Basemap doc.

    Possible values (by increasing quality): ‘c’, ‘l’, ‘i’, ‘h’, ‘f’.

  • specificproj

    enables to make basemap on the specified projection, among: ‘kav7’, ‘cyl’, ‘ortho’, (‘nsper’, {...}) (cf. Basemap doc). In ‘nsper’ case, the {} may contain:

    • ‘sat_height’ = satellite height in km;
    • ‘lon’ = longitude of nadir in degrees;
    • ‘lat’ = latitude of nadir in degrees.

    Overwritten by zoom.

  • zoom

    specifies the lon/lat borders of the map, implying hereby a ‘cyl’ projection. Must be a dict(lonmin=, lonmax=, latmin=, latmax=).

    Overwrites specificproj.

  • ax – a matplotlib ax on which to plot; if None, plots will be done on matplotlib.pyplot.gca()
nearest_points(lon, lat, interpolation, position=None, external_distance=None)[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.
  • interpolation

    can be:

    • ‘nearest’ to get the nearest point only
    • ‘linear’ to get the 2*2 points bordering the (lon, lat) position
    • ‘cubic’ to get the 4*4 points bordering the (lon, lat) position
  • 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|
resolution_ij(i, j)[source]

Returns the distance to the nearest point of (i,j) point.

Parameters:
  • i – X index of point in the 2D matrix of gridpoints
  • j – Y index of point in the 2D matrix of gridpoints
resolution_ll(lon, lat)[source]

Returns the local resolution at the nearest point of lon/lat. It’s the distance between this point and its closest neighbour.

Parameters:
  • lon – longitude of point in degrees.
  • lat – latitude of point in degrees.

class epygram.geometries.D3Geometry.D3AcademicGeometry(*args, **kwargs)[source]

Bases: epygram.geometries.D3Geometry.D3RectangularGridGeometry

Handles the geometry for an academic 3-Dimensions Field.

Note

This class is managed by footprint.

  • info: Not documented
  • priority: PriorityLevel::DEFAULT (rank=1)

Automatic parameters from the footprint:

  • dimensions (footprints.stdtypes.FPDict) - rxx - Handles grid dimensions.
  • geoid (footprints.stdtypes.FPDict) - rxx - To specify geoid shape; actually used in projected geometries only.
    • Optional. Default is FPDict::<<as_dict:: dict()>>.
  • grid (footprints.stdtypes.FPDict) - rxx - Handles description of the horizontal grid.
  • name (str) - rxx - Name of geometrical type of representation of points on the Globe.
    • Values: set([‘academic’])
  • position_on_horizontal_grid (str) - rwx - Position of points w/r to the horizontal.
    • Optional. Default is ‘__unknown__’.
    • Values: set([‘center-left’, ‘lower-right’, ‘upper-right’, ‘lower-center’, ‘lower-left’, ‘center-right’, ‘upper-left’, ‘__unknown__’, ‘upper-center’, ‘center’])
  • projection (footprints.stdtypes.FPDict) - rxx - Handles projection information.
  • structure (str) - rxx - Type of geometry.
    • Values: set([‘3D’])
  • vcoordinate (epygram.geometries.VGeometry.VGeometry) - rwx - Handles vertical geometry parameters.
azimuth(end1, end2)[source]

Initial bearing from end1 to end2 points in geometry.

Parameters:
  • end1 – must be a tuple (lon, lat) in degrees.
  • end2 – must be a tuple (lon, lat) in degrees.
distance(end1, end2)[source]

Computes the distance between two points along a straight line in the geometry. :param end1: must be a tuple (lon, lat) in degrees. :param end2: must be a tuple (lon, lat) in degrees.

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.

This routine has a special meaning for this geometry. It returns the (i, j) position in the original grid (especially after a section extraction) with an offset of one (for old tools compatibility).

ij2xy(i, j, position=None)[source]

Return the (x, y) coordinates of point (i,j), in the projection.

Parameters:
  • i – X index of point in the 2D matrix of gridpoints
  • j – Y index of point in the 2D matrix of gridpoints
  • position – position to return with respect to the model cell. Defaults to self.position_on_horizontal_grid.

Note that origin of coordinates in projection is the center of the C+I domain.

linspace(end1, end2, num)[source]

Returns evenly spaced points over the specified interval. Points are lined up in the geometry.

Parameters:
  • end1 – must be a tuple (lon, lat) in degrees.
  • end2 – must be a tuple (lon, lat) in degrees.
  • num – number of points, including point1 and point2.
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.

This routine has a special meaning for this geometry. It returns the (lon, lat) position in the original grid (especially after a section extraction) with an offset of one (for old tools compatibility).

ll2xy(lon, lat)[source]

Return the (x, y) coordinates of point (lon, lat) in degrees.

Parameters:
  • lon – longitude of point in degrees
  • lat – latitude of point in degrees

Note that origin of coordinates in projection is the center of the C+I domain.

make_section_geometry(end1, end2, points_number=None, resolution=None, position=None)[source]

Returns a academic V2DGeometry.

Parameters:
  • end1 – must be a tuple (lon, lat) in degrees.
  • end2 – must be a tuple (lon, lat) in degrees.
  • points_number – defines the total number of horizontal points of the section (including ends). If None, defaults to a number computed from the ends and the resolution.
  • resolution – defines the horizontal resolution to be given to the field. If None, defaults to the horizontal resolution of the field.
  • position – defines the position of data in the grid (defaults to ‘center’)
resolution_ij(*_, **__)[source]

Returns the minimum of X and Y resolution.

resolution_ll(*_, **__)[source]

Returns the minimum of X and Y resolution.

xy2ij(x, y, position=None)[source]

Return the (i, j) indexes of point (x, y), in the 2D matrix of gridpoints.

Parameters:
  • x – X coordinate of point in the academic projection
  • y – Y coordinate of point in the academic projection
  • position – position to return with respect to the model cell. Defaults to self.position_on_horizontal_grid.

Caution: (i,j) are float (the nearest grid point is the nearest integer).

Note that origin of coordinates in projection is the center of the C+I domain.

xy2ll(x, y)[source]

Return the (lon, lat) coordinates of point (x, y) in the 2D matrix of gridpoints*(i,j)*, in degrees.

Parameters:
  • x – X coordinate of point in the academic projection
  • y – Y coordinate of point in the academic projection

Note that origin of coordinates in projection is the center of the C+I domain.


class epygram.geometries.D3Geometry.D3RegLLGeometry(*args, **kwargs)[source]

Bases: epygram.geometries.D3Geometry.D3RectangularGridGeometry

Handles the geometry for a Regular Lon/Lat 3-Dimensions Field.

Note

This class is managed by footprint.

  • info: Not documented
  • priority: PriorityLevel::DEFAULT (rank=1)

Automatic parameters from the footprint:

  • dimensions (footprints.stdtypes.FPDict) - rxx - Handles grid dimensions.
  • geoid (footprints.stdtypes.FPDict) - rxx - To specify geoid shape; actually used in projected geometries only.
    • Optional. Default is FPDict::<<as_dict:: dict()>>.
  • grid (footprints.stdtypes.FPDict) - rxx - Handles description of the horizontal grid.
  • name (str) - rxx - Name of geometrical type of representation of points on the Globe.
    • Values: set([‘regular_lonlat’])
  • position_on_horizontal_grid (str) - rwx - Position of points w/r to the horizontal.
    • Optional. Default is ‘__unknown__’.
    • Values: set([‘center-left’, ‘lower-right’, ‘upper-right’, ‘lower-center’, ‘lower-left’, ‘center-right’, ‘upper-left’, ‘__unknown__’, ‘upper-center’, ‘center’])
  • structure (str) - rxx - Type of geometry.
    • Values: set([‘3D’])
  • vcoordinate (epygram.geometries.VGeometry.VGeometry) - rwx - Handles vertical geometry parameters.
azimuth(end1, end2)[source]

Initial bearing from end1 to end2 points in geometry.

Parameters:
  • end1 – must be a tuple (lon, lat) in degrees.
  • end2 – must be a tuple (lon, lat) in degrees.
distance(end1, end2)[source]

Computes the distance between two points along a straight line in the geometry.

Parameters:
  • end1 – must be a tuple (lon, lat) in degrees.
  • end2 – must be a tuple (lon, lat) in degrees.

Warning: requires the pyproj module.

getcenter()[source]

Returns the coordinate of the grid center as a tuple (center_lon, center_lat).

global_shift_center(longitude_shift)[source]

Shifts the center of the geometry by longitude_shift (in degrees). longitude_shift has to be a multiple of the grid’s resolution in longitude.

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.
ij2xy(i, j, position=None)[source]

Return the (x, y) coordinates of point (i,j), in the projection.

Parameters:
  • i – X index of point in the 2D matrix of gridpoints
  • j – Y index of point in the 2D matrix of gridpoints
  • position – position to return with respect to the model cell. Defaults to self.position_on_horizontal_grid.

Note that origin of coordinates in projection is the center of the C+I domain.

linspace(end1, end2, num)[source]

Returns evenly spaced points over the specified interval. Points are lined up in the geometry.

Parameters:
  • end1 – must be a tuple (lon, lat) in degrees.
  • end2 – must be a tuple (lon, lat) in degrees.
  • num – number of points, including point1 and point2.
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: (i,j) are float.

ll2xy(lon, lat)[source]

Return the (x, y) coordinates of point (lon, lat) in degrees.

Parameters:
  • lon – longitude of point in degrees
  • lat – latitude of point in degrees

Note that origin of coordinates in projection is the center of the C+I domain.

make_basemap(gisquality=u'i', subzone=None, specificproj=None, zoom=None, ax=None)[source]

Returns a matplotlib.basemap.Basemap object of the ‘ad hoc’ projection (if available). This is designed to avoid explicit handling of deep horizontal geometry attributes.

Parameters:
  • gisquality

    defines the quality of GIS contours, cf. Basemap doc.

    Possible values (by increasing quality): ‘c’, ‘l’, ‘i’, ‘h’, ‘f’.

  • subzone – defines the LAM subzone to be included, in LAM case, among: ‘C’, ‘CI’.
  • specificproj

    enables to make basemap on the specified projection, among: ‘kav7’, ‘cyl’, ‘ortho’, (‘nsper’, {...}) (cf. Basemap doc).

    In ‘nsper’ case, the {} may contain:

    • ‘sat_height’ = satellite height in km;
    • ‘lon’ = longitude of nadir in degrees;
    • ‘lat’ = latitude of nadir in degrees.

    Overwritten by zoom.

  • zoom

    specifies the lon/lat borders of the map, implying hereby a ‘cyl’ projection. Must be a dict(lonmin=, lonmax=, latmin=, latmax=).

    Overwrites specificproj.

  • ax – a matplotlib ax on which to plot; if None, plots will be done on matplotlib.pyplot.gca()
resolution_ij(i, j)[source]

Returns the distance to the nearest point of (i,j) point.

Parameters:
  • i – X index of point in the 2D matrix of gridpoints
  • j – Y index of point in the 2D matrix of gridpoints
resolution_ll(lon, lat)[source]

Returns the local resolution at the nearest point of lon/lat. It’s the distance between this point and its closest neighbour.

Parameters:
  • lon – longitude of the point in degrees
  • lat – latitude of the point in degrees
xy2ij(x, y, position=None)[source]

Return the (i, j) indexes of point (x, y), in the 2D matrix of gridpoints.

Parameters:
  • x – X coordinate of point in the projection
  • y – Y coordinate of point in the projection
  • position – position to return with respect to the model cell. Defaults to self.position_on_horizontal_grid.

Caution: (i,j) are float (the nearest grid point is the nearest integer).

Note that origin of coordinates in projection is the center of the C+I domain.

xy2ll(x, y)[source]

Return the (lon, lat) coordinates of point (x, y) in the 2D matrix of gridpoints*(i,j)*, in degrees.

Parameters:
  • x – X coordinate of point in the projection
  • y – Y coordinate of point in the projection

Note that origin of coordinates in projection is the center of the C+I domain.


class epygram.geometries.D3Geometry.D3ProjectedGeometry(*args, **kwargs)[source]

Bases: epygram.geometries.D3Geometry.D3RectangularGridGeometry

Handles the geometry for a Projected 3-Dimensions Field.

Note

This class is managed by footprint.

  • info: Not documented
  • priority: PriorityLevel::DEFAULT (rank=1)

Automatic parameters from the footprint:

  • dimensions (footprints.stdtypes.FPDict) - rxx - Handles grid dimensions.
  • geoid (footprints.stdtypes.FPDict) - rxx - Geoid definition in projections.
    • Optional. Default is FPDict::<<as_dict:: dict(ellps = ‘WGS84’,)>>.
  • grid (footprints.stdtypes.FPDict) - rxx - Handles description of the horizontal grid.
  • name (str) - rxx - Name of geometrical type of representation of points on the Globe.
    • Values: set([‘lambert’, ‘space_view’, ‘polar_stereographic’, ‘mercator’])
  • position_on_horizontal_grid (str) - rwx - Position of points w/r to the horizontal.
    • Optional. Default is ‘__unknown__’.
    • Values: set([‘center-left’, ‘lower-right’, ‘upper-right’, ‘lower-center’, ‘lower-left’, ‘center-right’, ‘upper-left’, ‘__unknown__’, ‘upper-center’, ‘center’])
  • projection (footprints.stdtypes.FPDict) - rxx - Handles projection information.
  • projtool (str) - rxx - To use pyproj or epygram.myproj.
    • Optional. Default is ‘pyproj’.
  • structure (str) - rxx - Type of geometry.
    • Values: set([‘3D’])
  • vcoordinate (epygram.geometries.VGeometry.VGeometry) - rwx - Handles vertical geometry parameters.
azimuth(end1, end2)[source]

Initial bearing from end1 to end2 points in geometry.

Parameters:
  • end1 – must be a tuple (lon, lat) in degrees.
  • end2 – must be a tuple (lon, lat) in degrees.
compass_grid(subzone=None, position=None)[source]

Get the compass grid, i.e. the angle between Y-axis and North for each gridpoint.

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.
distance(end1, end2)[source]

Computes the distance between two points along a straight line in the geometry.

Parameters:
  • end1 – must be a tuple (lon, lat) in degrees.
  • end2 – must be a tuple (lon, lat) in degrees.
getcenter()[source]

Returns the coordinate of the grid center as a tuple (center_lon, center_lat).

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.
ij2xy(i, j, position=None)[source]

Return the (x, y) coordinates of point (i,j), in the projection.

Parameters:
  • i – X index of point in the 2D matrix of gridpoints
  • j – Y index of point in the 2D matrix of gridpoints
  • position – position to return with respect to the model cell. Defaults to self.position_on_horizontal_grid.

Note that origin of coordinates in projection is the center of the C+I domain.

linspace(end1, end2, num)[source]

Returns evenly spaced points over the specified interval. Points are lined up in the geometry.

Parameters:
  • end1 – must be a tuple (lon, lat) in degrees.
  • end2 – must be a tuple (lon, lat) in degrees.
  • num – number of points, including point1 and point2.
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: (i,j) are float.

ll2xy(lon, lat)[source]

Return the (x, y) coordinates of point (lon, lat) in degrees.

Parameters:
  • lon – longitude of point in degrees
  • lat – latitude of point in degrees

Note that origin of coordinates in projection is the center of the C+I domain.

make_basemap(gisquality=u'i', subzone=None, specificproj=None, zoom=None, ax=None)[source]

Returns a matplotlib.basemap.Basemap object of the ‘ad hoc’ projection (if available). This is designed to avoid explicit handling of deep horizontal geometry attributes.

Parameters:
  • gisquality – defines the quality of GIS contours, cf. Basemap doc. Possible values (by increasing quality): ‘c’, ‘l’, ‘i’, ‘h’, ‘f’.
  • subzone – defines the LAM subzone to be included, in LAM case, among: ‘C’, ‘CI’.
  • specificproj

    enables to make basemap on the specified projection, among: ‘kav7’, ‘cyl’, ‘ortho’, (‘nsper’, {...}) (cf. Basemap doc).

    In ‘nsper’ case, the {} may contain:

    • ‘sat_height’ = satellite height in km;
    • ‘lon’ = longitude of nadir in degrees;
    • ‘lat’ = latitude of nadir in degrees.

    Overwritten by zoom.

  • zoom – specifies the lon/lat borders of the map, implying hereby a ‘cyl’ projection. Must be a dict(lonmin=, lonmax=, latmin=, latmax=). Overwrites specificproj.
  • ax – a matplotlib ax on which to plot; if None, plots will be done on matplotlib.pyplot.gca()
make_section_geometry(end1, end2, points_number=None, resolution=None, position=None)[source]

Returns a projected V2DGeometry.

Parameters:
  • end1 – must be a tuple (lon, lat) in degrees.
  • end2 – must be a tuple (lon, lat) in degrees.
  • points_number – defines the total number of horizontal points of the section (including ends). If None, defaults to a number computed from the ends and the resolution.
  • resolution – defines the horizontal resolution to be given to the field. If None, defaults to the horizontal resolution of the field.
  • position – defines the position of data in the grid (defaults to ‘center’)
map_factor(lat)[source]

Returns the map factor at the given latitude(s) lat in degrees.

map_factor_field(position=None)[source]

Returns a new field whose data is the map factor over the field.

Parameters:position – grid position with respect to the model cell. Defaults to self.position_on_horizontal_grid.
mesh_area(lat)[source]

Compute the area of a mesh/gridpoint, given its latitude.

mesh_area_field(position=None)[source]

Returns a new field whose data is the mesh area of gridpoints, i.e. X_resolution x Y_resolution / m^2, where m is the local map factor.

Parameters:position – grid position with respect to the model cell. Defaults to self.position_on_horizontal_grid.
reproject_wind_on_lonlat(u, v, lon=None, lat=None, map_factor_correction=True, reverse=False)[source]

Reprojects a wind vector (u, v) on the grid onto real axes, i.e. with components on true zonal/meridian axes.

Parameters:
  • u – the u == zonal-on-the-grid component of wind
  • v – the v == meridian-on-the-grid component of wind
  • lon – longitudes of points in degrees, if u/v are not vectors on the whole grid
  • lat – latitudes of points in degrees, if u/v are not vectors on the whole grid
:param map_factor_correction:, applies a correction of magnitude due
to map factor.
Parameters:reverse – if True, apply the reverse reprojection.
resolution_ij(i, j)[source]

Returns the distance to the nearest point of (i,j) point.

Parameters:
  • i – X index of point in the 2D matrix of gridpoints
  • j – Y index of point in the 2D matrix of gridpoints
resolution_ll(lon, lat)[source]

Returns the local resolution at the nearest point of lon/lat. It’s the distance between this point and its closest neighbour.

Parameters:
  • lon – longitude of the point in degrees
  • lat – latitude of the point in degrees
secant_projection

Is the projection secant to the sphere ? (or tangent)

select_subzone(subzone)[source]

If a LAMzone defines the geometry, select only the subzone from it and return a new geometry object.

Parameters:subzone – among (‘C’, ‘CI’).
xy2ij(x, y, position=None)[source]

Return the (i, j) indexes of point (x, y), in the 2D matrix of gridpoints.

Parameters:
  • x – X coordinate of point in the projection
  • y – Y coordinate of point in the projection
  • position – position to return with respect to the model cell. Defaults to self.position_on_horizontal_grid.

Caution: (i,j) are float (the nearest grid point is the nearest integer).

Note that origin of coordinates in projection is the center of the C+I domain.

xy2ll(x, y)[source]

Return the (lon, lat) coordinates of point (x, y) in the 2D matrix of gridpoints*(i,j)*, in degrees.

Parameters:
  • x – X coordinate of point in the projection
  • y – Y coordinate of point in the projection

Note that origin of coordinates in projection is the center of the C+I domain.


class epygram.geometries.D3Geometry.D3GaussGeometry(*args, **kwargs)[source]

Bases: epygram.geometries.D3Geometry.D3Geometry

Handles the geometry for a Global Gauss grid 3-Dimensions Field.

Note

This class is managed by footprint.

  • info: Not documented
  • priority: PriorityLevel::DEFAULT (rank=1)

Automatic parameters from the footprint:

  • dimensions (footprints.stdtypes.FPDict) - rxx - Handles grid dimensions.
  • geoid (footprints.stdtypes.FPDict) - rxx - To specify geoid shape; actually used in projected geometries only.
    • Optional. Default is FPDict::<<as_dict:: dict()>>.
  • grid (footprints.stdtypes.FPDict) - rxx - Handles description of the horizontal grid.
  • name (str) - rxx - Name of geometrical type of representation of points on the Globe.
    • Values: set([‘reduced_gauss’, ‘regular_gauss’, ‘rotated_reduced_gauss’])
  • position_on_horizontal_grid (str) - rwx - Position of points w/r to the horizontal.
    • Optional. Default is ‘__unknown__’.
    • Values: set([‘center-left’, ‘lower-right’, ‘upper-right’, ‘lower-center’, ‘lower-left’, ‘center-right’, ‘upper-left’, ‘__unknown__’, ‘upper-center’, ‘center’])
  • structure (str) - rxx - Type of geometry.
    • Values: set([‘3D’])
  • vcoordinate (epygram.geometries.VGeometry.VGeometry) - rwx - Handles vertical geometry parameters.
distance_to_nearest_neighbour_ij(i, j)[source]

Returns the distance to the nearest point of (i,j) point

Parameters:
  • i – X index of point in the 2D matrix of gridpoints
  • j – Y index of point in the 2D matrix of gridpoints
distance_to_nearest_neighbour_ll(lon, lat)[source]

Returns the local resolution at the nearest point of lon/lat. It’s the distance between this point and its closest neighbour.

Parameters:
  • lon – longitude of the point in degrees
  • lat – latitude of the point in degrees
fill_maskedvalues(data, fill_value=None)[source]

Returns a copy of data with ‘real’ masked values (i.e. not those linked to reduced Gauss) filled with fill_value. data must be already 4D for simplicity reasons.

get_datashape(force_dimZ=None, dimT=None, d4=False, **_)[source]

Returns the data shape according to the geometry.

Parameters:
  • force_dimZ – if supplied, force the Z dimension instead of that of the vertical geometry
  • dimT – if supplied, is the time dimension to be added to the data shape
  • d4
    • if True, shape is 4D (need to specify dimT)
    • if False, shape is 3D if dimZ > 1 else 2D
get_lonlat_grid(position=None, d4=False, nb_validities=0, **_)[source]

Returns a tuple of two tables containing one the longitude of each point, the other the latitude, with 2D shape.

Shape of 2D data in Gauss grids:

  • grid[0, 0:Nj] is first (Northern) band of latitude, masked after Nj = number of longitudes for latitude j
  • grid[-1, 0:Nj] is last (Southern) band of latitude (idem).
Parameters:
  • 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
gridpoints_number

Returns the number of gridpoints of the grid.

horizontally_flattened(data)[source]

Returns a copy of data with horizontal dimensions flattened and compressed (cf. numpy.ma.masked_array.compressed). data must be 4D for simplicity reasons.

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) coordinates in the 2D matrix of gridpoints, of the gridpoint nearest to (lon, lat).

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.
make_basemap(gisquality=u'l', specificproj=None, zoom=None, ax=None, **_)[source]

Returns a matplotlib.basemap.Basemap object of the ‘ad hoc’ projection (if available). This is designed to avoid explicit handling of deep horizontal geometry attributes.

Parameters:
  • gisquality

    defines the quality of GIS contours, cf. Basemap doc.

    Possible values (by increasing quality): ‘c’, ‘l’, ‘i’, ‘h’, ‘f’. WARNING: this is forced to ‘l’ inside (except if a zoom is given), for time-consumption reasons.

  • specificproj

    enables to make basemap on the specified projection, among: ‘kav7’, ‘cyl’, ‘ortho’, (‘nsper’, {...}) (cf. Basemap doc).

    In ‘nsper’ case, the {} may contain:

    • ‘sat_height’ = satellite height in km;
    • ‘lon’ = longitude of nadir in degrees;
    • ‘lat’ = latitude of nadir in degrees.

    Overwritten by zoom.

  • zoom

    specifies the lon/lat borders of the map, implying hereby a ‘cyl’ projection. Must be a dict(lonmin=, lonmax=, latmin=, latmax=).

    Overwrites specificproj.

  • ax – a matplotlib ax on which to plot; if None, plots will be done on matplotlib.pyplot.gca()
map_factor(lon, lat)[source]

Returns the map factor at the given longitude/latitude(s)

Parameters:
  • lon – longitude in degrees
  • lat – latitude in degrees
map_factor_field(position=None)[source]

Returns a new field whose data is the map factor over the field.

Parameters:position – grid position with respect to the model cell. Defaults to self.position_on_horizontal_grid.
meridian_resolution_j(j)[source]

Returns the average meridian resolution at longitude circle number j.

nearest_points(lon, lat, request, position=None, external_distance=None)[source]

Returns a list of the (i, j) position of the points needed to perform an interpolation.

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 * {‘n’:‘2*2’} - the 2*2 square points around the position * {‘n’:‘4*4’} - the 4*4 square points around the position * {‘n’:’N*N’} - the N*N square points around the position: N must be even * {‘radius’:xxxx, ‘shape’:’square’} - the points which are xxxx metres

    around the position in X or Y direction
    • {‘radius’:xxxx, ‘shape’:’circle’} - the points within xxxx metres around the position. (default shape == circle)
  • 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|
point_is_inside_domain_ij(i, j, margin=-0.1)[source]

Returns True if the point(s) of lon/lat coordinates is(are) inside the field.

Parameters:
  • i – X index of point in the 2D matrix of gridpoints
  • j – Y index of point in the 2D matrix of gridpoints
  • margin – considers the point inside if at least ‘margin’ points far from the border. The -0.1 default is a safety for precision errors.
point_is_inside_domain_ll(lon, *_, **__)[source]

Returns True if the point(s) of lon/lat coordinates is(are) inside the field. This is always the case in Gauss grids, no real meaning.

Parameters:
  • lon – longitude of the point in degrees
  • lat – latitude of the point in degrees
  • margin – considers the point inside if at least ‘margin’ points far from the border. The -0.1 default is a safety for precision errors.
  • position – position of the grid with respect to the model cell. Defaults to self.position_on_horizontal_grid.
reproject_wind_on_lonlat(u, v, lon, lat, map_factor_correction=True, reverse=False)[source]

Reprojects a wind vector (u, v) on rotated/stretched sphere onto real sphere, i.e. with components on true zonal/meridian axes.

Parameters:
  • u – the u == zonal-on-the-grid component of wind
  • v – the v == meridian-on-the-grid component of wind
  • lon – longitudes of points in degrees
  • lat – latitudes of points in degrees
  • map_factor_correction – applies a correction of magnitude due to map factor.
  • reverse – if True, apply the reverse reprojection.

lon/lat are coordinates on real sphere.

reshape_data(data, first_dimension=None, d4=False)[source]

Returns a 2D data (horizontal dimensions) reshaped from 1D, according to geometry.

Parameters:
  • data – the 1D data (or 3D with a T and Z dimensions, or 2D with either a T/Z dimension, to be specified), of dimension concording with geometry. In case data is 3D, T must be first dimension and Z the second.
  • first_dimension – in case data is 2D, specify what is the first dimension of data among (‘T’, ‘Z’)
  • d4
    • if True, returned values are shaped in a 4 dimensions array
    • if False, shape of returned values is determined with respect to geometry
resolution_field(direction=u'meridian')[source]

Returns a field whose values are the local resolution in m.

Parameters:direction – among (‘zonal’, ‘meridian’), direction in which the resolution is computed.
resolution_j(j)[source]

Returns the average meridian resolution at longitude circle number j.

resolution_ll(lon, lat)[source]

Returns the average meridian resolution (worst directional resolution) at point position.

Parameters:
  • lon – longitude of the point in degrees
  • lat – latitude of the point in degrees
zonal_resolution_j(j)[source]

Returns the average zonal resolution at longitude circle number j.