caput.tod

Data formats for Time Ordered Data.

This module contains data containers, data formats, and utilities based on caput.memh5. The data represented must have an axis representing time, and, in particular, concatenating multiple datasets along a time axis must be a sensible operation.

class caput.tod.Reader(files, file_format=None)[source]

Bases: object

Provides high level reading of time ordered data.

Parses and stores meta-data from file headers allowing for the interpretation and selection of the data without reading it all from disk.

Parameters
  • files (filename, h5py.File or list there-of or filename pattern) – Files containing data. Filename patterns with wild cards (e.g. “foo*.h5”) are supported.

  • file_format (fileformats.FileFormat) – File format to use. Default None (format will be guessed).

data_class

alias of caput.tod.TOData

property dataset_sel

Which datasets to read.

Returns

dataset_sel – Names of datasets to read.

Return type

tuple of strings

property datasets

Datasets available in data files.

property files

Data files.

read(out_group=None)[source]

Read the selected data.

Parameters

out_group (h5py.Group, hdf5 filename or memh5.Group) – Underlying hdf5 like container that will store the data for the BaseData instance.

Returns

data – Data read from files based on the selections made by user.

Return type

TOData

select_time_range(start_time=None, stop_time=None)[source]

Sets time_sel to include a time range.

The times from the samples selected will have bin centre timestamps that are bracketed by the given start_time and stop_time.

Parameter time should be in the same format as TOData.time, and mush be comparable through standard comparison operator (<, >=, etc.). Conversion using TOData.convert_time() is attempted.

Parameters
  • start_time (scalar time) – Affects the first element of time_sel. Default leaves it unchanged.

  • stop_time (scalar time) – Affects the second element of time_sel. Default leaves it unchanged.

property time

Time bin centres in data files.

property time_sel

Start and stop indices to read in the frequency axis.

Returns

time_sel – Start and stop indices for reading along the time axis.

Return type

pair of ints

class caput.tod.TOData(*args, **kwargs)[source]

Bases: caput.memh5.BasicCont

Time ordered data.

Inherits from caput.memh5.BasicCont. A data container in with all the functionality of its base class but with the concept of a time axis which can be concatenated over. Currently the time axis must be the fastest varying axis is present.

static convert_time(time)[source]

Overload to provide support for multiple time formats.

Method accepts scalar times in supported formats and converts them to the same format as self.time.

classmethod from_mult_files(files, data_group=None, start=None, stop=None, datasets=None, dataset_filter=None, **kwargs)[source]

Create new data object by concatenating a series of objects.

:param Accepts any parameter for concatenate() (which controls the: :param concatenation) or this class’s constructor (which controls the: :param initialization of each file). By default: :param each file is opened with: :param ondisk=True and mode=’r’.:

property time

Representation of the “time” axis.

The value of self.index_map['time'].

caput.tod.concatenate(data_list, out_group=None, start=None, stop=None, datasets=None, dataset_filter=None, convert_attribute_strings=True, convert_dataset_strings=False)[source]

Concatenate data along the time axis.

All TOData objects to be concatenated are assumed to have the same datasets and index_maps with compatible shapes and data types.

Currently only ‘time’ axis concatenation is supported, and it must be the fastest varying index.

All attributes, history, and other non-time-dependant information is copied from the first item.

Parameters
  • data_list (list of TOData. These are assumed to be identical in) – every way except along the axes representing time, over which they are concatenated. All other data and attributes are simply copied from the first entry of the list.

  • out_group (h5py.Group, hdf5 filename or memh5.Group) – Underlying hdf5 like container that will store the data for the BaseData instance.

  • start (int or dict with keys data_list[0].time_axes) – In the aggregate datasets at what index to start. Every thing before this index is excluded.

  • stop (int or dict with keys data_list[0].time_axes) – In the aggregate datasets at what index to stop. Every thing after this index is excluded.

  • datasets (sequence of strings) – Which datasets to include. Default is all of them.

  • dataset_filter (callable with one or two arguments) – Function for preprocessing all datasets. Useful for changing data types etc. Takes a dataset as an arguement and should return a dataset (either h5py or memh5). Optionally may accept a second argument that is slice along the time axis, which the filter should apply.

  • convert_attribute_strings (bool, optional) – Try and convert attribute string types to unicode. Default is True.

  • convert_dataset_strings (bool, optional) – Try and convert dataset string types to unicode. Default is False.

Returns

data

Return type

TOData

caput.tod.ensure_file_list(files)[source]

Tries to interpret the input as a sequence of files

Expands filename wildcards (“globs”) and casts sequeces to a list.