Skip to content

Commit

Permalink
Merge pull request #151 from tjgalvin/polname
Browse files Browse the repository at this point in the history
Fixed the creation og the output cube name
  • Loading branch information
tjgalvin authored Jul 27, 2024
2 parents 6510568 + f31acc8 commit 4c43fea
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
8 changes: 3 additions & 5 deletions flint/imager/wsclean.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from flint.exceptions import CleanDivergenceError
from flint.logging import logger
from flint.ms import MS
from flint.naming import create_imaging_name_prefix
from flint.naming import create_image_cube_name, create_imaging_name_prefix
from flint.options import options_to_dict
from flint.sclient import run_singularity_command
from flint.utils import (
Expand Down Expand Up @@ -520,8 +520,6 @@ def combine_subbands_to_cube(
f"Input imageset of type {type(imageset)}, expect {type(ImageSet)}"
)

image_prefix = Path(imageset.prefix)

imageset_dict = options_to_dict(input_options=imageset)

for mode in ("image", "residual", "dirty", "model", "psf"):
Expand All @@ -542,8 +540,8 @@ def combine_subbands_to_cube(
hdu1, freqs = combine_fits(file_list=subband_images)

# TODOL This could be moved to the naming module
output_cube_name = (
Path(image_prefix.parent) / f"{str(image_prefix.stem)}.{mode}.cube.fits"
output_cube_name = create_image_cube_name(
image_prefix=imageset.prefix, mode=mode
)
logger.info(f"Writing {output_cube_name=}")
hdu1.writeto(output_cube_name, overwrite=True)
Expand Down
24 changes: 24 additions & 0 deletions flint/naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,30 @@
from flint.options import MS


def create_image_cube_name(
image_prefix: Path, mode: str, suffix: str = "cube.fits"
) -> Path:
"""Create a consistent naming scheme when combining images into cube images. Intended to
be used whhen combining many subband images together into a single cube.
The name returned will be:
>> {image_prefix}.{mode}.{suffix}
Args:
image_prefix (Path): The unique path of the name. Generally this is the common part among the input planes
mode (str): Additional mode to add to the file name
suffix (str, optional): The final suffix to appened. Defaults to ".cube.fits".
Returns:
Path: The final path and file name
"""
# NOTE: This is likely a function to grow in time as more imaging and pipeline modes added. Putting
# it here for future proofing
output_cube_name = f"{str(Path(image_prefix))}.{mode}.{suffix}"

return Path(output_cube_name)


def create_imaging_name_prefix(ms: Union[MS, Path], pol: Optional[str] = None) -> str:
"""Given a measurement set and a polarisation, create the naming prefix to be used
by some imager
Expand Down
24 changes: 24 additions & 0 deletions tests/test_naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
add_timestamp_to_path,
casda_ms_format,
create_fits_mask_names,
create_image_cube_name,
create_ms_name,
extract_beam_from_name,
extract_components_from_name,
Expand All @@ -26,6 +27,29 @@
)


def test_create_image_cube_name():
"""Put together a consistent file cube name"""
name = create_image_cube_name(
image_prefix=Path(
"/jack/sparrow/worst/pirate/flint_fitscube/57222/SB57222.RACS_1141-55.beam10.round3.poli"
),
mode="image",
)
assert isinstance(name, Path)
assert name == Path(
"/jack/sparrow/worst/pirate/flint_fitscube/57222/SB57222.RACS_1141-55.beam10.round3.poli.image.cube.fits"
)

name = create_image_cube_name(
image_prefix=Path("./57222/SB57222.RACS_1141-55.beam10.round3.poli"),
mode="residual",
)
assert isinstance(name, Path)
assert name == Path(
"./57222/SB57222.RACS_1141-55.beam10.round3.poli.residual.cube.fits"
)


def test_get_beam_resolution_str():
"""Map the known / support modes of beam resolution in file names"""
assert "raw" == get_beam_resolution_str(mode="raw")
Expand Down

0 comments on commit 4c43fea

Please sign in to comment.