Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

# This file is part of obs_decam. 

# 

# 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/>. 

 

"""Unit tests for gen3 DECam raw formatter, which has to determine which 

HDU a given detector is in in a multi-extension FITS file. 

""" 

 

import astro_metadata_translator 

import unittest 

import os 

 

import lsst.utils.tests 

import lsst.obs.decam 

import lsst.daf.butler 

import lsst.afw.image 

 

testDataPackage = "testdata_decam" 

try: 

testDataDirectory = lsst.utils.getPackageDir(testDataPackage) 

except LookupError: 

testDataDirectory = None 

 

 

@unittest.skipIf(testDataDirectory is None, "testdata_decam must be set up") 

class DarkEnergyCameraRawFormatterTestCase(lsst.utils.tests.TestCase): 

def setUp(self): 

self.filename = os.path.join(testDataDirectory, 'rawData/2013-09-01/z/decam0229388.fits.fz') 

location = lsst.daf.butler.Location(testDataDirectory, 'rawData/2013-09-01/z/decam0229388.fits.fz') 

self.fileDescriptor = lsst.daf.butler.FileDescriptor(location, None) 

 

def check_readMetadata(self, dataId, expected): 

formatter = lsst.obs.decam.DarkEnergyCameraRawFormatter(self.fileDescriptor, dataId) 

metadata = formatter.readMetadata() 

self.assertEqual(metadata, expected) 

 

def test_readMetadata(self): 

dataId = {'detector': 25} 

# detector 25 is in HDU 1 

expected = lsst.afw.image.readMetadata(self.filename, 1) 

self.assertEqual(expected['CCDNUM'], 25) # sanity check 

self.check_readMetadata(dataId, expected) 

 

dataId = {'detector': 1} 

# detector 1 is in HDU 2 

expected = lsst.afw.image.readMetadata(self.filename, 2) 

astro_metadata_translator.fix_header(expected) 

self.assertEqual(expected['CCDNUM'], 1) # sanity check 

self.check_readMetadata(dataId, expected) 

 

def test_readMetadata_raises(self): 

dataId = {'detector': 70} 

formatter = lsst.obs.decam.DarkEnergyCameraRawFormatter(self.fileDescriptor, dataId) 

with self.assertRaisesRegex(ValueError, "detectorId=70"): 

formatter.readMetadata() 

 

def check_readImage(self, dataId, expected): 

formatter = lsst.obs.decam.DarkEnergyCameraRawFormatter(self.fileDescriptor, dataId) 

image = formatter.readImage() 

self.assertImagesEqual(image, expected) 

 

def test_readImage(self): 

dataId = {'detector': 25} 

# detector 25 is in HDU 1 

expected = lsst.afw.image.ImageI(self.filename, 1) 

self.check_readImage(dataId, expected) 

 

dataId = {'detector': 1} 

# detector 1 is in HDU 2 

expected = lsst.afw.image.ImageI(self.filename, 2) 

self.check_readImage(dataId, expected) 

 

def test_readMetadata_full_file(self): 

"""Test reading a file with all HDUs, and with all HDUs in a shuffled 

order. 

""" 

 

full_file = 'rawData/raw/c4d_150227_012718_ori-stripped.fits.fz' 

full_location = lsst.daf.butler.Location(testDataDirectory, full_file) 

full_fileDescriptor = lsst.daf.butler.FileDescriptor(full_location, None) 

 

shuffled_file = 'rawData/raw/c4d_150227_012718_ori-stripped-shuffled.fits.fz' 

shuffled_location = lsst.daf.butler.Location(testDataDirectory, shuffled_file) 

shuffled_fileDescriptor = lsst.daf.butler.FileDescriptor(shuffled_location, None) 

 

for detector in range(1, 63): 

formatter = lsst.obs.decam.DarkEnergyCameraRawFormatter(full_fileDescriptor, detector) 

full_index, full_metadata = formatter._determineHDU(detector) 

formatter = lsst.obs.decam.DarkEnergyCameraRawFormatter(shuffled_fileDescriptor, detector) 

shuffled_index, shuffled_metadata = formatter._determineHDU(detector) 

 

# The shuffled file should have different indices, 

self.assertNotEqual(full_index, shuffled_index) 

# but the metadata should be the same in both files. 

self.assertEqual(shuffled_metadata, full_metadata) 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

119 ↛ 120line 119 didn't jump to line 120, because the condition on line 119 was never trueif __name__ == "__main__": 

lsst.utils.tests.init() 

unittest.main()