Created
May 29, 2025 03:33
-
-
Save d3v-null/35ec5838ced6c4f991c13660a741e55c to your computer and use it in GitHub Desktop.
mwa phase3 temporary fix needed to process shao receivers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from astropy.io import fits | |
from pprint import pprint | |
import numpy as np | |
from sys import argv | |
from os.path import exists | |
path = argv[-1] | |
if not exists(path): | |
print(f"""Usage: {argv[0]} <metafits> | |
File {path} does not exist.""") | |
exit(1) | |
new_dig_gains=[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 208, 164, 131, 105, 86, 71, 60, 52, 45, 40, 36, 32, 30, 28, 27, 25, 25, 24, 24, 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 27, 27, 27, 27, 28, 28, 28, 29, 29, 29, 30, 30, 30, 30, 30, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 33, 33, 33, 34, 35, 35, 36, 36, 37, 38, 39, 40, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 56, 57, 58, 59, 61, 62, 64, 65, 66, 67, 69, 70, 70, 71, 72, 72, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 74, 75, 76, 78, 79, 81, 84, 86, 89, 92, 95, 98, 101, 104, 106, 108, 110, 112, 113, 114, 114, 115, 115, 116, 117, 119, 121, 125, 129, 135, 142, 151, 161, 173, 188, 206, 227, 253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255] | |
def split_strip_filter(str): | |
return list(filter(None, map(lambda tok: tok.strip(), str.split(',')))) | |
with fits.open(path) as hdul: | |
hdul.info() | |
phdu = hdul['PRIMARY'] | |
# pprint(phdu.header) | |
channels = [*map(int, split_strip_filter(phdu.header['CHANNELS']))] | |
# pprint(channels) | |
chan_dig_gains = np.array(new_dig_gains)[channels] | |
# print(chan_dig_gains) | |
td = hdul['TILEDATA'].data | |
# print(td['Gains']) | |
# set all rows in the td['Gains'] column to the new digital gains | |
hdul['TILEDATA'].data['Gains'] = np.array([chan_dig_gains] * len(td), dtype=td['Gains'].dtype) | |
out_path = path.replace('.metafits', '_fixed.metafits') | |
hdul.writeto(out_path, overwrite=True) | |
print(f"Fixed metafits written to {out_path}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment