Module Contents



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



class opendrift.models.basemodel.environment.Environment(required_variables, required_profiles_z_range, _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
required_profiles_z_range: List[float]
discarded_readers: Dict
__finalized__ = False
finalize(simulation_extent=None, start=None, end=None)[source]

Prepare environment for simulation.


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]
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.


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


Return list of all variables provided by the added readers.


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’.


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


Returns reader if successful and None if no more readers

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

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

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

Retrieve environmental variables at requested positions.


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: ?

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]

environment: recarray with variables as named attributes,

interpolated to requested positions/time.

get_variables_along_trajectory(variables, lons, lats, times)[source]