Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial continuum-subtraction and spectral line prefect flow #192

Merged
merged 66 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
fffedc2
initial beginnings of cube imaging script
Nov 25, 2024
80bcb3c
Initial toying around with subtracted cube
Nov 26, 2024
a467e37
added subtract cube operaiton
Nov 26, 2024
71f56c9
fixed installed flint flow entrypoint
Nov 26, 2024
7a550ef
relocated SubtractFieldOptions/fixed argparser / test
Nov 26, 2024
f9c4779
calling the flow
Nov 26, 2024
4ea8925
using ummaped
Nov 26, 2024
73b3947
patching in channel range into naming
Nov 26, 2024
57f9b56
rejigging the wsclean names that are generated
Nov 26, 2024
9720434
filter corrected#
Nov 26, 2024
1e33f09
adding linmos filter
Nov 26, 2024
4678a56
some logging output on valueerror
Nov 27, 2024
aacf1f7
added a NaN beam shape
Nov 27, 2024
49243c3
setting a zero'd beam when NaN beam detected
Nov 27, 2024
4dd0d46
bumped the default number
Nov 27, 2024
cae2c1c
Added copyfile for bad conv beams
Nov 27, 2024
f429ee6
copy zero beams
Nov 27, 2024
3e80dd0
no-reorder added to WSCleanOptions
Nov 27, 2024
66fa7ef
corected local variable unbound
Nov 27, 2024
8457628
rejigged the wsclean delete cleanups
Nov 27, 2024
cf05290
prefix log
Nov 27, 2024
20cfc7e
updated prefix creation
Nov 27, 2024
d4ca8a4
tweaked logs
Nov 27, 2024
94b78bd
unlinking preconvolved images after convolve
Nov 27, 2024
a83db77
typo fix
Nov 27, 2024
7e99854
added to the chanelog
Nov 27, 2024
9b3f976
batching the results
Nov 28, 2024
a2b6b07
batched limit added to SubtractFieldOptions
Nov 28, 2024
44f8298
added else to for loop
Nov 28, 2024
1d05caa
fixed the check on list
Nov 28, 2024
d433525
treat as rate limit
Nov 28, 2024
ed1cb45
single item waiting
Nov 28, 2024
9bd4781
silly list index missing
Nov 28, 2024
ead44da
added a more aggressive loop for complete
Nov 28, 2024
c4f125a
sleep
Nov 28, 2024
fc2f8e1
rejigged again
Nov 28, 2024
26b95b1
inverted state test
Nov 28, 2024
9070cc1
no sleep
Nov 28, 2024
b696b3c
sleeping
Nov 28, 2024
35b04f8
10 to 5
Nov 28, 2024
fd3fb23
added a stagger_delay_seconds
Nov 28, 2024
eae2ba4
removed comments
Nov 29, 2024
63250e5
fixed subtract column output / test
Nov 29, 2024
f6d0455
initial subtraction
Nov 29, 2024
fbf881c
commited options to SubtractFieldOptions
Nov 29, 2024
dfc9119
added mandatory argument
Nov 29, 2024
aba5054
a silly
Nov 29, 2024
b25a5d4
initiall addmodel prediction
Nov 30, 2024
a4395c0
options fix
Nov 30, 2024
285d78c
unmapped
Nov 30, 2024
38de970
fixede mode input
Nov 30, 2024
3affdcc
changelog
Nov 30, 2024
c97f94a
optional attempt_subtract
Dec 1, 2024
b3696f0
typo fix
Dec 1, 2024
b88cadd
silly typo pirate
Dec 1, 2024
7d7b0af
added subflow for addmodel
Dec 2, 2024
4b38655
missing keyword argument
Dec 2, 2024
f623ca4
another keyword typo
Dec 2, 2024
5cae2e4
silly
Dec 2, 2024
9f851bd
more silly pirate business
Dec 2, 2024
56078cf
typing and binding error
Dec 2, 2024
0abe295
corrected column
Dec 2, 2024
e19c61c
updated log message
Dec 2, 2024
465048f
added a flint_ skip options in the wsclean logger
Dec 3, 2024
d957406
added some notes to the changelog
Dec 3, 2024
4c47a9f
fixed type errors raised on pre-commit
Dec 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Change log

# dev

- Created `subtract_cube_pipeline.py`. Associated changes include:
- wsclean imaging will delete files while still in temporary storage (for
instance is a ramdisk is used)
- added option to prefect convol task to delete files once they have be
convoled
- predicting model produced by `wsclean -save-source-list` into measurement
set
- using `taql` to subtract model from nominated data column
- added a 'flow_addmodel_to_mss` to allow different task runner to be
specified
- added `flint_no_log_wsclean_output` to `WSCleanOptions` to disable wsclean
logging
- added flag to disable logging singularity command output to the
`flint.logging.logger`

# 0.2.8

- added `wrapper_options_from_strategy` decorator helper function
Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,8 @@ tasks together (outlined above) into a single data-processing pipeline.
observation sequence.
- `flint_flow_continuum_pipeline`: Performs bandpass calibration, solution
copying, imaging, self-calibration and mosaicing.
- `flint_flow_cointinuum_mask_pipeline`: Performs bandpass calibration, solution
copying, imaging, self-calibration and mosaicing. In this flow a process to
construct a robust clean mask is performed by exploiting an initial imaging
round. The field image is constructed across all beams, S/N clipping is
performed, then guard masks on a per-beam basis are extracted. This pipeline
has fallen out of use and could be removed.
- `flint_flow_subtract_cube_pipeline`: Subtract a continuum model and image the
residual data.

## Sky-model catalogues

Expand Down
13 changes: 8 additions & 5 deletions flint/coadd/linmos.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ def linmos_images(
container: Path = Path("yandasoft.sif"),
cutoff: float = 0.001,
pol_axis: Optional[float] = None,
trim_linmos_fits: bool = True,
) -> LinmosCommand:
"""Create a linmos parset file and execute it.

Expand All @@ -538,6 +539,7 @@ def linmos_images(
container (Path, optional): Path to the singularity container that has the yandasoft tools. Defaults to Path('yandasoft.sif').
cutoff (float, optional): Pixels whose primary beam attenuation is below this cutoff value are blanked. Defaults to 0.001.
pol_axis (Optional[float], optional): The physical oritentation of the ASKAP third-axis in radians. Defaults to None.
trim_linmos_fits (bool, optional): Attempt to trim the output linmos files of as much empty space as possible. Defaults to True.

Returns:
LinmosCommand: The linmos command executed and the associated parset file
Expand Down Expand Up @@ -577,11 +579,12 @@ def linmos_images(
)

# Trim the fits image to remove empty pixels
image_trim_results = trim_fits_image(image_path=linmos_names.image_fits)
trim_fits_image(
image_path=linmos_names.weight_fits,
bounding_box=image_trim_results.bounding_box,
)
if trim_linmos_fits:
image_trim_results = trim_fits_image(image_path=linmos_names.image_fits)
trim_fits_image(
image_path=linmos_names.weight_fits,
bounding_box=image_trim_results.bounding_box,
)

return linmos_cmd

Expand Down
28 changes: 27 additions & 1 deletion flint/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# into there

KNOWN_HEADERS = ("defaults", "initial", "selfcal", "version")
KNOWN_OPERATIONS = ("stokesv",)
KNOWN_OPERATIONS = ("stokesv", "subtractcube")
FORMAT_VERSION = 0.1
MODE_OPTIONS_MAPPING = {
"wsclean": WSCleanOptions,
Expand Down Expand Up @@ -81,6 +81,32 @@ def copy_and_timestamp_strategy_file(output_dir: Path, input_yaml: Path) -> Path
return Path(stamped_imaging_strategy)


def _load_and_copy_strategy(
output_split_science_path: Path, imaging_strategy: Optional[Path] = None
) -> Union[Strategy, None]:
"""Load a strategy file and copy a timestamped version into the output directory
that would contain the science processing.

Args:
output_split_science_path (Path): Where the strategy file should be copied to (where the data would be processed)
imaging_strategy (Optional[Path], optional): Location of the strategy file. Defaults to None.

Returns:
Union[Strategy, None]: The loadded strategy file if provided, `None` otherwise
"""
return (
load_strategy_yaml(
input_yaml=copy_and_timestamp_strategy_file(
output_dir=output_split_science_path,
input_yaml=imaging_strategy,
),
verify=True,
)
if imaging_strategy
else None
)


def get_selfcal_options_from_yaml(input_yaml: Optional[Path] = None) -> Dict:
"""Stub to represent interaction with a configurationf ile

Expand Down
58 changes: 42 additions & 16 deletions flint/convol.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import warnings
from argparse import ArgumentParser
from pathlib import Path
from shutil import copyfile
from typing import Collection, List, Literal, NamedTuple, Optional

import astropy.units as u
Expand Down Expand Up @@ -198,10 +199,14 @@ def get_common_beam(
if cutoff:
logger.info(f"Setting beam cutoff to {cutoff} arcseconds. ")

beam, beams = beamcon_2D.get_common_beam(files=list(image_paths), cutoff=cutoff)
try:
beam, beams = beamcon_2D.get_common_beam(files=list(image_paths), cutoff=cutoff)

beam_shape = BeamShape.from_radio_beam(beam)
logger.info(f"Constructed {beam_shape=}")
beam_shape = BeamShape.from_radio_beam(beam)
logger.info(f"Constructed {beam_shape=}")
except ValueError:
logger.info("The beam was not constrained. Setting to NaNs")
beam_shape = BeamShape(bmaj_arcsec=np.nan, bmin_arcsec=np.nan, bpa_deg=np.nan)

return beam_shape

Expand Down Expand Up @@ -231,29 +236,50 @@ def convolve_images(
if cutoff:
logger.info(f"Supplied cutoff of {cutoff} arcsecond")

if not np.isfinite(beam_shape.bmaj_arcsec):
logger.info("Beam shape is not defined. Copying files into place. ")

conv_image_paths = [
Path(str(image_path).replace(".fits", f".{convol_suffix}.fits"))
for image_path in image_paths
]
# If the beam is not defined, simply copy the file into place. Although
# this takes up more space, it is not more than otherwise
for original_path, copy_path in zip(image_paths, conv_image_paths):
logger.info(f"Copying {original_path=} {copy_path=}")
copyfile(original_path, copy_path)

return conv_image_paths

radio_beam = Beam(
major=beam_shape.bmaj_arcsec * u.arcsecond,
minor=beam_shape.bmin_arcsec * u.arcsecond,
pa=beam_shape.bpa_deg * u.deg,
)

conv_image_paths: List[Path] = []
return_conv_image_paths: List[Path] = []

for image_path in image_paths:
logger.info(f"Convolving {str(image_path.name)}")
beamcon_2D.beamcon_2d_on_fits(
file=image_path,
outdir=None,
new_beam=radio_beam,
conv_mode="robust",
suffix=convol_suffix,
cutoff=cutoff,
)
conv_image_paths.append(
Path(str(image_path).replace(".fits", f".{convol_suffix}.fits"))
convol_output_path = Path(
str(image_path).replace(".fits", f".{convol_suffix}.fits")
)
header = fits.getheader(image_path)
if header["BMAJ"] == 0.0:
logger.info(f"Copying {image_path} to {convol_output_path=} for empty beam")
copyfile(image_path, convol_output_path)
else:
logger.info(f"Convolving {str(image_path.name)}")
beamcon_2D.beamcon_2d_on_fits(
file=image_path,
outdir=None,
new_beam=radio_beam,
conv_mode="robust",
suffix=convol_suffix,
cutoff=cutoff,
)
return_conv_image_paths.append(convol_output_path)

return conv_image_paths
return return_conv_image_paths


def get_parser() -> ArgumentParser:
Expand Down
4 changes: 4 additions & 0 deletions flint/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ class MSError(Exception):
pass


class FrequencyMismatchError(Exception):
"""Raised when there are differences in frequencies"""


class PhaseOutlierFitError(Exception):
"""Raised when the phase outlier fit routine fails."""

Expand Down
Loading