pysiral.core.output

Classes

OutputHandlerBase

A class that defines properties of output files (content, location, format)

DefaultLevel2OutputHandler

Default output handler with pysiral conventions. Uses product directory from

NCDateNumDef

Holds definition for datetime conversion to numbers and vice versa

NCDataFile

Template for default pysiral class with logging/error handling capabilities

L1bDataNC

Class to export a L1bdata object into a netcdf file

Level1POutput

Class to export a l2data object into a netcdf file

Level2Output

Class to export a l2data object into a netcdf file

Level3Output

Class to export a Level-3 data object into a netcdf file.

PysiralOutputFilenaming

Class for generating and parsing of pysiral output filenames for all data levels

PysiralOutputFolder

Class for generating and retrieving output folders

Functions

get_output_class(name)

Module Contents

class pysiral.core.output.OutputHandlerBase(output_def, applicable_data_level=None, subfolder_tags=None, default_file_location=None)

Bases: pysiral.core.legacy_classes.DefaultLoggingClass

A class that defines properties of output files (content, location, format) based on the output definition, data container and other processor settings

subfolder_format
pysiral_config
error
_basedir = 'n/a'
_doi = None
subfolders = None
subfolder_tags = None
applicable_data_level = None
default_file_location = None
output_def_filename
fill_template_string(template, dataset)

Fill an template string with information of a dataset object (in this case Level2Data)

get_dt_subfolders(dt, subfolder_tags)

Returns a list of subdirectories based on a datetime object (usually the start time of data collection)

static get_template_attrs(template)

Extract attribute names and options (if defined) for a give template string

_init_from_output_def(output_def)

Adds the information for the output def yaml files (either full filename or treedict structure)

_set_basedir(basedir, create=True)

Sets and (per default) creates the main output directory

_create_directory(directory)

Convinience method to create a directory and add an error when failed

_get_subdirectories(dt)
_get_directory_from_dt(dt)
_validate_outputdef() None

Run a series of tests to check if a valid output definition has been passed. Note: these tests will only check existing items of the output definition. If the requested item is missing a separate exception will be evoked

Returns:

property has_doi
property id
property product_level_subfolder
property data_level
property basedir
property output_def
property now_directory

Returns a directory suitable string with the current time

property variable_def
class pysiral.core.output.DefaultLevel2OutputHandler(output_def='default', subdirectory='default_output', overwrite_protection=True, period='default')

Bases: OutputHandlerBase

Default output handler with pysiral conventions. Uses product directory from local_machine_def.yaml as standard repository

subdirectory = 'default_output'
overwrite_protection = True
_period = 'default'
get_filename_from_data(l2)

Return the filename for a defined level-2 data object based on tag filenaming in output definition file :param l2: l2data.Level2Data :return: str

get_directory_from_data(l2, create=True)

Return the output directory based on information provided in an l2 data object :param l2: :param create: :return:

get_fullpath_from_data(l2)

Return export path and filename based on information provided in the l2 data object :param l2: :return:

get_global_attribute_dict(l2)
remove_old(time_range)

This method will erase all files in the target orbit for a given time range. Use with care

_init_product_directory()

Get main product directory from local_machine_def, add mandatory runtag subdirectory, optional second subdirectory for overwrite protection and product level id subfolder

property default_output_def_filename
class pysiral.core.output.NCDateNumDef(units: str = 'seconds since 1970-01-01')

Bases: object

Holds definition for datetime conversion to numbers and vice versa for netCDF operations

units = 'seconds since 1970-01-01'
calendar = 'standard'
class pysiral.core.output.NCDataFile(output_handler)

Bases: pysiral.core.legacy_classes.DefaultLoggingClass

Template for default pysiral class with logging/error handling capabilities

error
output_handler
data = None
filename = None
base_export_path = None
parameter_attributes = None
time_def
zlib = True
_rootgrp = None
_options = None
_proc_settings = None
verbose = False
set_options(**opt_dict)
set_processor_settings(proc_settings)
set_base_export_path(path)
_set_doi()
_set_data_record_type()
_write_global_attributes()
_populate_data_groups(level3=False, flip_yc=False)
_create_root_group(attdict, **global_attr_keyw)

Create the root group and add l1b metadata as global attributes

_convert_datetime_attributes(attdict)

Replace l1b info parameters of type datetime.datetime by a double representation to match requirements for netCDF attribute data type rules

static _convert_bool_attributes(attdict)

Replace l1b info parameters of type bool [‘b1’] by a integer representation to match requirements for netCDF attribute data type rules

static _convert_nonetype_attributes(attdict)

Replace l1b info parameters of type bool [‘b1’] by a integer representation to match requirements for netCDF attribute data type rules

_set_global_attributes(attdict, prefix='')

Save l1b.info dictionary as global attributes

_get_variable_attr_dict(parameter)

Retrieve the parameter attributes

_write_processor_settings()
_open_file()
_write_to_file()
property export_path

Evoking this property will also create the directory if it does not already exist

property export_filename

Returns the filename for the level2 output file

property full_path
class pysiral.core.output.L1bDataNC

Bases: pysiral.core.legacy_classes.DefaultLoggingClass

Class to export a L1bdata object into a netcdf file NOTE: This class is different from the other netCDF output classes as

it uses data groups.

datagroups = ['waveform', 'surface_type', 'time_orbit', 'classifier', 'correction']
filename = None
time_def
zlib = True
_rootgrp = None
_options = None
_proc_settings = None
verbose = False
output_folder = None
l1b = None
parameter_attributes = []
export()
_validate()
_create_filename()
_set_global_attributes(attdict, prefix='')

Save l1b.info dictionary as global attributes

_create_root_group(attdict, **global_attr_keyw)

Create the root group and add l1b metadata as global attributes :param attdict: A dictionary containing the global attributes :param global_attr_keyw: :return:

_populate_data_groups()
_convert_datetime_attributes(attdict)

Change any datetime-like object to a netCDF compatible numerical representation :param attdict: dictionary-like :return:

static _convert_bool_attributes(attdict)

Replace l1b info parameters of type bool [‘b1’] by a integer representation to match requirements for netCDF attribute data type rules :param attdict: dictionary-like :return:

static _convert_nonetype_attributes(attdict)

Change empty (None) values in an attrdict to an empty string :param attdict: dictionary like :return: None, will be changed in place

_get_variable_attr_dict(parameter)

Retrieve the parameter attributes

_open_file()
_write_to_file()
class pysiral.core.output.Level1POutput(data, output_handler)

Bases: NCDataFile

Class to export a l2data object into a netcdf file

data
class pysiral.core.output.Level2Output(data, output_handler)

Bases: NCDataFile

Class to export a l2data object into a netcdf file

time_def
data
_export_content()
Returns:

class pysiral.core.output.Level3Output(data, output_handler)

Bases: NCDataFile

Class to export a Level-3 data object into a netcdf file. Differences to Level2Output are small but substantial (e.g. with the additional time dimension)

data
_export_content()
_add_time_variables()

Add the required variables describing the temporal coverage and the reference time of the Level-3 data product. :return:

_add_grid_mapping_variables()

This method adds a variable to the netCDF file that contains the grid definition and is named after the projection. E.g:

byte Lambert_Azimuthal_Grid;

:latitude_of_projection_origin = 90.0; // double :longitude_of_projection_origin = 0.0; // double :proj4_string = “+proj=laea +lon_0=0 +datum=WGS84 +ellps=WGS84 +lat_0=90.0”; :semi_major_axis = 6378137.0; // double :false_easting = 0.0; // double :false_northing = 0.0; // double :grid_mapping_name = “lambert_azimuthal_equal_area”; :inverse_flattening = 298.257223563; // double

The information is taken 1:1 from the netcdf_grid_description entry in the grid definition file.

Returns:

class pysiral.core.output.PysiralOutputFilenaming

Bases: object

Class for generating and parsing of pysiral output filenames for all data levels TODO: Find out if this is still needed (probably for l1p) and remove if obsolet

error
data_level = None
version = None
hemisphere = None
mission_id = None
orbit = None
start = None
stop = None
resolution = None
grid = None
_registered_parsers
parse_filename(fn)

Parse info from pysiral output filename

static _datetime_format(dt)
class pysiral.core.output.PysiralOutputFolder

Bases: object

Class for generating and retrieving output folders

error
data_level = None
path = None
version = 'default'
mission_id = None
year = None
month = None
hemisphere = None
config
l1bdata_from_list(mission_id, version, hemisphere, year, month)
l1bdata_from_l1b(l1b, version='default')
l2i_from_startdt(startdt, base_path, subfolders)
create()
_set_folder_as_l1bdata()
pysiral.core.output.get_output_class(name)