Skip to content

Commit 7efc0df

Browse files
committed
improve handling of missing visit cache
1 parent ecb8ae4 commit 7efc0df

2 files changed

Lines changed: 28 additions & 24 deletions

File tree

python/lsst/ip/diffim/detectAndMeasure.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,23 +1014,24 @@ def filterSatellites(self, diaSources, science):
10141014
sattle_output = requests.put(
10151015
f'{self.config.sattle_host}:{self.config.sattle_port}/diasource_allow_list',
10161016
json={"visit_id": visit_id, "detector_id": detector_id, "diasources": dia_sources_json})
1017+
10171018
if sattle_output.status_code != 200:
10181019
# Check if the cache is missing the visit and retry once
10191020
if sattle_output.status_code == 404:
10201021
try:
1021-
self.log.info('Sending data to the visit cache')
1022+
self.log.info('Visit not found in sattle cache, re-sending')
10221023

1023-
visit_id = science.exposure.getInfo().getVisitInfo().id
1024+
visit_id = science.getInfo().getVisitInfo().id
10241025

10251026
visit_date = Time(
1026-
science.exposure.getInfo().getVisitInfo().getDate().toPython()).jd
1027+
science.getInfo().getVisitInfo().getDate().toPython()).jd
10271028

1028-
exposure_time_jd = science.exposure.getInfo().getVisitInfo().getExposureTime() / 86400.0
1029+
exposure_time_jd = science.getInfo().getVisitInfo().getExposureTime() / 86400.0
10291030
exposure_end_jd = visit_date + exposure_time_jd / 2.0
10301031
exposure_start_jd = visit_date - exposure_time_jd / 2.0
10311032

1032-
boresight_ra = science.exposure.getInfo().getVisitInfo().boresightRaDec[0].asDegrees()
1033-
boresight_dec = science.exposure.getInfo().getVisitInfo().boresightRaDec[1].asDegrees()
1033+
boresight_ra = science.getInfo().getVisitInfo().boresightRaDec[0].asDegrees()
1034+
boresight_dec = science.getInfo().getVisitInfo().boresightRaDec[1].asDegrees()
10341035

10351036
r = requests.put(
10361037
f'{self.config.sattle_host}:{self.config.sattle_port}/visit_cache',
@@ -1041,7 +1042,13 @@ def filterSatellites(self, diaSources, science):
10411042
"boresight_dec": boresight_dec,
10421043
"historical": self.config.sattle_historical})
10431044

1044-
self.log.info(f'status code: {r.status_code}')
1045+
sattle_output = requests.put(
1046+
f'{self.config.sattle_host}:{self.config.sattle_port}/diasource_allow_list',
1047+
json={"visit_id": visit_id, "detector_id": detector_id, "diasources": dia_sources_json})
1048+
1049+
# fail on any non-success
1050+
if sattle_output.status_code != 200:
1051+
raise RuntimeError(sattle_output.text)
10451052

10461053
except (requests.RequestException, ConnectionError) as e:
10471054
raise RuntimeError(sattle_output.text) from e

tests/test_detectAndMeasure.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ def _check_values(self, values, minValue=None, maxValue=None):
108108
if maxValue is not None:
109109
self.assertTrue(np.all(values <= maxValue))
110110

111-
def _setup_detection(self, doSkySources=True, nSkySources=5, doSubtractBackground=False, doSattle=False, **kwargs):
111+
def _setup_detection(self, doSkySources=True, nSkySources=5,
112+
doSubtractBackground=False, doSattle=False, **kwargs):
112113
"""Setup and configure the detection and measurement PipelineTask.
113114
114115
Parameters
@@ -747,7 +748,7 @@ def json(self):
747748
f"Provided visit {data['visit_id']} not present in cache!")
748749
# All sources are allowed
749750
elif data['visit_id'] == 3:
750-
return MockResponse({"allow_list": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ,17,
751+
return MockResponse({"allow_list": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
751752
18, 19, 20]},
752753
200, "test 3")
753754
# ALl sources are filtered, bad things happen
@@ -774,13 +775,13 @@ def test_filter_id_not_in_sattle(self, mock_put):
774775
difference = science.clone()
775776
detectionTask = self._setup_detection(doDeblend=True,
776777
badSubtractionRatioThreshold=1.,
777-
doSkySources=False)
778+
doSkySources=False, doSattle=True)
778779

779-
# Run detection and check the results
780-
output = detectionTask.run(science, matchedTemplate, difference,
780+
# Nothing in the visit cache raises
781+
with self.assertRaises(RuntimeError):
782+
detectionTask.run(science, matchedTemplate, difference,
781783
sources,
782784
idFactory=IdFactory.makeSimple())
783-
# The returned soured table should be empty, which raises a warning
784785

785786
@mock.patch('lsst.ip.diffim.detectAndMeasure.requests.put', side_effect=mocked_requests_put)
786787
def test_filter_satellites_some_allowed(self, mock_put):
@@ -855,15 +856,11 @@ def test_filter_satellites_none_allowed(self, mock_put):
855856
badSubtractionRatioThreshold=1.,
856857
doSkySources=False, doSattle=True)
857858

858-
# Run detection and check the results
859-
output = detectionTask.run(science, matchedTemplate, difference,
860-
sources,
861-
idFactory=IdFactory.makeSimple())
862-
863-
# The returned source table should be completely empty, which raises a
864-
# warning but not a runtime error.
865-
866-
self.assertEqual(len(output.diaSources), 0)
859+
# Run detection and confirm it raises for no diasources
860+
with self.assertRaises(detectAndMeasure.NoDiaSourcesError):
861+
detectionTask.run(science, matchedTemplate, difference,
862+
sources,
863+
idFactory=IdFactory.makeSimple())
867864

868865

869866
class DetectAndMeasureScoreTest(DetectAndMeasureTestBase, lsst.utils.tests.TestCase):
@@ -1313,9 +1310,9 @@ def testMergeFootprints(self):
13131310
self.assertEqual((~result.diaSources["is_negative"]).sum(), 3)
13141311

13151312

1316-
def makeVisitInfo(id = 1):
1313+
def makeVisitInfo(id=1):
13171314
"""Return a non-NaN visitInfo."""
1318-
return afwImage.VisitInfo(id = id,
1315+
return afwImage.VisitInfo(id=id,
13191316
exposureTime=10.01,
13201317
darkTime=11.02,
13211318
date=dafBase.DateTime(65321.1, dafBase.DateTime.MJD, dafBase.DateTime.TAI),

0 commit comments

Comments
 (0)