Skip to content

Commit

Permalink
Merge pull request #335 from lsst/tickets/DM-39720
Browse files Browse the repository at this point in the history
DM-39720: Use default factory for Stamps class
  • Loading branch information
timj committed Jun 20, 2023
2 parents 41a93ce + f8ecf2a commit 93864be
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 6 additions & 4 deletions python/lsst/meas/algorithms/accumulator_mean_stack.py
Expand Up @@ -19,6 +19,8 @@
# the GNU General Public License along with this program. If not,
# see <https://www.lsstcorp.org/LegalNotices/>.
#
import warnings

import numpy as np


Expand Down Expand Up @@ -133,9 +135,9 @@ def fill_stacked_masked_image(self, stacked_masked_image):
stacked_masked_image : `lsst.afw.image.MaskedImage`
Total masked image.
"""
with np.warnings.catch_warnings():
with warnings.catch_warnings():
# Let the NaNs through and flag bad pixels below
np.warnings.simplefilter("ignore")
warnings.simplefilter("ignore")

# The image plane is sum(weight*data)/sum(weight)
stacked_masked_image.image.array[:, :] = self.sum_wdata/self.sum_weight
Expand Down Expand Up @@ -203,10 +205,10 @@ def fill_stacked_image(self, stacked_image):
stacked_image : `lsst.afw.image.Image`
Total image.
"""
with np.warnings.catch_warnings():
with warnings.catch_warnings():
# Let the NaNs through, this should only happen
# if we're stacking with no inputs.
np.warnings.simplefilter("ignore")
warnings.simplefilter("ignore")

# The image plane is sum(weight*data)/sum(weight)
stacked_image.array[:, :] = self.sum_wdata/self.sum_weight
Expand Down
10 changes: 8 additions & 2 deletions python/lsst/meas/algorithms/stamps.py
Expand Up @@ -25,7 +25,7 @@

import abc
from collections.abc import Sequence
from dataclasses import dataclass
from dataclasses import dataclass, field

import numpy as np
from lsst.afw.fits import Fits, readMetadata
Expand Down Expand Up @@ -213,6 +213,12 @@ def factory(cls, stamp_im, metadata, index, archive_element=None):
raise NotImplementedError


def _default_position():
# SpherePoint is nominally mutable in C++ so we must use a factory
# and return an entirely new SpherePoint each time a Stamps is created.
return SpherePoint(Angle(np.nan), Angle(np.nan))


@dataclass
class Stamp(AbstractStamp):
"""Single stamp.
Expand All @@ -230,7 +236,7 @@ class Stamp(AbstractStamp):

stamp_im: MaskedImageF
archive_element: Persistable | None = None
position: SpherePoint | None = SpherePoint(Angle(np.nan), Angle(np.nan))
position: SpherePoint | None = field(default_factory=_default_position)

@classmethod
def factory(cls, stamp_im, metadata, index, archive_element=None):
Expand Down

0 comments on commit 93864be

Please sign in to comment.