calamari.catalog.Catalog#
- class calamari.catalog.Catalog(df, root)#
Bases:
objectA directory’s recognised measurement files: the inventory rows plus the root they resolve against.
The class exists because a bare DataFrame kept losing its
root: every trip back from rows to files – printing a logbook of a filtered inventory, loading the survivors for a family plot – made the caller re-supply the root and re-join the paths by hand. ACatalogremembers it, so the rows and the files stay one object.Selection methods (
where(),of_type(),at(),drop(),sort_by(),select_representative(),deduplicated(), and boolean-mask indexing) each return a newCatalog– the same bargain asrestrict()– so they chain, and the original is never mutated. Only what pandas is clumsy at gets a named method; for everything else the frame itself is one attribute away (cat.df),cat["col"]returns the column, andcat[mask]filters, so any pandas expression still works.Iterating a
Catalogyields its files’ absolute paths, which is what lets the plot helpers consume one directly: every family and map helper accepts paths and loads them itself, soplot_chi_vs_t_family(cat.of_type("AC"))needs no intermediate list.load()is the explicit spelling of the same bridge. What crosses it is a whole file: selection works on rows of the inventory, one per file, so a combined VSM+AC run chosen byof_type("AC")still loads with its VSM rows – and a chi plot’ssource='auto'refuses it, since it offers both an AC chi and a DC moment. Passsource='ac'on a tree that may hold combined runs.The repr is the logbook – see
__repr__().- Parameters:
df (
DataFrame) – Inventory rows asbuild_catalog()produces them (onesummarise()dict per row).root (
Path|str) – Directory therelative_pathcolumn resolves against.
- property df: DataFrame#
The inventory as a plain DataFrame – the pandas escape hatch.
This is the live frame, not a copy: cheap to read, and any pandas expression works on it. Catalog methods never mutate it; treat it the same way.
- property parse_errors: list[tuple[str, str]]#
(path, error message)for each file the build failed to parse.
- property name_collision_differs: list[str]#
Filenames in both
dedup_betweengroups with differing content.
- where(**criteria)#
Rows matching every
column=valueequality, as a new Catalog.The keyword spelling of the boolean-mask filter, for the common case:
cat.where(group="mt_family", scan_kind="T-scan").value=Nonematches rows where the column is missing (pandasNaN/None), sowhere(sample_mass_mg=None)finds the files whose operator left the mass blank. Selecting nothing is an ordinary answer and returns an empty Catalog; a column that does not exist raisesKeyErrornaming the columns that do, because that is a typo, not a selection.- Return type:
- of_type(measurement_type)#
Rows whose file contains the given measurement family.
Composite-aware, which is the reason it exists: a combined run’s
measurement_typecolumn reads'VSM+AC', so the equality filterwhere(measurement_type="AC")silently misses it – the same trap asm.measurement_type == 'AC'on a loaded file, and the same fix.of_type("AC")matches'AC'and'VSM+AC'alike, using the vocabulary ofmeasurement_types. An empty result is an ordinary answer (a directory may hold no AC runs), matchingwhere()rather than the loaded-fileof_type, which raises on a family the file lacks.The two share a name but not a grain: this one keeps files, the loaded-file one keeps rows. A combined run selected here comes back from
load()still'VSM+AC'; take the family from each loaded file ([m.of_type("AC") for m in cat.of_type("AC").load()]) or name the plot’ssource=when the rows must be one family.- Return type:
- at(T_K=None, H_Oe=None, *, t_tol_K=0.5, h_tol_Oe=10.0)#
Rows whose sweep held a setpoint at the given value.
The tolerance filter pandas equality cannot express: a “10000 Oe” isotherm is recorded as 9998.7 Oe, so
where(H_min_Oe=10000)finds nothing. A row matches when the quantity’s whole span[min, max]lies withintolof the value – which also excludes sweeps that merely pass through it, since their span breaks the window. The default tolerances are the held-quantity tolerances used everywhere else (0.5 K, 10 Oe), so “held” here agrees withscan_kindand the logbook’sH = 1 Tcells. GiveT_K,H_Oe, or both (both must hold).- Return type:
- drop(*filenames)#
Everything except the named files, as a new Catalog.
A filename that matches no row raises
CatalogSelectionErrorrather than being ignored: naming a file is a claim that it is in the inventory, and a typo that silently “dropped” nothing would leave the unwanted file in every downstream plot. A name appearing in several rows (the same filename under two subfolders) drops all of them – use a mask onrelative_pathto distinguish copies.- Return type:
- sort_by(*columns, ascending=True)#
The same rows reordered by the given column(s), as a new Catalog.
Row order is presentation order – the repr and
logbook()render it as-is – so this is how the logbook gets a physics ordering:cat.sort_by("H_min_Oe")lists a field family by field, where the build’s default (group, then filename) would string-sort'500Oe'after'4000Oe'. The sort is stable, so earlier orderings survive as tie-breaks in later ones.- Return type:
- select_representative(*, by, prefer_span=None, tol=0.0, keep='widest')#
One representative row per nominal setpoint, as a new Catalog.
The method form of
select_representative()(see there for the policies and their blind spots), so it chains with the other selections:cat.of_type("AC").select_representative(...).- Return type:
- deduplicated()#
The rows not flagged as verified duplicates, as a new Catalog.
The method form of
deduplicated(). Byte-equality flags are recorded bybuild_catalog()withdedup_between=; without that comparison all rows remain. Files are not rechecked here.- Return type:
- load()#
Every row’s file as a loaded Measurement, in row order.
The explicit bridge back to the single-file API – and to anything a Catalog cannot be handed directly. (The plot helpers do not need it: they accept the Catalog itself, loading its paths as they draw.) Loading is eager and unguarded on purpose: these paths came from a walk that already vetted them, so a failure here means the tree changed underneath the catalog, which deserves its raise.
- Return type:
- load_one()#
The single remaining file, loaded – or a refusal naming the count.
The handoff from “select the run” to “inspect the run”:
cat.where(filename="mh_5K.dat").load_one(). RaisesCatalogSelectionErrorunless exactly one row remains, because a filter quietly matching two files and handing back either would be the wrong file half the time, with nothing to show it.
- logbook(*, delimiter=None)#
This catalog as aligned logbook lines, one per row, in row order.
Rendered from the rows alone – no file is re-read – so it is instant and works even if the tree has since moved. Row order is the catalog’s own:
sort_by()is the knob, where the walk-basedlogbook()always sorts by date. Passdelimiter='\t'for spreadsheet-ready lines.