sp_validation.tables

Tables: where a catalogue’s rows are stored, behind one interface.

A table is anything with

  • dtype: a numpy structured dtype naming its columns, each with the dtype (and any subarray shape) it reads as, known without reading rows;

  • len(table): its number of rows;

  • read(names, rows=None, out=None): {name: array} holding columns names at rows, which is None (every row), a range, or an integer index array in any order, repeats allowed. out, {name: array} for some of names, receives their values in place (e.g. the fields of a structured array) and is what is returned for them;

  • row_major: whether reading any column reads whole rows from disk, so a selection of rows is best read for every column at once;

  • concurrent: whether reads of several such tables gain from running in parallel threads.

ArrayTable (a numpy structured array or FITS_rec, in memory or memory-mapped), HDF5Table (an h5py compound dataset) and ParquetFile store rows; JoinedFile is a HATS extension’s pixel file joined to its primary’s on a key; ConcatTable stacks tables end to end. grammar.V2View presents any of them in the v2 column grammar, and is itself a table.

MAX_READ_THREADS = 32

Upper bound on the threads reading the tables of a ConcatTable at once.

BLOCK_BYTES = 268435456

Bytes of whole HDF5 rows read per block when selecting rows of a dataset.

as_table(obj)[source]

Return obj as a table: a structured array or FITS_rec becomes an ArrayTable, an h5py Dataset an HDF5Table; a table is returned as is.

read_structured(table, names=None, rows=None)[source]

Read columns names (default all) of table at rows into a numpy structured array, in place.

_outputs(dtype, names, n, out)[source]

Return out with an empty n-row array added for each other name.

_deliver(columns, out)[source]

Copy columns into the arrays out holds for some of them.

_contiguous(rows, n)[source]

Return (start, stop) if rows is every row or a unit-step range.

class ArrayTable(array)[source]

Bases: object

A numpy structured array or FITS_rec, in memory or memory-mapped.

Reading every row of a column returns the array’s own column, so a memory-mapped FITS table is read only where it is indexed.

row_major = False
concurrent = False
read(names, rows=None, out=None)[source]
class HDF5Table(dataset)[source]

Bases: object

An h5py compound dataset.

Its rows are stored whole, so a selection is read in one pass for every column wanted, in blocks of BLOCK_BYTES of whole rows over its span written straight into the output, skipping blocks that hold no selected row: each byte of the file is read at most once. h5py serialises all reads on one lock, so datasets are not read concurrently.

row_major = True
concurrent = False
read(names, rows=None, out=None)[source]
class ParquetFile(path, footer, dtype)[source]

Bases: object

One parquet file, read by row windows of some columns.

Only the row-group sizes are kept from the footer: a parsed footer holds every column’s statistics (~2 MB each on run1-snap3-hats, GBs over a catalogue), so each read parses it afresh, once for all its columns. A read touches only the row groups spanning its rows. Null values read as NaN in floating columns (an integer column holding nulls reads as float64, see parquet_dtype), as None in string columns, and raise in any other.

row_major = False
concurrent = True
read(names, rows=None, out=None)[source]
_window(names, start, stop)[source]
parquet_dtype(schema, footers=())[source]

Return the numpy structured dtype of a parquet schema.

An integer column holding nulls in any of the files footers reads as float64, NaN where null, as a float column’s nulls do.

class JoinedFile(file, primary, keys, dtype)[source]

Bases: object

A HATS extension’s pixel file, joined to its primary’s on a key.

dtype names the extension’s own columns. A read returns them for the primary’s rows: each row takes the extension row whose join column equals its own (keys: this file’s join column, the primary’s), and a row with none takes null (NaN in a floating column, None in a string column; another column cannot hold null, and a read that needs one raises). file is None where the extension has no file for the pixel. An extension may hold the primary’s rows in its own order or only some of them; one holding them in the same order is read at the same rows.

row_major = False
concurrent = True
read(names, rows=None, out=None)[source]
class ConcatTable(tables)[source]

Bases: object

Tables stacked end to end.

Its columns are those every table has, each promoted to hold all of them (group_dtype). concurrent tables are read in parallel threads, at most MAX_READ_THREADS at once.

read(names, rows=None, out=None)[source]
group_dtype(tables, columns=None)[source]

Return the structured dtype of a group of row-chunk tables.

Each column is promoted across every table (np.promote_types), so a partially reprocessed campaign carrying S7 and S12 tile IDs, or f4 next to f8, reads without truncation. tables is a list or a dict keyed by name for error messages; columns defaults to those of the first table. Raises KeyError naming the tables that lack a column.