Mixin that provides folder/glob expansion and robust
parsing orchestration for Jones J-format collections.
The mixin augments a stateful base (e.g.,
JCBBase) with helpers to normalize user input
paths, expand folders and wildcards, deduplicate
candidates, and parse items using a tolerant strategy.
Implementations typically use
JFile as the per-item reader,
but the mixin is agnostic to the concrete class as long
as it exposes a compatible from_file constructor.
Notes
The design keeps discovery and parsing separate. First
the mixin expands and filters path candidates; then the
owning class decides how to instantiate items and how to
record failures. This separation avoids tight coupling
and keeps error handling clear.
The mixin favors permissive heuristics while still
catching obvious mistakes (non-files, unreadable paths,
extensions that are unlikely to be J-format, etc.).
Combines JCBBase (state container) with
JCollectionMixin (discovery/orchestration) to
offer a convenient interface for batch loading, quick
metadata browsing, and simple filtering over many J files.
Optional, serialize a CSV/TSV inventory for the
collection.
Notes
The collection is intentionally lightweight. It does not
enforce a database schema, and it avoids implicitly
reading large arrays until needed. This makes it suitable
for quick exploration and CI tests.
Error handling is conservative: unreadable paths or parse
errors are usually skipped with a warning (unless
strict=True is requested).
Exports all JFile items to a directory with advanced options.
This method orchestrates the writing of each JFile in the collection
to a specified directory, with flexible naming, error handling, and
an optional summary CSV file.
Parameters:
output_dir (Pathish) – The path to the directory where files will be saved. It will
be created if it does not exist.
file_pattern (str, default="{station}.j") – A format string for output filenames. Can use attributes of
JFile like {station}, {name}, {site}.
export_summary (bool, default=False) – If True, a summary of the collection will also be saved as a
CSV file in the output directory.
summary_filename (str, default="summary.csv") – The name of the summary file if export_summary is True.
**jfile_write_kwargs – Keyword arguments to be passed directly to each JFile.write()
call (e.g., datatype=”ZRT”, overwrite=True).
Returns:
A dictionary with two keys:
- ‘successful’: A list of paths to successfully written files.
- ‘failed’: A list of tuples, where each tuple contains the
Fetches JFile objects from the collection based on specified criteria.
This method provides a flexible way to search for J-format files
by site name, geographic coordinates, or any other attribute of
the JFile object or its nested Heads sections.
Parameters:
site (str, optional) – The site or station name to search for. The comparison is
case-insensitive.
lat (float, optional) – The latitude to search for, in decimal degrees.
lon (float, optional) – The longitude to search for, in decimal degrees.
tol (float, default=0.001) – The tolerance in decimal degrees for geographic coordinate
searches. A match is found if the absolute difference is
within this tolerance.
first (bool, default=False) – If True, returns only the first matching JFile object found,
or None if no match is found. If False, returns a list of
all matching objects.
**kwargs (Any) – Additional keyword arguments to match against attributes of
the JFile object or its nested Heads object (e.g.,
acqby=’Contractor’). The attribute name is case-insensitive.
Returns:
If first=True, returns the first matching JFile or None.
If first=False, returns a list of all matching JFile objects.
An empty list is returned if no matches are found.