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 columnsnamesatrows, which isNone(every row), arange, or an integer index array in any order, repeats allowed.out,{name: array}for some ofnames, 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
ConcatTableat once.
- BLOCK_BYTES = 268435456¶
Bytes of whole HDF5 rows read per block when selecting rows of a dataset.
- as_table(obj)[source]¶
Return
objas a table: a structured array or FITS_rec becomes anArrayTable, an h5py Dataset anHDF5Table; a table is returned as is.
- read_structured(table, names=None, rows=None)[source]¶
Read columns
names(default all) oftableatrowsinto a numpy structured array, in place.
- _outputs(dtype, names, n, out)[source]¶
Return
outwith an emptyn-row array added for each other name.
- class ArrayTable(array)[source]¶
Bases:
objectA 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¶
- class HDF5Table(dataset)[source]¶
Bases:
objectAn h5py compound dataset.
Its rows are stored whole, so a selection is read in one pass for every column wanted, in blocks of
BLOCK_BYTESof 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¶
- class ParquetFile(path, footer, dtype)[source]¶
Bases:
objectOne 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¶
- parquet_dtype(schema, footers=())[source]¶
Return the numpy structured dtype of a parquet schema.
An integer column holding nulls in any of the files
footersreads as float64, NaN where null, as a float column’s nulls do.
- class JoinedFile(file, primary, keys, dtype)[source]¶
Bases:
objectA HATS extension’s pixel file, joined to its primary’s on a key.
dtypenames 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).fileisNonewhere 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¶
- class ConcatTable(tables)[source]¶
Bases:
objectTables stacked end to end.
Its columns are those every table has, each promoted to hold all of them (
group_dtype).concurrenttables are read in parallel threads, at mostMAX_READ_THREADSat once.
- 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 carryingS7andS12tile IDs, orf4next tof8, reads without truncation.tablesis a list or a dict keyed by name for error messages;columnsdefaults to those of the first table. RaisesKeyErrornaming the tables that lack a column.