Skip to content

Commit 02a002a

Browse files
committed
fix bug with RM synthesis failing to handle cal scans, fixes #38
1 parent 896d78f commit 02a002a

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

dstools/dynamic_spectrum.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,8 @@ def rm_synthesis(self, I, L):
627627
# to pull Q / U from the cleaned RM synthesis FDF spectrum.
628628
fdf_peak_timeseries = np.argmax(np.abs(fdf_spectrum), axis=0)
629629
peak_rm_spectrum = phis[fdf_peak_timeseries]
630-
tslice = np.argmax(np.nanmean(I.real, axis=1))
630+
tslice = np.nanargmax(np.nanmean(I.real, axis=1))
631+
631632
RM = peak_rm_spectrum[tslice]
632633
logger.debug(f"Peak RM of {RM:.1f} rad/m2")
633634

tests/test_dynamic_spectrum.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,22 @@ def test_rm_synthesis(ds_paths):
155155
assert round(ds.RM, 1) == -830.5
156156

157157

158+
def test_rm_synthesis_handles_calibrator_scan(ds_paths):
159+
ds_path = ds_paths.get("atca_pulse")
160+
ds = DynamicSpectrum(ds_path)
161+
162+
# Simulate early cal scan
163+
ds.data["I"][5, :] = np.nan
164+
ds.data["L"][5, :] = np.nan
165+
166+
# Test that RM extraction runs on the pulse at later time index
167+
I = ds.data["I"]
168+
L = ds.data["L"].T
169+
RM = ds.rm_synthesis(I, L)
170+
171+
assert round(RM, 1) == -830.5
172+
173+
158174
def test_ds_acf(ds_paths):
159175
ds_path = ds_paths.get("atca_pulse")
160176
ds = DynamicSpectrum(ds_path)

0 commit comments

Comments
 (0)