Skip to content

Commit

Permalink
Merge pull request #166 from simonsobs/rush-before-tag
Browse files Browse the repository at this point in the history
Rush before tag
  • Loading branch information
mhasself authored Feb 2, 2024
2 parents 6f04188 + 50b184e commit 8f8ed1e
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 139 deletions.
10 changes: 5 additions & 5 deletions python/hk/getdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,13 +775,13 @@ def load_range(start, stop, fields=None, alias=None,
dirs and pkl files in the pre_proc_dir. No chmod if None.
folder_patterns: List of patterns to search for in folders. If
None, default pattern is ['{folder}', 'hk_{folder}_*']. If not
None, usage for .g3 folder: ['{folder}'], and example usage
None, usage for .g3 folder: ['{folder}'], and example usage
for HK books: ['hk_{folder}_lat'] where {folder} will be replaced
with the first 5 digits of the unix timestamp when looping through
files.
strict: If False, log and skip missing fields rather than
raising a KeyError.
Returns:
Dictionary with structure::
Expand All @@ -791,7 +791,7 @@ def load_range(start, stop, fields=None, alias=None,
}
It will be masked to only have data between start and stop.
Notes:
The "start" and "stop" argument accept a variety of formats,
Expand Down Expand Up @@ -858,10 +858,10 @@ def load_range(start, stop, fields=None, alias=None,
bases = []
for pattern in folder_patterns:
extended_pattern = pattern.format(folder=folder)

base = glob.glob(os.path.join(data_dir, extended_pattern))
bases.extend(base)

if len(bases) > 1:
bases.sort
base = bases[0]
Expand Down
10 changes: 10 additions & 0 deletions python/proj/ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ def collect(items, join_depth):
return RangesMatrix(ranges, child_shape=items[0].shape[1:])
return collect(items, axis)

def close_gaps(self, gap_size=0):
"""Call close_gaps(gap_size) on all children. Any ranges that abutt
each other within the gap_size are merged into a single entry.
Usually a gap_size of 0 is not possible, but if a caller is
carefully using append_interval_no_check, then it can happen.
"""
for r in self.ranges:
r.close_gaps(gap_size)

def get_stats(self):
samples, intervals = [], []
for r in self.ranges:
Expand Down
29 changes: 23 additions & 6 deletions python/proj/wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
# called "q_native". This is usually the thing to pass to C++ level.


#: Valid settings for "interpol". First entry is the default.
INTERPOLS = ['nearest', 'bilinear']


class Projectionist:
"""This class assists with analyzing WCS information to populate data
structures needed for accelerated pointing routines.
Expand Down Expand Up @@ -152,6 +156,12 @@ def __init__(self):
self._q_fp_to_native = None
self._q_fp_to_celestial = None
self.tile_shape = None
self.active_tiles = None
self.wcs = None
self.proj_name = None
self.q_celestial_to_native = None
self.interpol = INTERPOLS[0]

self.naxis = np.array([0, 0])
self.cdelt = np.array([0., 0.])
self.crpix = np.array([0., 0.])
Expand Down Expand Up @@ -194,7 +204,8 @@ def for_geom(cls, shape, wcs, interpol=None):
self.crpix = np.array(wcs.wcs.crpix)

# Pixel interpolation mode
if interpol is None: interpol = "nearest"
if interpol is None:
interpol = INTERPOLS[0]
self.interpol = interpol

return self
Expand All @@ -213,7 +224,7 @@ def for_map(cls, emap, wcs=None, interpol=None):
"""
if wcs is None:
wcs = emap.wcs
return cls.for_geom(emap.shape, wcs)
return cls.for_geom(emap.shape, wcs, interpol=interpol)

@classmethod
def for_source_at(cls, alpha0, delta0, gamma0=0.,
Expand Down Expand Up @@ -286,11 +297,17 @@ def get_ProjEng(self, comps='TQU', proj_name=None, get=True,
"""
if proj_name is None: proj_name = self.proj_name
tile_suffix = 'Tiled' if self.tiling else 'NonTiled'

# Interpolation mode
if interpol is None: interpol = self.interpol
if interpol in ["nn", "nearest"]: interpol_suffix = ""
elif interpol in ["lin", "bilinear"]: interpol_suffix = "_Bilinear"
else: raise ValueError("ProjEng interpol '%s' not recognized" % str(interpol))
if interpol is None:
interpol = self.interpol
if interpol in ["nn", "nearest"]:
interpol_suffix = ""
elif interpol in ["lin", "bilinear"]:
interpol_suffix = "_Bilinear"
else:
raise ValueError("ProjEng interpol '%s' not recognized" % str(interpol))

projeng_name = f'ProjEng_{proj_name}_{comps}_{tile_suffix}{interpol_suffix}'
if not get:
return projeng_name
Expand Down
Loading

0 comments on commit 8f8ed1e

Please sign in to comment.