tidy3d.components.data.data_array.DataArray#
- class DataArray[source]#
Bases:
DataArray
Subclass of
xr.DataArray
that requires _dims to match the keys of the coords.Attributes
Absolute value of data array.
Whether each element is of equal value in the data array
The array's data converted to a numpy.ndarray.
Methods
__init__
(data, *args, **kwargs)assign_coord_attrs
(val)Assign the correct coordinate attributes to the
DataArray
.assign_data_attrs
(val)Assign the correct data attributes to the
DataArray
.check_unloaded_data
(val)If the data comes in as the raw data array string, raise a custom warning.
from_file
(fname, group_path)Load an DataArray from an hdf5 file with a given path to the group.
from_hdf5
(fname, group_path)Load an DataArray from an hdf5 file with a given path to the group.
interp
([coords, method, assume_sorted, kwargs])Interpolate this DataArray to new coordinate values.
item
(*args)Copy an element of an array to a standard Python scalar and return it.
multiply_at
(value, coord_name, indices)Multiply self by value at indices.
searchsorted
(v[, side, sorter])Find indices where elements of v should be inserted in a to maintain order.
to_hdf5
(fname, group_path)Save an xr.DataArray to the hdf5 file or file handle with a given path to the group.
to_hdf5_handle
(f_handle, group_path)Save an xr.DataArray to the hdf5 file handle with a given path to the group.
validate_dims
(val)Make sure the dims are the same as _dims, then put them in the correct order.
Inherited Common Usage
- classmethod __get_validators__()[source]#
Validators that get run when
DataArray
objects are added to pydantic models.
- classmethod check_unloaded_data(val)[source]#
If the data comes in as the raw data array string, raise a custom warning.
- classmethod validate_dims(val)[source]#
Make sure the dims are the same as _dims, then put them in the correct order.
- classmethod assign_coord_attrs(val)[source]#
Assign the correct coordinate attributes to the
DataArray
.
- property values#
The array’s data converted to a numpy.ndarray.
- Returns:
The values of the DataArray.
- Return type:
np.ndarray
- property abs#
Absolute value of data array.
- property is_uniform#
Whether each element is of equal value in the data array
- to_hdf5(fname, group_path)[source]#
Save an xr.DataArray to the hdf5 file or file handle with a given path to the group.
- to_hdf5_handle(f_handle, group_path)[source]#
Save an xr.DataArray to the hdf5 file handle with a given path to the group.
- classmethod from_hdf5(fname, group_path)[source]#
Load an DataArray from an hdf5 file with a given path to the group.
- classmethod from_file(fname, group_path)[source]#
Load an DataArray from an hdf5 file with a given path to the group.
- __hash__()[source]#
Generate hash value for a :class:.`DataArray` instance, needed for custom components.
- interp(coords=None, method='linear', assume_sorted=False, kwargs=None, **coords_kwargs)[source]#
Interpolate this DataArray to new coordinate values.
- Parameters:
coords (Union[Mapping[Any, Any], None] = None) – A mapping from dimension names to new coordinate labels.
method (InterpOptions = "linear") – The interpolation method to use.
assume_sorted (bool = False) – If True, skip sorting of coordinates.
kwargs (Union[Mapping[str, Any], None] = None) – Additional keyword arguments to pass to the interpolation function.
**coords_kwargs (Any) – The keyword arguments form of coords.
- Returns:
A new DataArray with interpolated values.
- Return type:
- Raises:
KeyError – If any of the specified coordinates are not in the DataArray.
- item(*args)#
Copy an element of an array to a standard Python scalar and return it.
- Parameters:
*args (Arguments (variable number and type)) –
none: in this case, the method only works for arrays with one element (a.size == 1), which element is copied into a standard Python scalar object and returned.
int_type: this argument is interpreted as a flat index into the array, specifying which element to copy and return.
tuple of int_types: functions as does a single int_type argument, except that the argument is interpreted as an nd-index into the array.
- Returns:
z – A copy of the specified element of the array as a suitable Python scalar
- Return type:
Standard Python scalar object
Notes
When the data type of a is longdouble or clongdouble, item() returns a scalar array object because there is no available Python scalar that would not lose information. Void arrays return a buffer object for item(), unless fields are defined, in which case a tuple is returned.
item is very similar to a[args], except, instead of an array scalar, a standard Python scalar is returned. This can be useful for speeding up access to elements of the array and doing arithmetic on elements of the array using Python’s optimized math.
Examples
>>> import numpy as np >>> np.random.seed(123) >>> x = np.random.randint(9, size=(3, 3)) >>> x array([[2, 2, 6], [1, 3, 6], [1, 0, 1]]) >>> x.item(3) 1 >>> x.item(7) 0 >>> x.item((0, 1)) 2 >>> x.item((2, 2)) 1
For an array with object dtype, elements are returned as-is.
>>> a = np.array([np.int64(1)], dtype=object) >>> a.item() #return np.int64 np.int64(1)
- searchsorted(v, side='left', sorter=None)#
Find indices where elements of v should be inserted in a to maintain order.
For full documentation, see numpy.searchsorted
See also
numpy.searchsorted
equivalent function