Skip to content

Commit

Permalink
Format the transferred files
Browse files Browse the repository at this point in the history
  • Loading branch information
arunkannawadi committed Nov 18, 2024
1 parent 8ed7d73 commit ef8e72e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 108 deletions.
25 changes: 6 additions & 19 deletions python/lsst/drp/tasks/make_direct_warp.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,28 @@

from __future__ import annotations

from collections.abc import Mapping
import dataclasses
from collections.abc import Mapping
from typing import TYPE_CHECKING, Iterable

import numpy as np

from lsst.afw.image import ExposureF, Mask
from lsst.afw.math import BackgroundList, Warper
from lsst.coadd.utils import copyGoodPixels
from lsst.daf.butler import DataCoordinate, DeferredDatasetHandle
from lsst.geom import Box2D
from lsst.meas.algorithms import CoaddPsf, CoaddPsfConfig
from lsst.meas.algorithms.cloughTocher2DInterpolator import (
CloughTocher2DInterpolateTask,
)
from lsst.meas.algorithms.cloughTocher2DInterpolator import CloughTocher2DInterpolateTask
from lsst.meas.base import DetectorVisitIdGeneratorConfig
from lsst.pex.config import (
ConfigField,
ConfigurableField,
Field,
RangeField,
)
from lsst.pipe.base import (
NoWorkFound,
PipelineTask,
PipelineTaskConfig,
PipelineTaskConnections,
Struct,
)
from lsst.pex.config import ConfigField, ConfigurableField, Field, RangeField
from lsst.pipe.base import NoWorkFound, PipelineTask, PipelineTaskConfig, PipelineTaskConnections, Struct
from lsst.pipe.base.connectionTypes import Input, Output
from lsst.pipe.tasks.coaddBase import makeSkyInfo
from lsst.pipe.tasks.coaddInputRecorder import CoaddInputRecorderTask
from lsst.pipe.tasks.selectImages import PsfWcsSelectImagesTask
from lsst.skymap import BaseSkyMap

from lsst.pipe.tasks.coaddInputRecorder import CoaddInputRecorderTask

if TYPE_CHECKING:
from lsst.afw.image import MaskedImage
from lsst.afw.table import ExposureCatalog
Expand Down
38 changes: 15 additions & 23 deletions python/lsst/drp/tasks/make_psf_matched_warp.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,20 @@
"MakePsfMatchedWarpTask",
)

import warnings
from typing import TYPE_CHECKING

import lsst.geom as geom
import numpy as np
import warnings

from lsst.afw.geom import Polygon, makeWcsPairTransform, SinglePolygonException
import lsst.geom as geom
from lsst.afw.geom import Polygon, SinglePolygonException, makeWcsPairTransform
from lsst.coadd.utils import copyGoodPixels
from lsst.ip.diffim import ModelPsfMatchTask
from lsst.meas.algorithms import GaussianPsfFactory, WarpedPsf
from lsst.pex.config import ConfigurableField
from lsst.pipe.base import (
PipelineTask,
PipelineTaskConfig,
PipelineTaskConnections,
Struct,
)
from lsst.pipe.base import PipelineTask, PipelineTaskConfig, PipelineTaskConnections, Struct
from lsst.pipe.base.connectionTypes import Input, Output
from lsst.pipe.tasks.coaddBase import makeSkyInfo, growValidPolygons
from lsst.pipe.tasks.coaddBase import growValidPolygons, makeSkyInfo
from lsst.skymap import BaseSkyMap
from lsst.utils.timer import timeMethod

Expand All @@ -61,6 +56,7 @@ class MakePsfMatchedWarpConnections(
},
):
"""Connections for MakePsfMatchedWarpTask"""

sky_map = Input(
doc="Input definition of geometry/bbox and projection/wcs for warps.",
name=BaseSkyMap.SKYMAP_DATASET_TYPE_NAME,
Expand Down Expand Up @@ -173,18 +169,12 @@ def run(self, direct_warp: Exposure, bbox: geom.Box2I):

if (src_polygon := row.validPolygon) is None:
# Calculate the polygon for this detector.
src_polygon = Polygon(
[geom.Point2D(corner) for corner in row.getBBox().getCorners()]
)
self.log.debug("Polygon for detector=%d is calculated as %s",
row["ccd"],
src_polygon
)
src_polygon = Polygon([geom.Point2D(corner) for corner in row.getBBox().getCorners()])
self.log.debug("Polygon for detector=%d is calculated as %s", row["ccd"], src_polygon)
else:
self.log.debug("Polygon for detector=%d is read from the input calexp as %s",
row["ccd"],
src_polygon
)
self.log.debug(
"Polygon for detector=%d is read from the input calexp as %s", row["ccd"], src_polygon
)

try:
destination_polygon = src_polygon.transform(transform).intersectionSingle(
Expand Down Expand Up @@ -249,7 +239,9 @@ def run(self, direct_warp: Exposure, bbox: geom.Box2I):
del temp_psf_matched

self.log.info(
"Copied %d pixels from CCD %d to exposure_psf_matched", num_good_pixels, row["ccd"],
"Copied %d pixels from CCD %d to exposure_psf_matched",
num_good_pixels,
row["ccd"],
)
total_good_pixels += num_good_pixels

Expand All @@ -258,7 +250,7 @@ def run(self, direct_warp: Exposure, bbox: geom.Box2I):
if total_good_pixels > 0:
growValidPolygons(
exposure_psf_matched.info.getCoaddInputs(),
-self.config.psfMatch.kernel.active.kernelSize // 2
-self.config.psfMatch.kernel.active.kernelSize // 2,
)

return Struct(psf_matched_warp=exposure_psf_matched)
Expand Down
2 changes: 1 addition & 1 deletion tests/assemble_coadd_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
from lsst.geom import arcseconds, degrees
from lsst.meas.algorithms.testUtils import plantSources
from lsst.obs.base import MakeRawVisitInfoViaObsInfo
from lsst.pipe.tasks.coaddInputRecorder import CoaddInputRecorderConfig, CoaddInputRecorderTask
from lsst.pipe.tasks.coaddBase import growValidPolygons
from lsst.pipe.tasks.coaddInputRecorder import CoaddInputRecorderConfig, CoaddInputRecorderTask
from lsst.skymap import Index2D, PatchInfo

__all__ = ["makeMockSkyInfo", "MockCoaddTestData"]
Expand Down
75 changes: 21 additions & 54 deletions tests/test_make_direct_warp.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,22 @@

from __future__ import annotations

from typing import Self, Type

import unittest
from typing import Self, Type

import numpy as np

import lsst.utils.tests

import lsst.afw.cameraGeom.testUtils
import lsst.afw.image
import lsst.afw.math as afwMath
import lsst.skymap as skyMap
import lsst.utils.tests
from lsst.afw.detection import GaussianPsf
from lsst.daf.butler import DataCoordinate, DimensionUniverse
from lsst.drp.tasks.make_direct_warp import MakeDirectWarpConfig, MakeDirectWarpTask, WarpDetectorInputs
from lsst.pipe.base import InMemoryDatasetHandle
from lsst.drp.tasks.make_direct_warp import (MakeDirectWarpConfig, MakeDirectWarpTask, WarpDetectorInputs)
from lsst.pipe.tasks.makeWarp import MakeWarpTask
from lsst.pipe.tasks.coaddBase import makeSkyInfo
import lsst.skymap as skyMap
from lsst.afw.detection import GaussianPsf
import lsst.afw.cameraGeom.testUtils
from lsst.pipe.tasks.makeWarp import MakeWarpTask


class MakeWarpTestCase(lsst.utils.tests.TestCase):
Expand All @@ -59,9 +57,9 @@ def setUp(self):

crpix = lsst.geom.Point2D(0, 0)
crval = lsst.geom.SpherePoint(0, 45, lsst.geom.degrees)
cdMatrix = lsst.afw.geom.makeCdMatrix(scale=1.0*lsst.geom.arcseconds)
cdMatrix = lsst.afw.geom.makeCdMatrix(scale=1.0 * lsst.geom.arcseconds)
self.skyWcs = lsst.afw.geom.makeSkyWcs(crpix, crval, cdMatrix)
externalCdMatrix = lsst.afw.geom.makeCdMatrix(scale=0.9*lsst.geom.arcseconds)
externalCdMatrix = lsst.afw.geom.makeCdMatrix(scale=0.9 * lsst.geom.arcseconds)
# An external skyWcs to return
self.externalSkyWcs = lsst.afw.geom.makeSkyWcs(crpix, crval, externalCdMatrix)

Expand Down Expand Up @@ -105,7 +103,7 @@ def generate_data_id(
detector_id: int = 9,
visit_id: int = 1234,
detector_max: int = 109,
visit_max: int = 10000
visit_max: int = 10000,
) -> DataCoordinate:
"""Generate a DataCoordinate instance to use as data_id.
Expand Down Expand Up @@ -158,7 +156,9 @@ def generate_data_id(

patch_element = universe["patch"]
patch_record = patch_element.RecordClass(
skymap="test_skymap", tract=tract, patch=patch,
skymap="test_skymap",
tract=tract,
patch=patch,
)

if "day_obs" in universe:
Expand Down Expand Up @@ -201,11 +201,7 @@ def test_makeWarp(self):
data_id=self.dataRef.dataId,
)
}
result = makeWarp.run(
warp_detector_inputs,
sky_info=self.skyInfo,
visit_summary=None
)
result = makeWarp.run(warp_detector_inputs, sky_info=self.skyInfo, visit_summary=None)

warp = result.warp
mfrac = result.masked_fraction_warp
Expand Down Expand Up @@ -264,11 +260,7 @@ def test_compare_warps(self):
)
}

result1 = task.run(
warp_detector_inputs,
sky_info=self.skyInfo,
visit_summary=None
)
result1 = task.run(warp_detector_inputs, sky_info=self.skyInfo, visit_summary=None)
warp0 = result0.exposures["direct"]
warp1 = result1.warp[warp0.getBBox()]
self.assertMaskedImagesAlmostEqual(warp0.maskedImage, warp1.maskedImage, rtol=3e-7, atol=6e-6)
Expand Down Expand Up @@ -308,7 +300,6 @@ def test_backgrounds(self, doApplyNewBackground, doRevertOldBackground):
data_id=self.dataRef.dataId,
background_apply=backgroundList if doApplyNewBackground else None,
background_revert=backgroundList if doRevertOldBackground else None,

)
}

Expand All @@ -317,11 +308,7 @@ def test_backgrounds(self, doApplyNewBackground, doRevertOldBackground):
self.config.doRevertOldBackground = doRevertOldBackground

makeWarp = MakeDirectWarpTask(config=self.config)
makeWarp.run(
warp_detector_inputs,
sky_info=self.skyInfo,
visit_summary=None
)
makeWarp.run(warp_detector_inputs, sky_info=self.skyInfo, visit_summary=None)

def test_background_errors(self):
"""Test that MakeDirectWarpTask raises errors when backgrounds are not
Expand All @@ -339,11 +326,7 @@ def test_background_errors(self):
}
makeWarp = MakeDirectWarpTask(config=self.config)
with self.assertRaises(RuntimeError, msg="doApplyNewBackground is False, but"):
makeWarp.run(
warp_detector_inputs,
sky_info=self.skyInfo,
visit_summary=None
)
makeWarp.run(warp_detector_inputs, sky_info=self.skyInfo, visit_summary=None)

warp_detector_inputs = {
self.dataRef.dataId.detector.id: WarpDetectorInputs(
Expand All @@ -355,11 +338,7 @@ def test_background_errors(self):
self.config.doApplyNewBackground = True
makeWarp = MakeDirectWarpTask(config=self.config)
with self.assertRaises(RuntimeError, msg="No background to apply"):
makeWarp.run(
warp_detector_inputs,
sky_info=self.skyInfo,
visit_summary=None
)
makeWarp.run(warp_detector_inputs, sky_info=self.skyInfo, visit_summary=None)

warp_detector_inputs = {
self.dataRef.dataId.detector.id: WarpDetectorInputs(
Expand All @@ -371,11 +350,7 @@ def test_background_errors(self):
}
makeWarp = MakeDirectWarpTask(config=self.config)
with self.assertRaises(RuntimeError, msg="doRevertOldBackground is False, but"):
makeWarp.run(
warp_detector_inputs,
sky_info=self.skyInfo,
visit_summary=None
)
makeWarp.run(warp_detector_inputs, sky_info=self.skyInfo, visit_summary=None)

warp_detector_inputs = {
self.dataRef.dataId.detector.id: WarpDetectorInputs(
Expand All @@ -388,11 +363,7 @@ def test_background_errors(self):
self.config.doRevertOldBackground = True
makeWarp = MakeDirectWarpTask(config=self.config)
with self.assertRaises(RuntimeError, msg="No background to revert"):
makeWarp.run(
warp_detector_inputs,
sky_info=self.skyInfo,
visit_summary=None
)
makeWarp.run(warp_detector_inputs, sky_info=self.skyInfo, visit_summary=None)


class MakeWarpNoGoodPixelsTestCase(MakeWarpTestCase):
Expand All @@ -412,11 +383,7 @@ def test_makeWarp(self):
exposure_or_handle=self.dataRef, data_id=self.dataRef.dataId
)
}
result = makeWarp.run(
warp_detector_inputs,
sky_info=self.skyInfo,
visit_summary=None
)
result = makeWarp.run(warp_detector_inputs, sky_info=self.skyInfo, visit_summary=None)

# Ensure we got None
self.assertIsNone(result.warp)
Expand Down
15 changes: 4 additions & 11 deletions tests/test_make_psf_matched_warp.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,13 @@
import unittest

import numpy as np
from test_make_direct_warp import MakeWarpTestCase

import lsst.utils.tests

import lsst.afw.cameraGeom.testUtils
import lsst.afw.image

import lsst.utils.tests
from lsst.drp.tasks.make_direct_warp import MakeDirectWarpTask, WarpDetectorInputs
from lsst.drp.tasks.make_psf_matched_warp import MakePsfMatchedWarpTask
import lsst.afw.cameraGeom.testUtils

from test_make_direct_warp import MakeWarpTestCase


class MakePsfMatchedWarpTestCase(MakeWarpTestCase):
Expand All @@ -50,11 +47,7 @@ def test_makeWarp(self):
exposure_or_handle=self.dataRef, data_id=self.dataRef.dataId
)
}
result = makeWarp.run(
warp_detector_inputs,
sky_info=self.skyInfo,
visit_summary=None
)
result = makeWarp.run(warp_detector_inputs, sky_info=self.skyInfo, visit_summary=None)

warp = result.warp

Expand Down

0 comments on commit ef8e72e

Please sign in to comment.