pyresample.area_config module

Area config handling and creation utilities.

exception pyresample.area_config.AreaNotFound

Bases: KeyError

Exception raised when specified are is no found in file.

pyresample.area_config._capture_subarguments(params, arg_name, sub_arg_list)

Capture create_area_def() sub-arguments (i.e. units, height, dx, etc) from a yaml file.

Example

Specify the units for the individual dx/dy values:

resolution:
  dx: 11
  dy: 22
  units: meters

would return the equivalent of DataArray((11, 22), attrs={'units': 'meters}).

Return type:

Any

pyresample.area_config._convert_coordinate_for_metered_units(var, units, src_crs, dst_crs)
pyresample.area_config._convert_units(var, name, units, p, crs, inverse=False, center=None)

Convert units from lon/lat to projection coordinates (meters).

If inverse it True then the inverse calculation is done.

pyresample.area_config._create_area(area_id, area_content)

Parse area configuration.

pyresample.area_config._create_area_def_from_dict(area_name, params)

Create an area definition from a string of parameters.

pyresample.area_config._distance_from_center_forward(var, center, p)

Convert distances in degrees to projection units.

pyresample.area_config._extract_and_validate_units(var, units, crs)
Return type:

tuple[tuple[float, float], str]

pyresample.area_config._extrapolate_information(area_extent, shape, center, radius, resolution, upper_left_extent, units, p, crs)

Attempt to find shape and area_extent based on data provided.

Parameters are used in a specific order to determine area_extent and shape. The area_extent and shape are later used to create an AreaDefinition. Providing some parameters may have no effect if other parameters could be used to determine area_extent and shape. The order of the parameters used is:

  1. area_extent

  2. upper_left_extent and center

  3. radius and resolution

  4. resolution and shape

  5. radius and center

  6. upper_left_extent and radius

pyresample.area_config._format_list(var, name)

Ensure that parameter is list-like of numbers.

Used to let resolution and radius be single numbers if their elements are equal.

pyresample.area_config._get_proj4_args(proj4_args)

Create dict from proj4 args.

pyresample.area_config._get_proj_data(projection)

Take projection information and returns a proj CRS.

Takes projection information in any format understood by pyproj.crs.CRS.from_user_input(). There is special handling for the “EPSG:XXXX” case where “XXXX” is an EPSG number code. It can be provided as a string “EPSG:XXXX” or as a dictionary (when provided via YAML) as {‘EPSG’: XXXX}. If it is passed as a string (“EPSG:XXXX”) then the rules of proj4_str_to_dict() are followed. If a dictionary and pyproj 2.0+ is installed then the string “EPSG:XXXX” is passed to proj4_str_to_dict. If pyproj<2.0 is installed then the string +init=EPSG:XXXX is passed to proj4_str_to_dict which provides limited information to area config operations.

Return type:

CRS

pyresample.area_config._get_proj_units(crs)
pyresample.area_config._make_area(area_id, description, proj_id, projection, shape, area_extent, optimize_projection=False, resolution=None, **kwargs)

Handle the creation of an area definition for create_area_def.

pyresample.area_config._parse_legacy_area_file(area_file_name, *regions)

Parse area information from a legacy area file.

pyresample.area_config._parse_one_legacy_area_lines(area_file, area_id)
pyresample.area_config._parse_yaml_area_file(area_file_name, *regions)

Parse area information from a yaml area file.

Parameters:
  • area_file_name – filename, file-like object, yaml string, or list of these.

  • regions (str) – Names of areas to parse. Optional and defaults to all areas in the file.

The result of loading multiple area files is the combination of all the files, using the first file as the “base”, replacing things after that.

pyresample.area_config._read_legacy_area_file_lines(area_file_name)
pyresample.area_config._read_yaml_area_file_content(area_file_name)

Read one or more area files in to a single dict object.

pyresample.area_config._round_poles(center, units, p)

Round center to the nearest pole if it is extremely close to said pole.

Used to work around floating point precision issues .

pyresample.area_config._round_shape(shape, radius=None, resolution=None, units='meters')

Make sure shape is an integer.

Rounds down if shape is less than .01 above nearest whole number to handle floating point precision issues. Otherwise the number is round up.

pyresample.area_config._sign(num)

Return the sign of the number provided.

Returns:

1 if number is greater than 0, -1 otherwise

pyresample.area_config._validate_sub_arg_list(argument, arg_name, sub_arg_list)
pyresample.area_config._validate_variable(var, new_var, var_name, input_list)

Make sure data given by the user does not conflict with itself.

If a variable that was given by the user contradicts other data provided, an exception is raised. Example: upper_left_extent is (-10, 10), but area_extent is (-20, -20, 20, 20).

pyresample.area_config._verify_list(name, var, length)

Check that list-like variables are list-like, shapes are accurate, and values are numbers.

pyresample.area_config.convert_def_to_yaml(def_area_file, yaml_area_file)

Convert a legacy area def file to the yaml counter partself.

yaml_area_file will be overwritten by the operation.

pyresample.area_config.create_area_def(area_id, projection, width=None, height=None, area_extent=None, shape=None, upper_left_extent=None, center=None, resolution=None, radius=None, units=None, optimize_projection=False, **kwargs)

Create AreaDefinition from whatever information is known.

Parameters:
  • area_id (str) – ID of area

  • projection (pyproj CRS object, dict, str, int, tuple, object) – Projection parameters. This can be in any format understood by pyproj.crs.CRS.from_user_input(), such as a pyproj CRS object, proj4 dict, proj4 string, EPSG integer code, or others.

  • description (str, optional) – Description/name of area. Defaults to area_id

  • proj_id (str, optional) – ID of projection (deprecated)

  • 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:

    1. units expressed with each variable through a DataArray’s attrs attribute.

    2. units passed to units

    3. units used in projection

    4. meters

  • width (str, optional) – Number of pixels in the x direction

  • height (str, optional) – Number of pixels in the y direction

  • area_extent (list, optional) – Area extent as a list (lower_left_x, lower_left_y, upper_right_x, upper_right_y)

  • shape (list, optional) – Number of pixels in the y and x direction (height, width)

  • upper_left_extent (list, optional) – Upper left corner of upper left pixel (x, y)

  • center (list, optional) – Center of projection (x, y)

  • resolution (list or float, optional) – Size of pixels: (dx, dy)

  • radius (list or float, optional) – Length from the center to the edges of the projection (dx, dy)

  • 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:

area – If shape and area_extent are found, an AreaDefinition object is returned. If only shape or area_extent can be found, a DynamicAreaDefinition object is returned

Return type:

pyresample.geometry.AreaDefinition or pyresample.geometry.DynamicAreaDefinition

Raises:

ValueError: – If neither shape nor area_extent could be found

Notes

  • resolution and radius can be specified with one value if dx == dy

  • If resolution and radius are provided as angles, center must be given or findable. In such a case, they represent [projection x distance from center[0] to center[0]+dx, projection y distance from center[1] to center[1]+dy]

pyresample.area_config.generate_area_def_rst_list(area_file)

Create rst list of available area definitions with overview plot.

Parameters:

area_file (str) – Path to area yaml file.

Return type:

str

Returns:

rst list formatted string.

pyresample.area_config.get_area_def(area_id, area_name, proj_id, proj4_args, width, height, area_extent)

Construct AreaDefinition object from arguments.

Parameters:
  • area_id (str) – ID of area

  • area_name (str) – Description of area

  • proj_id (str) – ID of projection

  • proj4_args (dict, CRS, or str) – Projection information passed to pyproj’s CRS object

  • width (int) – Number of pixel in x dimension

  • height (int) – Number of pixel in y dimension

  • area_extent (list | tuple) – Area extent as a list of ints (LL_x, LL_y, UR_x, UR_y)

Returns:

area_def – AreaDefinition object

Return type:

object

pyresample.area_config.load_area(area_file_name, *regions)

Load area(s) from area file.

Parameters:
  • area_file_name (str, pathlib.Path, stream, or list thereof) – List of paths or streams. Any str or pathlib.Path will be interpreted as a path to a file. Any stream will be interpreted as containing a yaml definition file. To read directly from a string, use load_area_from_string().

  • regions (str argument list) – Regions to parse. If no regions are specified all regions in the file are returned

Returns:

area_defs – If one area name is specified a single AreaDefinition object is returned. If several area names are specified a list of AreaDefinition objects is returned

Return type:

pyresample.geometry.AreaDefinition or list

Raises:

AreaNotFound: – If a specified area name is not found

pyresample.area_config.load_area_from_string(area_strs, *regions)

Load area(s) from area strings.

Like load_area(), but load from string directly.

For the opposite (i.e. to create a YAML string from an area), use dump().

Parameters:
  • area_strs (str or List[str]) – Strings containing yaml definitions.

  • regions (str) – Regions to parse.

Returns:

area_defs – If one area name is specified a single AreaDefinition object is returned. If several area names are specified a list of AreaDefinition objects is returned

Return type:

pyresample.geometry.AreaDefinition or list

pyresample.area_config.parse_area_file(area_file_name, *regions)

Parse area information from area file.

Parameters:
  • area_file_name (str or list) – One or more paths to area definition files

  • regions (str argument list) – Regions to parse. If no regions are specified all regions in the file are returned

Returns:

area_defs – List of AreaDefinition objects

Return type:

list

Raises:

AreaNotFound: – If a specified area is not found