Skip to content

Commit

Permalink
fix naming func
Browse files Browse the repository at this point in the history
  • Loading branch information
AlecThomson committed Jan 15, 2025
1 parent b23492c commit 3ded138
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
33 changes: 22 additions & 11 deletions flint/naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import re
from datetime import datetime
from pathlib import Path
from typing import Any, NamedTuple
from typing import Any, NamedTuple, overload

from prefect import task

Expand All @@ -16,22 +16,33 @@
from flint.options import MS


def rename_linear_to_stokes(
linear_name: Path | str,
def _rename_linear_to_stokes(
linear_name_str: str,
stokes: str,
) -> Path | str:
) -> str:
if stokes.lower() not in ("q", "u"):
raise NameError(f"Stokes {stokes=} is not linear!")

pattern = r"\.qu\." # Regex pattern to replace
stokes_name = re.sub(pattern, stokes, linear_name_str)
return stokes_name


@overload
def rename_linear_to_stokes(linear_name: Path, stokes: str) -> Path: ...


@overload
def rename_linear_to_stokes(linear_name: str, stokes: str) -> str: ...


def rename_linear_to_stokes(
linear_name: Path | str,
stokes: str,
) -> Path | str:
if isinstance(linear_name, Path):
name_str = linear_name.as_posix()
stokes_name = re.sub(pattern, stokes, name_str)
return Path(stokes_name)
else:
stokes_name = re.sub(pattern, stokes, linear_name)
return stokes_name
return Path(_rename_linear_to_stokes(linear_name.as_posix(), stokes))

return _rename_linear_to_stokes(linear_name, stokes)


task_rename_linear_to_stokes = task(rename_linear_to_stokes)
Expand Down
5 changes: 4 additions & 1 deletion flint/prefect/flows/polarisation_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ def process_science_fields_pol(
if polarisation == "linear":
# Get single Stokes prefix - the original prefix is the linear prefix
# i.e. `.qu.` -> `.q.` or `.u.` depending on the stokes
prefix = task_rename_linear_to_stokes.submit(prefix)
prefix = task_rename_linear_to_stokes.submit(
linear_name=prefix,
stokes=stokes,
)
cube_path = combine_images_to_cube.submit(
images=channel_image_list,
prefix=prefix,
Expand Down

0 comments on commit 3ded138

Please sign in to comment.