Skip to content

Commit 90e6042

Browse files
authored
Update for new deps (#80)
* Version bumps * Bump verions * Fix beamcon API * Flag the rms!! * Fix prefect verions * Bump versions * Bump racs-tools * API fixes * Bump racs-tools
1 parent b8e447f commit 90e6042

File tree

4 files changed

+63
-37
lines changed

4 files changed

+63
-37
lines changed

arrakis/imager.py

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -580,14 +580,31 @@ def make_cube(
580580
logger = get_run_logger()
581581

582582
logger.info(f"Creating cube for {pol=} {image_set.ms=}")
583-
image_list = image_set.image_lists[pol]
583+
image_list = [Path(i) for i in image_set.image_lists[pol]]
584584

585585
image_type = "restored" if aux_mode is None else aux_mode
586586

587+
# Create a cube name
588+
old_name = image_list[0]
589+
out_dir = os.path.dirname(old_name)
590+
old_base = os.path.basename(old_name)
591+
new_base = old_base
592+
b_idx = new_base.find("beam") + len("beam") + 2
593+
sub = new_base[b_idx:]
594+
new_base = new_base.replace(sub, ".conv.fits")
595+
new_base = new_base.replace("image", f"image.{image_type}.{pol.lower()}")
596+
new_name = Path(out_dir) / new_base
597+
587598
# First combine images into cubes
588-
hdu_list, freqs = combine_fits(file_list=image_list, create_blanks=True)
589-
new_header = hdu_list[0].header
590-
data_cube = hdu_list[0].data
599+
_ = combine_fits(
600+
file_list=image_list,
601+
out_cube=new_name,
602+
create_blanks=True,
603+
overwrite=True,
604+
)
605+
with fits.open(new_name, mode="denywrite", memmap=True) as hdu_list:
606+
new_header = hdu_list[0].header
607+
data_cube = hdu_list[0].data
591608

592609
# Add pol angle to header
593610
new_header["INSTRUMENT_RECEPTOR_ANGLE"] = (
@@ -610,16 +627,6 @@ def make_cube(
610627
# Calculate rms noise
611628
rmss_arr = mad_std(data_cube, axis=(1, 2, 3), ignore_nan=True)
612629

613-
# Create a cube name
614-
old_name = image_list[0]
615-
out_dir = os.path.dirname(old_name)
616-
old_base = os.path.basename(old_name)
617-
new_base = old_base
618-
b_idx = new_base.find("beam") + len("beam") + 2
619-
sub = new_base[b_idx:]
620-
new_base = new_base.replace(sub, ".conv.fits")
621-
new_base = new_base.replace("image", f"image.{image_type}.{pol.lower()}")
622-
new_name = os.path.join(out_dir, new_base)
623630
# Deserialise beam
624631
with open(common_beam_pkl, "rb") as f:
625632
common_beam = pickle.load(f)
@@ -633,9 +640,9 @@ def make_cube(
633640
# 0 1234.5
634641
# 1 6789.0
635642
# etc.
636-
new_w_name = new_name.replace(
637-
f"image.{image_type}", f"weights.{image_type}"
638-
).replace(".fits", ".txt")
643+
new_w_name = Path(
644+
new_name.as_posix().replace(f"image.{image_type}", f"weights.{image_type}")
645+
).with_suffix(".txt")
639646
data = dict(
640647
Channel=np.arange(len(rmss_arr)),
641648
Weight=1 / rmss_arr**2, # Want inverse variance
@@ -673,8 +680,26 @@ def get_beam(image_set: ImageSet, cutoff: Optional[float]) -> Path:
673680

674681
# Create a unique hash for the beam log filename
675682
image_hash = hashlib.md5("".join(image_list).encode()).hexdigest()
683+
try:
684+
common_beam, _ = beamcon_2D.get_common_beam(files=image_list, cutoff=cutoff)
685+
except Exception as e:
686+
import traceback
687+
import sys
688+
689+
tbe = traceback.TracebackException.from_exception(e)
690+
logger.error(f"Local {''.join(tbe.format())}")
691+
f = sys.exc_info()[2].tb_frame
692+
f = f.f_back
693+
while f is not None:
694+
tbe.stack.append(
695+
traceback.FrameSummary(
696+
f.f_code.co_filename, f.f_lineno, f.f_code.co_name
697+
)
698+
)
699+
f = f.f_back
676700

677-
common_beam, _ = beamcon_2D.getmaxbeam(files=image_list, cutoff=cutoff)
701+
logger.error(f"Full {''.join(tbe.format())}")
702+
raise e
678703

679704
logger.info(f"The common beam is: {common_beam=}")
680705

@@ -740,8 +765,8 @@ def smooth_imageset(
740765
for img in pol_images:
741766
logger.info(f"Smoothing {img}")
742767
last_result = executor.submit(
743-
beamcon_2D.worker,
744-
file=img,
768+
beamcon_2D.beamcon_2d_on_fits,
769+
file=Path(img),
745770
outdir=None,
746771
new_beam=common_beam,
747772
conv_mode="robust",

arrakis/linmos.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,21 +123,18 @@ def smooth_images(
123123
"""
124124
smooth_dict: Dict[str, ImagePaths] = {}
125125
for stoke, image_list in image_dict.items():
126-
infiles: List[str] = []
126+
infiles: List[Path] = []
127127
for im in image_list.images:
128128
if im.suffix == ".fits":
129-
infiles.append(im.resolve().as_posix())
130-
datadict = beamcon_3D.main(
131-
infile=[im.resolve().as_posix() for im in image_list.images],
129+
infiles.append(im.resolve())
130+
_, _, output_files = beamcon_3D.smooth_fits_cube(
131+
infiles_list=infiles,
132132
uselogs=False,
133133
mode="total",
134134
conv_mode="robust",
135135
suffix="cres",
136136
)
137-
smooth_files: List[Path] = []
138-
for key, val in datadict.items():
139-
smooth_files.append(Path(val["outfile"]))
140-
smooth_dict[stoke] = ImagePaths(smooth_files, image_list.weights)
137+
smooth_dict[stoke] = ImagePaths(output_files, image_list.weights)
141138

142139
return smooth_dict
143140

arrakis/rmsynth_oncuts.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,15 @@ def sigma_clip_spectra(
359359
for spectrum in stokes_spectra:
360360
filtered_data = spectrum.data.copy()
361361
filtered_data[filter_idx] = np.nan
362+
filtered_rms = spectrum.rms.copy()
363+
# Set the RMS to NaN where the data is NaN!
364+
filtered_rms[filter_idx] = np.nan
365+
filtered_bkg = spectrum.bkg.copy()
366+
filtered_bkg[filter_idx] = np.nan
362367
filtered_spectrum = Spectrum(
363368
data=filtered_data,
364-
rms=spectrum.rms,
365-
bkg=spectrum.bkg,
369+
rms=filtered_rms,
370+
bkg=filtered_bkg,
366371
filename=spectrum.filename,
367372
header=spectrum.header,
368373
)

pyproject.toml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dask = "*"
3434
distributed = {git="https://github.com/AlecThomson/distributed", branch="drainclose"}
3535
dask_jobqueue = {version=">=0.8.3", optional=true}
3636
dask_mpi = "*"
37-
FRion = ">=1.1.3"
37+
FRion = ">=1.1.4"
3838
h5py = "*"
3939
ipython = "*"
4040
matplotlib = ">=3.8"
@@ -46,9 +46,9 @@ pymongo = "*"
4646
pymultinest = "*"
4747
pytest = "*"
4848
python_casacore = "*"
49-
RACS-tools = ">=3.0.5"
49+
RACS-tools = ">=4.1.2"
5050
radio_beam = "*"
51-
RMextract = {git = "https://github.com/lofar-astron/RMextract", optional=true}
51+
RMextract = ">=0.5.1"
5252
schwimmbad = "*"
5353
scipy = "*"
5454
spectral_cube = ">=0.6.3"
@@ -57,14 +57,13 @@ tqdm = "*"
5757
vorbin = "*"
5858
graphviz = "*"
5959
bokeh = "<3"
60-
prefect = ">=2"
61-
prefect-dask = "*"
60+
prefect = {version=">=2,<3", extras=["dask"]}
6261
RMTable = ">=1.2.1"
6362
RM-Tools = ">=1.4.2"
6463
PolSpectra = ">=1.1.0"
6564
setuptools = "*"
66-
fixms = ">=0.2.6"
67-
fitscube = ">=0.3"
65+
fixms = ">=0.3.3"
66+
fitscube = ">=0.5.4"
6867
psycopg2-binary = "*"
6968
sqlalchemy = "*"
7069
scikit-image = ">=0.23"

0 commit comments

Comments
 (0)