Skip to content

Commit 5550c00

Browse files
committed
Update to photutils v2.0.
1 parent dbd82c4 commit 5550c00

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

statmorph/statmorph.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
from astropy.utils.exceptions import (AstropyUserWarning,
2222
AstropyDeprecationWarning)
2323
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+
2529

2630
__all__ = [
2731
'ConvolvedSersic2D',
@@ -161,7 +165,7 @@ def _fraction_of_total_function_circ(r, image, center, fraction, total_sum):
161165
if r == 0:
162166
cur_fraction = 0.0
163167
else:
164-
ap = photutils.aperture.CircularAperture(center, r)
168+
ap = CircularAperture(center, r)
165169
# Force flux sum to be positive:
166170
ap_sum = np.abs(ap.do_photometry(image, method='exact')[0][0])
167171
cur_fraction = ap_sum / total_sum
@@ -176,7 +180,7 @@ def _radius_at_fraction_of_total_circ(image, center, r_total, fraction):
176180
"""
177181
flag = 0
178182

179-
ap_total = photutils.aperture.CircularAperture(center, r_total)
183+
ap_total = CircularAperture(center, r_total)
180184

181185
total_sum = ap_total.do_photometry(image, method='exact')[0][0]
182186
if total_sum == 0:
@@ -220,7 +224,7 @@ def _fraction_of_total_function_ellip(a, image, center, elongation, theta,
220224
cur_fraction = 0.0
221225
else:
222226
b = a / elongation
223-
ap = photutils.aperture.EllipticalAperture(center, a, b, theta=theta)
227+
ap = EllipticalAperture(center, a, b, theta=theta)
224228
# Force flux sum to be positive:
225229
ap_sum = np.abs(ap.do_photometry(image, method='exact')[0][0])
226230
cur_fraction = ap_sum / total_sum
@@ -238,7 +242,7 @@ def _radius_at_fraction_of_total_ellip(image, center, elongation, theta,
238242
flag = 0
239243

240244
b_total = a_total / elongation
241-
ap_total = photutils.aperture.EllipticalAperture(
245+
ap_total = EllipticalAperture(
242246
center, a_total, b_total, theta=theta)
243247

244248
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,
595599
# Measure runtime
596600
start = time.time()
597601

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)
600604

601605
# Check sanity of input data
602606
self._segmap.check_labels([self.label])
@@ -1110,8 +1114,8 @@ def _petrosian_function_circ(self, r, center):
11101114
r_in = r - 0.5 * self._annulus_width
11111115
r_out = r + 0.5 * self._annulus_width
11121116

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)
11151119

11161120
# Force mean fluxes to be positive:
11171121
circ_annulus_mean_flux = np.abs(_aperture_mean_nomask(
@@ -1208,7 +1212,7 @@ def flux_circ(self):
12081212
"""
12091213
image = self._cutout_stamp_maskzeroed
12101214
r = self._petro_extent_flux * self.rpetro_circ
1211-
ap = photutils.aperture.CircularAperture(self._asymmetry_center, r)
1215+
ap = CircularAperture(self._asymmetry_center, r)
12121216
# Force flux sum to be positive:
12131217
ap_sum = np.abs(ap.do_photometry(image, method='exact')[0][0])
12141218
return ap_sum
@@ -1232,9 +1236,9 @@ def _petrosian_function_ellip(self, a, center, elongation, theta):
12321236

12331237
b_out = a_out / elongation
12341238

1235-
ellip_annulus = photutils.aperture.EllipticalAnnulus(
1239+
ellip_annulus = EllipticalAnnulus(
12361240
center, a_in, a_out, b_out, theta=theta)
1237-
ellip_aperture = photutils.aperture.EllipticalAperture(
1241+
ellip_aperture = EllipticalAperture(
12381242
center, a, b, theta=theta)
12391243

12401244
# Force mean fluxes to be positive:
@@ -1327,7 +1331,7 @@ def flux_ellip(self):
13271331
a = self._petro_extent_flux * self.rpetro_ellip
13281332
b = a / self.elongation_asymmetry
13291333
theta = self.orientation_asymmetry
1330-
ap = photutils.aperture.EllipticalAperture(
1334+
ap = EllipticalAperture(
13311335
self._asymmetry_center, a, b, theta=theta)
13321336
# Force flux sum to be positive:
13331337
ap_sum = np.abs(ap.do_photometry(image, method='exact')[0][0])
@@ -1352,7 +1356,7 @@ def _segmap_gini(self):
13521356
a_out = self.rpetro_ellip + 0.5 * self._annulus_width
13531357
b_out = a_out / self.elongation_asymmetry
13541358
theta = self.orientation_asymmetry
1355-
ellip_annulus = photutils.aperture.EllipticalAnnulus(
1359+
ellip_annulus = EllipticalAnnulus(
13561360
(self._xc_stamp, self._yc_stamp), a_in, a_out, b_out, theta=theta)
13571361
ellip_annulus_mean_flux = _aperture_mean_nomask(
13581362
ellip_annulus, cutout_smooth, method='exact')
@@ -1694,21 +1698,21 @@ def _asymmetry_function(self, center, image, kind):
16941698
# Create aperture for the chosen kind of asymmetry
16951699
if kind == 'cas' or kind == 'rms':
16961700
r = self._petro_extent_cas * self._rpetro_circ_centroid
1697-
ap = photutils.aperture.CircularAperture(center, r)
1701+
ap = CircularAperture(center, r)
16981702
elif kind == 'outer':
16991703
a_in = self.rhalf_ellip
17001704
a_out = self.rmax_ellip
17011705
b_out = a_out / self.elongation_asymmetry
17021706
theta = self.orientation_asymmetry
17031707
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)
17051709
elif kind == 'shape':
17061710
if np.isnan(self.rmax_circ) or (self.rmax_circ <= 0):
17071711
warnings.warn('[shape_asym] Invalid rmax_circ value.',
17081712
AstropyUserWarning)
17091713
self.flag = 2
17101714
return -99.0 # invalid
1711-
ap = photutils.aperture.CircularAperture(center, self.rmax_circ)
1715+
ap = CircularAperture(center, self.rmax_circ)
17121716
else:
17131717
raise NotImplementedError('Asymmetry kind not understood:', kind)
17141718

@@ -1939,7 +1943,7 @@ def smoothness(self):
19391943
# Exclude central region during smoothness calculation:
19401944
r_in = self._petro_fraction_cas * self.rpetro_circ
19411945
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)
19431947

19441948
boxcar_size = int(self._petro_fraction_cas * self.rpetro_circ)
19451949
image_smooth = ndi.uniform_filter(image, size=boxcar_size)
@@ -2405,7 +2409,7 @@ def _segmap_shape_asym(self):
24052409
# that only contains background sky (hopefully).
24062410
r_in = self._petro_extent_flux * self.rpetro_ellip
24072411
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)
24092413

24102414
# Convert circular annulus aperture to binary mask
24112415
circ_annulus_mask = circ_annulus.to_mask(method='center')
@@ -2431,7 +2435,7 @@ def _segmap_shape_asym(self):
24312435
return ~self._mask_stamp_no_bg
24322436

24332437
# Define the "mode" as in Bertin & Arnouts (1996):
2434-
bkg_estimator = photutils.background.ModeEstimatorBackground(
2438+
bkg_estimator = ModeEstimatorBackground(
24352439
median_factor=2.5, mean_factor=1.5)
24362440

24372441
# Do sigma-clipping until convergence
@@ -2624,7 +2628,7 @@ def _sersic_model(self):
26242628
self.flag_sersic = 2
26252629
a_in = guess_r_eff
26262630
b_out = (1 - guess_ellip) * a_out
2627-
ellip_annulus = photutils.aperture.EllipticalAnnulus(
2631+
ellip_annulus = EllipticalAnnulus(
26282632
guess_center, a_in, a_out, b_out, theta=guess_theta)
26292633
ellip_annulus_mean_flux = _aperture_mean_nomask(
26302634
ellip_annulus, image, method='exact')
@@ -3211,8 +3215,8 @@ def source_morphology(image, segmap, **kwargs):
32113215
See `README.rst` for a list of references.
32123216
32133217
"""
3214-
if not isinstance(segmap, photutils.segmentation.SegmentationImage):
3215-
segmap = photutils.segmentation.SegmentationImage(segmap)
3218+
if not isinstance(segmap, SegmentationImage):
3219+
segmap = SegmentationImage(segmap)
32163220

32173221
sources_morph = []
32183222
for label in segmap.labels:

statmorph/utils/image_diagnostics.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# Licensed under a 3-Clause BSD License.
77

88
import numpy as np
9-
import sys
109
import skimage.transform
1110
import statmorph
1211
from astropy.visualization import simple_norm

0 commit comments

Comments
 (0)