Skip to content

Commit

Permalink
Add hidden "waterfall_blacklist" option to enable downweighting of sp…
Browse files Browse the repository at this point in the history
…ecific freqs/times in smooth_cal
  • Loading branch information
jsdillon committed Feb 25, 2025
1 parent 2f63009 commit e58a939
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions hera_cal/smooth_cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,13 +720,15 @@ def build_freq_blacklist(freqs, freq_blacklists=[], chan_blacklists=[]):
return freq_blacklist_array


def _build_wgts_grid(flag_grid, time_blacklist=None, freq_blacklist=None, blacklist_wgt=0.0):
def _build_wgts_grid(flag_grid, time_blacklist=None, freq_blacklist=None, waterfall_blacklist=None, blacklist_wgt=0.0):
'''Builds a wgts_grid float array (Ntimes, Nfreqs) with 0s flagged or blacklisted data and 1s otherwise.'''
wgts_grid = np.ones_like(flag_grid, dtype=float)
if time_blacklist is not None:
wgts_grid[time_blacklist, :] = blacklist_wgt
if freq_blacklist is not None:
wgts_grid[:, freq_blacklist] = blacklist_wgt
if waterfall_blacklist is not None:
wgts_grid[waterfall_blacklist] = blacklist_wgt
wgts_grid[flag_grid] = 0.0
return wgts_grid

Expand Down Expand Up @@ -796,7 +798,9 @@ def __init__(self, calfits_list, flag_file_list=[], flag_filetype='h5', antflag_
this is not required.
freq_blacklists: list of pairs of frequencies in Hz hours bounding (inclusively) spectral regions
that are to receive 0 weight during smoothing, forcing the smoother to interpolate/extrapolate.
N.B. Blacklisted frequencies are not necessarily flagged.
N.B. Blacklisted frequencies are not necessarily flagged. Also note that there is a "hidden"
waterfall_blacklist parameter on this object that is a dictionary mapping antennas to boolean arrays
that allows for specific freqs/times to be blacklisted for specific antennas. This has to be set manually.
chan_blacklists: list of pairs of channel numbers bounding (inclusively) spectral regions
that are to receive 0 weight during smoothing, forcing the smoother to interpolate/extrapolate.
N.B. Blacklisted channels are not necessarily flagged.
Expand Down Expand Up @@ -901,6 +905,7 @@ def __init__(self, calfits_list, flag_file_list=[], flag_filetype='h5', antflag_
self.time_blacklist = build_time_blacklist(self.time_grid, time_blacklists=time_blacklists, lst_blacklists=lst_blacklists,
lat_lon_alt_degrees=lat_lon_alt_degrees, telescope_name=hc.telescope.name)
self.freq_blacklist = build_freq_blacklist(self.freqs, freq_blacklists=freq_blacklists, chan_blacklists=chan_blacklists)
self.waterfall_blacklist = {} # needs to be manually set by an advanced user as ant-->boolean waterfall

# pick a reference antenna that has the minimum number of flags (tie goes to lower antenna number) and then rephase
if pick_refant:
Expand Down Expand Up @@ -964,7 +969,8 @@ def time_filter(self, filter_scale=1800.0, mirror_kernel_min_sigmas=5):
for ant, gain_grid in self.gain_grids.items():
utils.echo(' Now smoothing antenna' + str(ant[0]) + ' ' + str(ant[1]) + ' in time...', verbose=self.verbose)
if not np.all(self.flag_grids[ant]):
wgts_grid = _build_wgts_grid(self.flag_grids[ant], self.time_blacklist, self.freq_blacklist, self.blacklist_wgt)
wgts_grid = _build_wgts_grid(self.flag_grids[ant], self.time_blacklist, self.freq_blacklist,
self.waterfall_blacklist.get(ant, None), self.blacklist_wgt)
self.gain_grids[ant] = time_filter(gain_grid, wgts_grid, self.time_grid,
filter_scale=filter_scale, nMirrors=nMirrors)

Expand Down Expand Up @@ -993,7 +999,8 @@ def filter_1d(self, filter_scale=None, tol=1e-09, skip_wgt=0.1, mode='clean', ax
cache = {}
for ant, gain_grid in self.gain_grids.items():
utils.echo(' Now filtering antenna' + str(ant[0]) + ' ' + str(ant[1]) + f' in {ax}...', verbose=self.verbose)
wgts_grid = _build_wgts_grid(self.flag_grids[ant], self.time_blacklist, self.freq_blacklist)
wgts_grid = _build_wgts_grid(self.flag_grids[ant], self.time_blacklist, self.freq_blacklist,
self.waterfall_blacklist.get(ant, None), self.blacklist_wgt)
if ax == 'freq':
xaxis = self.freqs
else:
Expand Down Expand Up @@ -1077,7 +1084,8 @@ def time_freq_2D_filter(self, freq_scale=10.0, time_scale=1800.0, tol=1e-09, fil
gain_grid = self.gain_grids[ant]
if not np.all(self.flag_grids[ant]):
utils.echo(' Now filtering antenna ' + str(ant[0]) + ' ' + str(ant[1]) + ' in time and frequency...', verbose=self.verbose)
wgts_grid = _build_wgts_grid(self.flag_grids[ant], self.time_blacklist, self.freq_blacklist, self.blacklist_wgt)
wgts_grid = _build_wgts_grid(self.flag_grids[ant], self.time_blacklist, self.freq_blacklist,
self.waterfall_blacklist.get(ant, None), self.blacklist_wgt)

# If the weights grid is the same as the previous, the solution matrix can be reused to speed up computation
if method == 'DPSS' or method == 'dpss_leastsq':
Expand Down

0 comments on commit e58a939

Please sign in to comment.