@@ -379,6 +379,11 @@ def calc_bounding_polygon(self, stepsize=None):
379
379
of the image are included automatically. If `stepsize` is `None`,
380
380
bounding polygon will contain only vertices of the image.
381
381
382
+ Notes
383
+ -----
384
+ The bounding polygon is defined from corners of pixels whereas the pixel
385
+ coordinates refer to their centers and therefore the lower-left corner
386
+ is located at (-0.5, -0.5)
382
387
"""
383
388
ny , nx = self .image_shape
384
389
@@ -451,14 +456,6 @@ def set_builtin_skystat(self, skystat='median', lower=None, upper=None,
451
456
binwidth = binwidth
452
457
)
453
458
454
- # TODO: due to a bug in the sphere package, see
455
- # https://github.com/spacetelescope/sphere/issues/74
456
- # intersections with polygons formed as union does not work.
457
- # For this reason I re-implement 'calc_sky' below with
458
- # a workaround for the bug.
459
- # The original implementation (now called ``_calc_sky_orig``
460
- # should replace current 'calc_sky' once the bug is fixed.
461
- #
462
459
def calc_sky (self , overlap = None , delta = True ):
463
460
"""
464
461
Compute sky background value.
@@ -494,7 +491,15 @@ def calc_sky(self, overlap=None, delta=True):
494
491
polyarea : float
495
492
Area (in srad) of the polygon that bounds data used to compute
496
493
sky statistics.
497
-
494
+
495
+ Notes
496
+ -----
497
+ Due to a bug in the sphere package, see
498
+ https://github.com/spacetelescope/sphere/issues/74
499
+ intersections with polygons formed as union does not work.
500
+ For this reason I re-implement 'calc_sky' below with a workaround for
501
+ the bug. The original implementation should be used when the bug is
502
+ fixed.
498
503
"""
499
504
if overlap is None :
500
505
@@ -582,109 +587,6 @@ def calc_sky(self, overlap=None, delta=True):
582
587
583
588
return skyval , npix , polyarea
584
589
585
- # def _calc_sky_orig(self, overlap=None, delta=True):
586
- # """
587
- # Compute sky background value.
588
- #
589
- # Parameters
590
- # ----------
591
- # overlap : SkyImage, SkyGroup, SphericalPolygon, list of tuples, \
592
- # None, optional
593
- # Another `SkyImage`, `SkyGroup`,
594
- # :py:class:`spherical_geometry.polygons.SphericalPolygon`, or
595
- # a list of tuples of (RA, DEC) of vertices of a spherical
596
- # polygon. This parameter is used to indicate that sky statistics
597
- # should computed only in the region of intersection of *this*
598
- # image with the polygon indicated by `overlap`. When `overlap` is
599
- # `None`, sky statistics will be computed over the entire image.
600
- #
601
- # delta : bool, optional
602
- # Should this function return absolute sky value or the difference
603
- # between the computed value and the value of the sky stored in the
604
- # `sky` property.
605
- #
606
- # Returns
607
- # -------
608
- # skyval : float, None
609
- # Computed sky value (absolute or relative to the `sky` attribute).
610
- # If there are no valid data to perform this computations (e.g.,
611
- # because this image does not overlap with the image indicated by
612
- # `overlap`), `skyval` will be set to `None`.
613
- #
614
- # npix : int
615
- # Number of pixels used to compute sky statistics.
616
- #
617
- # polyarea : float
618
- # Area (in srad) of the polygon that bounds data used to compute
619
- # sky statistics.
620
- #
621
- # """
622
- #
623
- # if overlap is None:
624
- #
625
- # if self._mask is None:
626
- # data = self.image
627
- # else:
628
- # data = self.image[self._mask.get_data()]
629
- #
630
- # polyarea = self.poly_area
631
- #
632
- # else:
633
- # fill_mask = np.zeros(self.image_shape, dtype=bool)
634
- #
635
- # if isinstance(overlap, (SkyImage, SkyGroup, SphericalPolygon)):
636
- # intersection = self.intersection(overlap)
637
- # polyarea = np.fabs(intersection.area())
638
- # radec = intersection.to_radec()
639
- #
640
- # else: # assume a list of (ra, dec) tuples:
641
- # radec = []
642
- # polyarea = 0.0
643
- # for r, d in overlap:
644
- # poly = SphericalPolygon.from_radec(r, d)
645
- # polyarea1 = np.fabs(poly.area())
646
- # if polyarea1 == 0.0 or len(r) < 4:
647
- # continue
648
- # polyarea += polyarea1
649
- # radec.append(self.intersection(poly).to_radec())
650
- #
651
- # if polyarea == 0.0:
652
- # return None, 0, 0.0
653
- #
654
- # for ra, dec in radec:
655
- # if len(ra) < 4:
656
- # continue
657
- #
658
- # # set pixels in 'fill_mask' that are inside a polygon
659
- # # to True:
660
- # x, y = self.wcs_inv(ra, dec)
661
- # poly_vert = list(zip(*[x, y]))
662
- #
663
- # polygon = region.Polygon(True, poly_vert)
664
- # fill_mask = polygon.scan(fill_mask)
665
- #
666
- # if self._mask is not None:
667
- # fill_mask &= self._mask.get_data()
668
- #
669
- # data = self.image[fill_mask]
670
- #
671
- # if data.size < 1:
672
- # return None, 0, 0.0
673
- #
674
- # # Calculate sky
675
- # try:
676
- #
677
- # skyval, npix = self._skystat(data)
678
- #
679
- # except ValueError:
680
- #
681
- # return None, 0, 0.0
682
- #
683
- # if delta:
684
- # skyval -= self._sky
685
- #
686
- # return skyval, npix, polyarea
687
-
688
590
def copy (self ):
689
591
"""
690
592
Return a shallow copy of the `SkyImage` object.
0 commit comments