MBItem

class bapsf_motion.motion_builder.item.MBItem(ds: Dataset, base_name: str, name_pattern: Pattern)

Bases: ABC

A base class for any motion builder class that will interact with the xarray Dataset containing the motion builder configuration.

Parameters:
  • ds (Dataset) – The xarray Dataset the motion builder configuration is constructed in.

  • base_name (str) – A string representing the base name for the motion builder item in the Dataset ds.

  • name_pattern (str, re.Pattern) – A raw string r'' or re.Pattern representing the naming pattern for associated motion builder items in the Dataset. For example, if the base_name is 'player', then an appropriate pattern would look like r'player(?P<number>[0-9]+)'.

Attributes Summary

base_name

Base name for associated items in the Dataset.

item

The representative motion builder item in the Dataset.

mask

A \(N\)-D DataArray representing a boolean mask of the motion space.

mask_name

Name of the mask item it the Dataset.

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.

mspace_dims

Tuple of motion space dimension names.

mspace_ndims

Dimensionality of the motion space.

name

Name of the motion builder item in the Dataset.

name_pattern

The naming pattern for motion builder items in the Dataset.

Methods Summary

drop_vars(names, *[, errors])

Drop variables from this dataset.

Attributes Documentation

base_name

Base name for associated items in the Dataset.

item

The representative motion builder item in the Dataset.

mask

A \(N\)-D DataArray representing a boolean mask of the motion space. The mask is True where a probe drive is allowed to move, and False otherwise.

mask_name

Name of the mask item it the Dataset.

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 to coords of mask.

mspace_dims

Tuple of motion space dimension names. Quick access to dims of mask.

mspace_ndims

Dimensionality of the motion space. Synonymous with the number of axes of the probe drive.

name

Name of the motion builder item in the Dataset.

name_pattern

The naming pattern for motion builder items in the Dataset.

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