pyresample API¶
pyresample.geometry¶
Classes for geometry operations
-
class
pyresample.geometry.
AreaDefinition
(area_id, description, proj_id, projection, width, height, area_extent, rotation=None, nprocs=1, lons=None, lats=None, dtype=<class 'numpy.float64'>)¶ Holds definition of an area.
Parameters: - area_id (str) – Identifier for the area
- description (str) – Human-readable description of the area
- proj_id (str) – ID of projection
- projection (dict or str) – Dictionary or string of Proj.4 parameters
- width (int) – x dimension in number of pixels, aka number of grid columns
- height (int) – y dimension in number of pixels, aka number of grid rows
- rotation (float) – rotation in degrees (negative is cw)
- area_extent (list) – Area extent as a list (lower_left_x, lower_left_y, upper_right_x, upper_right_y)
- nprocs (int, optional) – Number of processor cores to be used for certain calculations
-
area_extent
¶ Area extent as a tuple (lower_left_x, lower_left_y, upper_right_x, upper_right_y)
Type: tuple
-
area_extent_ll
¶ Area extent in lons lats as a tuple (lower_left_lon, lower_left_lat, upper_right_lon, upper_right_lat)
Type: tuple
-
upper_left_extent
¶ Coordinates (x, y) of upper left corner of upper left pixel in projection units
Type: tuple
-
pixel_offset_x
¶ x offset between projection center and upper left corner of upper left pixel in units of pixels.
Type: float
-
pixel_offset_y
¶ y offset between projection center and upper left corner of upper left pixel in units of pixels..
Type: float
-
aggregate
(**dims)¶ Return an aggregated version of the area.
-
colrow2lonlat
(cols, rows)¶ Return longitudes and latitudes for the given image columns and rows. Both scalars and arrays are supported. To be used with scarse data points instead of slices (see get_lonlats).
-
copy
(**override_kwargs)¶ Make a copy of the current area.
This replaces the current values with anything in override_kwargs.
-
crop_around
(other_area)¶ Crop this area around other_area.
-
classmethod
from_area_of_interest
(area_id, projection, shape, center, resolution, units=None, **kwargs)¶ Creates an AreaDefinition object from center, resolution, and shape.
Parameters: - area_id (str) – ID of area
- projection (dict or str) – Projection parameters as a proj4_dict or proj4_string
- shape (list) – Number of pixels in the y and x direction (height, width)
- center (list) – Center of projection (x, y)
- resolution (list or float) – Size of pixels: (dx, dy). Can be specified with one value if dx == dy
- units (str, optional) –
Units that provided arguments should be interpreted as. This can be one of ‘deg’, ‘degrees’, ‘meters’, ‘metres’, and any parameter supported by the cs2cs -lu command. Units are determined in the following priority:
- units expressed with each variable through a DataArray’s attrs attribute.
- units passed to
units
- units used in
projection
- meters
- description (str, optional) – Description/name of area. Defaults to area_id
- proj_id (str, optional) – ID of projection
- rotation (float, optional) – rotation in degrees (negative is cw)
- nprocs (int, optional) – Number of processor cores to be used
- lons (numpy array, optional) – Grid lons
- lats (numpy array, optional) – Grid lats
Returns: AreaDefinition
Return type:
-
classmethod
from_circle
(area_id, projection, center, radius, shape=None, resolution=None, units=None, **kwargs)¶ Creates an AreaDefinition object from center, radius, and shape or from center, radius, and resolution.
Parameters: - area_id (str) – ID of area
- projection (dict or str) – Projection parameters as a proj4_dict or proj4_string
- center (list) – Center of projection (x, y)
- radius (list or float) – Length from the center to the edges of the projection (dx, dy)
- shape (list, optional) – Number of pixels in the y and x direction (height, width)
- resolution (list or float, optional) – Size of pixels: (dx, dy)
- units (str, optional) –
Units that provided arguments should be interpreted as. This can be one of ‘deg’, ‘degrees’, ‘meters’, ‘metres’, and any parameter supported by the cs2cs -lu command. Units are determined in the following priority:
- units expressed with each variable through a DataArray’s attrs attribute.
- units passed to
units
- units used in
projection
- meters
- description (str, optional) – Description/name of area. Defaults to area_id
- proj_id (str, optional) – ID of projection
- rotation (float, optional) – rotation in degrees (negative is cw)
- nprocs (int, optional) – Number of processor cores to be used
- lons (numpy array, optional) – Grid lons
- lats (numpy array, optional) – Grid lats
- optimize_projection – Whether the projection parameters have to be optimized for a DynamicAreaDefinition.
Returns: AreaDefinition or DynamicAreaDefinition – If shape or resolution are provided, an AreaDefinition object is returned. Else a DynamicAreaDefinition object is returned
Return type: Notes
resolution
andradius
can be specified with one value if dx == dy
-
classmethod
from_extent
(area_id, projection, shape, area_extent, units=None, **kwargs)¶ Creates an AreaDefinition object from area_extent and shape.
Parameters: - area_id (str) – ID of area
- projection (dict or str) – Projection parameters as a proj4_dict or proj4_string
- shape (list) – Number of pixels in the y and x direction (height, width)
- area_extent (list) – Area extent as a list (lower_left_x, lower_left_y, upper_right_x, upper_right_y)
- units (str, optional) –
Units that provided arguments should be interpreted as. This can be one of ‘deg’, ‘degrees’, ‘meters’, ‘metres’, and any parameter supported by the cs2cs -lu command. Units are determined in the following priority:
- units expressed with each variable through a DataArray’s attrs attribute.
- units passed to
units
- units used in
projection
- meters
- description (str, optional) – Description/name of area. Defaults to area_id
- proj_id (str, optional) – ID of projection
- rotation (float, optional) – rotation in degrees (negative is cw)
- nprocs (int, optional) – Number of processor cores to be used
- lons (numpy array, optional) – Grid lons
- lats (numpy array, optional) – Grid lats
Returns: AreaDefinition
Return type:
-
classmethod
from_ul_corner
(area_id, projection, shape, upper_left_extent, resolution, units=None, **kwargs)¶ Creates an AreaDefinition object from upper_left_extent, resolution, and shape.
Parameters: - area_id (str) – ID of area
- projection (dict or str) – Projection parameters as a proj4_dict or proj4_string
- shape (list) – Number of pixels in the y and x direction (height, width)
- upper_left_extent (list) – Upper left corner of upper left pixel (x, y)
- resolution (list or float) – Size of pixels in meters: (dx, dy). Can be specified with one value if dx == dy
- units (str, optional) –
Units that provided arguments should be interpreted as. This can be one of ‘deg’, ‘degrees’, ‘meters’, ‘metres’, and any parameter supported by the cs2cs -lu command. Units are determined in the following priority:
- units expressed with each variable through a DataArray’s attrs attribute.
- units passed to
units
- units used in
projection
- meters
- description (str, optional) – Description/name of area. Defaults to area_id
- proj_id (str, optional) – ID of projection
- rotation (float, optional) – rotation in degrees (negative is cw)
- nprocs (int, optional) – Number of processor cores to be used
- lons (numpy array, optional) – Grid lons
- lats (numpy array, optional) – Grid lats
Returns: AreaDefinition
Return type:
-
get_area_slices
(area_to_cover)¶ Compute the slice to read based on an area_to_cover.
-
get_lonlat
(row, col)¶ Retrieves lon and lat values of single point in area grid
Parameters: Returns: (lon, lat)
Return type: tuple of floats
-
get_lonlats
(nprocs=None, data_slice=None, cache=False, dtype=None, chunks=None)¶ Return lon and lat arrays of area.
Parameters: - nprocs (int, optional) – Number of processor cores to be used. Defaults to the nprocs set when instantiating object
- data_slice (slice object, optional) – Calculate only coordinates for specified slice
- cache (bool, optional) – Store result the result. Requires data_slice to be None
- dtype (numpy.dtype, optional) – Data type of the returned arrays
- chunks (int or tuple, optional) – Create dask arrays and use this chunk size
Returns: (lons, lats) – Grids of area lons and and lats
Return type: tuple of numpy arrays
-
get_lonlats_dask
(chunks=None, dtype=None)¶ Get the lon lats as a single dask array.
-
get_proj_coords
(data_slice=None, dtype=None, chunks=None)¶ Get projection coordinates of grid.
Parameters: - data_slice (slice object, optional) – Calculate only coordinates for specified slice
- dtype (numpy.dtype, optional) – Data type of the returned arrays
- chunks (int or tuple, optional) – Create dask arrays and use this chunk size
Returns: - (target_x, target_y) (tuple of numpy arrays) – Grids of area x- and y-coordinates in projection units
- .. versionchanged:: 1.11.0 – Removed ‘cache’ keyword argument and add ‘chunks’ for creating dask arrays.
-
get_proj_vectors
(dtype=None, chunks=None)¶ Calculate 1D projection coordinates for the X and Y dimension.
Parameters: - dtype (numpy.dtype) – Numpy data type for the returned arrays
- chunks (int or tuple) – Return dask arrays with the chunk size specified. If this is a tuple then the first element is the Y array’s chunk size and the second is the X array’s chunk size.
Returns: - tuple ((X, Y) where X and Y are 1-dimensional numpy arrays)
- The data type of the returned arrays can be controlled with the
- dtype keyword argument. If chunks is provided then dask arrays
- are returned instead.
-
get_xy_from_lonlat
(lon, lat)¶ Retrieve closest x and y coordinates (column, row indices) for the specified geolocation (lon,lat) if inside area. If lon,lat is a point a ValueError is raised if the return point is outside the area domain. If lon,lat is a tuple of sequences of longitudes and latitudes, a tuple of masked arrays are returned.
Input: lon : point or sequence (list or array) of longitudes lat : point or sequence (list or array) of latitudes
Returns: (x, y) : tuple of integer points/arrays
-
get_xy_from_proj_coords
(xm, ym)¶ Find closest grid cell index for a specified projection coordinate.
If xm, ym is a tuple of sequences of projection coordinates, a tuple of masked arrays are returned.
Parameters: Returns: column and row grid cell indexes as 2 scalars or arrays
Return type: x, y
Raises: ValueError
– if the return point is outside the area domain
-
lonlat2colrow
(lons, lats)¶ Return image columns and rows for the given longitudes and latitudes. Both scalars and arrays are supported. Same as get_xy_from_lonlat, renamed for convenience.
-
outer_boundary_corners
¶ Return the lon,lat of the outer edges of the corner points.
-
proj4_string
Return projection definition as Proj.4 string.
-
update_hash
(the_hash=None)¶ Update a hash, or return a new one if needed.
-
class
pyresample.geometry.
BaseDefinition
(lons=None, lats=None, nprocs=1)¶ Base class for geometry definitions.
Changed in version 1.8.0: BaseDefinition no longer checks the validity of the provided longitude and latitude coordinates to improve performance. Longitude arrays are expected to be between -180 and 180 degrees, latitude -90 to 90 degrees. Use
check_and_wrap()
to preprocess your arrays.-
corners
¶ Returns the corners of the current area.
-
get_area
()¶ Get the area of the convex area defined by the corners of the current area.
-
get_area_extent_for_subset
(row_LR, col_LR, row_UL, col_UL)¶ Calculate extent for a subdomain of this area
Rows are counted from upper left to lower left and columns are counted from upper left to upper right.
Parameters: Returns: Area extent (LL_x, LL_y, UR_x, UR_y) of the subset
Return type: area_extent (tuple)
- Author:
- Ulrich Hamann
-
get_area_slices
(area_to_cover)¶ Compute the slice to read based on an area_to_cover.
-
get_bbox_lonlats
()¶ Returns the bounding box lons and lats
-
get_boundary_lonlats
()¶ Return Boundary objects.
-
get_cartesian_coords
(nprocs=None, data_slice=None, cache=False)¶ Retrieve cartesian coordinates of geometry definition
Parameters: Returns: cartesian_coords
Return type: numpy array
-
get_lonlat
(row, col)¶ Retrieve lon and lat of single pixel
Parameters: Returns: (lon, lat)
Return type: tuple of floats
-
get_lonlats
(data_slice=None, chunks=None, **kwargs)¶ Get longitude and latitude arrays representing this geometry.
Returns: (lon, lat) – If chunks is provided then the arrays will be dask arrays with the provided chunk size. If chunks is not provided then the returned arrays are the same as the internal data types of this geometry object (numpy or dask). Return type: tuple of numpy arrays
-
get_lonlats_dask
(chunks=None)¶ Get the lon lats as a single dask array.
-
intersection
(other)¶ Returns the corners of the intersection polygon of the current area with other.
Parameters: other (object) – Instance of subclass of BaseDefinition Returns: (corner1, corner2, corner3, corner4) Return type: tuple of points
-
-
class
pyresample.geometry.
CoordinateDefinition
(lons, lats, nprocs=1)¶ Base class for geometry definitions defined by lons and lats only
-
exception
pyresample.geometry.
DimensionError
¶
-
class
pyresample.geometry.
DynamicAreaDefinition
(area_id=None, description=None, projection=None, width=None, height=None, area_extent=None, resolution=None, optimize_projection=False, rotation=None)¶ An AreaDefintion containing just a subset of the needed parameters.
The purpose of this class is to be able to adapt the area extent and shape of the area to a given set of longitudes and latitudes, such that e.g. polar satellite granules can be resampled optimaly to a give projection.
-
compute_domain
(corners, resolution=None, shape=None)¶ Compute shape and area_extent from corners and [shape or resolution] info.
Corners represents the center of pixels, while area_extent represents the edge of pixels.
-
freeze
(lonslats=None, resolution=None, shape=None, proj_info=None)¶ Create an AreaDefinition from this area with help of some extra info.
- lonlats:
- the geographical coordinates to contain in the resulting area.
- resolution:
- the resolution of the resulting area.
- shape:
- the shape of the resulting area.
- proj_info:
- complementing parameters to the projection info.
Resolution and shape parameters are ignored if the instance is created with the optimize_projection flag set to True.
-
-
class
pyresample.geometry.
GridDefinition
(lons, lats, nprocs=1)¶ Grid defined by lons and lats
Parameters: - lons (numpy array) –
- lats (numpy array) –
- nprocs (int, optional) – Number of processor cores to be used for calculations.
-
exception
pyresample.geometry.
IncompatibleAreas
¶ Error when the areas to combine are not compatible.
-
class
pyresample.geometry.
StackedAreaDefinition
(*definitions, **kwargs)¶ Definition based on muliple vertically stacked AreaDefinitions.
-
append
(definition)¶ Append another definition to the area.
-
get_lonlats
(nprocs=None, data_slice=None, cache=False, dtype=None, chunks=None)¶ Return lon and lat arrays of the area.
-
get_lonlats_dask
(chunks=None, dtype=None)¶ “Return lon and lat dask arrays of the area.
-
proj4_string
¶ Returns projection definition as Proj.4 string
-
proj_str
¶ Returns projection definition as Proj.4 string
-
squeeze
()¶ Generate a single AreaDefinition if possible.
-
-
class
pyresample.geometry.
SwathDefinition
(lons, lats, nprocs=1)¶ Swath defined by lons and lats.
Parameters: - lons (numpy array) –
- lats (numpy array) –
- nprocs (int, optional) – Number of processor cores to be used for calculations.
-
aggregate
(**dims)¶ Aggregate the current swath definition by averaging.
For example, averaging over 2x2 windows: sd.aggregate(x=2, y=2)
-
compute_optimal_bb_area
(proj_dict=None)¶ Compute the “best” bounding box area for this swath with proj_dict.
By default, the projection is Oblique Mercator (omerc in proj.4), in which case the right projection angle alpha is computed from the swath centerline. For other projections, only the appropriate center of projection and area extents are computed.
The height and width are computed so that the resolution is approximately the same across dimensions.
-
copy
()¶ Copy the current swath.
-
get_edge_lonlats
()¶ Get the concatenated boundary of the current swath.
-
pyresample.geometry.
combine_area_extents_vertical
(area1, area2)¶ Combine the area extents of areas 1 and 2.
-
pyresample.geometry.
concatenate_area_defs
(area1, area2, axis=0)¶ Append area2 to area1 and return the results.
-
pyresample.geometry.
get_array_hashable
(arr)¶ Compute a hashable form of the array arr.
Works with numpy arrays, dask.array.Array, and xarray.DataArray.
-
pyresample.geometry.
get_geostationary_angle_extent
(geos_area)¶ Get the max earth (vs space) viewing angles in x and y.
-
pyresample.geometry.
get_geostationary_bounding_box
(geos_area, nb_points=50)¶ Get the bbox in lon/lats of the valid pixels inside geos_area.
Parameters: nb_points – Number of points on the polygon
-
pyresample.geometry.
invproj
(data_x, data_y, proj_dict)¶ Perform inverse projection.
pyresample.image¶
Handles resampling of images with assigned geometry definitions
-
class
pyresample.image.
ImageContainer
(image_data, geo_def, fill_value=0, nprocs=1)¶ Holds image with geometry definition. Allows indexing with linesample arrays.
Parameters: -
image_data
¶ Image data
Type: numpy array
-
get_array_from_linesample
(row_indices, col_indices)¶ Samples from image based on index arrays.
Parameters: - row_indices (numpy array) – Row indices. Dimensions must match col_indices
- col_indices (numpy array) – Col indices. Dimensions must match row_indices
Returns: image_data – Resampled image data
Return type: numpy_array
-
get_array_from_neighbour_info
(*args, **kwargs)¶ Base method for resampling from preprocessed data.
-
resample
(target_geo_def)¶ Base method for resampling
-
-
class
pyresample.image.
ImageContainerBilinear
(image_data, geo_def, radius_of_influence, epsilon=0, fill_value=0, reduce_data=False, nprocs=1, segments=None, neighbours=32)¶ Holds image with geometry definition. Allows bilinear to new geometry definition.
Parameters: - image_data (numpy array) – Image data
- geo_def (object) – Geometry definition
- radius_of_influence (float) – Cut off distance in meters
- epsilon (float, optional) – Allowed uncertainty in meters. Increasing uncertainty reduces execution time
- fill_value (int or None, optional) – Set undetermined pixels to this value. If fill_value is None a masked array is returned with undetermined pixels masked
- reduce_data (bool, optional) – Perform coarse data reduction before resampling in order to reduce execution time
- nprocs (int, optional) – Number of processor cores to be used for geometry operations
- segments (int or None) – Number of segments to use when resampling. If set to None an estimate will be calculated
-
image_data
¶ Image data
Type: numpy array
-
class
pyresample.image.
ImageContainerNearest
(image_data, geo_def, radius_of_influence, epsilon=0, fill_value=0, reduce_data=True, nprocs=1, segments=None)¶ Holds image with geometry definition. Allows nearest neighbour to new geometry definition.
Parameters: - image_data (numpy array) – Image data
- geo_def (object) – Geometry definition
- radius_of_influence (float) – Cut off distance in meters
- epsilon (float, optional) – Allowed uncertainty in meters. Increasing uncertainty reduces execution time
- fill_value (int or None, optional) – Set undetermined pixels to this value. If fill_value is None a masked array is returned with undetermined pixels masked
- reduce_data (bool, optional) – Perform coarse data reduction before resampling in order to reduce execution time
- nprocs (int, optional) – Number of processor cores to be used for geometry operations
- segments (int or None) – Number of segments to use when resampling. If set to None an estimate will be calculated
-
image_data
¶ Image data
Type: numpy array
-
class
pyresample.image.
ImageContainerQuick
(image_data, geo_def, fill_value=0, nprocs=1, segments=None)¶ Holds image with area definition. ‘ Allows quick resampling within area.
Parameters: - image_data (numpy array) – Image data
- geo_def (object) – Area definition as AreaDefinition object
- fill_value (int or None, optional) – Set undetermined pixels to this value. If fill_value is None a masked array is returned with undetermined pixels masked
- nprocs (int, optional) – Number of processor cores to be used for geometry operations
- segments (int or None) – Number of segments to use when resampling. If set to None an estimate will be calculated
-
image_data
¶ Image data
Type: numpy array
pyresample.grid¶
Resample image from one projection to another using nearest neighbour method in cartesian projection coordinate systems
-
pyresample.grid.
get_image_from_linesample
(row_indices, col_indices, source_image, fill_value=0)¶ Samples from image based on index arrays.
Parameters: - row_indices (numpy array) – Row indices. Dimensions must match col_indices
- col_indices (numpy array) – Col indices. Dimensions must match row_indices
- source_image (numpy array) – Source image
- fill_value (int or None, optional) – Set undetermined pixels to this value. If fill_value is None a masked array is returned with undetermined pixels masked
Returns: image_data – Resampled image
Return type: numpy array
-
pyresample.grid.
get_image_from_lonlats
(lons, lats, source_area_def, source_image_data, fill_value=0, nprocs=1)¶ Samples from image based on lon lat arrays using nearest neighbour method in cartesian projection coordinate systems.
Parameters: - lons (numpy array) – Lons. Dimensions must match lats
- lats (numpy array) – Lats. Dimensions must match lons
- source_area_def (object) – Source definition as AreaDefinition object
- source_image_data (numpy array) – Source image data
- fill_value (int or None, optional) – Set undetermined pixels to this value. If fill_value is None a masked array is returned with undetermined pixels masked
- nprocs (int, optional) – Number of processor cores to be used
Returns: image_data – Resampled image data
Return type: numpy array
-
pyresample.grid.
get_linesample
(lons, lats, source_area_def, nprocs=1)¶ Returns index row and col arrays for resampling
Parameters: Returns: (row_indices, col_indices) – Arrays for resampling area by array indexing
Return type: tuple of numpy arrays
-
pyresample.grid.
get_resampled_image
(target_area_def, source_area_def, source_image_data, fill_value=0, nprocs=1, segments=None)¶ Resamples image using nearest neighbour method in cartesian projection coordinate systems.
Parameters: - target_area_def (object) – Target definition as AreaDefinition object
- source_area_def (object) – Source definition as AreaDefinition object
- source_image_data (numpy array) – Source image data
- fill_value ({int, None} optional) – Set undetermined pixels to this value. If fill_value is None a masked array is returned with undetermined pixels masked
- nprocs (int, optional) – Number of processor cores to be used
- segments ({int, None} optional) – Number of segments to use when resampling. If set to None an estimate will be calculated.
Returns: image_data – Resampled image data
Return type: numpy array
pyresample.kd_tree¶
Handles reprojection of geolocated data. Several types of resampling are supported
-
exception
pyresample.kd_tree.
EmptyResult
¶
-
pyresample.kd_tree.
get_neighbour_info
(source_geo_def, target_geo_def, radius_of_influence, neighbours=8, epsilon=0, reduce_data=True, nprocs=1, segments=None)¶ Returns neighbour info
Parameters: - source_geo_def (object) – Geometry definition of source
- target_geo_def (object) – Geometry definition of target
- radius_of_influence (float) – Cut off distance in meters
- neighbours (int, optional) – The number of neigbours to consider for each grid point
- epsilon (float, optional) – Allowed uncertainty in meters. Increasing uncertainty reduces execution time
- reduce_data (bool, optional) – Perform initial coarse reduction of source dataset in order to reduce execution time
- nprocs (int, optional) – Number of processor cores to be used
- segments (int or None) – Number of segments to use when resampling. If set to None an estimate will be calculated
Returns: - (valid_input_index, valid_output_index,
- index_array, distance_array) (tuple of numpy arrays) – Neighbour resampling info
-
pyresample.kd_tree.
get_sample_from_neighbour_info
(resample_type, output_shape, data, valid_input_index, valid_output_index, index_array, distance_array=None, weight_funcs=None, fill_value=0, with_uncert=False)¶ Resamples swath based on neighbour info
Parameters: - resample_type ({'nn', 'custom'}) – ‘nn’: Use nearest neighbour resampling ‘custom’: Resample based on weight_funcs
- output_shape ((int, int)) – Shape of output as (rows, cols)
- data (numpy array) – Source data
- valid_input_index (numpy array) – valid_input_index from get_neighbour_info
- valid_output_index (numpy array) – valid_output_index from get_neighbour_info
- index_array (numpy array) – index_array from get_neighbour_info
- distance_array (numpy array, optional) – distance_array from get_neighbour_info Not needed for ‘nn’ resample type
- weight_funcs (list of function objects or function object, optional) – List of weight functions f(dist) to use for the weighting of each channel 1 to k. If only one channel is resampled weight_funcs is a single function object. Must be supplied when using ‘custom’ resample type
- fill_value (int or None, optional) – Set undetermined pixels to this value. If fill_value is None a masked array is returned with undetermined pixels masked
Returns: result – Source data resampled to target geometry
Return type: numpy array
-
pyresample.kd_tree.
query_no_distance
(target_lons, target_lats, valid_output_index, mask=None, valid_input_index=None, neighbours=None, epsilon=None, radius=None, kdtree=None)¶ Query the kdtree. No distances are returned.
- NOTE: Dask array arguments must always come before other keyword arguments
- for da.blockwise arguments to work.
-
pyresample.kd_tree.
resample_custom
(source_geo_def, data, target_geo_def, radius_of_influence, weight_funcs, neighbours=8, epsilon=0, fill_value=0, reduce_data=True, nprocs=1, segments=None, with_uncert=False)¶ Resamples data using kd-tree custom radial weighting neighbour approach
Parameters: - source_geo_def (object) – Geometry definition of source
- data (numpy array) – Array of single channel data points or (source_geo_def.shape, k) array of k channels of datapoints
- target_geo_def (object) – Geometry definition of target
- radius_of_influence (float) – Cut off distance in meters
- weight_funcs (list of function objects or function object) – List of weight functions f(dist) to use for the weighting of each channel 1 to k. If only one channel is resampled weight_funcs is a single function object.
- neighbours (int, optional) – The number of neigbours to consider for each grid point
- epsilon (float, optional) – Allowed uncertainty in meters. Increasing uncertainty reduces execution time
- fill_value ({int, None}, optional) – Set undetermined pixels to this value. If fill_value is None a masked array is returned with undetermined pixels masked
- reduce_data (bool, optional) – Perform initial coarse reduction of source dataset in order to reduce execution time
- nprocs (int, optional) – Number of processor cores to be used
- segments ({int, None}) – Number of segments to use when resampling. If set to None an estimate will be calculated
Returns: - data (numpy array (default)) – Source data resampled to target geometry
- data, stddev, counts (numpy array, numpy array, numpy array (if with_uncert == True)) – Source data resampled to target geometry. Weighted standard devaition for all pixels having more than one source value Counts of number of source values used in weighting per pixel
-
pyresample.kd_tree.
resample_gauss
(source_geo_def, data, target_geo_def, radius_of_influence, sigmas, neighbours=8, epsilon=0, fill_value=0, reduce_data=True, nprocs=1, segments=None, with_uncert=False)¶ Resamples data using kd-tree gaussian weighting neighbour approach.
Parameters: - source_geo_def (object) – Geometry definition of source
- data (numpy array) – Array of single channel data points or (source_geo_def.shape, k) array of k channels of datapoints
- target_geo_def (object) – Geometry definition of target
- radius_of_influence (float) – Cut off distance in meters
- sigmas (list of floats or float) – List of sigmas to use for the gauss weighting of each channel 1 to k, w_k = exp(-dist^2/sigma_k^2). If only one channel is resampled sigmas is a single float value.
- neighbours (int, optional) – The number of neigbours to consider for each grid point
- epsilon (float, optional) – Allowed uncertainty in meters. Increasing uncertainty reduces execution time
- fill_value ({int, None}, optional) – Set undetermined pixels to this value. If fill_value is None a masked array is returned with undetermined pixels masked
- reduce_data (bool, optional) – Perform initial coarse reduction of source dataset in order to reduce execution time
- nprocs (int, optional) – Number of processor cores to be used
- segments (int or None) – Number of segments to use when resampling. If set to None an estimate will be calculated
- with_uncert (bool, optional) – Calculate uncertainty estimates
Returns: - data (numpy array (default)) – Source data resampled to target geometry
- data, stddev, counts (numpy array, numpy array, numpy array (if with_uncert == True)) – Source data resampled to target geometry. Weighted standard devaition for all pixels having more than one source value Counts of number of source values used in weighting per pixel
-
pyresample.kd_tree.
resample_nearest
(source_geo_def, data, target_geo_def, radius_of_influence, epsilon=0, fill_value=0, reduce_data=True, nprocs=1, segments=None)¶ Resamples data using kd-tree nearest neighbour approach
Parameters: - source_geo_def (object) – Geometry definition of source
- data (numpy array) – 1d array of single channel data points or (source_size, k) array of k channels of datapoints
- target_geo_def (object) – Geometry definition of target
- radius_of_influence (float) – Cut off distance in meters
- epsilon (float, optional) – Allowed uncertainty in meters. Increasing uncertainty reduces execution time
- fill_value (int or None, optional) – Set undetermined pixels to this value. If fill_value is None a masked array is returned with undetermined pixels masked
- reduce_data (bool, optional) – Perform initial coarse reduction of source dataset in order to reduce execution time
- nprocs (int, optional) – Number of processor cores to be used
- segments (int or None) – Number of segments to use when resampling. If set to None an estimate will be calculated
Returns: data – Source data resampled to target geometry
Return type: numpy array
pyresample.bilinear¶
Code for resampling using bilinear algorithm for irregular grids.
The algorithm is taken from
-
pyresample.bilinear.
get_bil_info
(source_geo_def, target_area_def, radius=50000.0, neighbours=32, nprocs=1, masked=False, reduce_data=True, segments=None, epsilon=0)¶ Calculate information needed for bilinear resampling.
- source_geo_def : object
- Geometry definition of source data
- target_area_def : object
- Geometry definition of target area
- radius : float, optional
- Cut-off distance in meters
- neighbours : int, optional
- Number of neighbours to consider for each grid point when searching the closest corner points
- nprocs : int, optional
- Number of processor cores to be used for getting neighbour info
- masked : bool, optional
- If true, return masked arrays, else return np.nan values for invalid points (default)
- reduce_data : bool, optional
- Perform initial coarse reduction of source dataset in order to reduce execution time
- segments : int or None
- Number of segments to use when resampling. If set to None an estimate will be calculated
- epsilon : float, optional
- Allowed uncertainty in meters. Increasing uncertainty reduces execution time
Returns: - t__ (numpy array) – Vertical fractional distances from corner to the new points
- s__ (numpy array) – Horizontal fractional distances from corner to the new points
- input_idxs (numpy array) – Valid indices in the input data
- idx_arr (numpy array) – Mapping array from valid source points to target points
-
pyresample.bilinear.
get_sample_from_bil_info
(data, t__, s__, input_idxs, idx_arr, output_shape=None)¶ Resample data using bilinear interpolation.
Parameters: - data (numpy array) – 1d array to be resampled
- t (numpy array) – Vertical fractional distances from corner to the new points
- s (numpy array) – Horizontal fractional distances from corner to the new points
- input_idxs (numpy array) – Valid indices in the input data
- idx_arr (numpy array) – Mapping array from valid source points to target points
- output_shape (tuple, optional) – Tuple of (y, x) dimension for the target projection. If None (default), do not reshape data.
Returns: result – Source data resampled to target geometry
Return type: numpy array
-
pyresample.bilinear.
resample_bilinear
(data, source_geo_def, target_area_def, radius=50000.0, neighbours=32, nprocs=1, fill_value=0, reduce_data=True, segments=None, epsilon=0)¶ Resample using bilinear interpolation.
- data : numpy array
- Array of single channel data points or (source_geo_def.shape, k) array of k channels of datapoints
- source_geo_def : object
- Geometry definition of source data
- target_area_def : object
- Geometry definition of target area
- radius : float, optional
- Cut-off distance in meters
- neighbours : int, optional
- Number of neighbours to consider for each grid point when searching the closest corner points
- nprocs : int, optional
- Number of processor cores to be used for getting neighbour info
- fill_value : {int, None}, optional
- Set undetermined pixels to this value. If fill_value is None a masked array is returned with undetermined pixels masked
- reduce_data : bool, optional
- Perform initial coarse reduction of source dataset in order to reduce execution time
- segments : int or None
- Number of segments to use when resampling. If set to None an estimate will be calculated
- epsilon : float, optional
- Allowed uncertainty in meters. Increasing uncertainty reduces execution time
Returns: data – Source data resampled to target geometry Return type: numpy array
pyresample.utils¶
Miscellaneous utility functions for pyresample.
-
pyresample.utils.
check_and_wrap
(lons, lats)¶ Wrap longitude to [-180:+180[ and check latitude for validity.
Parameters: - lons (ndarray) – Longitude degrees
- lats (ndarray) – Latitude degrees
Returns: - Longitude degrees in the range [-180:180[ and the original
latitude array
Return type: lons, lats
Raises: ValueError
– If latitude array is not between -90 and 90
-
pyresample.utils.
fwhm2sigma
(fwhm)¶ Calculate sigma for gauss function from FWHM (3 dB level)
Parameters: fwhm (float) – FWHM of gauss function (3 dB level of beam footprint) Returns: sigma – sigma for use in resampling gauss function Return type: float
-
pyresample.utils.
generate_nearest_neighbour_linesample_arrays
(source_area_def, target_area_def, radius_of_influence, nprocs=1)¶ Generate linesample arrays for nearest neighbour grid resampling
Parameters: Returns: (row_indices, col_indices)
Return type: tuple of numpy arrays
-
pyresample.utils.
generate_quick_linesample_arrays
(source_area_def, target_area_def, nprocs=1)¶ Generate linesample arrays for quick grid resampling
Parameters: Returns: (row_indices, col_indices)
Return type: tuple of numpy arrays
-
pyresample.utils.
is_pyproj2
()¶ Determine whether the current pyproj version is >= 2.0
-
pyresample.utils.
recursive_dict_update
(d, u)¶ Recursive dictionary update using
Copied from:
-
pyresample.utils.
wrap_longitudes
(lons)¶ Wrap longitudes to the [-180:+180[ validity range (preserves dtype)
Parameters: lons (numpy array) – Longitudes in degrees Returns: lons – Longitudes wrapped into [-180:+180[ validity range Return type: numpy array
pyresample.data_reduce¶
Reduce data sets based on geographical information
-
pyresample.data_reduce.
get_valid_index_from_cartesian_grid
(cart_grid, lons, lats, radius_of_influence)¶ Calculates relevant data indices using coarse data reduction of swath data by comparison with cartesian grid
Parameters: - chart_grid (numpy array) – Grid of area cartesian coordinates
- lons (numpy array) – Swath lons
- lats (numpy array) – Swath lats
- data (numpy array) – Swath data
- radius_of_influence (float) – Cut off distance in meters
Returns: valid_index – Boolean array of same size as lons and lats indicating relevant indices
Return type: numpy array
-
pyresample.data_reduce.
get_valid_index_from_lonlat_boundaries
(boundary_lons, boundary_lats, lons, lats, radius_of_influence)¶ Find relevant indices from grid boundaries using the winding number theorem
-
pyresample.data_reduce.
get_valid_index_from_lonlat_grid
(grid_lons, grid_lats, lons, lats, radius_of_influence)¶ Calculates relevant data indices using coarse data reduction of swath data by comparison with lon lat grid
Parameters: - chart_grid (numpy array) – Grid of area cartesian coordinates
- lons (numpy array) – Swath lons
- lats (numpy array) – Swath lats
- data (numpy array) – Swath data
- radius_of_influence (float) – Cut off distance in meters
Returns: valid_index – Boolean array of same size as lon and lat indicating relevant indices
Return type: numpy array
-
pyresample.data_reduce.
swath_from_cartesian_grid
(cart_grid, lons, lats, data, radius_of_influence)¶ Makes coarse data reduction of swath data by comparison with cartesian grid
Parameters: - chart_grid (numpy array) – Grid of area cartesian coordinates
- lons (numpy array) – Swath lons
- lats (numpy array) – Swath lats
- data (numpy array) – Swath data
- radius_of_influence (float) – Cut off distance in meters
Returns: (lons, lats, data) – Reduced swath data and coordinate set
Return type: list of numpy arrays
-
pyresample.data_reduce.
swath_from_lonlat_boundaries
(boundary_lons, boundary_lats, lons, lats, data, radius_of_influence)¶ Makes coarse data reduction of swath data by comparison with lon lat boundary
Parameters: - boundary_lons (numpy array) – Grid of area lons
- boundary_lats (numpy array) – Grid of area lats
- lons (numpy array) – Swath lons
- lats (numpy array) – Swath lats
- data (numpy array) – Swath data
- radius_of_influence (float) – Cut off distance in meters
Returns: (lons, lats, data) – Reduced swath data and coordinate set
Return type: list of numpy arrays
-
pyresample.data_reduce.
swath_from_lonlat_grid
(grid_lons, grid_lats, lons, lats, data, radius_of_influence)¶ Makes coarse data reduction of swath data by comparison with lon lat grid
Parameters: - grid_lons (numpy array) – Grid of area lons
- grid_lats (numpy array) – Grid of area lats
- lons (numpy array) – Swath lons
- lats (numpy array) – Swath lats
- data (numpy array) – Swath data
- radius_of_influence (float) – Cut off distance in meters
Returns: (lons, lats, data) – Reduced swath data and coordinate set
Return type: list of numpy arrays
pyresample.plot¶
-
pyresample.plot.
area_def2basemap
(area_def, **kwargs)¶ Get Basemap object from AreaDefinition
Parameters: - area_def (object) – geometry.AreaDefinition object
- **kwargs (Keyword arguments) – Additional initialization arguments for Basemap
Returns: bmap
Return type: Basemap object
-
pyresample.plot.
ellps2axis
(ellps_name)¶ Get semi-major and semi-minor axis from ellipsis definition
Parameters: ellps_name (str) – Standard name of ellipsis Returns: (a, b) Return type: semi-major and semi-minor axis
-
pyresample.plot.
save_quicklook
(filename, area_def, data, vmin=None, vmax=None, label='Variable (units)', num_meridians=45, num_parallels=10, coast_res='110m', backend='AGG', cmap='jet')¶ Display default quicklook plot
Parameters: - filename (str) – path to output file
- area_def (object) – geometry.AreaDefinition object
- data (numpy array | numpy masked array) – 2D array matching area_def. Use masked array for transparent values
- vmin (float, optional) – Min value for luminescence scaling
- vmax (float, optional) – Max value for luminescence scaling
- label (str, optional) – Label for data
- num_meridians (int, optional) – Number of meridians to plot on the globe
- num_parallels (int, optional) – Number of parallels to plot on the globe
- coast_res ({'c', 'l', 'i', 'h', 'f'}, optional) – Resolution of coastlines
- backend (str, optional) – matplotlib backend to use’
-
pyresample.plot.
show_quicklook
(area_def, data, vmin=None, vmax=None, label='Variable (units)', num_meridians=45, num_parallels=10, coast_res='110m', cmap='jet')¶ Display default quicklook plot
Parameters: - area_def (object) – geometry.AreaDefinition object
- data (numpy array | numpy masked array) – 2D array matching area_def. Use masked array for transparent values
- vmin (float, optional) – Min value for luminescence scaling
- vmax (float, optional) – Max value for luminescence scaling
- label (str, optional) – Label for data
- num_meridians (int, optional) – Number of meridians to plot on the globe
- num_parallels (int, optional) – Number of parallels to plot on the globe
- coast_res ({'c', 'l', 'i', 'h', 'f'}, optional) – Resolution of coastlines
Returns: bmap
Return type: Basemap object