API Reference — PyEPR 0.3 documentation

### Navigation

- index
- modules |
- next |
- previous |
- PyEPR 0.3 documentation »

# API Reference

PyEPR provides Python bindings for the ENVISAT Product Reader C API (EPR API) for reading satellite data from ENVISAT ESA (European Space Agency) mission.

PyEPR is fully object oriented and, as well as the EPR API for C, supports ENVISAT MERIS, AATSR Level 1B and Level 2 and also ASAR data products. It provides access to the data either on a geophysical (decoded, ready-to-use pixel samples) or on a raw data layer. The raw data access makes it possible to read any data field contained in a product file.

## Classes

### Product

class `epr.` `Product`

  ENVISAT product

  The Product class provides methods and properties to get information about an ENVISAT product file.

  See also

  `open()`

  `file_path`

    The file’s path including the file name

  `id_string`

    The product identifier string obtained from the MPH parameter ‘PRODUCT’

    The first 10 characters of this string identify the product type, e.g. “MER_1P__FR” for a MERIS Level 1b full resolution product. The rest of the string decodes product instance properties.

  `meris_iodd_version`

    For MERIS L1b and RR and FR to provide backward compatibility

  `tot_size`

    The total size in bytes of the product file

  `get_band`(name)

    Gets the band corresponding to the specified name.

    Parameters: | name – the name of the band
    Returns: | the requested `Band` instance, or raises a `EPRValueError` if not found

  `get_band_at`(index)

    Gets the band at the specified position within the product

    Parameters: | index – the index identifying the position of the band, starting with 0, must not be negative
    Returns: | the requested `Band` instance, or raises a `EPRValueError` if not found

  `get_dataset`(name)

    Gets the dataset corresponding to the specified dataset name

    Parameters: | name – the dataset name
    Returns: | the requested `Dataset` instance

  `get_dataset_at`(index)

    Gets the dataset at the specified position within the product

    Parameters: | index – the index identifying the position of the dataset, starting with 0, must not be negative
    Returns: | the requested `Dataset`

  `get_dsd_at`(index)

    Gets the DSD at the specified position

    Gets the DSD (dataset descriptor) at the specified position within the product.

    Parameters: | index – the index identifying the position of the DSD, starting with 0, must not be negative
    Returns: | the requested `DSD` instance

  `get_num_bands`()

    Gets the number of all bands contained in a product

  `get_num_datasets`()

    Gets the number of all datasets contained in a product

  `get_num_dsds`()

    Gets the number of all DSDs (dataset descriptors) contained in the product

  `get_scene_height`()

    Gets the product’s scene height in pixels

  `get_scene_width`()

    Gets the product’s scene width in pixels

  `get_mph`()

    The `Record` representing the main product header (MPH)

  `get_sph`()

    The `Record` representing the specific product header (SPH)

  `get_dataset_names`()

    Return the list of names of the datasets in the product

    Note

    this method has no correspondent in the C API

  `get_band_names`()

    Return the list of names of the bands in the product

    Note

    this method has no correspondent in the C API

  `datasets`()

    Return the list of dataset in the product

    Note

    this method has no correspondent in the C API

  `bands`()

    Return the list of bands in the product

    Note

    this method has no correspondent in the C API

  Implemented special methods

  - __repr__
  - __str__

### Dataset

class `epr.` `Dataset`

  ENVISAT dataset

  The Dataset class contains information about a dataset within an ENVISAT product file which has been opened with the `open()` function.

  A new Dataset instance can be obtained with the `Product.get_dataset()` or `Product.get_dataset_at()` methods.

  `description`

    A short description of the band’s contents

  `product`

    The `Product` instance to which this dataset belongs to

  `get_name`()

    Gets the name of the dataset

  `get_dsd`()

    Gets the dataset descriptor (DSD)

  `get_dsd_name`()

    Gets the name of the DSD (dataset descriptor)

  `get_num_records`()

    Gets the number of records of the dataset

  `create_record`()

    Creates a new record

    Creates a new, empty record with a structure compatible with the dataset. Such a record is typically used in subsequent calls to `Dataset.read_record()`.

    Returns: | the new record instance

  `read_record`(index[, record])

    Reads specified record of the dataset

    The record is identified through the given zero-based record index. In order to reduce memory reallocation, a record (pre-)created by the method `Dataset.create_record()` can be passed to this method. Data is then read into this given record.

    If no record (`None`) is given, the method initiates a new one.

    In both cases, the record in which the data is read into will be returned.

    Parameters: | index – the zero-based record index record – a pre-created record to reduce memory reallocation, can be `None` (default) to let the function allocate a new record
    Returns: | the record in which the data has been read into or raises an exception (`EPRValueError`) if an error occurred

  `records`()

    Return the list of records contained in the dataset

    Note

    this method has no correspondent in the C API

  Implemented special methods

  - __repr__
  - __str__
  - __iter__

### Record

class `epr.` `Record`

  Represents a record read from an ENVISAT dataset

  A record is composed of multiple fields.

  See also

  `Field`

  `get_field`(name)

    Gets a field specified by name

    The field is here identified through the given name. It contains the field info and all corresponding values.

    Parameters: | name – the the name of required field
    Returns: | the specified `Field` or raises an exception (`EPRValueError`) if an error occurred

  `get_field_at`(index)

    Gets a field at the specified position within the record

    Parameters: | index – the zero-based index (position within record) of the field
    Returns: | the field or raises and exception (`EPRValueError`) if an error occurred

  `get_num_fields`()

    Gets the number of fields contained in the record

  `print_`([ostream])

    Write the record to specified file (default: `sys.stdout`)

    This method writes formatted contents of the record to specified ostream text file or (default) the ASCII output is be printed to standard output (`sys.stdout`)

    Parameters: | ostream – the (opened) output file object

    Note

    the ostream parameter have to be a real file not a generic stream object like `StringIO` instances

  `print_element`(field_index, element_index[, ostream])

    Write the specified field element to file (default: `sys.stdout`)

    This method writes formatted contents of the specified field element to the ostream text file or (default) the ASCII output will be printed to standard output (`sys.stdout`)

    Parameters: | field_index – the index of field in the record element_index – the index of element in the specified field ostream – the (opened) output file object

    Note

    the ostream parameter have to be a real file not a generic stream object like `StringIO` instances

  `get_field_names`()

    Return the list of names of the fields in the product

    Note

    this method has no correspondent in the C API

  `fields`()

    Return the list of fields contained in the record

    Note

    this method has no correspondent in the C API

  Implemented special methods

  - __repr__
  - __str__
  - __iter__

### Field

class `epr.` `Field`

  Represents a field within a record

  A field is composed of one or more data elements of one of the types defined in the internal `field_info` structure.

  See also

  `Record`

  `get_description`()

    Gets the description of the field

  `get_name`()

    Gets the name of the field

  `get_num_elems`()

    Gets the number of elements of the field

  `get_type`()

    Gets the type of the field

  `get_unit`()

    Gets the unit of the field

  `get_elem`([index])

    Field single element access

    This function is for getting the elements of a field.

    Parameters: | index – the zero-based index of element to be returned, must not be negative. Default: 0.
    Returns: | the typed value from given field

  `get_elems`()

    Field array element access

    This function is for getting an array of field elements of the field.

    Returns: | the data array (`numpy.ndarray`) having the type of the field

  `print_`([ostream])

    Write the field to specified file (default: `sys.stdout`)

    This method writes formatted contents of the field to specified ostream text file or (default) the ASCII output is be printed to standard output (`sys.stdout`)

    Parameters: | ostream – the (opened) output file object

    Note

    the ostream parameter have to be a real file not a generic stream object like `StringIO` instances

  Implemented special methods

  - __repr__
  - __str__
  - __eq__
  - __ne__
  - __len__ [1]

Footnotes

[1] | if the field is a `E_TID_STRING` field then the `__len__()` method returns the string length, otherwise the number of elements of the field is returned (same as `Field.get_num_elems()`)

### DSD

class `epr.` `DSD`

  Dataset descriptor

  The DSD class contains information about the properties of a dataset and its location within an ENVISAT product file

  `ds_name`

    The dataset name

  `ds_offset`

    The offset of dataset-information the product file

  `ds_size`

    The size of dataset-information in dataset product file

  `ds_type`

    The dataset type descriptor

  `dsr_size`

    The size of dataset record for the given dataset name

  `filename`

    The filename in the DDDB with the description of this dataset

  `index`

    The index of this DSD (zero-based)

  `num_dsr`

    The number of dataset records for the given dataset name

  Implemented special methods

  - __repr__
  - __eq__
  - __ne__

### Band

class `epr.` `Band`

  The band of an ENVISAT product

  The Band class contains information about a band within an ENVISAT product file which has been opened with the `open()` function.

  A new Band instance can be obtained with the `Product.get_band()` method.

  `bm_expr`

    A bit-mask expression used to filter valid pixels

    All others are set to zero

  `data_type`

    The data type of the band’s pixels

    Possible values are:

    - `*` –> the datatype remains unchanged.
    - `uint8_t` –> 8-bit unsigned integer
    - `uint32_t` –> 32-bit unsigned integer
    - `Float` –> 32-bit IEEE floating point
  `description`

    A short description of the band’s contents

  `lines_mirrored`

    Mirrored lines flag

    If true (=1) lines will be mirrored (flipped) after read into a raster in order to ensure a pixel ordering in raster X direction from WEST to EAST.

  `product`

    The `Product` instance to which this band belongs to

  `sample_model`

    The sample model operation

    The sample model operation applied to the source dataset for getting the correct samples from the MDS (for example MERIS L2).

    Possible values are:

    - `*` –> no operation (direct copy)
    - `1OF2` –> first byte of 2-byte interleaved MDS
    - `2OF2` –> second byte of 2-byte interleaved MDS
    - `0123` –> combine 3-bytes interleaved to 4-byte integer
  `scaling_factor`

    The scaling factor

    Possible values are:

    - `*` –> no factor provided (implies scaling_method=*)
    - `const` –> a floating point constant
    - `GADS.field[.field2]` –> value is provided in global annotation dataset with name GADS in field field`. Optionally a second element index for multiple-element fields can be given too
  `scaling_method`

    The scaling method which must be applied to the raw source data in order to get the ‘real’ pixel values in geo-physical units.

    Possible values are:

    - `*` –> no scaling applied

    - `Linear_Scale` –> linear scaling applied:

          y = offset + scale * x

    - `Log_Scale` –> logarithmic scaling applied:

          y = log10(offset + scale * x)

  `scaling_offset`

    Possible values are:

    - `*` –> no offset provided (implies scaling_method=*)
    - `const` –> a floating point constant
    - `GADS.field[.field2]` --> value is provided in global annotation dataset with name ``GADS` in field `field`. Optionally a second element index for multiple-element fields can be given too
  `spectr_band_index`

    The (zero-based) spectral band index

    > -1 if this is not a spectral band

  `unit`

    The geophysical unit for the band’s pixel values

  `get_name`()

    Gets the name of the band

  `create_compatible_raster`(src_width, src_height[, xstep, ystep])

    Creates a raster which is compatible with the data type of the band

    The created raster is used to read the data in it (see `Band.read_raster()`).

    The raster is defined on the grid of the product, from which the data are read. Spatial subsets and under-sampling are possible) through the parameter of the method.

    A raster is an object that allows direct access to data of a certain portion of the ENVISAT product that are read into the it. Such a portion is called the source. The complete ENVISAT product can be much greater than the source. One can move the raster over the complete ENVISAT product and read in turn different parts (always of the size of the source) of it into the raster. The source is specified by the parameters height and width.

    A typical example is a processing in blocks. Lets say, a block has 64x32 pixel. Then, my source has a width of 64 pixel and a height of 32 pixel.

    Another example is a processing of complete image lines. Then, my source has a widths of the complete product (for example 1121 for a MERIS RR product), and a height of 1). One can loop over all blocks read into the raster and process it.

    In addition, it is possible to defined a sub-sampling step for a raster. This means, that the source is not read 1:1 into the raster, but that only every 2nd or 3rd pixel is read. This step can be set differently for the across track (source_step_x) and along track (source_step_y) directions.

    Parameters: | src_width – the width (across track dimension) of the source to be read into the raster src_height – the height (along track dimension) of the source to be read into the raster xstep – the sub-sampling step across track of the source when reading into the raster. Default 1. ystep – the sub-sampling step along track of the source when reading into the raster. Default 1.
    Returns: | the new raster instance or raises an exception (`EPRValueError`) if an error occurred

  `read_raster`([xoffset, yoffset, raster])

    Reads (geo-)physical values of the band of the specified source-region

    The source-region is a defined part of the whole ENVISAT product image, which shall be read into a raster. In this routine the co-ordinates are specified, where the source-region to be read starts. The dimension of the region and the sub-sampling are attributes of the raster into which the data are read.

    Parameters: | xoffset – across-track source co-ordinate in pixel co-ordinates (zero-based) of the upper right corner of the source-region. Default 0. yoffset – along-track source co-ordinate in pixel co-ordinates (zero-based) of the upper right corner of the source-region. Default 0. raster – `Raster` instance set with appropriate parameters to read into. If not provided a new `Raster` is instantiated
    Returns: | the `Raster` instance in which data are read

    This method raises an instance of the appropriate `EPRError` sub-class if case of errors

    See also

    `Band.create_compatible_raster()` and `create_raster()`

  `read_as_array`([width, height, xoffset, yoffset, xstep, ystep])

    Reads the specified source region as an `numpy.ndarray`

    The source-region is a defined part of the whole ENVISAT product image, which shall be read into a raster. In this routine the co-ordinates are specified, where the source-region to be read starts. The dimension of the region and the sub-sampling are attributes of the raster into which the data are read.

    Parameters: | src_width – the width (across track dimension) of the source to be read into the raster. If not provided reads as much as possible src_height – the height (along track dimension) of the source to be read into the raster, If not provided reads as much as possible xoffset – across-track source co-ordinate in pixel co-ordinates (zero-based) of the upper right corner of the source-region. Default 0. yoffset – along-track source co-ordinate in pixel co-ordinates (zero-based) of the upper right corner of the source-region. Default 0. xstep – the sub-sampling step across track of the source when reading into the raster. Default 1 ystep – the sub-sampling step along track of the source when reading into the raster. Default 1
    Returns: | the `numpy.ndarray` instance in which data are read

    This method raises an instance of the appropriate `EPRError` sub-class if case of errors

    Note

    this method has no correspondent in the C API

    See also

    `Band.create_compatible_raster()`, `create_raster()` and `Band.read_raster()`

  Implemented special methods

  - __repr__

### Raster

class `epr.` `Raster`

  Represents a raster in which data will be stored

  All ‘size’ parameter are in PIXEL.

  `data_type`

    The data type of the band’s pixels

    All `E_TID_*` types are possible

  `source_height`

    The height of the source

  `source_width`

    The width of the source

  `source_step_x`

    The sub-sampling for the across-track direction in pixel

  `source_step_y`

    The sub-sampling for the along-track direction in pixel

  `data`

    Raster data exposed as `numpy.ndarray` object

    Note

    this property shares the data buffer with the `Raster` object so any change in its contents is also reflected to the `Raster` object

    Note

    this property has no correspondent in the C API

  `get_pixel`(x, y)

    Single pixel access

    This function is for getting the values of the elements of a raster (i.e. pixel)

    Parameters: | x – the (zero-based) X coordinate of the pixel y – the (zero-based) Y coordinate of the pixel
    Returns: | the typed value at the given co-ordinate

  `get_elem_size`()

    The size in byte of a single element (sample) of this raster’s buffer

  `get_height`()

    Gets the raster’s height in pixels

  `get_width`()

    Gets the raster’s width in pixels

  Implemented special methods

  - __repr__

### EPRTime

class `epr.` `EPRTime`

  Convenience class for time data exchange.

  EPRTime is a `collections.namedtuple` with the following fields:

  `days`
  `seconds`
  `microseconds`

## Functions

`epr.` `open`(filename)

  Opens the ENVISAT product

  Opens the ENVISAT product file with the given file path, reads MPH, SPH and all DSDs, organized the table with parameter of line length and tie points number.

  Parameters: | product_file_path – the path to the ENVISAT product file
  Returns: | the `Product` instance representing the specified product. An exception (`ValueError`) is raised if the file could not be opened.

`epr.` `data_type_id_to_str`()

  Gets the ‘C’ data type string for the given data type

`epr.` `get_data_type_size`()

  Gets the size in bytes for an element of the given data type

`epr.` `get_sample_model_name`()

  Return the name of the specified sample model

`epr.` `get_scaling_method_name`()

  Return the name of the specified scaling method

`epr.` `create_raster`(data_type, src_width, src_height[, xstep, ystep])

  Creates a raster of the specified data type

  This function can be used to create any type of raster, e.g. for later use as a bit-mask.

  Parameters: | data_type – the type of the data to stored in the raster, must be one of E_TID_*. See also Data type Identifiers src_width – the width (across track dimension) of the source to be read into the raster. See description of `Band.create_compatible_raster()` src_height – the height (along track dimension) of the source to be read into the raster. See description of `Band.create_compatible_raster()` xstep – the sub-sampling step across track of the source when reading into the raster. Default 1. ystep – the sub-sampling step along track of the source when reading into the raster. Default 1.
  Returns: | the new `Raster` instance

  See also

  description of `Band.create_compatible_raster()`

`epr.` `create_bitmask_raster`(src_width, src_height[, xstep, ystep])

  Creates a raster to be used for reading bitmasks

  The raster returned always is of type `byte`.

  Parameters: | src_width – the width (across track dimension) of the source to be read into the raster src_height – the height (along track dimension) of the source to be read into the raster xstep – the sub-sampling step across track of the source when reading into the raster. Default 1. ystep – the sub-sampling step along track of the source when reading into the raster. Default 1.
  Returns: | the new raster instance or raises an exception (`EPRValueError`) if an error occurred

  See also

  the description of `Band.create_compatible_raster()`

## Exceptions

### EPRError

exception `epr.` `EPRError`

  EPR API error

  `code`

    EPR API error code

  `__init__`([message[, code, *args, **kwargs]])

    Initializer

    Parameters: | message – error message
    Pram code: | EPR error code

### EPRValueError

exception `epr.` `EPRValueError`

  Inherits both `EPRError` and standard `ValueError`

## Data

`epr.` `EPR_C_API_VERSION`

  Version string of the wrapped EPR API C library

### Data type identifiers

`epr.` `E_TID_UNKNOWN`

`epr.` `E_TID_UCHAR`

`epr.` `E_TID_CHAR`

`epr.` `E_TID_USHORT`

`epr.` `E_TID_SHORT`

`epr.` `E_TID_UINT`

`epr.` `E_TID_INT`

`epr.` `E_TID_FLOAT`

`epr.` `E_TID_DOUBLE`

`epr.` `E_TID_STRING`

`epr.` `E_TID_SPARE`

`epr.` `E_TID_TIME`

### Sample Models

`epr.` `E_SMOD_1OF1`

`epr.` `E_SMOD_1OF2`

`epr.` `E_SMOD_2OF2`

`epr.` `E_SMOD_3TOI`

`epr.` `E_SMOD_2TOF`

### Scaling Methods

`epr.` `E_SMID_NON`

  No scaling

`epr.` `E_SMID_LIN`

  Linear pixel scaling

`epr.` `E_SMID_LOG`

  Logarithmic pixel scaling

### Navigation

- index
- modules |
- next |
- previous |
- PyEPR 0.3 documentation »