2.13.2.5. pycsamt.stratagem.rename#
stratagem.rename#
EDI file renaming and rewriting utilities for Stratagem post-processing.
EDIRenamerRename a set of EDI files on disk according to a configurable basename, zero-pad width, and trailer, mirroring the
watex.utils.rename_filesworkflow used in the legacy pipeline. Simultaneously updates the>HEADDATAIDand linked sectionSECTIDfields so the EDI content stays consistent with the new filename.EDIWriterWrite a list of in-memory
EDIFileobjects to a directory, with optional renaming and>HEADmetadata overrides (station name / DATAID, acquisition info, etc.).
Both classes follow the fit() → out() pattern used by all stratagem
classes.
Classes
|
Rename Stratagem EDI files with a standardised naming convention. |
|
Write in-memory EDIFile objects to disk with optional HEAD overrides. |
- class pycsamt.stratagem.rename.EDIRenamer(*, basename='S', zero_pad=3, trailer='', update_dataid=True, overwrite=False, verbose=0)[source]
Bases:
PyCSAMTObjectRename Stratagem EDI files with a standardised naming convention.
Reads each source EDI, updates
>HEAD.DATAIDand the linkedSECTIDfields to match the new name, then writes the result to dst_path (keeping the source files untouched).- Parameters:
basename (str, default
'S') – Name prefix. E.g.'T2.'producesT2.000.edi,T2.001.edi, …zero_pad (int, default 3) – Width of the zero-padded integer part (
'T2.000'haszero_pad=3).trailer (str, default
'') – Optional string appended after the index (before.edi).update_dataid (bool, default True) – When True,
>HEAD.DATAIDand all linkedSECTIDfields are updated to match the new filename stem.overwrite (bool, default False) – Overwrite existing files in dst_path.
verbose (int, default 0)
- Variables:
Examples
Rename processed EDIs to
T2.000.edi…T2.082.edi:>>> rn = EDIRenamer(basename="T2.", zero_pad=3) >>> rn.fit("2/2EDIP", "2/renamedEDIs")
Or rename in-memory objects produced by the processing pipeline:
>>> rn.fit(nr.edi_objects_, "2/renamedEDIs")
- fit(source, dst_path)[source]
Rename EDI files and write them to dst_path.
- Parameters:
source (path-like, list of EDIFile, or list of Path) –
Input EDI files. Accepts:
A directory path — all
.edifiles in it (natural-sort order).A list of
EDIFileobjects (e.g. fromNoiseRemover.edi_objects_).A list of
pathlib.PathEDI paths.
dst_path (path-like) – Output directory. Created if absent.
- Return type:
self
- class pycsamt.stratagem.rename.EDIWriter(*, dataid_prefix=None, zero_pad=3, overwrite=False, verbose=0)[source]
Bases:
PyCSAMTObject,MetadataMixinWrite in-memory EDIFile objects to disk with optional HEAD overrides.
Provides a thin, consistent wrapper around
write()that also allows batch update of>HEADfields (DATAID, ACQBY, DATAID prefix, etc.) before writing.- Parameters:
dataid_prefix (str, optional) – When set, each station’s DATAID is overwritten with
f"{dataid_prefix}{i:0{zero_pad}d}". Useful for standardising station identifiers across a profile.zero_pad (int, default 3) – Zero-pad width used with dataid_prefix.
overwrite (bool, default False)
verbose (int, default 0)
- Variables:
Examples
Write the noise-corrected EDIs, keeping original file names:
>>> wr = EDIWriter() >>> wr.fit(nr.edi_objects_, "2/final") >>> wr.written_
Write with standardised DATAID
S000…S082:>>> wr = EDIWriter(dataid_prefix="S", zero_pad=3) >>> wr.fit(nr.edi_objects_, "2/final")
- fit(edi_objects, savepath, *, head_overrides=None)[source]
Write edi_objects to savepath.