Skip to content

Commit

Permalink
Merge pull request #200 from strampelligiovanni/gs-annulus-mask
Browse files Browse the repository at this point in the history
Gs annulus mask
  • Loading branch information
AarynnCarter authored Jul 9, 2024
2 parents b2fbe8a + f601c0b commit da8e3b2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions spaceKLIP/analysistools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,7 @@ def extract_companions(self,
appmag, # mag
appmag_err, # mag
mstar[filt], # mag
mstar_err, # mag
mstar_err_temp, # mag
np.nan,
np.nan,
scale_factor_avg,
Expand Down Expand Up @@ -1520,7 +1520,7 @@ def extract_companions(self,
appmag, # mag
appmag_err, # mag
mstar[filt], # mag
mstar_err, # mag
mstar_err_temp, # mag
np.nan,
evidence_ratio,
scale_factor_avg,
Expand Down
20 changes: 17 additions & 3 deletions spaceKLIP/imagetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2012,7 +2012,7 @@ def align_frames(self,
mask_override : str, optional
Mask some pixels when cross correlating for shifts
msk_shp : int, optional
Shape (height or radius) for custom mask invoked by "mask_override"
Shape (height or radius, or [inner radius, outer radius]) for custom mask invoked by "mask_override"
shft_exp : float, optional
Take image to the given power before cross correlating for shifts, default is 1. For instance, 1/2 helps align nircam bar/narrow data (or other data with weird speckles)
kwargs : dict, optional
Expand All @@ -2034,6 +2034,18 @@ def align_frames(self,
os.makedirs(output_dir)

# useful masks for computing shifts:
def create_annulus_mask(h, w, center=None, radius=None):

if center is None: # use the middle of the image
center = (int(w/2), int(h/2))
if radius is None: # use the smallest distance between the center and image walls
radius = min(center[0], center[1], w-center[0], h-center[1])

Y, X = np.ogrid[:h, :w]
dist_from_center = np.sqrt((X - center[0])**2 + (Y-center[1])**2)

mask = (dist_from_center <= radius[0]) | (dist_from_center >= radius[1])
return mask
def create_circular_mask(h, w, center=None, radius=None):

if center is None: # use the middle of the image
Expand Down Expand Up @@ -2080,7 +2092,9 @@ def create_rec_mask(h, w, center=None, z=None):
maskfile = self.database.obs[key]['MASKFILE'][j]
mask = ut.read_msk(maskfile)
if mask_override is not None:
if mask_override == 'circ':
if mask_override == 'ann':
mask_circ = create_annulus_mask(data[0].shape[0], data[0].shape[1], radius=msk_shp)
elif mask_override == 'circ':
mask_circ = create_circular_mask(data[0].shape[0],data[0].shape[1], radius=msk_shp)
elif mask_override == 'rec':
mask_circ = create_rec_mask(data[0].shape[0],data[0].shape[1], z=msk_shp)
Expand All @@ -2093,7 +2107,7 @@ def create_rec_mask(h, w, center=None, z=None):
mask_temp = np.ones_like(data[0])
else:
mask_temp = mask

# Align frames.
head, tail = os.path.split(fitsfile)
log.info(' --> Align frames: ' + tail)
Expand Down

0 comments on commit da8e3b2

Please sign in to comment.