String patterns support a minimal glob syntax. * matches
any sequence (possibly empty) and ? matches any single
character. If you need full regular expressions, pass a
compiled re.Pattern.
When multiple patterns are given, the match is an OR over all
patterns. Matching uses the station name as returned by
station_name(ed) which reflects header normalization.
Select sites by zero-based numeric indices, supporting negative
indices.
Indices are normalized exactly like Python sequence indexing:
-1 addresses the last item, -2 the one before last,
and so on. Out-of-range or non-integer indices are ignored.
The resulting subset preserves the original ordering of the
selected items, not the order in which indices are provided.
Parameters:
sites (Any) – A Sites instance, an
EDICollection, a sequence of EDIFile objects,
or any iterable yielding EDI-like objects.
indices (Iterable[int] or int) – One index or an iterable of indices. Negative indices
are supported and mapped to their Python equivalents.
Returns:
A new Sites wrapper containing only items at the
requested positions. If no valid indices remain after
normalization, an empty Sites is returned.
Duplicate indices are de-duplicated in the output since the
selection is implemented as a membership test over the set
of normalized indices. The relative order of kept items is
the same as in the original sequence.
Examples
>>> frompycsamt.site.baseimportSites>>> frompycsamt.site.selectionimportby_index>>> sites=Sites([e1,e2,e3])# names: A, B, C>>> out=by_index(sites,[0,-1])# first and last>>> [s.nameforsinout]['A', 'C']
>>> out=by_index(sites,1)# single integer>>> [s.nameforsinout]['B']
>>> out=by_index(sites,[10,-10])# both invalid -> empty>>> len(out)0
Select sites whose stored chainage falls within a closed
interval.
This helper reads the chainage value first from the EDI
HEAD section (head.chainage) and, if missing, from a
top-level attribute edi.chainage. Sites for which a
numeric chainage cannot be determined are silently skipped.
Parameters:
sites (Any) – A Sites instance, an
EDICollection, a sequence of EDIFile objects, or
any iterable yielding EDI-like items.
Chainage is a linear reference commonly used along profiles
or lines, typically measured in meters from a chosen origin.
If chainage is not present on a site, that site is excluded.
The original order of sites is preserved among the kept
items.
Select sites that contain at least one data row with
frequency inside a closed interval.
A site is kept if its frequency array f contains any
finite value satisfying \(fmin \le f \le fmax\). Sites
with empty or non-finite frequency arrays are skipped.
Parameters:
sites (Any) – A Sites instance, an
EDICollection, a sequence of EDIFile objects, or
any iterable yielding EDI-like items.
Frequencies are obtained via
pycsamt.site.utils.get_freq(ed). The check is membership
based (any row in range), not a full slicing or resampling.
Use pycsamt.site.edit.select_freq() to actually subset
rows by frequency.
This is a simple axis-aligned test in lat/lon and does not
handle antimeridian wrapping. If longitudes cross the
antimeridian (for example, from 170 to -170 deg), split the
selection into two boxes and union the results. Coordinates
are retrieved via
pycsamt.site.utils.get_coords().
Select sites using a user-supplied predicate function.
The predicate is called for each EDI-like object and should
return True to keep the site. Any exception raised by the
predicate is caught and treated as a False (site is not
kept). This makes bulk filtering robust against occasional
data issues.
Parameters:
sites (Any) – A Sites instance, an
EDICollection, a sequence of EDIFile objects, or
any iterable yielding EDI-like items.
pred (Callable[[Any], bool]) – Function receiving a single EDI-like object and returning
a boolean.
Returns:
A new Sites wrapper containing only the sites for
which pred(site) returned True.
This function is intended as a coarse pre-filter to remove
empty placeholders and fully invalid sites before more costly
processing. It does not inspect errors or phases, and it does
not modify the data. If a site has a Z container but all
arrays are missing or fully non-finite, the site is dropped.
Filter out sites whose maximum phase-error exceeds a threshold.
For each site, the function inspects the phase-error array
when present (common attribute names are tried, e.g.
_phase_err or phase_err). If no phase-error array is
found, the site is conservatively kept. Otherwise, the
site is kept only when the maximum finite phase-error is less
than or equal to thresh.
Parameters:
sites (Any) – A Sites object, an
EDICollection, a sequence of EDIFile objects, or
any iterable yielding EDI-like items.
thresh (float) – Threshold on phase-error (same units as stored by the
processing pipeline, usually degrees).
Returns:
New wrapper containing only sites that pass the phase
error test.
The check uses a “best effort” attribute lookup and ignores
non-finite values during the maximum computation. If the
phase-error array is entirely missing, the site is kept.
This behavior makes the filter robust when some sites did not
store uncertainty products.
This is a coarse, fast filter that checks structural
presence and basic array availability. It does not test
for NaN-only content; for that, consider
pycsamt.site.selection.keep_finite_z().