Skip to content

Commit

Permalink
just make a copy instead of moving
Browse files Browse the repository at this point in the history
  • Loading branch information
arunkannawadi committed May 28, 2024
1 parent 9cd38ba commit 0b6fccc
Showing 1 changed file with 104 additions and 2 deletions.
106 changes: 104 additions & 2 deletions tests/test_makeWarp.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@

import unittest

from typing import Self, Type

import numpy as np

import lsst.utils.tests

import lsst.afw.image
from lsst.daf.butler import DataCoordinate, DimensionUniverse
from lsst.pipe.base import InMemoryDatasetHandle
from lsst.pipe.tasks.make_direct_warp import MakeDirectWarpTask
from lsst.pipe.tasks.makeWarp import (MakeWarpTask, MakeWarpConfig)
Expand Down Expand Up @@ -82,6 +85,103 @@ def setUp(self):
self.patchId = self.simpleMap[0].findPatch(crval).sequential_index
self.skyInfo = makeSkyInfo(self.simpleMap, self.tractId, self.patchId)

@classmethod
def generate_data_id(
cls: Type[Self],
*,
tract: int = 9813,
patch: int = 42,
band: str = "r",
detector_id: int = 9,
visit_id: int = 1234,
detector_max: int = 109,
visit_max: int = 10000
) -> DataCoordinate:
"""Generate a DataCoordinate instance to use as data_id.
Parameters
----------
tract : `int`, optional
Tract ID for the data_id
patch : `int`, optional
Patch ID for the data_id
band : `str`, optional
Band for the data_id
detector_id : `int`, optional
Detector ID for the data_id
visit_id : `int`, optional
Visit ID for the data_id
detector_max : `int`, optional
Maximum detector ID for the data_id
visit_max : `int`, optional
Maximum visit ID for the data_id
Returns
-------
data_id : `lsst.daf.butler.DataCoordinate`
An expanded data_id instance.
"""
universe = DimensionUniverse()

instrument = universe["instrument"]
instrument_record = instrument.RecordClass(
name="DummyCam",
class_name="lsst.obs.base.instrument_tests.DummyCam",
detector_max=detector_max,
visit_max=visit_max,
)

skymap = universe["skymap"]
skymap_record = skymap.RecordClass(name="test_skymap")

band_element = universe["band"]
band_record = band_element.RecordClass(name=band)

visit = universe["visit"]
visit_record = visit.RecordClass(id=visit_id, instrument="test")

detector = universe["detector"]
detector_record = detector.RecordClass(id=detector_id, instrument="test")

physical_filter = universe["physical_filter"]
physical_filter_record = physical_filter.RecordClass(name=band, instrument="test", band=band)

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

if "day_obs" in universe:
day_obs_element = universe["day_obs"]
day_obs_record = day_obs_element.RecordClass(id=20240201, instrument="test")
else:
day_obs_record = None

# A dictionary with all the relevant records.
record = {
"instrument": instrument_record,
"visit": visit_record,
"detector": detector_record,
"patch": patch_record,
"tract": 9813,
"band": band_record.name,
"skymap": skymap_record.name,
"physical_filter": physical_filter_record,
}

if day_obs_record:
record["day_obs"] = day_obs_record

# A dictionary with all the relevant recordIds.
record_id = record.copy()
for key in ("visit", "detector"):
record_id[key] = record_id[key].id

# TODO: Catching mypy failures on Github Actions should be made easier,
# perhaps in DM-36873. Igroring these for now.
data_id = DataCoordinate.standardize(record_id, universe=universe)
return data_id.expanded(record)

def test_makeWarp(self):
"""Test basic MakeWarpTask."""
makeWarp = MakeWarpTask(config=self.config)
Expand Down Expand Up @@ -140,9 +240,11 @@ def test_psfMatched(self):
def test_compare_warps(self):
"""Test that the warp from MakeWarpTask and MakeDirectWarpTask agree.
"""
dataIdList = [{'visit': self.visit, 'detector': self.detector}]
dataIdList = [{'visit': self.visit, 'detector': self.detector, "band": "i"}]
dataId = dataIdList[0]
dataId["detector_id"] = dataId["detector"]

dataRef = InMemoryDatasetHandle(self.exposure, dataId=dataIdList[0])
dataRef = InMemoryDatasetHandle(self.exposure, dataId=self.generate_data_id(**dataId))
inputs = {"calexp_list": [dataRef]}

self.config.makePsfMatched = True
Expand Down

0 comments on commit 0b6fccc

Please sign in to comment.