Product description

pansat.products.product_description

The product_description module provides a class to parse product description files. Product descriptions are files in the .ini format that are used to describe data products. This is required for data products that do not use the NetCDf format and thus need additional information in order to read them into an xarray Dataset.

Example

The example below provides a minimal example for a product description file.

[1B-CPR]
type = properties
name = 1B-CPR

[rays]
type = dimension

[latitude]
type = coordinate
name = Latitude
description = Spacecraft geodetic latitude.
unit = degree
dimensions = ["rays"]

A product description files consists of different sections, each of which has a mandatory type defining its meaning. The following section types are currently supported:

properties

The properties section defines the general properties of the dataset. So far, this section is used only to set the name of the product. The title of the section is ignored.

dimension

The dimension section defines a dimension used in the dataset. If the section contains a field name, then the variable of this name will be used as numeric values defining the grid values along this dimension. If this is not the case, pansat will automatically try to infer the size of the dimension and use element indices [0, 1, ...] as grid values.

variable

The variable section defines a multi-dimensional data array. A variable section must have fields name and dimensions, which contain the name of the corresponding data variable in a file of the product and a list of corresponding dimensions names, respectively. Note that the dimension names must all be defined in the same product description file.

Optionally, the variable section may contain the following additional entries:

  • unit: The unit in which the data is given.

  • description: A string description of the variable

  • callback: Name of a function that is called on the corresponding attribute of a product file instead of trying to access the data directly through the attribute. This allows customized pre-processing of variable data.

coordinate

For coordinate sections, the same rules apply as for variable section. The difference between a coordinate and a variable is that variables are mapped to xarray Datasets, whereas coordinates are mapped to coordinates.

Reference

class pansat.products.product_description.Dimension(name, config_dict)

Represents a dimension of multi-dimensional dataset.

__init__(name, config_dict)

Create dimension object from .ini file section.

Parameters:
  • name (str) – The name of the .ini file section describing the the dimension.

  • config_dict – The dictionary describing the section of the .ini file.

__repr__()

Return repr(self).

__weakref__

list of weak references to the object (if defined)

property size

The size of the dimension.

exception pansat.products.product_description.DimensionNameError

This error is thrown when a dimension is requested that is not part of the product description.

__weakref__

list of weak references to the object (if defined)

exception pansat.products.product_description.InconsistentDimensionsError

This error is raised when inconsistent values have been deduced for the length of a Dimension object.

__weakref__

list of weak references to the object (if defined)

exception pansat.products.product_description.MissingFieldError

This error is raised when a section of an .ini file lacks a required key.

__weakref__

list of weak references to the object (if defined)

class pansat.products.product_description.ProductDescription(filename)

This class represents a description of a data product which is parsed from a .ini file.

name

The name of the dataset.

Type:

str

dimensions

List of the dimensions of the data product.

coordinates

List of the coordinate-type data in the data product.

variable

List of the variable-type data in the data product.

attribute

List of the attribute-type data in the data product.

__init__(filename)
_get_data(file_handle, context)

Reads dimensions, variables and coordinates from file_handle and returns them as dictionaries.

Parameters:

file_handle – File handle that provides access to the dimensions and variable in this product description.

Returns:

A tuple (variables, coordinates) containing a two dictionaries. The variables maps variable names to 2-tuples of dimensionlists and data arrays. The coordinates dict maps coordinate names to dimension names or to tuples of dimension lists and data arrays.

to_xarray_dataset(file_handle, context=None)

Convert data from file handle to xarray dataset.

Parameters:

file_handle – A file object providing access to the data product described by this product description object.

Returns:

xarray.Dataset containing the data from the provided file handle.

exception pansat.products.product_description.UnknownTypeError

This error is raised when an .ini file contains a section with an unknown type.

__weakref__

list of weak references to the object (if defined)

class pansat.products.product_description.Variable(name, config_dict)

Base class for all variable-type product description entries. Variable-type entries in a product description represent a multi-dimensional data array, which has a name and associated dimensions. Optionally, it may have a unit and a description.

__init__(name, config_dict)
Parameters:
  • name (str) – The section name of the .ini file. which is used as the variable name.

  • config_dict (dict) – The dict containing the keys from the .ini file.

__repr__()

Return repr(self).

__weakref__

list of weak references to the object (if defined)

_parse_config_dict(config_dict)

Helper function to parse config dict from .ini file.

get_attributes()

Get dict of xarray attributes containing unit and description.

get_data(file_handle, context)

Get data for variable from file_handle.

Retrieves data from given file handle by retrieving the attribute corresponding to the variables field_name attribute. If a callback is set for the variable, it is used to retrieve the data from the attribute otherwise the data is retrieved by calling __getitem__ with a single colon.

Parameters:
  • file_handle – Object providing access to a product file.

  • context – Namespace in which to lookup the callback function.