pycsamt.api.cli.params#

pycsamt.api.cli.params#

Custom Click parameter types for pyCSAMT-specific inputs.

Use these as the type= argument on @click.argument or @click.option to get automatic validation and helpful error messages.

Examples

import click
from pycsamt.api.cli.params import EDIPath, FreqRange, StationList

@click.command()
@click.argument("edi", type=EDIPath())
@click.option("--freq", type=FreqRange(), default=None)
@click.option("--stations", type=StationList(), default=None)
def my_command(edi, freq, stations):
    ...

Classes

EDIDir()

A Click Path type for a directory that contains EDI files.

EDIPath()

A Click Path type that additionally requires a .edi extension.

FreqRange()

Parse a fmin:fmax frequency-range string into (float, float).

PipeStepList()

Parse a comma-separated list of pipeline step codes or names.

StationList()

Parse a comma-separated list of station identifiers.

class pycsamt.api.cli.params.EDIDir[source]#

Bases: Path

A Click Path type for a directory that contains EDI files.

name: str = 'EDI_DIR'#

the descriptive name of this type

convert(value, param, ctx)[source]#

Convert the value to the correct type. This is not called if the value is None (the missing value).

This must accept string values from the command line, as well as values that are already the correct type. It may also convert other compatible types.

The param and ctx arguments may be None in certain situations, such as when converting prompt input.

If the value cannot be converted, call fail() with a descriptive message.

Parameters:
  • value (Any) – The value to convert.

  • param (Parameter | None) – The parameter that is using this type to convert its value. May be None.

  • ctx (Context | None) – The current context that arrived at this value. May be None.

Return type:

Path

class pycsamt.api.cli.params.EDIPath[source]#

Bases: Path

A Click Path type that additionally requires a .edi extension.

name: str = 'EDI_FILE'#

the descriptive name of this type

convert(value, param, ctx)[source]#

Convert the value to the correct type. This is not called if the value is None (the missing value).

This must accept string values from the command line, as well as values that are already the correct type. It may also convert other compatible types.

The param and ctx arguments may be None in certain situations, such as when converting prompt input.

If the value cannot be converted, call fail() with a descriptive message.

Parameters:
  • value (Any) – The value to convert.

  • param (Parameter | None) – The parameter that is using this type to convert its value. May be None.

  • ctx (Context | None) – The current context that arrived at this value. May be None.

Return type:

Path

class pycsamt.api.cli.params.FreqRange[source]#

Bases: ParamType

Parse a fmin:fmax frequency-range string into (float, float).

Examples

--freq 0.1:1000(0.1, 1000.0)

name: str = 'FREQ_RANGE'#

the descriptive name of this type

convert(value, param, ctx)[source]#

Convert the value to the correct type. This is not called if the value is None (the missing value).

This must accept string values from the command line, as well as values that are already the correct type. It may also convert other compatible types.

The param and ctx arguments may be None in certain situations, such as when converting prompt input.

If the value cannot be converted, call fail() with a descriptive message.

Parameters:
  • value (Any) – The value to convert.

  • param (Parameter | None) – The parameter that is using this type to convert its value. May be None.

  • ctx (Context | None) – The current context that arrived at this value. May be None.

Return type:

tuple[float, float]

class pycsamt.api.cli.params.PipeStepList[source]#

Bases: ParamType

Parse a comma-separated list of pipeline step codes or names.

Each token is validated against the step registry, so the user gets an immediate error with a hint if they mistype a code.

Examples

--steps NR001,FREQ002,FREQ001,FREQ004,SS001

['NR001', 'FREQ002', 'FREQ001', 'FREQ004', 'SS001']

--steps notch_powerline,drop_duplicates,align_grid

['NR001', 'FREQ002', 'FREQ004']

name: str = 'STEP_LIST'#

the descriptive name of this type

convert(value, param, ctx)[source]#

Convert the value to the correct type. This is not called if the value is None (the missing value).

This must accept string values from the command line, as well as values that are already the correct type. It may also convert other compatible types.

The param and ctx arguments may be None in certain situations, such as when converting prompt input.

If the value cannot be converted, call fail() with a descriptive message.

Parameters:
  • value (Any) – The value to convert.

  • param (Parameter | None) – The parameter that is using this type to convert its value. May be None.

  • ctx (Context | None) – The current context that arrived at this value. May be None.

Return type:

list[str]

class pycsamt.api.cli.params.StationList[source]#

Bases: ParamType

Parse a comma-separated list of station identifiers.

Examples

--stations S01,S02,S03['S01', 'S02', 'S03']

name: str = 'STATION_LIST'#

the descriptive name of this type

convert(value, param, ctx)[source]#

Convert the value to the correct type. This is not called if the value is None (the missing value).

This must accept string values from the command line, as well as values that are already the correct type. It may also convert other compatible types.

The param and ctx arguments may be None in certain situations, such as when converting prompt input.

If the value cannot be converted, call fail() with a descriptive message.

Parameters:
  • value (Any) – The value to convert.

  • param (Parameter | None) – The parameter that is using this type to convert its value. May be None.

  • ctx (Context | None) – The current context that arrived at this value. May be None.

Return type:

list[str]