Skip to content

Commit

Permalink
Covered a new test case for freq channel chopping
Browse files Browse the repository at this point in the history
  • Loading branch information
NickSwainston committed Feb 8, 2024
1 parent d685301 commit 37d5ef4
Show file tree
Hide file tree
Showing 3 changed files with 20,467 additions and 2 deletions.
18 changes: 16 additions & 2 deletions meerpipe/archive_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,21 @@ def chopping_utility(

# cloning archive and ensuring it has not been dedispersed
cleaned_ar = ps.Archive_load(archive_path)
cleaned_nchan = cleaned_ar.get_nchan()
chopped_ar = cleaned_ar.clone()
is_dedispered = chopped_ar.get_dedispersed()
if is_dedispered:
chopped_ar.dededisperse()

# Work out highest and lowest frequency channels to cut outside of based on band
if band == "LBAND":
low_freq = 895.92
high_freq = 1671.87
if cleaned_nchan == 4096:
# The 4096 nchan obs have a different zap range
low_freq = 895.95
high_freq = 1671.7
else:
low_freq = 895.7
high_freq = 1671.46
elif band == "UHF":
low_freq = 569.4
high_freq = 1062.4
Expand All @@ -176,6 +182,13 @@ def chopping_utility(
low_freq = 2665.2
high_freq = 3458.9

freqs = chopped_ar.get_frequencies()
nchan_remove = ( cleaned_nchan * 3 ) // 64
print(nchan_remove)
logger.debug(f"{band} below zap {freqs[nchan_remove-1]}-{freqs[nchan_remove]} and above zap {freqs[-nchan_remove-1]}-{freqs[-nchan_remove]}")
count_below_threshold = len([value for value in freqs if value < low_freq])
count_above_threshold = len([value for value in freqs if value > high_freq])
logger.debug(f"{band} {count_below_threshold} below zap and {count_above_threshold} above zap")

# complex structure required as with every channel removal, indexes of chopped_ar get reset
recheck = True
Expand All @@ -197,6 +210,7 @@ def chopping_utility(
assert chopped_ar.get_nchan() == 928
else:
# A simple check to ensure channels are a factor of 32
print(chopped_ar.get_nchan())
assert chopped_ar.get_nchan() % 32 == 0

logger.info("Done extracting")
Expand Down
2 changes: 2 additions & 0 deletions tests/test_archive_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def test_chopping_utility():
("LBAND", "J2317+1439_2022-12-03-15:09:15_zap.ar", 4096, 3712),
("UHF", "J1350-5115_2022-01-03-04:04:15_zap.ar", 4096, 3712),
("SBAND_0", "J0737-3039A_2023-05-16-11:38:55_zap_ch16384.ar", 16384, 14848),
("LBAND", "J0737-3039A_2022-09-18-07:10:50_zap.ar", 16384, 14848),
]
for band, archive, input_nchan, output_nchan in test_archives:
logger.info(f"Testing chopping utility for {archive} in {band} band")
Expand All @@ -41,6 +42,7 @@ def test_chopping_utility():
# Check the nchan of the chopped archive
chopped_archive = archive.replace(".ar", "_chopped.ar")
ar = ps.Archive_load(os.path.join(TEST_DATA_DIR, chopped_archive))
logger.info(f"Testing {ar.get_nchan()} == {output_nchan}")
assert ar.get_nchan() == output_nchan

# Remove the chopped archive
Expand Down
Loading

0 comments on commit 37d5ef4

Please sign in to comment.