Skip to content

Commit

Permalink
Add zeroed TS3 test data to butler repo and test for it
Browse files Browse the repository at this point in the history
Also document how the TS3 data was created.
  • Loading branch information
timj committed Feb 12, 2019
1 parent 37e3685 commit eaf23c1
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 2 deletions.
1 change: 1 addition & 0 deletions data/input/ts3/_mapper
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lsst.obs.lsst.ts3.Ts3Mapper
Binary file not shown.
Binary file not shown.
Binary file added data/input/ts3/registry.sqlite3
Binary file not shown.
21 changes: 19 additions & 2 deletions doc/lsst.obs.lsst/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,25 @@ New data can be added as follow:
The butler tests will work even if the data array is empty so long as those
dimensions are reflected in the butler tests. To retain the correct
dimensional information one technique is to zero out the pixel array and
compress with gzip. Do not use a ``.gz`` extension as we still need the
template strings to work to be able to locate the file. This file or files
compress with gzip. The following code shows one method of zeroing out all
the amplifiers:

..code-block:: python

from astropy.io import fits
import numpy

aim = fits.open("rawfile.fits")
aim.info() # inspect to ensure the extension numbers are plausible
for i in range(16):
amp = aim[i+1]
amp.data = numpy.zeros(amp.data.shape, dtype=amp.data.dtype)
aim.writeto('zeroed.fits')

Do not use a ``.gz`` extension as we still need the
template strings to work to be able to locate the file.

- This file or files
should be added to the test butler repository in ``data/input``. Create
directory ``data/input/fooCam``, if required, and into that directory add a file
``_mapper`` with contents ``lsst.obs.lsst.fooCam.FooCamMapper`` and then
Expand Down
159 changes: 159 additions & 0 deletions tests/test_ts3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# This file is part of obs_lsst.
#
# Developed for the LSST Data Management System.
# This product includes software developed by the LSST Project
# (http://www.lsst.org).
# See the COPYRIGHT file at the top-level directory of this distribution
# for details of code ownership.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import os
import sys
import unittest

import lsst.utils.tests
from lsst.geom import arcseconds, Extent2I
import lsst.afw.image

from lsst.obs.lsst.testHelper import ObsLsstButlerTests, ObsLsstObsBaseOverrides


class TestTs8(ObsLsstObsBaseOverrides, ObsLsstButlerTests):
instrumentDir = "ts3"

def setUp(self):
dataIds = {'raw': {'visit': 201607220607067, 'detectorName': 'S00', 'raftName': 'R071'},
'bias': unittest.SkipTest,
'flat': unittest.SkipTest,
'dark': unittest.SkipTest
}
self.setUp_tests(self._butler, self._mapper, dataIds)

ccdExposureId_bits = 36
exposureIds = {'raw': 201607220607067071}
filters = {'raw': '550CutOn'}
exptimes = {'raw': 30.611}
detectorIds = {'raw': 71}
detector_names = {'raw': 'R071_S00'}
detector_serials = {'raw': 'ITL-3800C-098'}
dimensions = {'raw': Extent2I(4352, 4096),
}
sky_origin = unittest.SkipTest
raw_subsets = (({'level': 'sensor', 'filter': '550CutOn'}, 2),
({'level': 'sensor', 'visit': 201607220607067}, 1),
({'level': 'filter', 'visit': 201607220607067}, 1),
({'level': 'visit', 'filter': '550CutOn'}, 2)
)
linearizer_type = unittest.SkipTest
self.setUp_butler_get(ccdExposureId_bits=ccdExposureId_bits,
exposureIds=exposureIds,
filters=filters,
exptimes=exptimes,
detectorIds=detectorIds,
detector_names=detector_names,
detector_serials=detector_serials,
dimensions=dimensions,
sky_origin=sky_origin,
raw_subsets=raw_subsets,
linearizer_type=linearizer_type
)

path_to_raw = os.path.join(self.data_dir, "raw", "2016-07-22", "201607220607067-R071-S00-det071.fits")
keys = set(('filter', 'patch', 'tract', 'visit', 'channel', 'amp', 'style', 'detector', 'dstype',
'calibDate', 'half', 'label', 'run', 'snap', 'detectorName', 'raftName',
'numSubfilters', 'fgcmcycle', 'name', 'pixel_id', 'description', 'subfilter'))
query_format = ["visit", "filter"]
queryMetadata = (({'visit': 201607220607067}, [(201607220607067, '550CutOn')]),
({'detector': 71}, [(201607220607067, '550CutOn')]),
({'detectorName': 'S00', 'raftName': 'R071'}, [(201607220607067, '550CutOn')]),
)
map_python_type = lsst.afw.image.DecoratedImageF
map_python_std_type = lsst.afw.image.ExposureF
map_cpp_type = 'DecoratedImageF'
map_storage_name = 'FitsStorage'
metadata_output_path = None # Not on sky data so processCcd not run.

raw_filename = '201607220607067-R071-S00-det071.fits'
default_level = 'visit'
raw_levels = (('skyTile', set(['visit', 'detector', 'run', 'detectorName', 'raftName'])),
('filter', set(['visit', 'detector', 'run', 'detectorName', 'raftName'])),
('visit', set(['visit', 'detector', 'run', 'detectorName', 'raftName']))
)
self.setUp_mapper(output=self.data_dir,
path_to_raw=path_to_raw,
keys=keys,
query_format=query_format,
queryMetadata=queryMetadata,
metadata_output_path=metadata_output_path,
map_python_type=map_python_type,
map_python_std_type=map_python_std_type,
map_cpp_type=map_cpp_type,
map_storage_name=map_storage_name,
raw_filename=raw_filename,
default_level=default_level,
raw_levels=raw_levels,
test_config_metadata=False,
)

self.setUp_camera(camera_name='lsstCam',
n_detectors=435,
first_detector_name='R000_S00',
plate_scale=20.0 * arcseconds,
)

super().setUp()

def testCcdExposureId(self):
exposureId = self.butler.get('ccdExposureId', dataId={})
self.assertEqual(exposureId, 0)

exposureId = self.butler.get('ccdExposureId', dataId={"visit": 1, "detector": 1})
self.assertEqual(exposureId, 1001)

exposureId = self.butler.get('ccdExposureId', dataId={"visit": 1, "detectorName": "S00",
"raftName": "R433"})
self.assertEqual(exposureId, 1433)

with self.assertRaises(KeyError):
self.butler.get('ccdExposureId', dataId={"visit": 1})

with self.assertRaises(KeyError):
self.butler.get('ccdExposureId', dataId={"detector": 1})

with self.assertRaises(KeyError):
self.butler.get('ccdExposureId', dataId={"visit": 1, "detectorName": "S00"})

def testDetectorName(self):
name = self.mapper._extractDetectorName({"detectorName": "S00", "raftName": "R002"})
self.assertEqual(name, "R002_S00")

name = self.mapper._extractDetectorName({"detector": 71, 'visit': 201607220607067})
self.assertEqual(name, "R071_S00")

name = self.mapper._extractDetectorName({"detector": 433, 'visit': 201811151255111, "channel": 1})
self.assertEqual(name, "R433_S00")


class MemoryTester(lsst.utils.tests.MemoryTestCase):
pass


def setup_module(module):
lsst.utils.tests.init()


if __name__ == '__main__':
setup_module(sys.modules[__name__])
unittest.main()

0 comments on commit eaf23c1

Please sign in to comment.