2.13.2.5. pycsamt.stratagem.rename#

stratagem.rename#

EDI file renaming and rewriting utilities for Stratagem post-processing.

EDIRenamer

Rename a set of EDI files on disk according to a configurable basename, zero-pad width, and trailer, mirroring the watex.utils.rename_files workflow used in the legacy pipeline. Simultaneously updates the >HEAD DATAID and linked section SECTID fields so the EDI content stays consistent with the new filename.

EDIWriter

Write a list of in-memory EDIFile objects to a directory, with optional renaming and >HEAD metadata overrides (station name / DATAID, acquisition info, etc.).

Both classes follow the fit() out() pattern used by all stratagem classes.

Classes

EDIRenamer(*[, basename, zero_pad, trailer, ...])

Rename Stratagem EDI files with a standardised naming convention.

EDIWriter(*[, dataid_prefix, zero_pad, ...])

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: PyCSAMTObject

Rename Stratagem EDI files with a standardised naming convention.

Reads each source EDI, updates >HEAD.DATAID and the linked SECTID fields 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.' produces T2.000.edi, T2.001.edi, …

  • zero_pad (int, default 3) – Width of the zero-padded integer part ('T2.000' has zero_pad=3).

  • trailer (str, default '') – Optional string appended after the index (before .edi).

  • update_dataid (bool, default True) – When True, >HEAD.DATAID and all linked SECTID fields are updated to match the new filename stem.

  • overwrite (bool, default False) – Overwrite existing files in dst_path.

  • verbose (int, default 0)

Variables:
  • renamed_pairs (list of (Path, Path)) – (src, dst) path pairs for every file that was processed.

  • skipped (list of Path) – Source files skipped because the destination already existed and overwrite=False.

Examples

Rename processed EDIs to T2.000.ediT2.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 .edi files in it (natural-sort order).

    • A list of EDIFile objects (e.g. from NoiseRemover.edi_objects_).

    • A list of pathlib.Path EDI paths.

  • dst_path (path-like) – Output directory. Created if absent.

Return type:

self

dst_paths()[source]

Return the list of written destination paths.

Return type:

list[Path]

class pycsamt.stratagem.rename.EDIWriter(*, dataid_prefix=None, zero_pad=3, overwrite=False, verbose=0)[source]

Bases: PyCSAMTObject, MetadataMixin

Write in-memory EDIFile objects to disk with optional HEAD overrides.

Provides a thin, consistent wrapper around write() that also allows batch update of >HEAD fields (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:
  • written (list of Path) – Paths of successfully written files.

  • failed (list of tuple(str, Exception)) – (filename, exc) for any file that could not be written.

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 S000S082:

>>> 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.

Parameters:
  • edi_objects (list of EDIFile)

  • savepath (path-like) – Output directory.

  • head_overrides (dict, optional) – Key-value pairs applied to every EDI’s >HEAD object before writing. Keys must be valid HEAD attribute names (e.g. 'acqby', 'stdvers').

Return type:

self