calamari.catalog.Catalog#

class calamari.catalog.Catalog(df, root)#

Bases: object

A 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. A Catalog remembers 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 new Catalog – the same bargain as restrict() – 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, and cat[mask] filters, so any pandas expression still works.

Iterating a Catalog yields 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, so plot_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 by of_type("AC") still loads with its VSM rows – and a chi plot’s source='auto' refuses it, since it offers both an AC chi and a DC moment. Pass source='ac' on a tree that may hold combined runs.

The repr is the logbook – see __repr__().

Parameters:
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 root: Path#

The directory the relative_path column resolves against.

property paths: list[Path]#

Every row’s file as an absolute path, in row order.

property parse_errors: list[tuple[str, str]]#

(path, error message) for each file the build failed to parse.

property n_scanned: int#

Files the build’s walk found, before any parse failures.

property name_collision_differs: list[str]#

Filenames in both dedup_between groups with differing content.

where(**criteria)#

Rows matching every column=value equality, 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=None matches rows where the column is missing (pandas NaN/None), so where(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 raises KeyError naming the columns that do, because that is a typo, not a selection.

Return type:

Catalog

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_type column reads 'VSM+AC', so the equality filter where(measurement_type="AC") silently misses it – the same trap as m.measurement_type == 'AC' on a loaded file, and the same fix. of_type("AC") matches 'AC' and 'VSM+AC' alike, using the vocabulary of measurement_types. An empty result is an ordinary answer (a directory may hold no AC runs), matching where() rather than the loaded-file of_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’s source= when the rows must be one family.

Return type:

Catalog

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 within tol of 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 with scan_kind and the logbook’s H = 1 T cells. Give T_K, H_Oe, or both (both must hold).

Return type:

Catalog

drop(*filenames)#

Everything except the named files, as a new Catalog.

A filename that matches no row raises CatalogSelectionError rather 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 on relative_path to distinguish copies.

Return type:

Catalog

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:

Catalog

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:

Catalog

deduplicated()#

The rows not flagged as verified duplicates, as a new Catalog.

The method form of deduplicated(). Byte-equality flags are recorded by build_catalog() with dedup_between=; without that comparison all rows remain. Files are not rechecked here.

Return type:

Catalog

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:

list

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(). Raises CatalogSelectionError unless 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-based logbook() always sorts by date. Pass delimiter='\t' for spreadsheet-ready lines.

Return type:

list[str]