pyresample.utils package

Submodules

pyresample.utils.cartopy module

Classes for geometry operations.

See the related Cartopy pull request that implements this functionality directly in Cartopy: https://github.com/SciTools/cartopy/pull/1888

class pyresample.utils.cartopy.Projection(crs: CRS, bounds: Optional[list[float, float, float, float]] = None, transform_bounds: bool = False)

Bases: Projection

Flexible generic Projection with optionally specified bounds.

pyresample.utils.cf module

Load an AreaDefinition object from a netCDF/CF file.

pyresample.utils.cf.load_cf_area(nc_file, variable=None, y=None, x=None)

Load an AreaDefinition object from a netCDF/CF file.

Parameters
  • nc_file (string or object) – path to a netCDF/CF file, or opened xarray.Dataset object

  • variable (string, optional) – name of the variable to load the AreaDefinition from. If the variable is not a CF grid_mapping container variable, it should be a variable having a :grid_mapping attribute. If variable is None the file will be searched for valid CF area definitions

  • y (string, optional) – name of the variable to use as ‘y’ axis of the CF area definition If y is None an appropriate ‘y’ axis will be deduced from the CF file

  • x (string, optional) – name of the variable to use as ‘x’ axis of the CF area definition If x is None an appropriate ‘x’ axis will be deduced from the CF file

Returns

are_def, cf_info – cf_info holds info about how the AreaDefinition was defined in the CF file.

Return type

geometry.AreaDefinition object, dict

pyresample.utils.errors module

Special exceptions and warnings specific to pyresample.

exception pyresample.utils.errors.PerformanceWarning

Bases: Warning

Warning raised when there is a possible performance impact.

pyresample.utils.proj4 module

Utilities for working with projection parameters.

class pyresample.utils.proj4.DaskFriendlyTransformer(src_crs, dst_crs, **kwargs)

Bases: object

Wrapper around the pyproj Transformer class that uses dask.

If the provided arrays are not dask arrays, they are converted to numpy arrays and pyproj will be called directly (dask is not used).

classmethod from_crs(crs_from, crs_to, **kwargs)

Create transformer object from two CRS objects.

transform(x, y, **kwargs)

Transform coordinates.

pyresample.utils.proj4.convert_proj_floats(proj_pairs)

Convert PROJ.4 parameters to floats if possible.

pyresample.utils.proj4.get_geostationary_height(geos_area_crs)

Get the height parameter from a geostationary CRS.

pyresample.utils.proj4.proj4_dict_to_str(proj4_dict, sort=False)

Convert a dictionary of PROJ.4 parameters to a valid PROJ.4 string.

pyresample.utils.proj4.proj4_radius_parameters(proj4_dict)

Calculate ‘a’ and ‘b’ radius parameters.

Parameters

proj4_dict (str or dict) – PROJ.4 parameters

Returns

equatorial and polar radius

Return type

a (float), b (float)

pyresample.utils.proj4.proj4_str_to_dict(proj4_str)

Convert PROJ.4 compatible string definition to dict.

EPSG codes should be provided as “EPSG:XXXX” where “XXXX” is the EPSG number code. It can also be provided as "+init=EPSG:XXXX" as long as the underlying PROJ library supports it (deprecated in PROJ 6.0+).

Note: Key only parameters will be assigned a value of True.

pyresample.utils.rasterio module

Utilities for working with rasterio objects.

pyresample.utils.rasterio.get_area_def_from_raster(source, area_id=None, name=None, proj_id=None, projection=None)

Construct AreaDefinition object from raster.

Parameters
  • source (str, Dataset, DatasetReader or DatasetWriter) – A file name. Also it can be osgeo.gdal.Dataset, rasterio.io.DatasetReader or rasterio.io.DatasetWriter

  • area_id (str, optional) – ID of area

  • name (str, optional) – Name of area

  • proj_id (str, optional) – ID of projection

  • projection (pyproj.CRS, dict, or string, optional) – Projection parameters as a CRS object or a dictionary or string of PROJ.4 parameters.

Returns

area_def – AreaDefinition object

Return type

object

Module contents

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.check_slice_orientation(sli)

Check that the slice is slicing the right way.

pyresample.utils.convert_def_to_yaml(*args, **kwargs)

Convert an area definition to yaml representation.

pyresample.utils.create_area_def(*args, **kwargs)

Create an area definition.

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
  • source_area_def (object) – Source area definition as geometry definition object

  • target_area_def (object) – Target area definition as geometry definition object

  • radius_of_influence (float) – Cut off distance in meters

  • nprocs (int, optional) – Number of processor cores to be used

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
  • source_area_def (object) – Source area definition as geometry definition object

  • target_area_def (object) – Target area definition as geometry definition object

  • nprocs (int, optional) – Number of processor cores to be used

Returns

(row_indices, col_indices)

Return type

tuple of numpy arrays

pyresample.utils.get_area_def(*args, **kwargs)

Get an area definition.

pyresample.utils.load_area(*args, **kwargs)

Load an area.

pyresample.utils.parse_area_file(*args, **kwargs)

Parse an area file.

pyresample.utils.recursive_dict_update(d, u)

Update dictionary recursively.

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