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[, in_name, out_name])

wind_from_speed_and_direction(env, in_name, out_name)

vector_from_speed_and_direction(env, in_name, out_name)

reverse_direction(env, in_name, out_name)

magnitude_from_components(env, in_name, out_name)

Attributes

logger

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

Returns center of reader (in lon, lat)

rotate_vectors(reader_x, reader_y, u_component, v_component, proj_from, proj_to)[source]
xy2lonlat(x, y)[source]

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

lonlat2xy(lon, lat)[source]

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

y_azimuth(lon, lat)[source]

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

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

String representation of the current reader.

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

Return indices of input points covered by reader.

Arguments in native projection of reader.

modulate_longitude(lons)[source]

Modulate the input longitude to the domain supported by the reader.

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

Return indices of input points covered by reader.

global_coverage()[source]

Return True if global coverage east-west

domain_grid(npoints=1000)[source]

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

coverage_string()[source]

Coverage of reader to be reported as string for debug output

check_arguments(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(time)[source]
nearest_time(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, in_name=None, out_name=None)[source]
opendrift.readers.basereader.variables.wind_from_speed_and_direction(env, in_name, out_name)[source]
opendrift.readers.basereader.variables.vector_from_speed_and_direction(env, in_name, out_name)[source]
opendrift.readers.basereader.variables.reverse_direction(env, in_name, out_name)[source]
opendrift.readers.basereader.variables.magnitude_from_components(env, in_name, out_name)[source]
class opendrift.readers.basereader.variables.Variables[source]

Bases: ReaderDomain

Handles reading and interpolation of variables.

variables
derived_variables
name
buffer = 0
activate_environment_mapping(mapping_name)[source]
__calculate_derived_environment_variables__(env)[source]
set_buffer_size(max_speed, time_coverage=None)[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 (m/s): the maximum speed anticipated for particles. time_coverage (timedelta): the time span to cover

__check_env_coordinates__(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__(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_(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(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(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: Profiles variables will be retrieved from surface and down to this depth. 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.