pyconform.physarray¶
Physical Array Class
This module contains the PhysArray class, which is the primary object passed along edges of a Data Flow graph. It is a subclass of the Numpy MaskedArray, and carries with its data the units associated with the data, the dimensions associated with each axis of the data.
Copyright 2017-2020, University Corporation for Atmospheric Research LICENSE: See the LICENSE.rst file for details
-
class
pyconform.physarray.
CharArray
(indata, name=None, dimensions=None)[source]¶ Bases:
pyconform.physarray.PhysArray
Special kind of PhysArray to deal with string arrays
-
convert
(units)[source]¶ Return a new PhysArray with new units
- Parameters
units (Unit) – The new units to which to convert the PhysArray
-
property
positive
¶ Positive direction (up or down) for the data
-
transpose
(*dims)[source]¶ Return a new PhysArray with dimensions transposed in the order given
Does nothing if no transpose is necesary
- Parameters
dims (tuple) – Tuple of dimension names in the new order
-
property
units
¶ Units of the data
-
-
exception
pyconform.physarray.
DimensionsError
[source]¶ Bases:
ValueError
Exception indicating an error involving dimensions of a PhysArray object
-
class
pyconform.physarray.
PhysArray
(indata, name=None, units=None, dimensions=None, positive='', **kwds)[source]¶ Bases:
numpy.ma.core.MaskedArray
A PhysArray is an array of data with both units and dimensions
The PhysArray is deried from the Numpy MaskedArray and is the basic object along the edges of a Data Flow graph.
-
convert
(units)[source]¶ Return a new PhysArray with new units
- Parameters
units (Unit) – The new units to which to convert the PhysArray
-
property
dimensions
¶ Named dimensions of the data
-
down
()[source]¶ Set the direction of the positive attribute to ‘down’ and multiply by -1, if necessary
Only multiplies by -1 if the positive attribute is already set to ‘up’.
-
flip
()[source]¶ Flip the direction of the positive attribute, if set, and correspondingly multiply by -1
Does nothing if the positive attribute is not set (i.e., equals None)
-
mean
(dimensions=None, **kwds)[source]¶ Returns the average of the array elements along given axis.
Masked entries are ignored, and result elements which are not finite will be masked.
Refer to numpy.mean for full documentation.
See also
numpy.ndarray.mean()
corresponding function for ndarrays
numpy.mean()
Equivalent function
numpy.ma.average()
Weighted average.
Examples
>>> a = np.ma.array([1,2,3], mask=[False, False, True]) >>> a masked_array(data=[1, 2, --], mask=[False, False, True], fill_value=999999) >>> a.mean() 1.5
-
property
name
¶ String name for the data
-
property
positive
¶ Positive direction (up or down) for the data
-
sum
(dimensions=None, **kwds)[source]¶ Return the sum of the array elements over the given axis.
Masked elements are set to 0 internally.
Refer to numpy.sum for full documentation.
See also
numpy.ndarray.sum()
corresponding function for ndarrays
numpy.sum()
equivalent function
Examples
>>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4) >>> x masked_array( data=[[1, --, 3], [--, 5, --], [7, --, 9]], mask=[[False, True, False], [ True, False, True], [False, True, False]], fill_value=999999) >>> x.sum() 25 >>> x.sum(axis=1) masked_array(data=[4, 5, 16], mask=[False, False, False], fill_value=999999) >>> x.sum(axis=0) masked_array(data=[8, 5, 12], mask=[False, False, False], fill_value=999999) >>> print(type(x.sum(axis=0, dtype=np.int64)[0])) <class 'numpy.int64'>
-
transpose
(*dims)[source]¶ Return a new PhysArray with dimensions transposed in the order given
Does nothing if no transpose is necesary
- Parameters
dims (tuple) – Tuple of dimension names in the new order
-
property
units
¶ Units of the data
-
-
exception
pyconform.physarray.
UnitsError
[source]¶ Bases:
ValueError
Exception indicating an error involving units of a PhysArray object
-
pyconform.physarray.
getdimensions
(obj)[source]¶ Retrieve the dimensions-tuple associated with the object