pulsarbat.readers.BaseReader#

class pulsarbat.readers.BaseReader(*, shape, dtype, signal_type=<class 'pulsarbat.core.Signal'>, sample_rate, start_time=None, **signal_kwargs)[source]#

Base class for readers.

Subclasses must either implement the _read_array() method if using the default .read() implementation, or implement their own .read() method.

Parameters
shapetuple of int

Signal shape.

dtypedtype

Data-type of signal data.

signal_typesubclass of Signal, default: Signal

Type of signal that will be returned by read().

sample_rateQuantity

The number of samples per second. Must be in units of frequency.

start_timeTime, optional

Timestamp at first sample of signal data. Default is None.

**signal_kwargs

Additional kwargs to pass on to signal_type when creating a Signal object.

Attributes

dt

Sample spacing (1 / sample_rate).

dtype

Data-type of data.

ndim

Number of dimensions in data.

sample_rate

Sample rate of the signal data.

sample_shape

Shape of a sample.

shape

Shape of data.

start_time

Timestamp at first sample.

stop_time

Timestamp after last sample.

time_length

Length of signal in time units.

Methods

contains(t, /)

Whether time(s) are within the bounds of the signal.

dask_read(offset, n, /, **kwargs)

Read n samples from given offset using Dask arrays.

offset_at(t, /)

Returns nearest integer offset at given time.

read(offset, n, /, **kwargs)

Read n samples from given offset.

time_at(offset, /[, unit])

Returns time at given offset.

contains(t, /)[source]#

Whether time(s) are within the bounds of the signal.

dask_read(offset, n, /, **kwargs)[source]#

Read n samples from given offset using Dask arrays.

A convenience method equivalent to the read() method with use_dask=True.

Parameters
offsetint

Position to read from. Must be non-negative.

nint

Number of samples to read. Must be non-negative.

**kwargs

See read() for list of supported kwargs.

Returns
Signal

Signal of length n containing data that was read as a Dask array.

offset_at(t, /)[source]#

Returns nearest integer offset at given time.

Parameters
tQuantity or Time

Can be an absolute time as an astropy Time object, or an astropy Quantity in time units relative to the start.

Returns
int

The nearest integer position (in number of samples).

read(offset, n, /, **kwargs)[source]#

Read n samples from given offset.

Parameters
offsetint

Position to read from. Must be non-negative.

nint

Number of samples to read. Must be non-negative.

**kwargs

Currently supported keyword arguments:

  • use_dask – Whether to use dask arrays.

  • chunks – Chunk sizes if using dask arrays. By default, there is no chunking along the zeroth dimension.

Returns
Signal

Signal of length n containing data that was read.

time_at(offset, /, unit=None)[source]#

Returns time at given offset.

Parameters
offsetint

Position in number of samples.

unitUnit, optional

Desired unit of returned value (as an astropy unit). By default (None), the absolute timestamp is returned.

Returns
Quantity or Time

Time relative to the start as an astropy Quantity if unit is provided, otherwise an absolute time as an astropy Time object.