envtoolkit.map¶
Functions/classes relative to maps
Functions
inpolygon (xin_2d, yin_2d, x_pol, y_pol) |
Determines whether points of a 2D-grid are within a polygon. |
lonflip (lon, data) |
Reorders a longitude and a data array about the central longitude |
make_bmap (lon, lat, **kwargs) |
Creates a basemap object by using the limites of input lon/lat arrays. |
Classes
Lambert (lonmin, lonmax, latmin, latmax[, …]) |
Class for the handling of Lambert Conic Projection. |
-
class
envtoolkit.map.
Lambert
(lonmin, lonmax, latmin, latmax, resolution='l')[source]¶ Class for the handling of Lambert Conic Projection.
It is initialised by providing the bounding longitudes and latitudes of the domain to plot. It may also take the resolution of the
mpl_toolkits.basemap.Basemap
class.Parameters: -
add_lc_labels
(labelleft=True, labelright=True, spacelat=10, spacelon=10, zorder=10001, nbspaces=15, **kwargs)[source]¶ Add the longitude and latitude labels on masked projection.
Adapted from NCL
Note
Does not work if usetex=True. Hence a call to this function sets it to False
Parameters: - labelleft (bool) – defines whether latitudes labels on the left of the map should be displayed
- labelright (bool) – defines whether latitudes on the right of the map should be displayed
- spacelat (float) – Latitude spacing between the labels
- spacelon (float) – Longitude spacing between the labels
- zorder (int) – plot order when the labels are drawn
- nbspaces (int) – number of whitespaces to add at the end (for left labels) or at the beginning (for right labels) of the string
- **kwargs (dict) – Text keyword arguments (fontsize for instance)
Returns: None
-
make_mask
(mask_res=300, zorder=1000, edcol='k', bgcolor='white', **kwargs)[source]¶ Masks the Lambert Conic projection.
It creates a dummy NxN array, which is then overlayed to the map using the imshow function. Data inside the data are plotted in transparent, data outside the domains are plotted in white. Finally, the domain boundaries are drawn.
Parameters:
-
-
envtoolkit.map.
inpolygon
(xin_2d, yin_2d, x_pol, y_pol)[source]¶ Determines whether points of a 2D-grid are within a polygon.
Equivalent to the inpolygon function of Matlab.
Note
If the input polygon is not closed, it is automatically closed
Parameters: - xin_2d (numpy.array) – 2-D array with the x-coords of the domain
- yin_2d (numpy.array) – 2-D array with the y-coords of the domain
- x_pol (numpy.array) – 1-D array with the x-coords of the polygon
- y_pol (numpy.array) – 1-D array with the y-coords of the polygon
Returns: A 2D array (same shape as xin_2d and yin_2d) with 1 when the point is within the polygon, else 0.
Return type: numpy.array
-
envtoolkit.map.
lonflip
(lon, data)[source]¶ Reorders a longitude and a data array about the central longitude
Adapted from the NCL lonFlip function.
Parameters: - lon (numpy.array) – 1D longitude array. The number of longitudes must be even
- data (numpy.array) – the data array. Can be 1D, 2D, 3D or 4D. Longitude must be the last dimension
Returns: A tuple with the first element containing the flipped longitude array, and the second element containing the flipped data array
Return type: tuple
-
envtoolkit.map.
make_bmap
(lon, lat, **kwargs)[source]¶ Creates a basemap object by using the limites of input lon/lat arrays.
Lower left corner coordinates = min(lon), min(lat)Upper right corner coordinates = max(lon), max(lat)Parameters: - lon (numpy.array) – longitude array (any dimension)
- lat (numpy.array) – latitude array (any dimension)
- **kwargs (dict) – keyword arguments that are passed to the Basemap class (proj, resolution, etc).
Returns: A Basemap object
Return type: