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

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

# See COPYRIGHT file at the top of the source tree. 

# 

# This file is part of fgcmcal. 

# 

# Developed for the LSST Data Management System. 

# This product includes software developed by the LSST Project 

# (https://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 <https://www.gnu.org/licenses/>. 

"""Test the fgcmcal code with testdata_jointcal/hsc. 

 

Run test suite on fgcmcal using HSC data from testdata_jointcal. 

""" 

 

import matplotlib 

matplotlib.use("Agg") # noqa E402 

 

import unittest 

import os 

import tempfile 

import numpy as np 

 

import lsst.utils 

import lsst.pex.exceptions 

 

import fgcmcalTestBase 

 

import lsst.fgcmcal as fgcmcal 

 

ROOT = os.path.abspath(os.path.dirname(__file__)) 

 

 

class FgcmcalTestHSC(fgcmcalTestBase.FgcmcalTestBase, lsst.utils.tests.TestCase): 

@classmethod 

def setUpClass(cls): 

try: 

cls.dataDir = lsst.utils.getPackageDir('testdata_jointcal') 

os.environ['ASTROMETRY_NET_DATA_DIR'] = os.path.join(cls.dataDir, 'hsc_and_index') 

except lsst.pex.exceptions.NotFoundError: 

raise unittest.SkipTest("testdata_jointcal not setup") 

 

def setUp(self): 

inputDir = os.path.join(self.dataDir, 'hsc') 

 

testDir = tempfile.mkdtemp(dir=ROOT, prefix="TestFgcm-") 

 

self.setUp_base(inputDir=inputDir, testDir=testDir) 

 

lsst.log.setLevel("HscMapper", lsst.log.FATAL) 

 

def test_fgcmcalTasks(self): 

# Set numpy seed for stability 

np.random.seed(seed=1000) 

 

visitDataRefName = 'visit' 

ccdDataRefName = 'ccd' 

 

# First test making the LUT 

self.config = fgcmcal.FgcmMakeLutConfig() 

self.config.filterNames = ['r', 'i'] 

self.config.stdFilterNames = ['r', 'i'] 

self.config.atmosphereTableName = 'fgcm_atm_subaru2_test' 

self.otherArgs = [] 

 

nBand = 2 

i0Std = np.array([0.07877351, 0.06464688]) 

i10Std = np.array([-0.00061516, -0.00063434]) 

i0Recon = np.array([0.0689530429, 0.05600673]) 

i10Recon = np.array([-7.01847144, 3.62675740]) 

 

self._testFgcmMakeLut(nBand, i0Std, i0Recon, i10Std, i10Recon) 

 

# Now the star building 

self.config = fgcmcal.FgcmBuildStarsConfig() 

self.config.filterToBand = {'r': 'r', 'i': 'i'} 

self.config.requiredBands = ['r', 'i'] 

self.config.referenceBands = ['i'] 

self.config.checkAllCcds = True 

self.config.visitDataRefName = visitDataRefName 

self.config.ccdDataRefName = ccdDataRefName 

self.otherArgs = [] 

 

nVisit = 11 

nStar = 472 

nObs = 5431 

 

self._testFgcmBuildStars(nVisit, nStar, nObs) 

 

# And the fit cycle 

self.config = fgcmcal.FgcmFitCycleConfig() 

self.config.outfileBase = 'TestFgcm' 

self.config.bands = ['r', 'i'] 

self.config.fitFlag = (1, 1) 

self.config.requiredFlag = (1, 1) 

self.config.filterToBand = {'r': 'r', 'i': 'i'} 

self.config.maxIterBeforeFinalCycle = 1 

self.config.nCore = 1 

self.config.cycleNumber = 0 

self.config.utBoundary = 0.0 

self.config.washMjds = (0.0, ) 

self.config.epochMjds = (0.0, 100000.0) 

self.config.latitude = 19.8256 

self.config.pixelScale = 0.17 

self.config.expGrayPhotometricCut = (-0.05, -0.05) 

self.config.expGrayHighCut = (0.2, 0.2) 

self.config.aperCorrFitNBins = 0 

self.config.sedFudgeFactors = (1.0, 1.0) 

self.config.starColorCuts = ('r,i,-0.50,2.25',) 

self.config.freezeStdAtmosphere = True 

self.config.precomputeSuperStarInitialCycle = False 

self.config.minExpPerNight = 1 

self.config.minStarPerExp = 50 

self.config.nStarPerRun = 50 

self.config.nExpPerRun = 2 

self.config.colorSplitIndices = (0, 1) 

self.config.superStarSubCcd = True 

self.config.superStarSubCcdChebyshevOrder = 1 

self.config.ccdGraySubCcd = False 

self.config.ccdGraySubCcdChebyshevOrder = 1 

self.config.ccdGraySubCcdTriangular = True 

self.config.modelMagErrors = False 

self.config.outputZeropointsBeforeFinalCycle = False 

self.config.outputStandardsBeforeFinalCycle = False 

self.config.sigmaCalRange = (0.003, 0.003) 

self.otherArgs = [] 

 

nZp = 1232 

nGoodZp = 26 

nOkZp = 32 

nBadZp = 1200 

nStdStars = 391 

nPlots = 30 

 

self._testFgcmFitCycle(nZp, nGoodZp, nOkZp, nBadZp, nStdStars, nPlots, skipChecks=True) 

 

# Test the second fit cycle -- need to copy to unfreeze config 

newConfig = fgcmcal.FgcmFitCycleConfig() 

newConfig.update(**self.config.toDict()) 

newConfig.cycleNumber = 1 

self.config = newConfig 

 

self._testFgcmFitCycle(nZp, nGoodZp, nOkZp, nBadZp, nStdStars, nPlots, skipChecks=True) 

 

# Test the "final" fit cycle 

newConfig = fgcmcal.FgcmFitCycleConfig() 

newConfig.update(**self.config.toDict()) 

newConfig.cycleNumber = 2 

newConfig.ccdGraySubCcd = True 

newConfig.isFinalCycle = True 

self.config = newConfig 

 

self._testFgcmFitCycle(nZp, nGoodZp, nOkZp, nBadZp, nStdStars, nPlots) 

 

# And output the products 

self.config = fgcmcal.FgcmOutputProductsConfig() 

self.config.cycleNumber = 2 

self.config.photoCal.photoCatName = 'sdss-dr9-fink-v5b' 

self.config.photoCal.colorterms.data = {} 

self.config.photoCal.colorterms.data['sdss*'] = lsst.pipe.tasks.colorterms.ColortermDict() 

self.config.photoCal.colorterms.data['sdss*'].data = {} 

self.config.photoCal.colorterms.data['sdss*'].data['g'] = lsst.pipe.tasks.colorterms.Colorterm() 

self.config.photoCal.colorterms.data['sdss*'].data['g'].primary = 'g' 

self.config.photoCal.colorterms.data['sdss*'].data['g'].secondary = 'r' 

self.config.photoCal.colorterms.data['sdss*'].data['g'].c0 = -0.00816446 

self.config.photoCal.colorterms.data['sdss*'].data['g'].c1 = -0.08366937 

self.config.photoCal.colorterms.data['sdss*'].data['g'].c2 = -0.00726883 

self.config.photoCal.colorterms.data['sdss*'].data['r'] = lsst.pipe.tasks.colorterms.Colorterm() 

self.config.photoCal.colorterms.data['sdss*'].data['r'].primary = 'r' 

self.config.photoCal.colorterms.data['sdss*'].data['r'].secondary = 'i' 

self.config.photoCal.colorterms.data['sdss*'].data['r'].c0 = 0.0013181 

self.config.photoCal.colorterms.data['sdss*'].data['r'].c1 = 0.01284177 

self.config.photoCal.colorterms.data['sdss*'].data['r'].c2 = -0.03068248 

self.config.photoCal.colorterms.data['sdss*'].data['i'] = lsst.pipe.tasks.colorterms.Colorterm() 

self.config.photoCal.colorterms.data['sdss*'].data['i'].primary = 'i' 

self.config.photoCal.colorterms.data['sdss*'].data['i'].secondary = 'z' 

self.config.photoCal.colorterms.data['sdss*'].data['i'].c0 = 0.00130204 

self.config.photoCal.colorterms.data['sdss*'].data['i'].c1 = -0.16922042 

self.config.photoCal.colorterms.data['sdss*'].data['i'].c2 = -0.01374245 

self.config.refObjLoader.ref_dataset_name = "sdss-dr9-fink-v5b" 

 

filterMapping = {'r': 'HSC-R', 'i': 'HSC-I'} 

# These zeropoint offsets are empirical, and are there 

# to check if changes in the code are altering the final 

# output in a measurable way. 

zpOffsets = np.array([-0.0223396513611, 0.266586363316]) 

 

self._testFgcmOutputProducts(visitDataRefName, ccdDataRefName, 

filterMapping, zpOffsets, 

904014, 12, 'i', 1) 

 

 

class TestMemory(lsst.utils.tests.MemoryTestCase): 

pass 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

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

lsst.utils.tests.init() 

unittest.main()