Array#

class gwpy.types.Array(
value: QuantityLike,
*,
unit: UnitBase | str | None = None,
name: str | None = None,
epoch: SupportsToGps | None = None,
channel: Channel | str | None = None,
dtype: DTypeLike = None,
copy: bool = True,
subok: bool = True,
order: str | None = None,
ndmin: int = 0,
)[source]#

Bases: Quantity

Array holding data with a unit, and other metadata.

This Array holds the input data and a standard set of metadata properties associated with GW data.

Parameters:
valuearray_like

Input data array.

unitUnit

Physical unit of these data.

epochLIGOTimeGPS, float, str

GPS epoch associated with these data, any input parsable by to_gps is fine

namestr

Descriptive title for this array.

channelChannel, str

Source data stream for these data.

dtypedtype

Input data type.

copybool

Choose to copy the input data to new memory.

subokbool

Allow passing of sub-classes by the array generator.

Returns:
arrayArray

A new array, with a view of the data, and all associated metadata.

Examples

To create a new Array from a list of samples:

>>> a = Array([1, 2, 3, 4, 5], 'm/s', name='my data')
>>> print(a)
Array([ 1., 2., 3., 4., 5.]
      unit: Unit("m / s"),
      name: 'my data',
      epoch: None,
      channel: None)

Attributes Summary

channel

Instrumental channel associated with these data.

epoch

GPS epoch associated with these data.

name

Name for this data set.

unit

The physical unit of these data.

Methods Summary

abs(**kwargs)

Return the absolute value of the data in this Array.

copy([order])

Return a copy of the array.

flatten([order])

Return a copy of the array collapsed into one dimension.

median([axis])

Return the median of the data in this Array.

override_unit(unit[, parse_strict])

Reset the unit of these data.

Attributes Documentation

channel[source]#

Instrumental channel associated with these data.

epoch[source]#

GPS epoch associated with these data.

name[source]#

Name for this data set.

unit[source]#

The physical unit of these data.

Methods Documentation

abs(**kwargs) Self | Quantity[source]#

Return the absolute value of the data in this Array.

See also

numpy.absolute

For details of all available positional and keyword arguments, and for details of the return value.

copy(order='C')[source]#

Return a copy of the array.

Parameters:
order{‘C’, ‘F’, ‘A’, ‘K’}, optional

Controls the memory layout of the copy. ‘C’ means C-order, ‘F’ means F-order, ‘A’ means ‘F’ if a is Fortran contiguous, ‘C’ otherwise. ‘K’ means match the layout of a as closely as possible. (Note that this function and numpy.copy() are very similar but have different default values for their order= arguments, and this function always passes sub-classes through.)

See also

numpy.copy

Similar function with different default behavior

numpy.copyto

Notes

This function is the preferred method for creating an array copy. The function numpy.copy() is similar, but it defaults to using order ‘K’, and will not pass sub-classes through by default.

Examples

>>> import numpy as np
>>> x = np.array([[1,2,3],[4,5,6]], order='F')
>>> y = x.copy()
>>> x.fill(0)
>>> x
array([[0, 0, 0],
       [0, 0, 0]])
>>> y
array([[1, 2, 3],
       [4, 5, 6]])
>>> y.flags['C_CONTIGUOUS']
True

For arrays containing Python objects (e.g. dtype=object), the copy is a shallow one. The new array will contain the same object which may lead to surprises if that object can be modified (is mutable):

>>> a = np.array([1, 'm', [2, 3, 4]], dtype=object)
>>> b = a.copy()
>>> b[2][0] = 10
>>> a
array([1, 'm', list([10, 3, 4])], dtype=object)

To ensure all elements within an object array are copied, use copy.deepcopy:

>>> import copy
>>> a = np.array([1, 'm', [2, 3, 4]], dtype=object)
>>> c = copy.deepcopy(a)
>>> c[2][0] = 10
>>> c
array([1, 'm', list([10, 3, 4])], dtype=object)
>>> a
array([1, 'm', list([2, 3, 4])], dtype=object)
flatten(order: str = 'C') Quantity[source]#

Return a copy of the array collapsed into one dimension.

Any index information is removed as part of the flattening, and the result is returned as a Quantity array.

Parameters:
order{‘C’, ‘F’, ‘A’, ‘K’}

‘C’ means to flatten in row-major (C-style) order. ‘F’ means to flatten in column-major (Fortran- style) order. ‘A’ means to flatten in column-major order if a is Fortran contiguous in memory, row-major order otherwise. ‘K’ means to flatten a in the order the elements occur in memory. The default is ‘C’.

Returns:
yQuantity

A copy of the input array, flattened to one dimension.

See also

ravel

Return a flattened array.

flat

A 1-D flat iterator over the array.

Examples

>>> a = Array([[1,2], [3,4]], unit='m', name='Test')
>>> a.flatten()
<Quantity [1., 2., 3., 4.] m>
median(
axis: int | Iterable[int] | None = None,
**kwargs,
) Self | Quantity[source]#

Return the median of the data in this Array.

See also

numpy.median

For details of all available positional and keyword arguments, and for details of the return value.

override_unit(
unit: UnitLike,
parse_strict: Literal['raise', 'warn', 'silent'] = 'raise',
) None[source]#

Reset the unit of these data.

Use of this method is discouraged in favour of to(), which performs accurate conversions from one unit to another. The method should really only be used when the original unit of the array is plain wrong.

Parameters:
unitUnit, str

the unit to force onto this array

parse_strictstr

how to handle errors in the unit parsing, default is to raise the underlying exception from astropy.units

See also

gwpy.detector.units.parse_unit

For details of unit string parsing.