A netcdf-like variable consisting of dimensions, data and attributes which describe a single Array. A single Variable object is not fully described outside the context of its parent Dataset (if you want such a fully described object, use a DataArray instead). The main functional dif
| 345 | |
| 346 | |
| 347 | class Variable(NamedArray, AbstractArray, VariableArithmetic): |
| 348 | """A netcdf-like variable consisting of dimensions, data and attributes |
| 349 | which describe a single Array. A single Variable object is not fully |
| 350 | described outside the context of its parent Dataset (if you want such a |
| 351 | fully described object, use a DataArray instead). |
| 352 | |
| 353 | The main functional difference between Variables and numpy arrays is that |
| 354 | numerical operations on Variables implement array broadcasting by dimension |
| 355 | name. For example, adding a Variable with dimensions `('time',)` to |
| 356 | another Variable with dimensions `('space',)` results in a new Variable |
| 357 | with dimensions `('time', 'space')`. Furthermore, numpy reduce operations |
| 358 | like ``mean`` or ``sum`` are overwritten to take a "dimension" argument |
| 359 | instead of an "axis". |
| 360 | |
| 361 | Variables are light-weight objects used as the building block for datasets. |
| 362 | They are more primitive objects, so operations with them provide marginally |
| 363 | higher performance than using DataArrays. However, manipulating data in the |
| 364 | form of a Dataset or DataArray should almost always be preferred, because |
| 365 | they can use more complete metadata in context of coordinate labels. |
| 366 | """ |
| 367 | |
| 368 | __slots__ = ("_attrs", "_data", "_dims", "_encoding") |
| 369 | |
| 370 | def __init__( |
| 371 | self, |
| 372 | dims, |
| 373 | data: T_DuckArray | np.typing.ArrayLike, |
| 374 | attrs=None, |
| 375 | encoding=None, |
| 376 | fastpath=False, |
| 377 | ): |
| 378 | """ |
| 379 | Parameters |
| 380 | ---------- |
| 381 | dims : str or sequence of str |
| 382 | Name(s) of the the data dimension(s). Must be either a string (only |
| 383 | for 1D data) or a sequence of strings with length equal to the |
| 384 | number of dimensions. |
| 385 | data : array_like |
| 386 | Data array which supports numpy-like data access. |
| 387 | attrs : dict_like or None, optional |
| 388 | Attributes to assign to the new variable. If None (default), an |
| 389 | empty attribute dictionary is initialized. |
| 390 | (see FAQ, :ref:`approach to metadata`) |
| 391 | encoding : dict_like or None, optional |
| 392 | Dictionary specifying how to encode this array's data into a |
| 393 | serialized format like netCDF4. Currently used keys (for netCDF) |
| 394 | include '_FillValue', 'scale_factor', 'add_offset' and 'dtype'. |
| 395 | Well-behaved code to serialize a Variable should ignore |
| 396 | unrecognized encoding items. |
| 397 | """ |
| 398 | super().__init__( |
| 399 | dims=dims, data=as_compatible_data(data, fastpath=fastpath), attrs=attrs |
| 400 | ) |
| 401 | |
| 402 | self._encoding: dict[Any, Any] | None = None |
| 403 | if encoding is not None: |
| 404 | self.encoding = encoding |
no outgoing calls
searching dependent graphs…