1.5.1.1.10.1.5. polar2grid.utils.legacy_compat module

Utilities for handling legacy behavior with Satpy interfaces.

class polar2grid.utils.legacy_compat.AliasHandler(all_aliases: dict[str, str | DataQuery], user_products: list[str])[source]

Bases: object

Utility class for converting internal Satpy names to user-facing Polar2Grid names.

Polar2Grid and Geo2Grid currently only allows users to specify the name of products to load as a string. For compatibility with older versions of Polar2Grid or for basic aesthetic differences, Polar2Grid sometimes has different names for products. There are also cases where Polar2Grid needs to provide a single name for a more complex Satpy product that normally requires a DataID.

This class provides the ability to convert between these different forms of naming. If a user provides a Satpy name then this class will not replace it with a P2G alias (if it exists). This should lead to the least amount of surprises for users.

static _unique_ordered_list(orig_list)[source]
apply_p2g_name_to_scene(scn: Scene)[source]

Assign a new ‘p2g_name’ string attribute to every DataArray.

This is typically done just before writing the ‘Scene’ output to disk so that the filename pattern used in Scene.save_datasets has access to the user-facing “P2G name” rather than the internal Satpy name or DataID.

available_product_names(all_p2g_products: list[str], available_custom_ids: list[DataID], available_satpy_ids: list[DataID]) tuple[list[str], list[str], list[str]][source]

Get separate lists of available Satpy products and Polar2Grid products.

convert_p2g_name_to_satpy(products: Iterable[str] | None = None) Generator[str | DataID, None, None][source]

Convert P2G names to corresponding Satpy name or DataID.

convert_satpy_to_p2g_name(satpy_products: Iterable[DataID], possible_p2g_names: list[str] | None = None)[source]

Get the P2G name for a series of Satpy names or DataIDs.

If a Satpy DataID does not have a Polar2Grid compatible name then None is yielded. A name is not compatible if requesting it would produce a different product than the original DataID.

remove_unknown_user_products(known_dataset_names: Iterable[str]) list[str][source]

Remove user products that aren’t known to the Scene.

This is for a Satpy reader that dynamically determines what datasets it knows about based on what is in the files it is provided. If the user (or more likely a P2G reader’s default products) asks for a product that isn’t known, we need to remove it so Satpy doesn’t error out. For example, the MiRS reader doesn’t know what BT bands are known until it knows what files are being read. Polar2Grid needs to default to all possible BT bands or else we can’t load specific BT bands.

property satpy_ids

All user provided product names as Satpy identifiers.

polar2grid.utils.legacy_compat._generate_old_p2g_date_formats()[source]

Convert old P2G output pattern date formats.

polar2grid.utils.legacy_compat._warn_on_format_replaced(pattern: str, old_format_param: str, new_format_param: str) str[source]
polar2grid.utils.legacy_compat.convert_p2g_pattern_to_satpy(pattern)[source]

Convert old P2G output patterns to new format.

polar2grid.utils.legacy_compat.get_sensor_alias(satpy_sensor)[source]