本文整理汇总了Python中photutils.CircularAperture.to_mask方法的典型用法代码示例。如果您正苦于以下问题:Python CircularAperture.to_mask方法的具体用法?Python CircularAperture.to_mask怎么用?Python CircularAperture.to_mask使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类photutils.CircularAperture
的用法示例。
在下文中一共展示了CircularAperture.to_mask方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: measure_one_annular_bg
# 需要导入模块: from photutils import CircularAperture [as 别名]
# 或者: from photutils.CircularAperture import to_mask [as 别名]
def measure_one_annular_bg(image, center, innerRad, outerRad, metric, apMethod='exact'):
"""Class methods are similar to regular functions.
Note:
Do not include the `self` parameter in the ``Args`` section.
Args:
param1: The first parameter.
param2: The second parameter.
Returns:
True if successful, False otherwise.
"""
innerAperture = CircularAperture(center, innerRad)
outerAperture = CircularAperture(center, outerRad)
inner_aper_mask = innerAperture.to_mask(method=apMethod)[0]
inner_aper_mask = inner_aper_mask.to_image(image.shape).astype(bool)
outer_aper_mask = outerAperture.to_mask(method=apMethod)[0]
outer_aper_mask = outer_aper_mask.to_image(image.shape).astype(bool)
backgroundMask = (~inner_aper_mask)*outer_aper_mask
return metric(image[backgroundMask])
示例2: measure_one_background
# 需要导入模块: from photutils import CircularAperture [as 别名]
# 或者: from photutils.CircularAperture import to_mask [as 别名]
def measure_one_background(image, center, aperRad, metric, apMethod='exact', bgMethod='circle'):
"""Class methods are similar to regular functions.
Note:
Do not include the `self` parameter in the ``Args`` section.
Args:
param1: The first parameter.
param2: The second parameter.
Returns:
True if successful, False otherwise.
"""
if np.ndim(aperRad) == 0:
aperture = CircularAperture(center, aperRad)
aperture = aperture.to_mask(method=apMethod)[0] # list of ApertureMask objects (one for each position)
aperture = ~aperture.to_image(image).astype(bool) # inverse to keep 'outside' aperture
else:
innerRad, outerRad = aperRad
innerAperture = CircularAperture(center, innerRad)
outerAperture = CircularAperture(center, outerRad)
inner_aper_mask = innerAperture.to_mask(method=method)[0]
inner_aper_mask = inner_aper_mask.to_image(image.shape).astype(bool)
outer_aper_mask = outerAperture.to_mask(method=method)[0]
outer_aper_mask = outer_aper_mask.to_image(image.shape).astype(bool)
aperture = (~inner_aper_mask)*outer_aper_mask
if bgMethod == 'median':
medFrame = median(image[aperture])
madFrame = scale.mad(image[aperture])
medianMask= abs(image - medFrame) < nSig*madFrame
aperture = medianMask*aperture
if bgMethod == 'kde':
kdeFrame = kde.KDEUnivariate(image[aperture].ravel())
kdeFrame.fit()
return kdeFrame.support[kdeFrame.density.argmax()]
return metric(image[aperture])
示例3: measure_one_median_bg
# 需要导入模块: from photutils import CircularAperture [as 别名]
# 或者: from photutils.CircularAperture import to_mask [as 别名]
def measure_one_median_bg(image, center, aperRad, metric, nSig, apMethod='exact'):
"""Class methods are similar to regular functions.
Note:
Do not include the `self` parameter in the ``Args`` section.
Args:
param1: The first parameter.
param2: The second parameter.
Returns:
True if successful, False otherwise.
"""
aperture = CircularAperture(center, aperRad)
aperture = aperture.to_mask(method=apMethod)[0]
aperture = aperture.to_image(image.shape).astype(bool)
backgroundMask = ~aperture
medFrame = median(image[backgroundMask])
madFrame = std(image[backgroundMask])
medianMask= abs(image - medFrame) < nSig*madFrame
maskComb = medianMask*backgroundMask
return median(image[maskComb])
示例4: measure_one_circle_bg
# 需要导入模块: from photutils import CircularAperture [as 别名]
# 或者: from photutils.CircularAperture import to_mask [as 别名]
def measure_one_circle_bg(image, center, aperRad, metric, apMethod='exact'):
"""Class methods are similar to regular functions.
Note:
Do not include the `self` parameter in the ``Args`` section.
Args:
param1: The first parameter.
param2: The second parameter.
Returns:
True if successful, False otherwise.
"""
aperture = CircularAperture(center, aperRad)
aper_mask = aperture.to_mask(method=apMethod)[0] # list of ApertureMask objects (one for each position)
# backgroundMask = abs(aperture.get_fractions(np.ones(self.imageCube[0].shape))-1)
backgroundMask = aper_mask.to_image(image.shape).astype(bool)
backgroundMask = ~backgroundMask#[backgroundMask == 0] = False
return metric(image[backgroundMask])
示例5: measure_one_KDE_bg
# 需要导入模块: from photutils import CircularAperture [as 别名]
# 或者: from photutils.CircularAperture import to_mask [as 别名]
def measure_one_KDE_bg(image, center, aperRad, metric, apMethod='exact'):
"""Class methods are similar to regular functions.
Note:
Do not include the `self` parameter in the ``Args`` section.
Args:
param1: The first parameter.
param2: The second parameter.
Returns:
True if successful, False otherwise.
"""
aperture = CircularAperture(center, aperRad)
aperture = aperture.to_mask(method=apMethod)[0]
aperture = aperture.to_image(image.shape).astype(bool)
backgroundMask = ~aperture
kdeFrame = kde.KDEUnivariate(image[backgroundMask])
kdeFrame.fit()
return kdeFrame.support[kdeFrame.density.argmax()]
示例6: photom_av
# 需要导入模块: from photutils import CircularAperture [as 别名]
# 或者: from photutils.CircularAperture import to_mask [as 别名]
def photom_av(ima, pos, radius, r_in=False, r_out=False, mode='median'):
'''
Aperture photometry in an aperture located at pixel coordinates
pos = ( (x0, y0), (x1, y1), ... ) with a radius=radius.
When r_in and r_out are given, background is estimated in CircularAnnulus and subtracted.
mode refers to how the background is estimated within the circlar annulus.
Can be 'median' or 'mean'
Photometry is calculating by median averaging the pixels within the aperture and
multiplying by the number of pixels in the aperture (including fractions of pixels).
'''
# Setting up the mask
if hasattr(ima, 'mask'):
if ima.mask.size == 1:
mask = np.zeros(ima.shape, dtype=np.bool) | ima.mask
else:
mask = ima.mask.copy()
else:
mask = np.zeros(ima.shape, dtype=np.bool)
### Performing the actual photometry - identical for each method
# Median averaging of flux in aperture
# Setting up the aperture
apertures = CircularAperture(pos, r = radius)
ap_mask = apertures.to_mask(method='center')
# Setting up arrays to store data
nflx = len(ap_mask)
flx = np.zeros(nflx, dtype=np.float)
flux_max = np.zeros(nflx, dtype=np.float)
flux_min = np.zeros(nflx, dtype=np.float)
# Median averaging of flux
for i, am in enumerate(ap_mask):
fluxmask = ~mask & am.to_image(shape=mask.shape).astype(np.bool)
flx[i] = np.median(ima[fluxmask])
flux_max[i] = np.max(ima[fluxmask])
flux_min[i] = np.min(ima[fluxmask])
# Aperture photometry on mask to see how many masked pixels are in the
# aperture
apm = aperture_photometry(mask.astype(int), apertures)
# Number of unmasked pixels in aperture
ap_area = Column(name = 'area_aper',
data=apertures.area() - apm['aperture_sum'].data)
# Flux in aperture using median av flux and fractional no. pixels in aperture
flux_init = flx*ap_area
### Two different modes for analysing the background
if ( r_in and r_out and mode in ('mean', 'median') ):
### This stuff is the same regardless of method
# Setting up the annulus
anulus_apertures = CircularAnnulus(pos, r_in=r_in, r_out=r_out)
# Performing annulus photometry on the mask
bkgm = aperture_photometry(mask.astype(int), anulus_apertures)
# Number of masked pixels in bkg
mbkg_area = Column(name = 'bpix_bkg',
data=bkgm['aperture_sum'])
# Number of non-masked pixels in aperture and bkg
bkg_area = Column(name = 'area_bkg',
data=anulus_apertures.area() - bkgm['aperture_sum'])
### This stuff is specific to the mean
if mode == 'mean':
# Perform the annulus photometry on the image
bkg = aperture_photometry(ima, anulus_apertures, mask=mask)
# Average bkg where this divides by only number of NONMASKED pixels
# as the aperture photometry ignores the masked pixels
bkga = Column(name='background',
data=bkg['aperture_sum']/bkg_area)
# Bkg subtracted flux
flux = flux_init - bkga*ap_area
# Adding that data
ap.add_column(bkga)
elif mode == 'median':
# Number of pixels in the annulus, a different method
aperture_mask = anulus_apertures.to_mask(method='center')
nbkg = len(aperture_mask)
# Background mask
bkgm = np.zeros(nbkg, dtype=np.float)
# Median averaging
for i, am in enumerate(aperture_mask):
bmask = ~mask & am.to_image(shape=mask.shape).astype(np.bool)
bkgm[i] = np.median(ima[bmask])
flux = flux_init - bkgm*ap_area
bkgm = Column(name = 'background', data = bkgm)
#.........这里部分代码省略.........
示例7: circular_mask
# 需要导入模块: from photutils import CircularAperture [as 别名]
# 或者: from photutils.CircularAperture import to_mask [as 别名]
def circular_mask(self, radius=4):
circ = CircularAperture(self.centroid, radius)
circ_mask = circ.to_mask()[0].to_image(self.image.shape).astype(bool)
return circ_mask
示例8: do_detection
# 需要导入模块: from photutils import CircularAperture [as 别名]
# 或者: from photutils.CircularAperture import to_mask [as 别名]
def do_detection(self):
"""Flag outlier pixels in DQ of input images."""
self.build_suffix(**self.outlierpars)
self._convert_inputs()
pars = self.outlierpars
save_intermediate_results = pars['save_intermediate_results']
# Start by performing initial TSO Photometry on stack of DataModels
# TODO: need information about the actual source position in
# TSO imaging mode (for all subarrays).
# Meanwhile, this is a placeholder representing the geometric
# center of the image.
nints, ny, nx = self.inputs.data.shape
xcenter = (ny - 1) / 2.
ycenter = (ny - 1) / 2.
# all radii are in pixel units
if self.inputs.meta.instrument.pupil == 'WLP8':
radius = 50
radius_inner = 60
radius_outer = 70
else:
radius = 3
radius_inner = 4
radius_outer = 5
apertures = CircularAperture((xcenter, ycenter), r=radius)
aperture_mask = apertures.to_mask(method='center')[0]
# This mask has 1 for mask region, 0 for outside of mask
median_mask = aperture_mask.to_image((ny, nx))
inv_median_mask = np.abs(median_mask - 1)
# Perform photometry
catalog = tso_aperture_photometry(self.inputs, xcenter, ycenter,
radius, radius_inner,
radius_outer)
# Extract net photometry for the source
# This will be the value used for scaling the median image within
# the aperture region
phot_values = catalog['net_aperture_sum']
# Convert CubeModel into ModelContainer of 2-D DataModels
for image in self.input_models:
image.wht = resample_utils.build_driz_weight(
image,
weight_type='exptime',
good_bits=pars['good_bits']
)
# Initialize intermediate products used in the outlier detection
input_shape = self.input_models[0].data.shape
median_model = datamodels.ImageModel(init=input_shape)
median_model.meta = deepcopy(self.input_models[0].meta)
base_filename = self.inputs.meta.filename
median_model.meta.filename = self.make_output_path(
basepath=base_filename, suffix='median'
)
# Perform median combination on set of drizzled mosaics
median_model.data = self.create_median(self.input_models)
aper2 = CircularAnnulus((xcenter, ycenter), r_in=radius_inner,
r_out=radius_outer)
tbl1 = aperture_photometry(median_model.data, apertures,
error=median_model.data * 0.0 + 1.0)
tbl2 = aperture_photometry(median_model.data, aper2,
error=median_model.data * 0.0 + 1.0)
aperture_sum = u.Quantity(tbl1['aperture_sum'][0])
annulus_sum = u.Quantity(tbl2['aperture_sum'][0])
annulus_mean = annulus_sum / aper2.area()
aperture_bkg = annulus_mean * apertures.area()
median_phot_value = aperture_sum - aperture_bkg
if save_intermediate_results:
log.info("Writing out MEDIAN image to: {}".format(
median_model.meta.filename))
median_model.save(median_model.meta.filename)
# Scale the median image by the initial photometry (only in aperture)
# to create equivalent of 'blot' images
# Area outside of aperture in median will remain unchanged
blot_models = datamodels.ModelContainer()
for i in range(nints):
scale_factor = float(phot_values[i] / median_phot_value)
scaled_image = datamodels.ImageModel(init=median_model.data.shape)
scaled_image.meta = deepcopy(median_model.meta)
scaled_data = (median_model.data * (scale_factor * median_mask) + (
median_model.data * inv_median_mask))
scaled_image.data = scaled_data
blot_models.append(scaled_image)
if save_intermediate_results:
log.info("Writing out Scaled Median images...")
def make_output_path(ignored, idx=None):
output_path = self.make_output_path(
basepath=base_filename, suffix='blot', idx=idx,
component_format='_{asn_id}_{idx}'
#.........这里部分代码省略.........
示例9: CircularAperture
# 需要导入模块: from photutils import CircularAperture [as 别名]
# 或者: from photutils.CircularAperture import to_mask [as 别名]
txdump_out.close()
g_iraf, ge_iraf, gf_iraf, gsky_iraf = np.loadtxt('phot_test_g.txdump', usecols=(1,2,3,4), unpack=True)
i_iraf, ie_iraf, if_iraf, isky_iraf = np.loadtxt('phot_test_i.txdump', usecols=(1,2,3,4), unpack=True)
# now try python
x, y = np.loadtxt(coords_file, usecols=(0,1), unpack=True)
positions = np.array(zip(x,y))
hdu_g = fits.open(fits_g)
hdu_i = fits.open(fits_i)
apertures = CircularAperture(positions, r=8.)
annulus_apertures = CircularAnnulus(positions, r_in=10., r_out=14.)
print apertures.area()
ap_mask = apertures.to_mask(method='subpixel', subpixels=7)
dummy = np.ones_like(hdu_g[0].data)
ann_mask = annulus_apertures.to_mask(method='center')
ap_g = [m.apply(hdu_g[0].data) for i,m in enumerate(ap_mask)]
ap_i = [m.apply(hdu_i[0].data) for i,m in enumerate(ap_mask)]
area_g = [np.sum(m.apply(dummy)) for i,m in enumerate(ap_mask)]
area_i = [np.sum(m.apply(dummy)) for i,m in enumerate(ap_mask)]
print area_g, area_i
# plt.imshow(ap_g[0], interpolation='nearest')
# plt.show()
ann_g = [m.apply(hdu_g[0].data, fill_value=-999.) for i,m in enumerate(ann_mask)]
ann_i = [m.apply(hdu_i[0].data, fill_value=-999.) for i,m in enumerate(ann_mask)]
flux_g = np.array([np.sum(a) for j,a in enumerate(ap_g)])
flux_i = np.array([np.sum(a) for j,a in enumerate(ap_i)])