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

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

# 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 lsst.pipe.tasks 

from lsst.pipe.tasks.colorterms import ColortermLibrary 

 

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) 

 

# Build the stars, adding in the reference stars 

self.config = fgcmcal.FgcmBuildStarsConfig() 

self.fillDefaultBuildStarsConfig(self.config, visitDataRefName, ccdDataRefName) 

self.otherArgs = [] 

 

nVisit = 11 

nStar = 472 

nObs = 5431 

 

self._testFgcmBuildStars(nVisit, nStar, nObs) 

 

# Perform the fit cycle 

self.config = fgcmcal.FgcmFitCycleConfig() 

self.fillDefaultFitCycleConfig(self.config) 

self.otherArgs = [] 

 

nZp = 1232 

nGoodZp = 26 

nOkZp = 26 

nBadZp = 1206 

nStdStars = 390 

nPlots = 34 

 

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) 

 

# Output the products 

 

self.config = fgcmcal.FgcmOutputProductsConfig() 

self.config.cycleNumber = 2 

# Turning on "reference calibration" is redundant in practice if 

# reference stars have been used in the fit, but this needs to 

# be exercised in testing. 

self.config.doReferenceCalibration = True 

self.config.photoCal.applyColorTerms = True 

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

self.config.photoCal.colorterms = self.sdssColorterms() 

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

 

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

zpOffsets = np.array([-0.0013903317740, -0.0020539460238]) 

 

self._testFgcmOutputProducts(visitDataRefName, ccdDataRefName, 

filterMapping, zpOffsets, 

904014, 12, 'i', 1) 

 

def test_fgcmcalTract(self): 

# Set numpy seed for stability 

np.random.seed(seed=1000) 

 

visitDataRefName = 'visit' 

ccdDataRefName = 'ccd' 

 

# First need to make 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) 

 

self.config = fgcmcal.FgcmCalibrateTractConfig() 

self.fillDefaultBuildStarsConfig(self.config.fgcmBuildStars, visitDataRefName, ccdDataRefName) 

self.config.fgcmBuildStars.checkAllCcds = False 

self.fillDefaultFitCycleConfig(self.config.fgcmFitCycle) 

self.config.maxFitCycles = 2 

 

self.config.fgcmOutputProducts.doRefcatOutput = True 

 

rawRepeatability = np.array([0.007070288705, 0.0074971053995]) 

filterNCalibMap = {'HSC-R': 13, 

'HSC-I': 13} 

 

visits = [903334, 903336, 903338, 903342, 903344, 903346, 

903986, 903988, 903990, 904010, 904014] 

tract = 0 

 

self._testFgcmCalibrateTract(visits, tract, 

rawRepeatability, filterNCalibMap) 

 

def sdssColorterms(self): 

""" 

Return the SDSS to HSC color terms 

""" 

 

colorterms = ColortermLibrary() 

colorterms.data = {} 

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

colorterms.data['sdss*'].data = {} 

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

colorterms.data['sdss*'].data['g'].primary = 'g' 

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

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

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

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

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

colorterms.data['sdss*'].data['r'].primary = 'r' 

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

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

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

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

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

colorterms.data['sdss*'].data['i'].primary = 'i' 

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

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

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

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

 

return colorterms 

 

def fillDefaultBuildStarsConfig(self, config, visitDataRefName, ccdDataRefName): 

""" 

Fill the config parameters for a build stars configuration 

 

Parameters 

---------- 

config: `lsst.fgcmcal.FgcmBuildStarsConfig` 

visitDataRefName: `str` 

Name of the dataRef key for the visit 

ccdDataRefName: `str` 

Name of the dataRef key for the ccd 

""" 

 

config.filterMap = {'r': 'r', 'i': 'i'} 

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

config.primaryBands = ['i'] 

config.checkAllCcds = True 

config.coarseNside = 64 

config.visitDataRefName = visitDataRefName 

config.ccdDataRefName = ccdDataRefName 

config.doReferenceMatches = True 

# The testdata catalogs have the old name 

config.psfCandidateName = 'calib_psfCandidate' 

config.fgcmLoadReferenceCatalog.refObjLoader.ref_dataset_name = 'sdss-dr9-fink-v5b' 

config.fgcmLoadReferenceCatalog.applyColorTerms = True 

config.fgcmLoadReferenceCatalog.colorterms = self.sdssColorterms() 

config.fgcmLoadReferenceCatalog.referenceSelector.doSignalToNoise = True 

config.fgcmLoadReferenceCatalog.referenceSelector.signalToNoise.fluxField = 'i_flux' 

config.fgcmLoadReferenceCatalog.referenceSelector.signalToNoise.errField = 'i_fluxErr' 

config.fgcmLoadReferenceCatalog.referenceSelector.signalToNoise.minimum = 50.0 

 

def fillDefaultFitCycleConfig(self, config): 

""" 

Fill the config parameters for a fit cycle configuration. 

 

Parameters 

---------- 

config: `lsst.fgcmcal.FgcmFitCycleConfig` 

""" 

 

config.outfileBase = 'TestFgcm' 

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

config.fitFlag = (1, 1) 

config.requiredFlag = (1, 1) 

config.filterMap = {'r': 'r', 'i': 'i'} 

config.doReferenceCalibration = True 

config.maxIterBeforeFinalCycle = 5 

config.nCore = 1 

config.cycleNumber = 0 

config.utBoundary = 0.0 

config.washMjds = (0.0, ) 

config.epochMjds = (0.0, 100000.0) 

config.latitude = 19.8256 

config.expGrayPhotometricCut = (-0.05, -0.05) 

config.expGrayHighCut = (0.2, 0.2) 

config.aperCorrFitNBins = 0 

config.aperCorrInputSlopes = (-0.9694, -1.7229) 

config.sedFudgeFactors = (1.0, 1.0) 

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

config.freezeStdAtmosphere = True 

config.precomputeSuperStarInitialCycle = False 

config.minExpPerNight = 1 

config.minStarPerExp = 50 

config.nStarPerRun = 50 

config.nExpPerRun = 2 

config.colorSplitIndices = (0, 1) 

config.superStarSubCcd = True 

config.superStarSubCcdChebyshevOrder = 1 

config.ccdGraySubCcd = False 

config.ccdGraySubCcdChebyshevOrder = 1 

config.ccdGraySubCcdTriangular = True 

config.modelMagErrors = False 

config.outputZeropointsBeforeFinalCycle = False 

config.outputStandardsBeforeFinalCycle = False 

config.sigmaCalRange = (0.003, 0.003) 

 

 

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

pass 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

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

lsst.utils.tests.init() 

unittest.main()