def estimate_background(self, method, sigma_clip=True, sigma_level=3.0):
"""
This function ...
:param method:
:param sigma_clip:
:param sigma_level:
:return:
"""
# Make a distinction between the "PTS" way of estimating the background and all other methods.
# For the PTS way, in case sigma clipping is disabled, this means it is disabled only for the 'polynomial fitting step'
# of the background estimation, so provide two distinct masks to the interpolated() method: the clipped mask for
# the 'background noise' estimation and the non-clipped mask for the 'polynomial fitting step'.
if method == "pts":
if sigma_clip:
try:
mask = statistics.sigma_clip_mask(self.cutout, sigma_level=sigma_level, mask=self.mask)
except TypeError:
#plotting.plot_box(self.cutout)
#plotting.plot_mask(self.mask)
#print("xsize", self.cutout.xsize, self.cutout.ysize)
radius = int(round(0.25 * self.cutout.xsize))
#print("radius", 0.25*self.cutout.xsize, radius)
disk = morphology.disk(radius, dtype=bool)
mask = Mask.empty_like(self.cutout)
x_min = int(round(0.5 * (self.cutout.xsize - disk.shape[1])))
y_min = int(round(0.5 * (self.cutout.ysize - disk.shape[0])))
#plotting.plot_mask(mask)
mask[y_min:y_min+disk.shape[0], x_min:x_min+disk.shape[1]] = disk
#plotting.plot_mask(mask)
no_clip_mask = None
else:
mask = statistics.sigma_clip_mask(self.cutout, sigma_level=sigma_level, mask=self.mask)
no_clip_mask = self.mask
else:
# Perform sigma-clipping on the background if requested
if sigma_clip: mask = statistics.sigma_clip_mask(self.cutout, sigma_level=sigma_level, mask=self.mask)
else: mask = self.mask
no_clip_mask = None
if self.contamination is not None:
mask = mask + self.contamination
if no_clip_mask is not None: no_clip_mask = no_clip_mask + self.contamination
# Perform the interpolation
self.background = self.cutout.interpolated(mask, method, no_clip_mask=no_clip_mask, plot=self.special)
if self.special: self.plot(title="background estimated")
# -----------------------------------------------------------------
评论列表
文章目录