Skip to content

Commit 705f544

Browse files
Update changes
1 parent 46a88e2 commit 705f544

File tree

3 files changed

+21
-119
lines changed

3 files changed

+21
-119
lines changed

Diff for: changes/310.general.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Move common parts of skymatch shared by both jwst and romancal into stcal.

Diff for: src/stcal/skymatch/skyimage.py

+14-112
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,11 @@ def calc_bounding_polygon(self, stepsize=None):
379379
of the image are included automatically. If `stepsize` is `None`,
380380
bounding polygon will contain only vertices of the image.
381381
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)
382387
"""
383388
ny, nx = self.image_shape
384389

@@ -451,14 +456,6 @@ def set_builtin_skystat(self, skystat='median', lower=None, upper=None,
451456
binwidth=binwidth
452457
)
453458

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-
#
462459
def calc_sky(self, overlap=None, delta=True):
463460
"""
464461
Compute sky background value.
@@ -494,7 +491,15 @@ def calc_sky(self, overlap=None, delta=True):
494491
polyarea : float
495492
Area (in srad) of the polygon that bounds data used to compute
496493
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.
498503
"""
499504
if overlap is None:
500505

@@ -582,109 +587,6 @@ def calc_sky(self, overlap=None, delta=True):
582587

583588
return skyval, npix, polyarea
584589

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-
688590
def copy(self):
689591
"""
690592
Return a shallow copy of the `SkyImage` object.

Diff for: src/stcal/skymatch/skystatistics.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414
__all__ = ['SkyStats']
1515

1616

17-
class SkyStats():
17+
class SkyStats:
1818
"""
19-
This is a superclass build on top of
20-
:py:class:`stsci.imagestats.ImageStats`. Compared to
21-
:py:class:`stsci.imagestats.ImageStats`, `SkyStats` has
22-
"persistent settings" in the sense that object's parameters need to be
23-
set once and these settings will be applied to all subsequent
24-
computations on different data.
19+
This class is built on top of :py:class:`stsci.imagestats.ImageStats`,
20+
deligating its functionality to calls to the ``ImageStats`` object. Compared
21+
to :py:class:`stsci.imagestats.ImageStats`, `SkyStats` has "persistent settings"
22+
in the sense that object's parameters need to be set once and these settings
23+
will be applied to all subsequent computations on different data.
2524
2625
"""
2726

0 commit comments

Comments
 (0)