pylag.datetime_reader module

A family of classes for reading dates/times.

class pylag.datetime_reader.DateTimeReader[source]

Bases: object

Abstract base class for DateTimeReaders

DatetimeReaders are responsible for reading in and processing datetime data within NetCDF4 datasets. Different models encode time in different ways. Hence, we introduce a family of objects to account for all possible approaches.

get_datetime(dataset, time_index=None)[source]

Get dates/times for the given dataset

Must be implemented in a derived class.

Parameters
  • dataset (Dataset) – Dataset object for an FVCOM data file.

  • time_index (int, optional) – The time index at which to extract data.

class pylag.datetime_reader.DefaultDateTimeReader(config, config_section_name)[source]

Bases: DateTimeReader

Default Datetime reader

Default datetime readers read in datetime information from a single variable in the NetCDF dataset. The name of the time variable should be given in the run config file. If one is not given, it defaults to the name time.

Parameters
  • config (ConfigParser) – A run configuration object,

  • config_section_name (str) – String identifying the type of data the time variable is associated with.

get_datetime(dataset, time_index=None)[source]

Get dates/times for the given dataset

This function searches for the basic variable time. If a given source of data uses a different variable name or approach to saving time points, support for them can be added through subclassing (as with FVCOM) DateTimeReader.

Parameters
  • dataset (Dataset) – Dataset object for an FVCOM data file.

  • time_index (int, optional) – The time index at which to extract data. Default behaviour is to return the full time array as datetime objects.

Returns

  • list[datetime] – If time_index is None, return a full list of datetime objects.

  • Datetime – If time_index is not None, a single datetime object.

class pylag.datetime_reader.FVCOMDateTimeReader(config, config_section_name)[source]

Bases: DateTimeReader

FVCOM Datetime reader

FVCOM datetime readers read in datetime information from a NetCDF input file generated by FVCOM.

Variables
  • config (ConfigParser) – See Parameters.

  • config_section_name (str) – See Parameters.

  • rounding_interval (int) – Apply rounding to datetime object using this interval, which is given in seconds.

Parameters
  • config (ConfigParser) – A run configuration object,

  • config_section_name (str) – String identifying the type of data the time variable is associated with.

get_datetime(dataset, time_index=None)[source]

Get FVCOM dates/times for the given dataset

The time variable in FVCOM has the lowest precision. Instead, we construct the time array from the Itime and Itime2 vars, before then constructing datetime objects.

Parameters
  • dataset (Dataset) – Dataset object for an FVCOM data file.

  • time_index (int, optional) – The time index at which to extract data. Default behaviour is to return the full time array as datetime objects.

Returns

  • list[datetime] – If time_index is None, return a full list of datetime objects.

  • Datetime

pylag.datetime_reader.get_datetime_reader(config, config_section_name)[source]

Factory method for datetime readers

There is a hierarchy of data sources. At the top level, the source may be associated with ocean, atmosphere or wave data. Below that, in principle, there are multiple types of ocean, atmosphere and wave data. The top-level data source must be specified through the appropriate config section name. This is then used to construct the required date time reader.

Parameters
  • config (ConfigParser) – Configuration object

  • config_section_name (str) – String identifying the type of data the time variable is associated with (e.g. WAVE_DATA, ATMOSPHERE_DATA etc).

Returns

A DatetimeReader.

Return type

DatetimeReader