opendrift.readers.basereader.variables

Module Contents

Classes

ReaderDomain

Projection, spatial and temporal domain of reader.

Variables

Handles reading and interpolation of variables.

Functions

land_binary_mask_from_ocean_depth(env)

wind_from_speed_and_direction(env)

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
center(self)[source]

Returns center of reader (in lon, lat)

rotate_vectors(self, reader_x, reader_y, u_component, v_component, proj_from, proj_to)[source]

Rotate vectors from one crs to another.

xy2lonlat(self, x, y)[source]

Calculate x,y in own projection from given lon,lat (scalars/arrays).

lonlat2xy(self, lon, lat)[source]

Calculate lon,lat from given x,y (scalars/arrays) in own projection.

y_azimuth(self, lon, lat)[source]

Calculate azimuth orientation of the y-axis of the reader CRS.

pixel_size(self)[source]
_coverage_unit_(self)[source]
__repr__(self)[source]

String representation of the current reader.

covers_positions_xy(self, x, y, z=0)[source]

Return indices of input points covered by reader.

Arguments in native projection of reader.

covers_positions(self, lon, lat, z=0)[source]

Return indices of input points covered by reader.

global_coverage(self)[source]

Return True if global coverage east-west

domain_grid(self, npoints=1000)[source]

Return arrays of lon,lat points spread evenly over reader domain.

coverage_string(self)[source]

Coverage of reader to be reported as string for debug output

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.

covers_time(self, time)[source]
nearest_time(self, time)[source]

Return nearest times before and after the requested time.

Returns:

nearest_time: datetime time_before: datetime time_after: datetime indx_nearest: int indx_before: int indx_after: int

opendrift.readers.basereader.variables.land_binary_mask_from_ocean_depth(env)[source]
opendrift.readers.basereader.variables.wind_from_speed_and_direction(env)[source]
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
activate_environment_mapping(self, mapping_name)[source]
__calculate_derived_environment_variables__(self, env)[source]
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 one-sided in time for the relevant particles.

Args:

max_speed: the maximum speed anticipated for particles.

__check_env_coordinates__(self, env)[source]

Make sure x and y are floats (and not e.g. int64)

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:

structured.StructuredReader.__check_env_arrays__()

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 [z-start, z-end] for which to return values for profile-variables. The exact z-depth 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 depth-profiles 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 z-direction.