GridCNStepLayer
- class bapsf_motion.motion_builder.layers.regular_grid.GridCNStepLayer(ds: Dataset, center: List[float], npoints: List[int], step_size: List[float], skip_ds_add: bool = False)
Bases:
GridLayerClass for defining a regularly spaced grid. The grid is configured by defining its
center, the number of pointsnpointsalong each dimension, and the step sizestep_sizebetween points.layer type:
'grid_CNStep'- Parameters:
ds (
DataSet) – ThexarrayDatasetthe motion builder configuration is constructed in.center (array_like) – An array-like object containing the center coordinates of the grid. Size
(N, )whereNis the dimensionality of the motion space.npoints (array_like) – An array-like object containing the number of points in the grid along each dimension. Size
(N, )whereNis the dimensionality of the motion space. Each entry indicates the number of points used along the associated axis. For example, a 2D spacenpointswould look like[Nx, Ny].step_size (array_like) – An array-like object containing the step size between grid points along each dimension. Size
(N, )whereNis the dimensionality of the motion space. Each entry indicates the step size for the associated axis. For example, a 2D spacestep_sizewould look like[dx, dy].skip_ds_add (bool) – If
True, then skip generating theDataArraycorresponding to the motion points and adding it to theDataset. This keyword is provided to facilitate functionality of composite layers. (DEFAULT:False)
Examples
Note
The following examples include examples for direct instantiation, as well as configuration passing at the
MotionGroupandRunManagerlevels.Assume we have a 2D motion space and want to define a grid of points centered at
(0, 10)with 21 points along each dimension, and a step size of1along each dimension. This would look like:ly = GridCNStepLayer( ds, center=[0, 10], npoints=[21, 21], step_size=[.1, .1], )
ly = layer_factory( ds, ly_type = "grid_CNStep", **{ "center": [0, 10], "npoints": [21, 21], "step_size": [.1, .1], }, )
[...motion_builder.layers] type = "grid_CNStep" center = [0, 10] npoints = [21, 21] step_size = [0.1, 0.1]
config["motion_builder"]["layers"] = { "type": "grid_CNStep", "center": [0, 10], "npoints": [21, 21], "step_size": [.1, .1], }
Attributes Summary
Base name for associated items in the
Dataset.Coordinates for the center of the grid.
Dictionary containing the full configuration of the motion layer.
The designed dimensionality of the point layer.
A dictionary of the configuration inputs passed during layer instantiation.
The representative motion builder item in the
Dataset.String naming the motion layer type.
An array of min and max pairs representing the range along each motion space dimensions that the point layer resides in.
A \(N\)-D
DataArrayrepresenting a boolean mask of the motion space.Tuple containing the spatial resolution of each dimension of the motion space (i.e. grid spacing in each dimension).
Dictionary-like container of motion space coordinates.
Tuple of motion space dimension names.
Dimensionality of the motion space.
Name of the motion builder item in the
Dataset.The naming pattern for motion builder items in the
Dataset.The number of points used along each dimension of the motion space.
The
DataArrayassociate with the layer.Grid point steps size along each spatial dimension.
The number of points used along each dimension of the motion space.
List of dependent motion layers used to make this more complex motion layer.
Methods Summary
drop_vars(names, *[, errors])Drop variables from this dataset.
Re-generated the motion layer, i.e.
points.Attributes Documentation
- center
Coordinates for the center of the grid.
- config
Dictionary containing the full configuration of the motion layer.
- dimensionality
The designed dimensionality of the point layer. If
-1, then the exclusion does not have a fixed dimensionality, and it can morph to the associated motion space.
- inputs
A dictionary of the configuration inputs passed during layer instantiation.
- layer_type
String naming the motion layer type. This is unique among all subclasses of
BaseLayer.
- limits
An array of min and max pairs representing the range along each motion space dimensions that the point layer resides in. Shape
(N, 2)whereNis the dimensionality of the motion space.
- mask
A \(N\)-D
DataArrayrepresenting a boolean mask of the motion space. The mask isTruewhere a probe drive is allowed to move, andFalseotherwise.
- mask_resolution
Tuple containing the spatial resolution of each dimension of the motion space (i.e. grid spacing in each dimension).
- mspace_coords
Dictionary-like container of motion space coordinates. Keys are given by
mspace_dims. Quick access tocoordsofmask.
- mspace_dims
Tuple of motion space dimension names. Quick access to
dimsofmask.
- mspace_ndims
Dimensionality of the motion space. Synonymous with the number of axes of the probe drive.
- npoints
The number of points used along each dimension of the motion space. Shape
(N, )whereNis the dimensionality of the motion space.
- points
The
DataArrayassociate with the layer. If the layer has not been generated, then it will be done automatically.
- step_size
Grid point steps size along each spatial dimension.
- steps
The number of points used along each dimension of the motion space. Shape
(N, )whereNis the dimensionality of the motion space.Deprecated since v0.2.4
- composed_layers: List[BaseLayer]
List of dependent motion layers used to make this more complex motion layer.
Methods Documentation
- drop_vars(names: str, *, errors: Literal['raise', 'ignore'] = 'raise')
Drop variables from this dataset.
- Parameters:
names (Hashable or iterable of Hashable or Callable) – Name(s) of variables to drop. If a Callable, this object is passed as its only argument and its result is used.
errors ({"raise", "ignore"}, default: "raise") – If ‘raise’, raises a ValueError error if any of the variable passed are not in the dataset. If ‘ignore’, any given names that are in the dataset are dropped and no error is raised.
Examples
>>> dataset = xr.Dataset( ... { ... "temperature": ( ... ["time", "latitude", "longitude"], ... [[[25.5, 26.3], [27.1, 28.0]]], ... ), ... "humidity": ( ... ["time", "latitude", "longitude"], ... [[[65.0, 63.8], [58.2, 59.6]]], ... ), ... "wind_speed": ( ... ["time", "latitude", "longitude"], ... [[[10.2, 8.5], [12.1, 9.8]]], ... ), ... }, ... coords={ ... "time": pd.date_range("2023-07-01", periods=1), ... "latitude": [40.0, 40.2], ... "longitude": [-75.0, -74.8], ... }, ... ) >>> dataset <xarray.Dataset> Size: 136B Dimensions: (time: 1, latitude: 2, longitude: 2) Coordinates: * time (time) datetime64[us] 8B 2023-07-01 * latitude (latitude) float64 16B 40.0 40.2 * longitude (longitude) float64 16B -75.0 -74.8 Data variables: temperature (time, latitude, longitude) float64 32B 25.5 26.3 27.1 28.0 humidity (time, latitude, longitude) float64 32B 65.0 63.8 58.2 59.6 wind_speed (time, latitude, longitude) float64 32B 10.2 8.5 12.1 9.8
Drop the ‘humidity’ variable
>>> dataset.drop_vars(["humidity"]) <xarray.Dataset> Size: 104B Dimensions: (time: 1, latitude: 2, longitude: 2) Coordinates: * time (time) datetime64[us] 8B 2023-07-01 * latitude (latitude) float64 16B 40.0 40.2 * longitude (longitude) float64 16B -75.0 -74.8 Data variables: temperature (time, latitude, longitude) float64 32B 25.5 26.3 27.1 28.0 wind_speed (time, latitude, longitude) float64 32B 10.2 8.5 12.1 9.8
Drop the ‘humidity’, ‘temperature’ variables
>>> dataset.drop_vars(["humidity", "temperature"]) <xarray.Dataset> Size: 72B Dimensions: (time: 1, latitude: 2, longitude: 2) Coordinates: * time (time) datetime64[us] 8B 2023-07-01 * latitude (latitude) float64 16B 40.0 40.2 * longitude (longitude) float64 16B -75.0 -74.8 Data variables: wind_speed (time, latitude, longitude) float64 32B 10.2 8.5 12.1 9.8
Drop all indexes
>>> dataset.drop_vars(lambda x: x.indexes) <xarray.Dataset> Size: 96B Dimensions: (time: 1, latitude: 2, longitude: 2) Dimensions without coordinates: time, latitude, longitude Data variables: temperature (time, latitude, longitude) float64 32B 25.5 26.3 27.1 28.0 humidity (time, latitude, longitude) float64 32B 65.0 63.8 58.2 59.6 wind_speed (time, latitude, longitude) float64 32B 10.2 8.5 12.1 9.8
Attempt to drop non-existent variable with errors=”ignore”
>>> dataset.drop_vars(["pressure"], errors="ignore") <xarray.Dataset> Size: 136B Dimensions: (time: 1, latitude: 2, longitude: 2) Coordinates: * time (time) datetime64[us] 8B 2023-07-01 * latitude (latitude) float64 16B 40.0 40.2 * longitude (longitude) float64 16B -75.0 -74.8 Data variables: temperature (time, latitude, longitude) float64 32B 25.5 26.3 27.1 28.0 humidity (time, latitude, longitude) float64 32B 65.0 63.8 58.2 59.6 wind_speed (time, latitude, longitude) float64 32B 10.2 8.5 12.1 9.8
Attempt to drop non-existent variable with errors=”raise”
>>> dataset.drop_vars(["pressure"], errors="raise") Traceback (most recent call last): ValueError: These variables cannot be found in this dataset: ['pressure']
- Raises:
ValueError – Raised if you attempt to drop a variable which is not present, and the kwarg
errors='raise'.- Returns:
dropped
- Return type:
Dataset
See also
DataArray.drop_vars
- regenerate_point_matrix()
Re-generated the motion layer, i.e.
points.