opendrift.models.basemodel.environment

Attributes

logger

Classes

Environment

Utility class for measuring total time spent in various steps in a class

Module Contents

opendrift.models.basemodel.environment.logger
class opendrift.models.basemodel.environment.Environment(required_variables, _config)[source]

Bases: opendrift.timer.Timeable, opendrift.config.Configurable

Utility class for measuring total time spent in various steps in a class throughout program execution.

readers: OrderedDict
priority_list: OrderedDict
required_variables: Dict
discarded_readers: Dict
proj_latlon
__finalized__ = False
_config
required_profiles
desired_variables
finalize(simulation_extent=None, start=None, end=None)[source]

Prepare environment for simulation.

Args:

simulation_extent: The expected extent of the simulation.

start: Expected start time of simulation.

end: Expected end time of simulation.

prepare_readers(extent, start_time, end_time)[source]
__generate_constant_readers__()[source]
__add_auto_landmask__()[source]
__assert_no_missing_variables__()[source]
add_readers_from_file(filename, timeout=10, lazy=True)[source]
add_readers_from_list(urls, timeout=10, lazy=True, variables=None)[source]

Make readers from a list of URLs or paths to netCDF datasets

add_reader(readers, variables=None, first=False)[source]

Add one or more readers providing variables used by this model.

Method may be called subsequently to add more readers for other variables.

Args:

readers: one or more (list) Reader objects.

variables (optional): list of strings of standard_name of variables to be provided by this/these reader(s). first: Set to True if this reader should be set as first option

list_environment_variables()[source]

Return list of all variables provided by the added readers.

get_reader_groups(variables=None)[source]

Find which groups of variables are provided by the same readers.

This function loops through ‘priority_list’ (see above) and groups all variables returned by the same readers in the same order. This allows asking readers for several variables simultaneously, improving performance. Used by method ‘get_environment’.

Returns:

variable_groups: list of lists of (environment) variables. reader_groups: list of list of reader names, corresponding to each of the variable_groups.

_lazy_readers()[source]
_unlazy_readers()[source]
_initialise_next_lazy_reader()[source]

Returns reader if successful and None if no more readers

discard_reader_if_not_relevant(reader, time)[source]
discard_reader(reader, reason)[source]
missing_variables()[source]

Return list of all variables for which no reader has been added.

get_environment(variables, time, lon, lat, z, profiles=None, profiles_depth=None)[source]

Retrieve environmental variables at requested positions.

Args:

variables: list of variable names

time: time to get environment for

lon: array of longitudes

lat: array of latitudes

z: depth to get value for

profiles: list of variables for which profiles are needed

profiles_depth: depth of profiles in meters, as a positive number

Updates:
Buffer (raw data blocks) for each reader stored for performance:

[readers].var_block_before (last before requested time) [readers].var_block_after (first after requested time) - lists of one ReaderBlock per variable group: time, x, y, [vars]

Returns:
environment: recarray with variables as named attributes,

interpolated to requested positions/time.

get_variables_along_trajectory(variables, lons, lats, times, z=0)[source]