stompy.xr_utils — xarray-related utilities¶
-
stompy.xr_utils.
bundle_components
(ds, new_var, comp_vars, frame, comp_names=None)[source]¶ ds: Dataset new_var: name of the vector-valued variable to create comp_vars: list of variables, one-per component frame: name to give the component dimension, i.e. the name of the
reference framecomp_names: list same length as comp_vars, used to name the components.
-
stompy.xr_utils.
concat_permissive
(srcs, **kw)[source]¶ Small wrapper around xr.concat which fills in nan coordinates where they are missing, in case some of the incoming datasets have more metadata than others.
-
stompy.xr_utils.
decode_sigma
(ds, sigma_v)[source]¶ ds: Dataset sigma_v: sigma coordinate variable. return DataArray of z coordinate implied by sigma_v
-
stompy.xr_utils.
redimension
(ds, new_dims, intragroup_dim=None, inplace=False, save_mapping=False)[source]¶ copy ds, making new_dims into the defining dimensions for variables which share shape with new_dims.
each entry in new_dims must have the same dimension, and must be unidimensional
Example: Dataset:
- coordinates
- sample [0,1,2..100]
- data variables
- date(sample) […] station(sample) […] depth(sample) […] salinity(sample) […]
- We’d like to end up with
- salinity(date,station,profile_sample) depth(date,station,profile_sample)
Or Dataset:
- coordinates
- time […] item […]
- data variables
- x(item) […] y(item) […] z(item) […] salinity(time,time) […,…]
Which you want to become
- Dataset:
- coordinates
- time [.] x [.] y [.] zi [.]
- data variables
- z(x,y,zi) […] salinity(time,x,y,zi) [….]
In other words, replace item with three orthogonal dimensions. Two of the orthogonal dimensions have existing coordinates, and the third is an index to elements within the bin defined by x,y.
save_mapping: create an additional variable in the output which stores the mapping of the linear dimension to the new, orthogonal dimensions
intragroup_dim: introduce an additional dimension to enumerate the original data which map to the same new coordinates.
-
stompy.xr_utils.
sort_dimension
(ds, sort_var, sort_dim, inplace=False)[source]¶ sort_var: variable whose value will be used to sort items along sort_dim. sort_dim must be in sort_var.dims only variables with dimensions the same or a superset of sort_var.dims can/will be sorted.
-
stompy.xr_utils.
structure_to_dataset
(arr, dim, extra={})[source]¶ Convert a numpy structure array to a dataset. arr: structure array. dim: name of the array dimension. can be a tuple with multiple dimension
names if arr.ndim>1.- extra: dict optionally mapping specific fields to additional dimensions
- within that field.
-
stompy.xr_utils.
z_from_sigma
(dataset, variable, interfaces=False, dz=False)[source]¶ Create a z coordinate for variable as a Dataset from the given dataset
- interfaces: False => do nothing related to layer boundaries
- variable name => use the given variable to define interfaces between layers. True => try to infer the variable, fallback to even spacing otherwise.
if interfaces is anything other than False, then the return value will be a Dataset with the centers in a ‘z_ctr’ variable and the interfaces in a ‘z_int’
dz: implies interfaces, and includes a z_dz variable giving thickness of each layer.