pycsamt.transformers.jedi#

Classes

AVGtoEDI()

Convert a Zonge AVG source to an EDICollection.

JtoEDI()

Convert a Jones J source to EDI or an EDI collection.

class pycsamt.transformers.jedi.AVGtoEDI[source]#

Bases: TransformerMixin

Convert a Zonge AVG source to an EDICollection.

This transformer orchestrates extraction of transfer functions from a Zonge AVG object (or file path), finalizes the neutral payload (TFBundle), and emits EDI objects. The result is always an EDICollection, even for single-site inputs.

The pipeline is:

  1. Parse TFs from the AVG using to_tensor. When Z is not present, fall back to (rho, phase).

  2. Finalize each bundle using TransformerMixin: validate the station name, order and de-duplicate frequencies, and fill missing parts if enabled by the global config.

  3. Materialize EDIFile objects and attach site metadata (e.g., coordinates) if available from avg.topo.frame.

Notes

  • Station naming obeys the global policy from pycsamt.core.config.

  • Frequency sorting and de-duplication follow freq_order and freq_tol.

  • If only (rho, phase) are present, Z can be reconstructed when compute_z_from_res is enabled.

  • If avg.topo exposes a DataFrame-like frame with columns station, latitude, longitude and optionally elevation, a >HEAD section is updated.

See also

pycsamt.core._transformers.TransformerMixin

Provides finalization steps and overridable hooks.

pycsamt.core.base.TFBundle

Neutral, backend-agnostic payload.

pycsamt.seg.edi.EDIFile

Concrete EDI object.

pycsamt.seg.collection.EDICollection

Collection wrapper for multiple EDI files.

Examples

>>> from pycsamt.core.transformers import AVGtoEDI
>>> # path or AVG object are both accepted
>>> # out = AVGtoEDI().transform(\"/path/to/data.avg\")
compute_z_from_res(b)[source]#

Reconstruct Z from apparent resistivity and phase.

If a bundle lacks Z but holds (rho, phase) and the global config enables compute_z_from_res, this method builds a complex tensor whose magnitude and angle satisfy the standard MT relations:

  • |Z| = sqrt( μ0 * ω * ρa )

  • phase is interpreted as milliradians and converted to radians before forming Z = |Z|(cos φ + i sin φ).

Parameters:

b (TFBundle) – Input bundle with rho and phase set.

Returns:

The same bundle with z populated.

Return type:

TFBundle

Notes

Ensure phase units are consistent. Zonge workflows often store milliradians; the implementation converts by dividing by 1000. If units differ, override this method.

References

extract(source)[source]#

Pull the first TFBundle from an AVG object or path.

Parameters:

source (Any) – AVG instance or path to an .avg file.

Returns:

The first available bundle (typically first station).

Return type:

TFBundle

Raises:

ValueError – If no transfer functions could be obtained.

Notes

Multi-station inputs are handled by transform(), which iterates and converts all sites to an EDI collection.

emit_edi(bundle)[source]#

Materialize an EDIFile from a finalized bundle.

Populates Z fields (_freq, _z, _z_err). If Z is missing but (rho, phase) are present, uses the backend method to set resistivity and phase. If tipper data exist, populates tipper arrays and derived attributes.

Parameters:

bundle (TFBundle) – Finalized transfer-function payload.

Returns:

A concrete EDI object.

Return type:

EDIFile

Notes

Errors during optional computations are silenced to keep the transformation robust on imperfect field data.

post_emit(edi_obj, source, bundle)[source]#

Attach station metadata and optional location to the EDI.

This step applies the global station naming policy and, if avg.topo.frame is present, injects coordinates into the >HEAD section.

Parameters:
  • edi_obj (EDIFile) – Newly created EDI object.

  • source (AVG) – Original AVG used to derive the bundle.

  • bundle (TFBundle) – Finalized bundle for this station.

Returns:

The updated EDI object.

Return type:

EDIFile

Notes

When a matching row is found in topo.frame (based on the station column), latitude, longitude and elevation are copied if available.

transform(source, *, name=None, station_id=None)[source]#

Convert an AVG source to an EDICollection.

Handles both objects and file paths. All stations found in the source are extracted, finalized, converted to EDI, and collected.

Parameters:
  • source (Any) – AVG instance or path-like.

  • name (str, optional) – Preferred station name override, applied during finalization when present.

  • station_id (str or int, optional) – Identifier used by the naming policy if a name must be synthesized.

Returns:

A collection of EDIFile objects, one per site.

Return type:

EDICollection

Examples

>>> from pycsamt.core.transformers import AVGtoEDI
>>> # out = AVGtoEDI().transform(\"/path/site.avg\")
class pycsamt.transformers.jedi.JtoEDI[source]#

Bases: TransformerMixin

Convert a Jones J source to EDI or an EDI collection.

This transformer ingests a JFile instance or a path to a .j file, extracts transfer functions (Z, tipper, or fallback rho/phase), finalizes a neutral payload (TFBundle), and emits concrete EDIFile objects. When given a JCollection, it produces an EDICollection.

The pipeline mirrors the AVG workflow:

  1. Extract TF arrays and metadata from the J structure, tolerating variant attribute names often found in legacy files.

  2. Finalize each bundle using the mixin logic: ensure a valid station name, order and de-duplicate frequencies, and fill missing TF parts if configured.

  3. Emit EDI and optionally attach site coordinates if a header-like structure is present on the J side.

Notes

  • Naming, frequency sorting, and de-duplication follow the global configuration in pycsamt.core.config.

  • If only (rho, phase) are present, Z can be reconstructed when allowed by compute_z_from_res (via the mixin hook).

  • A Head or head object on JFile with attributes lat, long, and elev is used to populate the EDI >HEAD section when available.

See also

pycsamt.core._transformers.TransformerMixin

Finalization steps and overridable hooks.

pycsamt.core.transformers.AVGtoEDI

Companion converter for Zonge AVG.

pycsamt.core.base.TFBundle

Neutral payload used across backends.

Examples

>>> from pycsamt.core.transformers import JtoEDI
>>> # Single file → EDIFile
>>> # edi = JtoEDI().transform(\"/path/site.j\")
>>> # Collection → EDICollection
>>> # out = JtoEDI().transform(j_collection)

References

extract(source)[source]#

Extract a TFBundle from a J file or object.

Parameters:

source (Any) – JFile instance or a path to a .j file.

Returns:

Bundle with TF arrays and basic site info.

Return type:

TFBundle

Raises:

ValueError – If no usable transfer functions are present.

Notes

This method does not reorder or de-duplicate; those steps are applied in the finalization phase.

emit_edi(bundle)[source]#

Create an EDIFile from a finalized bundle.

Populates impedance arrays when present. If Z is absent but (rho, phase) are available, the backend call is used to set resistivity/phase onto the EDI structure. Tipper data are also populated when provided.

Parameters:

bundle (TFBundle) – Finalized transfer-function payload.

Returns:

Concrete EDI object ready for downstream use.

Return type:

EDIFile

Notes

Optional computations are guarded; failures are ignored to remain robust on imperfect field data.

post_emit(edi_obj, source, bundle)[source]#

Attach naming and optional coordinates to the EDI.

Applies the global station naming policy and, when the J object exposes a Head/head with lat, long, and elev, updates the EDI header accordingly.

Parameters:
  • edi_obj (EDIFile) – Newly created EDI object.

  • source (JFile) – Original J source used for extraction.

  • bundle (TFBundle) – Finalized bundle for this site.

Returns:

The same EDI object, augmented in place.

Return type:

EDIFile

transform(source, *, name=None, station_id=None)[source]#

Convert a J source to EDI or an EDI collection.

A JCollection yields an EDICollection with one EDI per member. A single JFile (or path) yields a single EDIFile.

Parameters:
  • source (Any) – JFile instance, path-like, or JCollection.

  • name (str, optional) – Preferred station name override for finalization.

  • station_id (str or int, optional) – Identifier used when a name must be synthesized.

Returns:

EDI materialization corresponding to the input form.

Return type:

EDIFile or EDICollection

Examples

>>> from pycsamt.core.transformers import JtoEDI
>>> # Single file
>>> # edi = JtoEDI().transform(\"/data/site.j\")
>>> # Collection
>>> # out = JtoEDI().transform(j_collection)