Skip to content

Commit

Permalink
Merge pull request #84 from tjgalvin/configargparse
Browse files Browse the repository at this point in the history
Add Configargparse to main continuum pipeline
  • Loading branch information
tjgalvin authored Apr 13, 2024
2 parents 38146f8 + c25bd1c commit 630cc05
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
7 changes: 5 additions & 2 deletions flint/prefect/flows/continuum_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
- run aegean source finding
"""

from argparse import ArgumentParser
from pathlib import Path
from typing import Union

from configargparse import ArgumentParser
from prefect import flow, unmapped

from flint.calibrate.aocalibrate import find_existing_solutions
Expand Down Expand Up @@ -368,6 +368,10 @@ def setup_run_process_science_field(
def get_parser() -> ArgumentParser:
parser = ArgumentParser(description=__doc__)

parser.add_argument(
"--cli-config", is_config_file=True, help="Path to configuration file"
)

parser.add_argument(
"science_path",
type=Path,
Expand Down Expand Up @@ -470,7 +474,6 @@ def get_parser() -> ArgumentParser:
parser.add_argument(
"--linmos-residuals",
action="store_true",
default=False,
help="Co-add the per-beam cleaning residuals into a field image",
)
parser.add_argument(
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ radio-beam = "^0.3.4"
reproject = "*"
scikit-image = "*"
pandas = "*"
ConfigArgParse = "^1.7"

[tool.poetry.group.dev.dependencies]
black = "^23.3.0"
Expand Down
55 changes: 55 additions & 0 deletions tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,61 @@
from flint.prefect.flows.continuum_pipeline import get_parser


def test_config_field_options(tmpdir):
output_file = f"{tmpdir}/example.config"
contents = """--holofile /scratch3/projects/spiceracs/RACS_Low2_Holography/akpb.iquv.square_6x6.63.887MHz.SB39549.cube.fits
--calibrate-container /scratch3/gal16b/containers/calibrate.sif
--flagger-container /scratch3/gal16b/containers/aoflagger.sif
--wsclean-container /scratch3/projects/spiceracs/singularity_images/wsclean_force_mask.sif
--yandasoft-container /scratch3/gal16b/containers/yandasoft.sif
--cluster-config /scratch3/gal16b/split/petrichor.yaml
--selfcal-rounds 2
--split-path $(pwd)
--zip-ms
--run-aegean
--aegean-container '/scratch3/gal16b/containers/aegean.sif'
--reference-catalogue-directory '/scratch3/gal16b/reference_catalogues/'
--linmos-residuals
"""

with open(output_file, "w") as out:
for line in contents.split("\n"):
out.write(f"{line.lstrip()}\n")

parser = get_parser()
args = parser.parse_args(
f"""/scratch3/gal16b/askap_sbids/112334/
/scratch3/gal16b/askap_sbids/111/
--cli-config {str(output_file)}""".split()
)

field_options = FieldOptions(
flagger_container=args.flagger_container,
calibrate_container=args.calibrate_container,
holofile=args.holofile,
expected_ms=args.expected_ms,
wsclean_container=args.wsclean_container,
yandasoft_container=args.yandasoft_container,
rounds=args.selfcal_rounds,
zip_ms=args.zip_ms,
run_aegean=args.run_aegean,
aegean_container=args.aegean_container,
no_imaging=args.no_imaging,
reference_catalogue_directory=args.reference_catalogue_directory,
linmos_residuals=args.linmos_residuals,
beam_cutoff=args.beam_cutoff,
pb_cutoff=args.pb_cutoff,
use_preflagger=args.use_preflagger,
)

assert isinstance(field_options, FieldOptions)
assert field_options.use_preflagger is False
assert field_options.zip_ms is True
assert field_options.linmos_residuals is True
assert field_options.rounds == 2
assert isinstance(field_options.wsclean_container, Path)


def test_create_field_options():
parser = get_parser()
args = parser.parse_args(
Expand Down

0 comments on commit 630cc05

Please sign in to comment.