goldpan.runmeta¶
Run metadata (high voltage, trigger setting, …) per event, from a table keyed by series.
Metadata applies to whole series, but an analysis needs it per event: a cut, a histogram, a colour. This joins the two in
one pass over the events. numpy.unique(series, return_inverse=True) finds the few distinct series and the inverse index
picks the table row of each event, so there is no string comparison per event and no pandas merge:
from goldpan import runmeta
meta = runmeta.read_table("series.csv") # a CSV with a `series` column and any others
cols = runmeta.per_event(q["series"], meta) # {"hv_v": array, "trigger_value": array, ...}, one value per event
sel = (cols["hv_v"] == -34.0) & (cols["trigger_value"] == 2)
for key, idx in runmeta.groups(q["series"], meta, by=("hv_v", "trigger_value")):
print(key, len(idx)) # idx: the indices of the events of that chunk
The table is data and is not in this library. Where it lives (a file next to the outputs, or the detector registry) is
not decided here: every function takes the table as an argument. Numeric columns come back as float arrays (an empty cell
is NaN), the others as text. The series column is always text. write_table writes such a table (a program that makes the
file, such as a form in a browser, builds the columns and calls it); read_table of the file gives the same table back.
Functions
|
Yield |
|
One value per event for each metadata column, as |
|
Read a CSV with a |
|
Write a table ( |
- goldpan.runmeta.read_table(path)[source]¶
Read a CSV with a
seriescolumn into{column: numpy array}.A column whose every cell is a number becomes a float array (an empty cell is NaN), any other column stays text.
seriesalways stays text: names such as07221121_2214are numbers tofloat(it accepts underscores). A series listed twice is an error.
- goldpan.runmeta.write_table(path, table)[source]¶
Write a table (
{column: sequence}, asread_tablegives it) to the CSV filepathand return whatread_tablegives for that file.tableneeds aseriescolumn (text, every series once), written first; the other columns follow in the order of the mapping and have as many values asseries. A column is all numbers (Noneor NaN is an empty cell) or all text (Noneis an empty cell), so the file reads back the same: a text column whose every cell looks like a number, or that mixes the two, is an error that names the column, and so are true/false values and a table without rows. Nothing is written when the table is refused.
- goldpan.runmeta.per_event(series, table, columns=None)[source]¶
One value per event for each metadata column, as
{column: array}in the order ofseries.seriesis theseriescolumn of the events. A series that is not intableis an error that names it.columnspicks which table columns to return (default: all butseries).