Utilities for working with collections of EDIFile
objects.
The mixin adds non-IO helpers that operate on a set of
items already loaded in memory. Typical operations
include filtering, mapping, grouping, and summarizing.
It is designed to be combined with a small container
base, such as CBBase.
Parameters:
None – This is a mixin. It does not define its own public
constructor parameters.
Variables:
items (dict) – Mapping from collection key (for example the station
id) to EDIFile. Expected to be provided by
the host collection.
order (list of str) – Insertion order of keys. Used to preserve stable
iteration and deterministic summaries.
Notes
The mixin focuses on pure-Python transformations. The
typical methods provided by implementations include:
select(keys=None,predicate=None) : return a new
view with items that match the keys or satisfy the
boolean predicate.
map(func) : apply a callable to each
EDIFile and collect the results in a list.
groupby(keyfunc) : bucket items by a user-defined
key and return a mapping to lists of EDIFile.
summary(fields=('station','n_freq',...)) :
build a compact table of common attributes for quick
inspection.
These helpers do not read from disk and do not mutate
EDIFile content unless explicitly documented by
the host class.
Examples
Filter by station prefix and compute sample counts:
High-level collection of EDIFile objects with
integrated loading and summarization.
The class couples the small container
CBBase with CoreParser to discover,
read, and manage many EDI files at once. Items are
indexed by station id or by absolute path, with a
configurable duplicate policy.
Parameters:
sources (path-like or sequence of path-like, optional) – Files, folders, or glob patterns to load. When
omitted the collection is created empty. Use
load() later to populate it.
recursive (bool, default True) – Recurse into subdirectories when scanning folders.
on_dup ({‘replace’, ‘keep’}, default 'replace') – Duplicate policy for items that share the same key.
With 'replace' the last item wins. With
'keep' the first item is preserved.
index_by ({‘station’, ‘path’}, default 'station') – Key used to index items. When 'station' the
EDIFile.station is preferred with a fallback to
file path if unspecified.
strict (bool, default False) – If True read errors are raised. If False
they are captured and available via
errors().
verbose (int, default 0) – Verbosity forwarded to the underlying
EDIFile readers.
Return a list of (path,exception) pairs from the
last load() call.
Notes
The class aims to be pragmatic. Loading is done with a
single pass of CoreParser. Summaries are built
from lightweight attributes that are cheap to access,
such as station, number of frequencies, and section
presence. Heavy analysis should be implemented outside
the collection to keep the API small.
Examples
Load a folder, keep first duplicates, and summarize:
Fetch EDI files by station, coordinates, or other metadata.
This method searches the collection for
EDIFile objects by
station name, geographic coordinates, or any
attribute exposed on the EDI or its >HEAD
section.
Parameters:
site (str or int or float, optional) – Station selector. Case-insensitive. Numeric-like
values are normalized using the active
StationNamePolicy
and station-variant expansion. Variants tried
include the raw token, integer form, zero-padded
prefix form (e.g. S150), and common ×10
slips (1500 <-> 150).
lat (float, optional) – Latitude in decimal degrees. Compared against the
>HEAD field lat using the tolerance
tol.
lon (float, optional) – Longitude in decimal degrees. Compared against the
>HEAD field long using the tolerance
tol.
tol (float, default 0.001) – Absolute tolerance (decimal degrees) used when
matching lat and lon.
first (bool, default False) – If True, return only the first matching object
or None if no match (unless strict=True,
see Raises). If False, return a list of all
matches (possibly empty).
strict (bool, default False) – If True and no match is found, raise
SiteError with a
helpful message suggesting
<collection>.stations().
**kwargs (Any) – Additional attribute filters. Keys are matched
(case-insensitive) first on the EDI object, then
on its head section. String values compare in
a case-insensitive way; non-strings compare by
equality.
Returns:
If first=True, an EDIFile or None
when no match and strict=False. If
first=False, a list of matches (possibly
empty).
SiteError – Raised when no match is found and strict=True.
The error message lists available stations and
suggests calling <collection>.stations().
Notes
Station matching expands candidate variants using the
active StationNamePolicy and a small set of
robust transforms (integer form, zero-padded with
prefix, and common ×10 slips).
Geographic matching uses absolute tolerance on decimal
degrees and compares against >HEAD fields lat
and long.
Arbitrary filters in **kwargs are applied after
station and coordinate tests. String comparisons are
case-insensitive; other types use equality.
Examples
>>> # List available stations>>> coll.stations()['S150', 'S200', 'S250', 'S300', ...]
>>> # Fetch a single station by numeric label>>> ed=coll.fetch(site=150,first=True)
>>> # Enforce a helpful error when not found>>> coll.fetch(site='S999',first=True,strict=True)Traceback (most recent call last):...SiteError: No station found. Try one of: ...
>>> # Fetch by coordinates within tolerance>>> ed=coll.fetch(lat=-22.37,lon=139.19,first=True)
>>> # Filter by metadata on >HEAD (case-insensitive)>>> zs=coll.fetch(acqby='Zonge')