21
21
from astropy .utils .exceptions import (AstropyUserWarning ,
22
22
AstropyDeprecationWarning )
23
23
from astropy .convolution import convolve
24
- import photutils
24
+ from photutils .aperture import (CircularAperture , CircularAnnulus ,
25
+ EllipticalAperture , EllipticalAnnulus )
26
+ from photutils .background import ModeEstimatorBackground
27
+ from photutils .segmentation import SegmentationImage
28
+
25
29
26
30
__all__ = [
27
31
'ConvolvedSersic2D' ,
@@ -161,7 +165,7 @@ def _fraction_of_total_function_circ(r, image, center, fraction, total_sum):
161
165
if r == 0 :
162
166
cur_fraction = 0.0
163
167
else :
164
- ap = photutils . aperture . CircularAperture (center , r )
168
+ ap = CircularAperture (center , r )
165
169
# Force flux sum to be positive:
166
170
ap_sum = np .abs (ap .do_photometry (image , method = 'exact' )[0 ][0 ])
167
171
cur_fraction = ap_sum / total_sum
@@ -176,7 +180,7 @@ def _radius_at_fraction_of_total_circ(image, center, r_total, fraction):
176
180
"""
177
181
flag = 0
178
182
179
- ap_total = photutils . aperture . CircularAperture (center , r_total )
183
+ ap_total = CircularAperture (center , r_total )
180
184
181
185
total_sum = ap_total .do_photometry (image , method = 'exact' )[0 ][0 ]
182
186
if total_sum == 0 :
@@ -220,7 +224,7 @@ def _fraction_of_total_function_ellip(a, image, center, elongation, theta,
220
224
cur_fraction = 0.0
221
225
else :
222
226
b = a / elongation
223
- ap = photutils . aperture . EllipticalAperture (center , a , b , theta = theta )
227
+ ap = EllipticalAperture (center , a , b , theta = theta )
224
228
# Force flux sum to be positive:
225
229
ap_sum = np .abs (ap .do_photometry (image , method = 'exact' )[0 ][0 ])
226
230
cur_fraction = ap_sum / total_sum
@@ -238,7 +242,7 @@ def _radius_at_fraction_of_total_ellip(image, center, elongation, theta,
238
242
flag = 0
239
243
240
244
b_total = a_total / elongation
241
- ap_total = photutils . aperture . EllipticalAperture (
245
+ ap_total = EllipticalAperture (
242
246
center , a_total , b_total , theta = theta )
243
247
244
248
total_sum = ap_total .do_photometry (image , method = 'exact' )[0 ][0 ]
@@ -595,8 +599,8 @@ def __init__(self, image, segmap, label, mask=None, weightmap=None,
595
599
# Measure runtime
596
600
start = time .time ()
597
601
598
- if not isinstance (self ._segmap , photutils . segmentation . SegmentationImage ):
599
- self ._segmap = photutils . segmentation . SegmentationImage (self ._segmap )
602
+ if not isinstance (self ._segmap , SegmentationImage ):
603
+ self ._segmap = SegmentationImage (self ._segmap )
600
604
601
605
# Check sanity of input data
602
606
self ._segmap .check_labels ([self .label ])
@@ -1110,8 +1114,8 @@ def _petrosian_function_circ(self, r, center):
1110
1114
r_in = r - 0.5 * self ._annulus_width
1111
1115
r_out = r + 0.5 * self ._annulus_width
1112
1116
1113
- circ_annulus = photutils . aperture . CircularAnnulus (center , r_in , r_out )
1114
- circ_aperture = photutils . aperture . CircularAperture (center , r )
1117
+ circ_annulus = CircularAnnulus (center , r_in , r_out )
1118
+ circ_aperture = CircularAperture (center , r )
1115
1119
1116
1120
# Force mean fluxes to be positive:
1117
1121
circ_annulus_mean_flux = np .abs (_aperture_mean_nomask (
@@ -1208,7 +1212,7 @@ def flux_circ(self):
1208
1212
"""
1209
1213
image = self ._cutout_stamp_maskzeroed
1210
1214
r = self ._petro_extent_flux * self .rpetro_circ
1211
- ap = photutils . aperture . CircularAperture (self ._asymmetry_center , r )
1215
+ ap = CircularAperture (self ._asymmetry_center , r )
1212
1216
# Force flux sum to be positive:
1213
1217
ap_sum = np .abs (ap .do_photometry (image , method = 'exact' )[0 ][0 ])
1214
1218
return ap_sum
@@ -1232,9 +1236,9 @@ def _petrosian_function_ellip(self, a, center, elongation, theta):
1232
1236
1233
1237
b_out = a_out / elongation
1234
1238
1235
- ellip_annulus = photutils . aperture . EllipticalAnnulus (
1239
+ ellip_annulus = EllipticalAnnulus (
1236
1240
center , a_in , a_out , b_out , theta = theta )
1237
- ellip_aperture = photutils . aperture . EllipticalAperture (
1241
+ ellip_aperture = EllipticalAperture (
1238
1242
center , a , b , theta = theta )
1239
1243
1240
1244
# Force mean fluxes to be positive:
@@ -1327,7 +1331,7 @@ def flux_ellip(self):
1327
1331
a = self ._petro_extent_flux * self .rpetro_ellip
1328
1332
b = a / self .elongation_asymmetry
1329
1333
theta = self .orientation_asymmetry
1330
- ap = photutils . aperture . EllipticalAperture (
1334
+ ap = EllipticalAperture (
1331
1335
self ._asymmetry_center , a , b , theta = theta )
1332
1336
# Force flux sum to be positive:
1333
1337
ap_sum = np .abs (ap .do_photometry (image , method = 'exact' )[0 ][0 ])
@@ -1352,7 +1356,7 @@ def _segmap_gini(self):
1352
1356
a_out = self .rpetro_ellip + 0.5 * self ._annulus_width
1353
1357
b_out = a_out / self .elongation_asymmetry
1354
1358
theta = self .orientation_asymmetry
1355
- ellip_annulus = photutils . aperture . EllipticalAnnulus (
1359
+ ellip_annulus = EllipticalAnnulus (
1356
1360
(self ._xc_stamp , self ._yc_stamp ), a_in , a_out , b_out , theta = theta )
1357
1361
ellip_annulus_mean_flux = _aperture_mean_nomask (
1358
1362
ellip_annulus , cutout_smooth , method = 'exact' )
@@ -1694,21 +1698,21 @@ def _asymmetry_function(self, center, image, kind):
1694
1698
# Create aperture for the chosen kind of asymmetry
1695
1699
if kind == 'cas' or kind == 'rms' :
1696
1700
r = self ._petro_extent_cas * self ._rpetro_circ_centroid
1697
- ap = photutils . aperture . CircularAperture (center , r )
1701
+ ap = CircularAperture (center , r )
1698
1702
elif kind == 'outer' :
1699
1703
a_in = self .rhalf_ellip
1700
1704
a_out = self .rmax_ellip
1701
1705
b_out = a_out / self .elongation_asymmetry
1702
1706
theta = self .orientation_asymmetry
1703
1707
assert (a_in > 0 ) & (a_out > 0 )
1704
- ap = photutils . aperture . EllipticalAnnulus (center , a_in , a_out , b_out , theta = theta )
1708
+ ap = EllipticalAnnulus (center , a_in , a_out , b_out , theta = theta )
1705
1709
elif kind == 'shape' :
1706
1710
if np .isnan (self .rmax_circ ) or (self .rmax_circ <= 0 ):
1707
1711
warnings .warn ('[shape_asym] Invalid rmax_circ value.' ,
1708
1712
AstropyUserWarning )
1709
1713
self .flag = 2
1710
1714
return - 99.0 # invalid
1711
- ap = photutils . aperture . CircularAperture (center , self .rmax_circ )
1715
+ ap = CircularAperture (center , self .rmax_circ )
1712
1716
else :
1713
1717
raise NotImplementedError ('Asymmetry kind not understood:' , kind )
1714
1718
@@ -1939,7 +1943,7 @@ def smoothness(self):
1939
1943
# Exclude central region during smoothness calculation:
1940
1944
r_in = self ._petro_fraction_cas * self .rpetro_circ
1941
1945
r_out = self ._petro_extent_cas * self .rpetro_circ
1942
- ap = photutils . aperture . CircularAnnulus (self ._asymmetry_center , r_in , r_out )
1946
+ ap = CircularAnnulus (self ._asymmetry_center , r_in , r_out )
1943
1947
1944
1948
boxcar_size = int (self ._petro_fraction_cas * self .rpetro_circ )
1945
1949
image_smooth = ndi .uniform_filter (image , size = boxcar_size )
@@ -2405,7 +2409,7 @@ def _segmap_shape_asym(self):
2405
2409
# that only contains background sky (hopefully).
2406
2410
r_in = self ._petro_extent_flux * self .rpetro_ellip
2407
2411
r_out = 2.0 * self ._petro_extent_flux * self .rpetro_ellip
2408
- circ_annulus = photutils . aperture . CircularAnnulus (center , r_in , r_out )
2412
+ circ_annulus = CircularAnnulus (center , r_in , r_out )
2409
2413
2410
2414
# Convert circular annulus aperture to binary mask
2411
2415
circ_annulus_mask = circ_annulus .to_mask (method = 'center' )
@@ -2431,7 +2435,7 @@ def _segmap_shape_asym(self):
2431
2435
return ~ self ._mask_stamp_no_bg
2432
2436
2433
2437
# Define the "mode" as in Bertin & Arnouts (1996):
2434
- bkg_estimator = photutils . background . ModeEstimatorBackground (
2438
+ bkg_estimator = ModeEstimatorBackground (
2435
2439
median_factor = 2.5 , mean_factor = 1.5 )
2436
2440
2437
2441
# Do sigma-clipping until convergence
@@ -2624,7 +2628,7 @@ def _sersic_model(self):
2624
2628
self .flag_sersic = 2
2625
2629
a_in = guess_r_eff
2626
2630
b_out = (1 - guess_ellip ) * a_out
2627
- ellip_annulus = photutils . aperture . EllipticalAnnulus (
2631
+ ellip_annulus = EllipticalAnnulus (
2628
2632
guess_center , a_in , a_out , b_out , theta = guess_theta )
2629
2633
ellip_annulus_mean_flux = _aperture_mean_nomask (
2630
2634
ellip_annulus , image , method = 'exact' )
@@ -3211,8 +3215,8 @@ def source_morphology(image, segmap, **kwargs):
3211
3215
See `README.rst` for a list of references.
3212
3216
3213
3217
"""
3214
- if not isinstance (segmap , photutils . segmentation . SegmentationImage ):
3215
- segmap = photutils . segmentation . SegmentationImage (segmap )
3218
+ if not isinstance (segmap , SegmentationImage ):
3219
+ segmap = SegmentationImage (segmap )
3216
3220
3217
3221
sources_morph = []
3218
3222
for label in segmap .labels :
0 commit comments