Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-33766: Photodiode test depends on other tests having run #392

Merged
merged 4 commits into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions python/lsst/obs/lsst/_ingestPhotodiode.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ def run(self, locations, run=None, file_filter=r".*Photodiode_Readings.*txt",

Raises
------
RuntimeError :
Raised if multiple exposures are found for a photodiode file.
RuntimeError
Raised if the number of exposures found for a photodiode
file is not one
"""
files = ResourcePath.findFileResources(locations, file_filter)

Expand All @@ -139,6 +140,7 @@ def run(self, locations, run=None, file_filter=r".*Photodiode_Readings.*txt",

refs = []
numExisting = 0
numFailed = 0
for inputFile in files:
# Convert the file into the right class.
with inputFile.as_local() as localFile:
Expand All @@ -161,12 +163,15 @@ def run(self, locations, run=None, file_filter=r".*Photodiode_Readings.*txt",
exposureId = exposureRecords[0].id
calib.updateMetadata(camera=self.camera, exposure=exposureId)
elif nRecords == 0:
numFailed += 1
self.log.warning("Skipping instrument %s and dayObs/seqNum %d %d: no exposures found.",
instrumentName, dayObs, seqNum)
continue
else:
raise RuntimeError(f"Multiple exposure entries found for instrument {instrumentName} and "
f"dayObs/seqNum {dayObs} {seqNum}")
numFailed += 1
self.log.warning("Multiple exposure entries found for instrument %s and "
"dayObs/seqNum %d %d.", instrumentName, dayObs, seqNum)
continue

# Generate the dataId for this file.
dataId = DataCoordinate.standardize(
Expand Down Expand Up @@ -208,5 +213,6 @@ def run(self, locations, run=None, file_filter=r".*Photodiode_Readings.*txt",

if numExisting != 0:
self.log.warning("Skipped %d entries that already existed in run %s", numExisting, run)

if numFailed != 0:
raise RuntimeError(f"Failed to ingest {numFailed} entries due to missing exposure information.")
return refs
66 changes: 59 additions & 7 deletions tests/test_ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import unittest
import os
import tempfile
import lsst.utils.tests

from lsst.afw.math import flipImage
Expand Down Expand Up @@ -130,32 +131,83 @@ class LSSTCamIngestTestCase(IngestTestBase, lsst.utils.tests.TestCase):
filterLabel = lsst.afw.image.FilterLabel(physical="unknown", band="unknown")


class LSSTCamPhotodiodeIngestTestCase(IngestTestBase, lsst.utils.tests.TestCase):

curatedCalibrationDatasetTypes = ("camera",)
class LSSTCamPhotodiodeIngestTestCase(lsst.utils.tests.TestCase):
instrumentClassName = "lsst.obs.lsst.LsstCam"
rawIngestTask = "lsst.obs.base.RawIngestTask"
ingestDir = TESTDIR
file = os.path.join(DATAROOT, "lsstCam", "raw", "2021-12-12",
"30211212000310", "30211212000310-R22-S22-det098.fits")
dataIds = [dict(instrument="LSSTCam", exposure=3021121200310, detector=98)]
filterLabel = lsst.afw.image.FilterLabel(physical="SDSSi", band="i")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line still needed?

pdPath = os.path.join(DATAROOT, "lsstCam", "raw")

def testPhotodiode(self, pdPath=None):
if pdPath is None:
pdPath = self.pdPath
def setUp(self):
"""Setup for lightweight photodiode ingest task.

This will create the repo and register the instrument.
"""
self.root = tempfile.mkdtemp(dir=self.ingestDir)

# Create Repo
runner = LogCliRunner()
result = runner.invoke(butlerCli, ["create", self.root])
self.assertEqual(result.exit_code, 0, f"output: {result.output} exception: {result.exception}")

# Register Instrument
runner = LogCliRunner()
result = runner.invoke(butlerCli, ["register-instrument", self.root, self.instrumentClassName])
self.assertEqual(result.exit_code, 0, f"output: {result.output} exception: {result.exception}")

def testPhotodiodeFailure(self):
"""Test ingest to a repo missing exposure information will raise.
"""
runner = LogCliRunner()
result = runner.invoke(
butlerCli,
[
"ingest-photodiode",
self.root,
self.instrumentClassName,
self.pdPath,
],
)
self.assertEqual(result.exit_code, 1, f"output: {result.output} exception: {result.exception}")

def testPhotodiode(self):
"""Test ingest to a repo with the exposure information will not raise.
"""
# Ingest raw to provide exposure information.
outputRun = "raw_ingest_" + self.id()
runner = LogCliRunner()
result = runner.invoke(
butlerCli,
[
"ingest-raws",
self.root,
self.file,
"--output-run",
outputRun,
"--ingest-task",
self.rawIngestTask,
],
)
self.assertEqual(result.exit_code, 0, f"output: {result.output} exception: {result.exception}")

# Ingest photodiode matching this exposure.
runner = LogCliRunner()
result = runner.invoke(
butlerCli,
[
"ingest-photodiode",
self.root,
self.instrumentClassName,
pdPath,
self.pdPath,
],
)
self.assertEqual(result.exit_code, 0, f"output: {result.output} exception: {result.exception}")

# Confirm that we can retrieve the ingested photodiode, and
# that it has the correct type.
butler = Butler(self.root, run="LSSTCam/calib/photodiode")
getResult = butler.get('photodiode', dataId=self.dataIds[0])
self.assertIsInstance(getResult, PhotodiodeCalib)
Expand Down