pylag.mediator module

The module provides a set of classes to assist with communication between objects of type DataReader and objects of type FileReader. Primarily, the mediator module was introduced in order to abstract away the MPI interface, making it easier to PyLag either in serial or parallel. It also assists with testing.

class pylag.mediator.Mediator[source]

Bases: object

Base class for objects of type Mediator.

Mediators manage data transfers between FileReaders and other objects. Data transfers are typically between objects of type FileReader and objects of type DataReader. The decoupling between FileReader and DataReader objects was put in place in order to support parallel simulations where it is preferable for just a single process to access the file system.

get_dimension_variable(var_name)[source]

Wrapper for FileReader’s get_dimension_variable

Parameters:

var_name (str) – The name of the dimension variable.

Returns:

The size of the dimensions variable.

Return type:

int

get_grid_variable(var_name, var_dims, var_type)[source]

Wrapper for FileReader’s get_grid_variable

Parameters:

var_name (str) – The name of the variable.

Returns:

The the grid variable.

Return type:

NDArray

get_grid_variable_dimensions(var_name)[source]

Wrapper for FileReader’s get_grid_variable_dimensions

Parameters:

var_name (str) – The name of the variable.

Returns:

The variable’s dimensions

Return type:

tuple(str)

get_mask_at_last_time_index(var_name, var_dims)[source]

Wrapper for FileReader’s function of the same name

Parameters:
  • var_name (str) – The name of the variable.

  • var_dims (tuple) – Tuple of variable dimensions.

Returns:

The variable array

Return type:

NDArray

get_mask_at_next_time_index(var_name, var_dims)[source]

Wrapper for FileReader’s function of the same name

Parameters:
  • var_name (str) – The name of the variable.

  • var_dims (tuple) – Tuple of variable dimensions.

Returns:

The variable array

Return type:

NDArray

get_time_at_last_time_index()[source]

Wrapper for FileReader’s get_time_at_last_time_index

Returns:

The time at the last time index.

Return type:

float

get_time_at_next_time_index()[source]

Wrapper for FileReader’s get_time_at_next_time_index

Returns:

The time at the last time index.

Return type:

float

get_time_dependent_variable_at_last_time_index(var_name, var_dims, var_type)[source]

Wrapper for FileReader’s function of the same name

Parameters:
  • var_name (str) – The name of the variable.

  • var_dims (tuple) – Tuple of variable dimensions.

  • var_type (type) – The variable type.

Returns:

The variable array

Return type:

NDArray

get_time_dependent_variable_at_next_time_index(var_name, var_dims, var_type)[source]

Wrapper for FileReader’s function of the same name

Parameters:
  • var_name (str) – The name of the variable.

  • var_dims (tuple) – Tuple of variable dimensions.

  • var_type (type) – The variable type.

Returns:

The variable array

Return type:

NDArray

get_variable_dimensions(var_name, include_time=True)[source]

Wrapper for FileReader’s get_variable_dimension

Parameters:
  • var_name (str) – The name of the variable.

  • include_time (bool) – If True, the time dimension is included. Optional, default is True.

Returns:

The variable’s dimensions

Return type:

tuple(str)

get_variable_shape(var_name, include_time=True)[source]

Wrapper for FileReader’s get_variable_shape

Parameters:
  • var_name (str) – The name of the variable.

  • include_time (bool) – If True, the time dimension is included. Optional, default is True.

Returns:

The variable’s shape

Return type:

tuple(int)

setup_data_access(start_datetime, end_datetime)[source]

Wrapper for FileReader’s setup_data_access

Parameters:
  • start_datetime (Datetime) – Simulation start date/time.

  • end_datetime (Datetime) – Simulation end date/time.

update_reading_frames(time)[source]

Wrapper for FileReader’s update_reading_frames

Parameters:

time (float) – Time

class pylag.mediator.SerialMediator(config, data_source, datetime_start, datetime_end)[source]

Bases: Mediator

Serial mediator

Serial mediator for serial runs.

Parameters:
  • config (ConfigParser) – Run configuration object

  • data_source (str) – String indicating what type of data the datetime objects will be associated with. Options are: ‘ocean’, ‘atmosphere’, and ‘wave’.

  • start_datetime (Datetime) – Simulation start date/time.

  • end_datetime (Datetime) – Simulation end date/time.

Variables:
  • config (ConfigParser) – Run configuration object

  • file_reader (pylag.FileReader) – FileReader object.

get_dimension_variable(var_name)[source]

Wrapper for FileReader’s get_dimension_variable

Parameters:

var_name (str) – The name of the dimension variable.

Returns:

The size of the dimensions variable.

Return type:

int

get_grid_variable(var_name, var_dims, var_type)[source]

Wrapper for FileReader’s get_grid_variable

Parameters:

var_name (str) – The name of the variable.

Returns:

The the grid variable.

Return type:

NDArray

get_grid_variable_dimensions(var_name)[source]

Wrapper for FileReader’s get_grid_variable_dimensions

Parameters:

var_name (str) – The name of the variable.

Returns:

The variable’s dimensions

Return type:

tuple(str)

get_mask_at_last_time_index(var_name, var_dims)[source]

Wrapper for FileReader’s function of the same name

Parameters:
  • var_name (str) – The name of the variable.

  • var_dims (tuple) – Tuple of variable dimensions.

Returns:

The variable array

Return type:

NDArray

get_mask_at_next_time_index(var_name, var_dims)[source]

Wrapper for FileReader’s function of the same name

Parameters:
  • var_name (str) – The name of the variable.

  • var_dims (tuple) – Tuple of variable dimensions.

Returns:

The variable array

Return type:

NDArray

get_time_at_last_time_index()[source]

Wrapper for FileReader’s get_time_at_last_time_index

Returns:

The time at the last time index.

Return type:

float

get_time_at_next_time_index()[source]

Wrapper for FileReader’s get_time_at_next_time_index

Returns:

The time at the last time index.

Return type:

float

get_time_dependent_variable_at_last_time_index(var_name, var_dims, var_type)[source]

Wrapper for FileReader’s function of the same name

Parameters:
  • var_name (str) – The name of the variable.

  • var_dims (tuple) – Tuple of variable dimensions.

  • var_type (type) – The variable type.

Returns:

The variable array

Return type:

NDArray

get_time_dependent_variable_at_next_time_index(var_name, var_dims, var_type)[source]

Wrapper for FileReader’s function of the same name

Parameters:
  • var_name (str) – The name of the variable.

  • var_dims (tuple) – Tuple of variable dimensions.

  • var_type (type) – The variable type.

Returns:

The variable array

Return type:

NDArray

get_variable_dimensions(var_name, include_time=True)[source]

Wrapper for FileReader’s get_variable_dimension

Parameters:
  • var_name (str) – The name of the variable.

  • include_time (bool) – If True, the time dimension is included. Optional, default is True.

Returns:

The variable’s dimensions

Return type:

tuple(str)

get_variable_shape(var_name, include_time=True)[source]

Wrapper for FileReader’s get_variable_shape

Parameters:
  • var_name (str) – The name of the variable.

  • include_time (bool) – If True, the time dimension is included. Optional, default is True.

Returns:

The variable’s shape

Return type:

tuple(int)

setup_data_access(datetime_start, datetime_end)[source]

Wrapper for FileReader’s setup_data_access

Parameters:
  • start_datetime (Datetime) – Simulation start date/time.

  • end_datetime (Datetime) – Simulation end date/time.

update_reading_frames(time)[source]

Wrapper for FileReader’s update_reading_frames

Parameters:

time (float) – Time