opendrift.readers.basereader.variables
Module Contents
Classes
Projection, spatial and temporal domain of reader. 

Handles reading and interpolation of variables. 
Functions
 opendrift.readers.basereader.variables.logger
 class opendrift.readers.basereader.variables.ReaderDomain[source]
Bases:
opendrift.timer.Timeable
Projection, spatial and temporal domain of reader.
 name
 proj4
 proj
 lon
 lat
 xmin
 xmax
 ymin
 ymax
 zmin
 zmax
 delta_x
 delta_y
 shape
 start_time
 end_time
 time_step
 times
Setting this to True overrides temporal and spatial bounds checks. Also useful for readers that are constant and do not have a temporal dimension.
 always_valid = False
 rotate_vectors(self, reader_x, reader_y, u_component, v_component, proj_from, proj_to)[source]
Rotate vectors from one crs to another.
 lonlat2xy(self, lon, lat)[source]
Calculate lon,lat from given x,y (scalars/arrays) in own projection.
 covers_positions_xy(self, x, y, z=0)[source]
Return indices of input points covered by reader.
Arguments in native projection of reader.
 domain_grid(self, npoints=1000)[source]
Return arrays of lon,lat points spread evenly over reader domain.
 check_arguments(self, variables, time, x, y, z)[source]
Check validity of arguments input to method get_variables.
Checks that requested positions and time are within coverage of this reader, and that it can provide the requested variable(s). Returns the input arguments, possibly modified/corrected (below)
 Arguments:
See function get_variables for definition.
 Returns:
variables: same as input, but converted to list if given as string.
time: same as input, or start_time of reader if given as None.
x, y, z: same as input, but converted to ndarrays if given as scalars.
 outside: boolean array which is True for any particles outside
the spatial domain covered by this reader.
Raises:
ValueError:
if requested time is outside coverage of reader.
if all requested positions are outside coverage of reader.
 class opendrift.readers.basereader.variables.Variables[source]
Bases:
opendrift.readers.basereader.variables.ReaderDomain
Handles reading and interpolation of variables.
Initialize self. See help(type(self)) for accurate signature.
 variables
 derived_variables
 name
 buffer = 0
 set_buffer_size(self, max_speed)[source]
Adjust buffer to minimise data block size needed to cover elements.
The buffer size is calculated from the maximum anticpated speed. Seeding over a large area or over longer time can easily cause particles to be located outside the block. This is not critical, but causes interpolation to be onesided in time for the relevant particles.
Args:
max_speed: the maximum speed anticipated for particles.
 static __check_variable_array__(name, variable)[source]
Ensure arrays are not masked arrays and that values are within valid ranges.
 __check_env_arrays__(self, env)[source]
Ensure arrays are not masked arrays and that values are within valid ranges.
See also
Disabled in StructuredReader because variables are valided before entered into interpolator:
 abstract _get_variables_interpolated_(self, variables, profiles, profiles_depth, time, reader_x, reader_y, z)[source]
This method _must_ be implemented by every reader. Usually by subclassing one of the reader types (e.g.
structured.StructuredReader
).Arguments are in _native projection_ of reader.
 get_variables_interpolated_xy(self, variables, profiles=None, profiles_depth=None, time=None, x=None, y=None, z=None, rotate_to_proj=None)[source]
Get variables in native projection of reader.
 get_variables_interpolated(self, variables, profiles=None, profiles_depth=None, time=None, lon=None, lat=None, z=None, rotate_to_proj=None)[source]
get_variables_interpolated is the main interface to
opendrift.basemodel.OpenDriftSimulation
, and is responsible for returning variables at the correct positions.Readers should implement
_get_variables_interpolated_()
. Arguments:
 variables: string, or list of strings (standard_name) of
requested variables. These must be provided by reader.
profiles: List of variable names that should be returned for the range in profiles_depth.
profiles_depth: A range [zstart, zend] for which to return values for profilevariables. The exact zdepth are given by the reader and returned as z variable in env_profiles.
 time: datetime or None, time at which data are requested.
Can be None (default) if reader/variable has no time dimension (e.g. climatology or landmask).
lon: longitude, 1d array.
lat: latitude, 1d array, same length as lon.
 z: float or ndarray; vertical position (in meters, positive up)
of requested points. either scalar or same length as lon, lat. default: 0 m (unless otherwise documented by reader)
block: bool, see return below
rotate_to_proj: N/A
Returns:
(env, env_profiles)
Interpolated variables at x, y and z. env contains values at a fixed depth (z), while env_profiles contains depthprofiles in the range profile_depth for the variables listed in profiles for each element (in x, y). The exact depth is determined by the reader and specified in env_profiles[‘z’]. Thus variables in env_profiles are not interpolated in zdirection.
See also