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

1import unittest 

2import os 

3import numpy as np 

4import tempfile 

5import palpy 

6 

7import lsst.utils.tests 

8from lsst.utils import getPackageDir 

9 

10import lsst.obs.lsst.phosim as obs_lsst_phosim 

11from lsst.sims.catalogs.db import fileDBObject 

12from lsst.sims.utils import _angularSeparation 

13from lsst.sims.utils import angularSeparation 

14from lsst.sims.utils import arcsecFromRadians 

15from lsst.sims.catalogs.definitions import InstanceCatalog 

16from lsst.sims.catUtils.utils import makePhoSimTestDB 

17from lsst.sims.catUtils.utils import testStarsDBObj, testGalaxyDiskDBObj 

18from lsst.sims.catUtils.mixins import PhoSimAstrometryBase 

19from lsst.sims.catUtils.mixins import PhoSimAstrometryStars 

20from lsst.sims.catUtils.mixins import PhoSimAstrometryGalaxies 

21 

22from lsst.sims.utils import _observedFromICRS 

23from lsst.sims.utils import _observedFromAppGeo 

24 

25from lsst.sims.utils import observedFromICRS 

26from lsst.sims.utils import observedFromAppGeo 

27 

28from lsst.sims.utils import Site, ObservationMetaData 

29from lsst.sims.utils import distanceToSun 

30from lsst.sims.utils import raDecFromAltAz 

31from lsst.sims.utils import pupilCoordsFromRaDec 

32from lsst.sims.coordUtils import focalPlaneCoordsFromPupilCoords 

33 

34from lsst.sims.utils.CodeUtilities import sims_clean_up 

35from lsst.sims.utils.CodeUtilities import _validate_inputs 

36 

37from lsst.sims.catUtils.exampleCatalogDefinitions import PhoSimCatalogPoint 

38from lsst.sims.catUtils.exampleCatalogDefinitions import DefaultPhoSimHeaderMap 

39 

40from lsst.sims.utils import angularSeparation 

41from lsst.sims.utils import _angularSeparation,arcsecFromRadians 

42 

43 

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

45 

46 

47def setup_module(module): 

48 lsst.utils.tests.init() 

49 

50 

51def _naivePupilCoordsFromObserved(ra_obs, dec_obs, ra0, dec0, rotSkyPos): 

52 """ 

53 Convert Observed RA, Dec into pupil coordinates 

54 

55 Parameters 

56 ---------- 

57 ra_obs is the observed RA in radians 

58 

59 dec_obs is the observed Dec in radians 

60 

61 obs_metadata is an ObservationMetaData characterizing the telescope location and pointing 

62 

63 epoch is the epoch of the mean RA and Dec in julian years (default=2000.0) 

64 

65 includeRefraction is a boolean controlling the application of refraction. 

66 

67 Returns 

68 -------- 

69 A numpy array whose first row is the x coordinate on the pupil in 

70 radians and whose second row is the y coordinate in radians 

71 """ 

72 

73 are_arrays = _validate_inputs([ra_obs, dec_obs], ['ra_obs', 'dec_obs'], 

74 "pupilCoordsFromObserved") 

75 

76 theta = -1.0*rotSkyPos 

77 

78 ra_pointing = ra0 

79 dec_pointing = dec0 

80 

81 # palpy.ds2tp performs the gnomonic projection on ra_in and dec_in 

82 # with a tangent point at (pointingRA, pointingDec) 

83 # 

84 if not are_arrays: 

85 try: 

86 x, y = palpy.ds2tp(ra_obs, dec_obs, ra_pointing, dec_pointing) 

87 except: 

88 x = np.NaN 

89 y = np.NaN 

90 else: 

91 try: 

92 x, y = palpy.ds2tpVector(ra_obs, dec_obs, ra_pointing, dec_pointing) 

93 except: 

94 # apparently, one of your ra/dec values was improper; we will have to do this 

95 # element-wise, putting NaN in the place of the bad values 

96 x = [] 

97 y = [] 

98 for rr, dd in zip(ra_obs, dec_obs): 

99 try: 

100 xx, yy = palpy.ds2tp(rr, dd, ra_pointing, dec_pointing) 

101 except: 

102 xx = np.NaN 

103 yy = np.NaN 

104 x.append(xx) 

105 y.append(yy) 

106 x = np.array(x) 

107 y = np.array(y) 

108 

109 # rotate the result by rotskypos (rotskypos being "the angle of the sky relative to 

110 # camera coordinates" according to phoSim documentation) to account for 

111 # the rotation of the focal plane about the telescope pointing 

112 

113 x_out = x*np.cos(theta) - y*np.sin(theta) 

114 y_out = x*np.sin(theta) + y*np.cos(theta) 

115 

116 return np.array([x_out, y_out]) 

117 

118 

119class StarTestCatalog(PhoSimAstrometryStars, InstanceCatalog): 

120 column_outputs = ['raICRS', 'decICRS', 'raPhoSim', 'decPhoSim', 

121 'raJ2000', 'decJ2000', 

122 'properMotionRa','properMotionDec', 'parallax', 

123 'radialVelocity'] 

124 

125 transformations = {'raICRS': np.degrees, 'decICRS': np.degrees, 

126 'raPhoSim': np.degrees, 'decPhoSim': np.degrees} 

127 

128 default_formats = {'f': '%.12g'} 

129 

130 delimiter = ' ' 

131 

132 

133class GalaxyTestCatalog(PhoSimAstrometryGalaxies, InstanceCatalog): 

134 column_outputs = ['raICRS', 'decICRS', 'raPhoSim', 'decPhoSim'] 

135 transformations = {'raICRS': np.degrees, 'decICRS': np.degrees, 

136 'raPhoSim': np.degrees, 'decPhoSim': np.degrees} 

137 

138 override_formats = {'raICRS': '%.12g', 'decICRS': '%.12g', 

139 'raPhoSim': '%.12g', 'decPhoSim': '%.12g'} 

140 

141 delimiter = ' ' 

142 

143 

144class PhoSimAstrometryTestCase(unittest.TestCase): 

145 

146 @classmethod 

147 def setUpClass(cls): 

148 cls.camera = obs_lsst_phosim.PhosimMapper().camera 

149 cls.db_name = tempfile.mktemp(dir=ROOT, prefix='PhoSimAstDB', suffix='.db') 

150 cls.obs = makePhoSimTestDB(filename=cls.db_name, 

151 size=1000) 

152 

153 @classmethod 

154 def tearDownClass(cls): 

155 sims_clean_up() 

156 if os.path.exists(cls.db_name): 

157 os.unlink(cls.db_name) 

158 

159 def test_stellar_astrometry_radians(self): 

160 """ 

161 Test that we can go from raPhoSim, decPhoSim to ICRS coordinates 

162 in the case of stars (in radians) 

163 """ 

164 db = testStarsDBObj(driver='sqlite', database=self.db_name) 

165 cat = StarTestCatalog(db, obs_metadata=self.obs) 

166 with lsst.utils.tests.getTempFilePath('.txt') as cat_name: 

167 cat.write_catalog(cat_name) 

168 dtype = np.dtype([('raICRS', float), ('decICRS', float), 

169 ('raPhoSim', float), ('decPhoSim', float), 

170 ('raJ2000', float), ('decJ2000', float), 

171 ('pmRA', float), ('pmDec', float), 

172 ('parallax', float), ('vRad', float)]) 

173 data = np.genfromtxt(cat_name, dtype=dtype) 

174 self.assertGreater(len(data), 100) 

175 ra_pho_rad = np.radians(data['raPhoSim']) 

176 dec_pho_rad = np.radians(data['decPhoSim']) 

177 

178 # verify that, when transforming back to ICRS, we are within 

179 # 10^-3 arcsec 

180 ra_icrs, dec_icrs = PhoSimAstrometryBase._icrsFromPhoSim(ra_pho_rad, 

181 dec_pho_rad, 

182 self.obs) 

183 dist = _angularSeparation(np.radians(data['raICRS']), 

184 np.radians(data['decICRS']), 

185 ra_icrs, dec_icrs) 

186 

187 dist = arcsecFromRadians(dist) 

188 self.assertLess(dist.max(), 0.001) 

189 

190 # verify that the distance between raPhoSim, decPhoSim and 

191 # raICRS, decICRS is greater than the distance between 

192 # the original raICRS, decICRS and the newly-calculated 

193 # raICRS, decICRS 

194 dist_bad = _angularSeparation(ra_pho_rad, dec_pho_rad, 

195 np.radians(data['raICRS']), 

196 np.radians(data['decICRS'])) 

197 

198 dist_bad = arcsecFromRadians(dist_bad) 

199 self.assertGreater(dist_bad.min(), dist.max()) 

200 

201 del db 

202 

203 def test_stellar_astrometry_degrees(self): 

204 """ 

205 Test that we can go from raPhoSim, decPhoSim to ICRS coordinates 

206 in the case of stars (in degrees) 

207 """ 

208 db = testStarsDBObj(driver='sqlite', database=self.db_name) 

209 cat = StarTestCatalog(db, obs_metadata=self.obs) 

210 with lsst.utils.tests.getTempFilePath('.txt') as cat_name: 

211 cat.write_catalog(cat_name) 

212 dtype = np.dtype([('raICRS', float), ('decICRS', float), 

213 ('raPhoSim', float), ('decPhoSim', float), 

214 ('raJ2000', float), ('decJ2000', float), 

215 ('pmRA', float), ('pmDec', float), 

216 ('parallax', float), ('vRad', float)]) 

217 data = np.genfromtxt(cat_name, dtype=dtype) 

218 self.assertGreater(len(data), 100) 

219 

220 # verify that, when transforming back to ICRS, we are within 

221 # 10^-3 arcsec 

222 ra_icrs, dec_icrs = PhoSimAstrometryBase.icrsFromPhoSim(data['raPhoSim'], 

223 data['decPhoSim'], 

224 self.obs) 

225 dist = angularSeparation(data['raICRS'], data['decICRS'], 

226 ra_icrs, dec_icrs) 

227 

228 dist = 3600.0*dist 

229 self.assertLess(dist.max(), 0.001) 

230 

231 # verify that the distance between raPhoSim, decPhoSim and 

232 # raICRS, decICRS is greater than the distance between 

233 # the original raICRS, decICRS and the newly-calculated 

234 # raICRS, decICRS 

235 dist_bad = angularSeparation(data['raPhoSim'], data['decPhoSim'], 

236 data['raICRS'], data['decICRS']) 

237 

238 dist_bad = 3600.0*dist_bad 

239 self.assertGreater(dist_bad.min(), dist.max()) 

240 

241 del db 

242 

243 def test_stellar_observed_radians(self): 

244 """ 

245 Test ability to go all the way to observed RA, Dec 

246 from PhoSim (this is necessary for the ImSim software 

247 that DESC is working on) 

248 """ 

249 db = testStarsDBObj(driver='sqlite', database=self.db_name) 

250 cat = StarTestCatalog(db, obs_metadata=self.obs) 

251 with lsst.utils.tests.getTempFilePath('.txt') as cat_name: 

252 cat.write_catalog(cat_name) 

253 dtype = np.dtype([('raICRS', float), ('decICRS', float), 

254 ('raPhoSim', float), ('decPhoSim', float), 

255 ('raJ2000', float), ('decJ2000', float), 

256 ('pmRA', float), ('pmDec', float), 

257 ('parallax', float), ('vRad', float)]) 

258 data = np.genfromtxt(cat_name, dtype=dtype) 

259 self.assertGreater(len(data), 100) 

260 

261 (ra_obs, 

262 dec_obs) = _observedFromICRS(data['raJ2000'], 

263 data['decJ2000'], 

264 obs_metadata=self.obs, 

265 pm_ra=data['pmRA'], 

266 pm_dec=data['pmDec'], 

267 parallax=data['parallax'], 

268 v_rad=data['vRad'], 

269 includeRefraction=True, 

270 epoch=2000.0) 

271 

272 (ra_appGeo, 

273 dec_appGeo) = PhoSimAstrometryBase._appGeoFromPhoSim(np.radians(data['raPhoSim']), 

274 np.radians(data['decPhoSim']), 

275 self.obs) 

276 

277 (ra_obs_2, 

278 dec_obs_2) = _observedFromAppGeo(ra_appGeo, dec_appGeo, 

279 obs_metadata=self.obs, 

280 includeRefraction=True) 

281 

282 dd = arcsecFromRadians(_angularSeparation(ra_obs, dec_obs, ra_obs_2, dec_obs_2)) 

283 self.assertLess(dd.max(), 1.0e-5) 

284 

285 def test_stellar_observed_degrees(self): 

286 """ 

287 Test ability to go all the way to observed RA, Dec 

288 from PhoSim (this is necessary for the ImSim software 

289 that DESC is working on) 

290 """ 

291 db = testStarsDBObj(driver='sqlite', database=self.db_name) 

292 cat = StarTestCatalog(db, obs_metadata=self.obs) 

293 with lsst.utils.tests.getTempFilePath('.txt') as cat_name: 

294 cat.write_catalog(cat_name) 

295 dtype = np.dtype([('raICRS', float), ('decICRS', float), 

296 ('raPhoSim', float), ('decPhoSim', float), 

297 ('raJ2000', float), ('decJ2000', float), 

298 ('pmRA', float), ('pmDec', float), 

299 ('parallax', float), ('vRad', float)]) 

300 data = np.genfromtxt(cat_name, dtype=dtype) 

301 self.assertGreater(len(data), 100) 

302 

303 (ra_obs, 

304 dec_obs) = observedFromICRS(np.degrees(data['raJ2000']), 

305 np.degrees(data['decJ2000']), 

306 obs_metadata=self.obs, 

307 pm_ra=arcsecFromRadians(data['pmRA']), 

308 pm_dec=arcsecFromRadians(data['pmDec']), 

309 parallax=arcsecFromRadians(data['parallax']), 

310 v_rad=data['vRad'], 

311 includeRefraction=True, 

312 epoch=2000.0) 

313 

314 (ra_appGeo, 

315 dec_appGeo) = PhoSimAstrometryBase.appGeoFromPhoSim(data['raPhoSim'], 

316 data['decPhoSim'], 

317 self.obs) 

318 

319 (ra_obs_2, 

320 dec_obs_2) = observedFromAppGeo(ra_appGeo, dec_appGeo, 

321 obs_metadata=self.obs, 

322 includeRefraction=True) 

323 

324 dd = 3600.0*angularSeparation(ra_obs, dec_obs, ra_obs_2, dec_obs_2) 

325 self.assertLess(dd.max(), 1.0e-5) 

326 

327 def test_galaxy_astrometry_radians(self): 

328 """ 

329 Test that we can go from raPhoSim, decPhoSim to ICRS coordinates 

330 in the case of galaxies (in radians) 

331 """ 

332 db = testGalaxyDiskDBObj(driver='sqlite', database=self.db_name) 

333 cat = GalaxyTestCatalog(db, obs_metadata=self.obs) 

334 with lsst.utils.tests.getTempFilePath('.txt') as cat_name: 

335 cat.write_catalog(cat_name) 

336 dtype = np.dtype([('raICRS', float), ('decICRS', float), 

337 ('raPhoSim', float), ('decPhoSim', float)]) 

338 data = np.genfromtxt(cat_name, dtype=dtype) 

339 self.assertGreater(len(data), 100) 

340 ra_pho_rad = np.radians(data['raPhoSim']) 

341 dec_pho_rad = np.radians(data['decPhoSim']) 

342 

343 # verify that, when transforming back to ICRS, we are within 

344 # 10^-3 arcsec 

345 ra_icrs, dec_icrs = PhoSimAstrometryBase._icrsFromPhoSim(ra_pho_rad, 

346 dec_pho_rad, 

347 self.obs) 

348 dist = _angularSeparation(np.radians(data['raICRS']), 

349 np.radians(data['decICRS']), 

350 ra_icrs, dec_icrs) 

351 

352 dist = arcsecFromRadians(dist) 

353 self.assertLess(dist.max(), 0.001) 

354 

355 # verify that the distance between raPhoSim, decPhoSim and 

356 # raICRS, decICRS is greater than the distance between 

357 # the original raICRS, decICRS and the newly-calculated 

358 # raICRS, decICRS 

359 dist_bad = _angularSeparation(ra_pho_rad, dec_pho_rad, 

360 np.radians(data['raICRS']), 

361 np.radians(data['decICRS'])) 

362 

363 dist_bad = arcsecFromRadians(dist_bad) 

364 self.assertGreater(dist_bad.min(), dist.max()) 

365 

366 del db 

367 

368 def test_galaxy_astrometry_degrees(self): 

369 """ 

370 Test that we can go from raPhoSim, decPhoSim to ICRS coordinates 

371 in the case of galaxies (in degrees) 

372 """ 

373 db = testGalaxyDiskDBObj(driver='sqlite', database=self.db_name) 

374 cat = GalaxyTestCatalog(db, obs_metadata=self.obs) 

375 with lsst.utils.tests.getTempFilePath('.txt') as cat_name: 

376 cat.write_catalog(cat_name) 

377 dtype = np.dtype([('raICRS', float), ('decICRS', float), 

378 ('raPhoSim', float), ('decPhoSim', float)]) 

379 data = np.genfromtxt(cat_name, dtype=dtype) 

380 self.assertGreater(len(data), 100) 

381 

382 # verify that, when transforming back to ICRS, we are within 

383 # 10^-3 arcsec 

384 ra_icrs, dec_icrs = PhoSimAstrometryBase.icrsFromPhoSim(data['raPhoSim'], 

385 data['decPhoSim'], 

386 self.obs) 

387 dist = angularSeparation(data['raICRS'], data['decICRS'], 

388 ra_icrs, dec_icrs) 

389 

390 dist = 3600.0*dist 

391 self.assertLess(dist.max(), 0.001) 

392 

393 # verify that the distance between raPhoSim, decPhoSim and 

394 # raICRS, decICRS is greater than the distance between 

395 # the original raICRS, decICRS and the newly-calculated 

396 # raICRS, decICRS 

397 dist_bad = angularSeparation(data['raPhoSim'], data['decPhoSim'], 

398 data['raICRS'], data['decICRS']) 

399 

400 dist_bad = 3600.0*dist_bad 

401 self.assertGreater(dist_bad.min(), dist.max()) 

402 

403 del db 

404 

405 def test_naive_focal_plane_position(self): 

406 """ 

407 Test deprecession of PhoSim coordinates by comparing 

408 the focal plane position predicted by CatSim from ICRS 

409 with the focal plane position predicted by CatSim from deprecessed 

410 coordinates. 

411 """ 

412 

413 phosim_mixin = PhoSimAstrometryBase() 

414 

415 mjd = 59587.2 

416 

417 # create site with no atmosphere so that we can avoid 

418 # refraction 

419 site = Site(name="LSST", pressure=0.0, humidity=0.0) 

420 

421 obs = ObservationMetaData(mjd=mjd, site=site) 

422 ra, dec = raDecFromAltAz(31.0, 112.0, obs) 

423 

424 d_sun = distanceToSun(ra, dec, obs.mjd) 

425 self.assertGreater(d_sun, 45.0) 

426 

427 obs = ObservationMetaData(pointingRA=ra, pointingDec=dec, 

428 rotSkyPos=27.3, mjd=mjd, 

429 site=site) 

430 ra_icrs = np.arange(obs.pointingRA-2.0, obs.pointingRA+2.0, 0.05) 

431 dec_icrs = np.arange(obs.pointingDec-2.0, obs.pointingDec+2.0, 0.05) 

432 

433 coord_grid = np.meshgrid(ra_icrs, dec_icrs) 

434 ra_icrs = coord_grid[0].flatten() 

435 dec_icrs = coord_grid[1].flatten() 

436 

437 (xpup_icrs, 

438 ypup_icrs) = pupilCoordsFromRaDec(ra_icrs, dec_icrs, 

439 obs_metadata=obs, 

440 epoch=2000.0, 

441 includeRefraction=False) 

442 

443 (x_focal_icrs, 

444 y_focal_icrs) = focalPlaneCoordsFromPupilCoords(xpup_icrs, 

445 ypup_icrs, 

446 camera=self.camera) 

447 

448 ra_obs, dec_obs = observedFromICRS(ra_icrs, dec_icrs, obs_metadata=obs, 

449 epoch=2000.0, 

450 includeRefraction=False) 

451 

452 ra_obs_rad = np.radians(ra_obs) 

453 dec_obs_rad = np.radians(dec_obs) 

454 

455 (ra_deprecessed_rad, 

456 dec_deprecessed_rad) = phosim_mixin._dePrecess(ra_obs_rad, 

457 dec_obs_rad, obs) 

458 

459 (xpup_deprecessed, 

460 ypup_deprecessed) = _naivePupilCoordsFromObserved(ra_deprecessed_rad, 

461 dec_deprecessed_rad, 

462 obs._pointingRA, 

463 obs._pointingDec, 

464 obs._rotSkyPos) 

465 

466 (x_focal_deprecessed, 

467 y_focal_deprecessed) = focalPlaneCoordsFromPupilCoords(xpup_deprecessed, 

468 ypup_deprecessed, 

469 camera=self.camera) 

470 

471 dd = np.sqrt((x_focal_icrs-x_focal_deprecessed)**2 

472 +(y_focal_icrs-y_focal_deprecessed)**2) 

473 

474 self.assertLess(dd.max(), 5.0e-8) 

475 

476 def test_against_catalog(self): 

477 """ 

478 Compare deprecession results to a catalog that was validated 

479 with PhoSim. 

480 """ 

481 obs = ObservationMetaData(pointingRA=53.00913847303155535, 

482 pointingDec=-27.43894880881512321, 

483 rotSkyPos=256.75075318193080420, 

484 mjd=59580.13955500000156462, 

485 site=Site(name="LSST", pressure=0.0, 

486 humidity=0.0)) 

487 

488 dtype = np.dtype([('id', int), ('ra', float), ('dec', float), 

489 ('ra_deprecessed', float), ('dec_deprecessed', float), 

490 ('x_dm', float), ('y_dm', float), 

491 ('x_focal', float), ('y_focal', float), 

492 ('x_cam', float), ('y_cam', float)]) 

493 

494 data = np.genfromtxt(os.path.join(getPackageDir('sims_catUtils'), 

495 'tests', 'testData', 

496 'pixel_prediction_catalog.txt'), 

497 dtype=dtype) 

498 

499 ra_obs, dec_obs = observedFromICRS(data['ra'], data['dec'], 

500 obs_metadata=obs, 

501 includeRefraction=False, 

502 epoch=2000.0) 

503 

504 phosim_mixin = PhoSimAstrometryBase() 

505 ra_dep, dec_dep = phosim_mixin._dePrecess(np.radians(ra_obs), 

506 np.radians(dec_obs), 

507 obs) 

508 

509 dd = 3600.0*angularSeparation(data['ra_deprecessed'], data['dec_deprecessed'], 

510 np.degrees(ra_dep), np.degrees(dec_dep)) 

511 self.assertLess(dd.max(), 1.0e-5) 

512 

513 def test_InstanceCatalog_against_catalog(self): 

514 """ 

515 Test that we can reproduce the validated data using the 

516 InstanceCatalog framework 

517 """ 

518 

519 obs = ObservationMetaData(pointingRA=53.00913847303155535, 

520 pointingDec=-27.43894880881512321, 

521 rotSkyPos=256.75075318193080420, 

522 mjd=59580.13955500000156462, 

523 bandpassName='r', 

524 site=Site(name="LSST", pressure=0.0, 

525 humidity=0.0)) 

526 

527 data_dir = os.path.join(getPackageDir('sims_catUtils'),'tests', 

528 'testData') 

529 

530 dtype = np.dtype([('id', int), ('ra', float), ('dec', float), 

531 ('ra_deprecessed', float), ('dec_deprecessed', float), 

532 ('x_dm', float), ('y_dm', float), 

533 ('x_focal', float), ('y_focal', float), 

534 ('x_cam', float), ('y_cam', float)]) 

535 

536 data = np.genfromtxt(os.path.join(data_dir, 

537 'pixel_prediction_catalog.txt'), 

538 dtype=dtype) 

539 

540 data_txt_file = tempfile.mktemp(dir=data_dir, 

541 prefix='ic_validation_cat', 

542 suffix='.txt') 

543 

544 cat_dtype = np.dtype([('id', int), 

545 ('raJ2000', float), ('decJ2000', float)]) 

546 

547 with open(data_txt_file, 'w') as out_file: 

548 out_file.write('# a header\n') 

549 for ii, rr, dd in zip(data['id'], 

550 np.radians(data['ra']), 

551 np.radians(data['dec'])): 

552 

553 out_file.write('%d %.17f %.17f\n' % (ii, rr, dd)) 

554 

555 db = fileDBObject(data_txt_file, idColKey='id', dtype=cat_dtype, 

556 delimiter=' ') 

557 

558 class DeprecessionTestCatalog(PhoSimCatalogPoint): 

559 def get_uniqueId(self): 

560 return self.column_by_name('id') 

561 

562 def get_properMotionRa(self): 

563 return np.zeros(len(self.column_by_name('raJ2000'))) 

564 

565 def get_properMotionDec(self): 

566 return np.zeros(len(self.column_by_name('raJ2000'))) 

567 

568 def get_radialVelocity(self): 

569 return np.zeros(len(self.column_by_name('raJ2000'))) 

570 

571 def get_parallax(self): 

572 return np.zeros(len(self.column_by_name('raJ2000'))) 

573 

574 def get_galacticAv(self): 

575 return np.zeros(len(self.column_by_name('raJ2000'))) 

576 

577 def get_galacticRv(self): 

578 return 3.1*np.ones(len(self.column_by_name('raJ2000'))) 

579 

580 def get_sedFilepath(self): 

581 return np.array(['sed_flat.txt.gz']*len(self.column_by_name('raJ2000'))) 

582 

583 def get_phoSimMagNorm(self): 

584 return np.ones(len(self.column_by_name('raJ2000'))) 

585 

586 cat = DeprecessionTestCatalog(db, obs_metadata=obs) 

587 cat.phoSimHeaderMap = DefaultPhoSimHeaderMap 

588 

589 id_list = [] 

590 ra_dep_list = [] 

591 dec_dep_list= [] 

592 

593 phosim_cat_name = tempfile.mktemp(dir=data_dir, 

594 prefix='phosim_dep', 

595 suffix='.txt') 

596 

597 cat.write_catalog(phosim_cat_name) 

598 with open(phosim_cat_name, 'r') as input_file: 

599 for line in input_file: 

600 params = line.strip().split() 

601 if len(params) < 3: 

602 continue 

603 id_list.append(int(params[1])) 

604 ra_dep_list.append(float(params[2])) 

605 dec_dep_list.append(float(params[3])) 

606 

607 id_list = np.array(id_list) 

608 np.testing.assert_array_equal(id_list, data['id']) 

609 ra_dep_list = np.array(ra_dep_list) 

610 dec_dep_list = np.array(dec_dep_list) 

611 

612 dd = 3600.0*angularSeparation(data['ra_deprecessed'], data['dec_deprecessed'], 

613 ra_dep_list, dec_dep_list) 

614 

615 self.assertLess(dd.max(), 1.0e-5) 

616 

617 if os.path.exists(data_txt_file): 

618 os.unlink(data_txt_file) 

619 

620 if os.path.exists(phosim_cat_name): 

621 os.unlink(phosim_cat_name) 

622 

623 def test_InstanceCatalog_against_catalog_chunks(self): 

624 """ 

625 Test that we can reproduce the validated data using the 

626 InstanceCatalog framework when the catalog must be written 

627 in multiple chunks 

628 """ 

629 

630 obs = ObservationMetaData(pointingRA=53.00913847303155535, 

631 pointingDec=-27.43894880881512321, 

632 rotSkyPos=256.75075318193080420, 

633 mjd=59580.13955500000156462, 

634 bandpassName='r', 

635 site=Site(name="LSST", pressure=0.0, 

636 humidity=0.0)) 

637 

638 data_dir = os.path.join(getPackageDir('sims_catUtils'),'tests', 

639 'testData') 

640 

641 dtype = np.dtype([('id', int), ('ra', float), ('dec', float), 

642 ('ra_deprecessed', float), ('dec_deprecessed', float), 

643 ('x_dm', float), ('y_dm', float), 

644 ('x_focal', float), ('y_focal', float), 

645 ('x_cam', float), ('y_cam', float)]) 

646 

647 data = np.genfromtxt(os.path.join(data_dir, 

648 'pixel_prediction_catalog.txt'), 

649 dtype=dtype) 

650 

651 data_txt_file = tempfile.mktemp(dir=data_dir, 

652 prefix='ic_validation_cat', 

653 suffix='.txt') 

654 

655 cat_dtype = np.dtype([('id', int), 

656 ('raJ2000', float), ('decJ2000', float)]) 

657 

658 with open(data_txt_file, 'w') as out_file: 

659 out_file.write('# a header\n') 

660 for ii, rr, dd in zip(data['id'], 

661 np.radians(data['ra']), 

662 np.radians(data['dec'])): 

663 

664 out_file.write('%d %.17f %.17f\n' % (ii, rr, dd)) 

665 

666 db = fileDBObject(data_txt_file, idColKey='id', dtype=cat_dtype, 

667 delimiter=' ') 

668 

669 class DeprecessionTestCatalog_chunks(PhoSimCatalogPoint): 

670 def get_uniqueId(self): 

671 return self.column_by_name('id') 

672 

673 def get_properMotionRa(self): 

674 return np.zeros(len(self.column_by_name('raJ2000'))) 

675 

676 def get_properMotionDec(self): 

677 return np.zeros(len(self.column_by_name('raJ2000'))) 

678 

679 def get_radialVelocity(self): 

680 return np.zeros(len(self.column_by_name('raJ2000'))) 

681 

682 def get_parallax(self): 

683 return np.zeros(len(self.column_by_name('raJ2000'))) 

684 

685 def get_galacticAv(self): 

686 return np.zeros(len(self.column_by_name('raJ2000'))) 

687 

688 def get_galacticRv(self): 

689 return 3.1*np.ones(len(self.column_by_name('raJ2000'))) 

690 

691 def get_sedFilepath(self): 

692 return np.array(['sed_flat.txt.gz']*len(self.column_by_name('raJ2000'))) 

693 

694 def get_phoSimMagNorm(self): 

695 return np.ones(len(self.column_by_name('raJ2000'))) 

696 

697 cat = DeprecessionTestCatalog_chunks(db, obs_metadata=obs) 

698 cat.phoSimHeaderMap = DefaultPhoSimHeaderMap 

699 

700 id_list = [] 

701 ra_dep_list = [] 

702 dec_dep_list= [] 

703 

704 phosim_cat_name = tempfile.mktemp(dir=data_dir, 

705 prefix='phosim_dep', 

706 suffix='.txt') 

707 

708 cat.write_catalog(phosim_cat_name, chunk_size=10) 

709 with open(phosim_cat_name, 'r') as input_file: 

710 for line in input_file: 

711 params = line.strip().split() 

712 if len(params) < 3: 

713 continue 

714 id_list.append(int(params[1])) 

715 ra_dep_list.append(float(params[2])) 

716 dec_dep_list.append(float(params[3])) 

717 

718 id_list = np.array(id_list) 

719 np.testing.assert_array_equal(id_list, data['id']) 

720 ra_dep_list = np.array(ra_dep_list) 

721 dec_dep_list = np.array(dec_dep_list) 

722 

723 dd = 3600.0*angularSeparation(data['ra_deprecessed'], data['dec_deprecessed'], 

724 ra_dep_list, dec_dep_list) 

725 

726 self.assertLess(dd.max(), 1.0e-5) 

727 

728 if os.path.exists(data_txt_file): 

729 os.unlink(data_txt_file) 

730 

731 if os.path.exists(phosim_cat_name): 

732 os.unlink(phosim_cat_name) 

733 

734 

735class MemoryTestClass(lsst.utils.tests.MemoryTestCase): 

736 pass 

737 

738 

739if __name__ == "__main__": 739 ↛ 740line 739 didn't jump to line 740, because the condition on line 739 was never true

740 lsst.utils.tests.init() 

741 unittest.main()