Coverage for tests/testPhoSimAstrometry.py : 18%

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
7import lsst.utils.tests
8from lsst.utils import getPackageDir
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
22from lsst.sims.utils import _observedFromICRS
23from lsst.sims.utils import _observedFromAppGeo
25from lsst.sims.utils import observedFromICRS
26from lsst.sims.utils import observedFromAppGeo
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
34from lsst.sims.utils.CodeUtilities import sims_clean_up
35from lsst.sims.utils.CodeUtilities import _validate_inputs
37from lsst.sims.catUtils.exampleCatalogDefinitions import PhoSimCatalogPoint
38from lsst.sims.catUtils.exampleCatalogDefinitions import DefaultPhoSimHeaderMap
40from lsst.sims.utils import angularSeparation
41from lsst.sims.utils import _angularSeparation,arcsecFromRadians
44ROOT = os.path.abspath(os.path.dirname(__file__))
47def setup_module(module):
48 lsst.utils.tests.init()
51def _naivePupilCoordsFromObserved(ra_obs, dec_obs, ra0, dec0, rotSkyPos):
52 """
53 Convert Observed RA, Dec into pupil coordinates
55 Parameters
56 ----------
57 ra_obs is the observed RA in radians
59 dec_obs is the observed Dec in radians
61 obs_metadata is an ObservationMetaData characterizing the telescope location and pointing
63 epoch is the epoch of the mean RA and Dec in julian years (default=2000.0)
65 includeRefraction is a boolean controlling the application of refraction.
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 """
73 are_arrays = _validate_inputs([ra_obs, dec_obs], ['ra_obs', 'dec_obs'],
74 "pupilCoordsFromObserved")
76 theta = -1.0*rotSkyPos
78 ra_pointing = ra0
79 dec_pointing = dec0
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)
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
113 x_out = x*np.cos(theta) - y*np.sin(theta)
114 y_out = x*np.sin(theta) + y*np.cos(theta)
116 return np.array([x_out, y_out])
119class StarTestCatalog(PhoSimAstrometryStars, InstanceCatalog):
120 column_outputs = ['raICRS', 'decICRS', 'raPhoSim', 'decPhoSim',
121 'raJ2000', 'decJ2000',
122 'properMotionRa','properMotionDec', 'parallax',
123 'radialVelocity']
125 transformations = {'raICRS': np.degrees, 'decICRS': np.degrees,
126 'raPhoSim': np.degrees, 'decPhoSim': np.degrees}
128 default_formats = {'f': '%.12g'}
130 delimiter = ' '
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}
138 override_formats = {'raICRS': '%.12g', 'decICRS': '%.12g',
139 'raPhoSim': '%.12g', 'decPhoSim': '%.12g'}
141 delimiter = ' '
144class PhoSimAstrometryTestCase(unittest.TestCase):
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)
153 @classmethod
154 def tearDownClass(cls):
155 sims_clean_up()
156 if os.path.exists(cls.db_name):
157 os.unlink(cls.db_name)
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'])
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)
187 dist = arcsecFromRadians(dist)
188 self.assertLess(dist.max(), 0.001)
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']))
198 dist_bad = arcsecFromRadians(dist_bad)
199 self.assertGreater(dist_bad.min(), dist.max())
201 del db
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)
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)
228 dist = 3600.0*dist
229 self.assertLess(dist.max(), 0.001)
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'])
238 dist_bad = 3600.0*dist_bad
239 self.assertGreater(dist_bad.min(), dist.max())
241 del db
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)
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)
272 (ra_appGeo,
273 dec_appGeo) = PhoSimAstrometryBase._appGeoFromPhoSim(np.radians(data['raPhoSim']),
274 np.radians(data['decPhoSim']),
275 self.obs)
277 (ra_obs_2,
278 dec_obs_2) = _observedFromAppGeo(ra_appGeo, dec_appGeo,
279 obs_metadata=self.obs,
280 includeRefraction=True)
282 dd = arcsecFromRadians(_angularSeparation(ra_obs, dec_obs, ra_obs_2, dec_obs_2))
283 self.assertLess(dd.max(), 1.0e-5)
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)
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)
314 (ra_appGeo,
315 dec_appGeo) = PhoSimAstrometryBase.appGeoFromPhoSim(data['raPhoSim'],
316 data['decPhoSim'],
317 self.obs)
319 (ra_obs_2,
320 dec_obs_2) = observedFromAppGeo(ra_appGeo, dec_appGeo,
321 obs_metadata=self.obs,
322 includeRefraction=True)
324 dd = 3600.0*angularSeparation(ra_obs, dec_obs, ra_obs_2, dec_obs_2)
325 self.assertLess(dd.max(), 1.0e-5)
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'])
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)
352 dist = arcsecFromRadians(dist)
353 self.assertLess(dist.max(), 0.001)
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']))
363 dist_bad = arcsecFromRadians(dist_bad)
364 self.assertGreater(dist_bad.min(), dist.max())
366 del db
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)
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)
390 dist = 3600.0*dist
391 self.assertLess(dist.max(), 0.001)
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'])
400 dist_bad = 3600.0*dist_bad
401 self.assertGreater(dist_bad.min(), dist.max())
403 del db
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 """
413 phosim_mixin = PhoSimAstrometryBase()
415 mjd = 59587.2
417 # create site with no atmosphere so that we can avoid
418 # refraction
419 site = Site(name="LSST", pressure=0.0, humidity=0.0)
421 obs = ObservationMetaData(mjd=mjd, site=site)
422 ra, dec = raDecFromAltAz(31.0, 112.0, obs)
424 d_sun = distanceToSun(ra, dec, obs.mjd)
425 self.assertGreater(d_sun, 45.0)
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)
433 coord_grid = np.meshgrid(ra_icrs, dec_icrs)
434 ra_icrs = coord_grid[0].flatten()
435 dec_icrs = coord_grid[1].flatten()
437 (xpup_icrs,
438 ypup_icrs) = pupilCoordsFromRaDec(ra_icrs, dec_icrs,
439 obs_metadata=obs,
440 epoch=2000.0,
441 includeRefraction=False)
443 (x_focal_icrs,
444 y_focal_icrs) = focalPlaneCoordsFromPupilCoords(xpup_icrs,
445 ypup_icrs,
446 camera=self.camera)
448 ra_obs, dec_obs = observedFromICRS(ra_icrs, dec_icrs, obs_metadata=obs,
449 epoch=2000.0,
450 includeRefraction=False)
452 ra_obs_rad = np.radians(ra_obs)
453 dec_obs_rad = np.radians(dec_obs)
455 (ra_deprecessed_rad,
456 dec_deprecessed_rad) = phosim_mixin._dePrecess(ra_obs_rad,
457 dec_obs_rad, obs)
459 (xpup_deprecessed,
460 ypup_deprecessed) = _naivePupilCoordsFromObserved(ra_deprecessed_rad,
461 dec_deprecessed_rad,
462 obs._pointingRA,
463 obs._pointingDec,
464 obs._rotSkyPos)
466 (x_focal_deprecessed,
467 y_focal_deprecessed) = focalPlaneCoordsFromPupilCoords(xpup_deprecessed,
468 ypup_deprecessed,
469 camera=self.camera)
471 dd = np.sqrt((x_focal_icrs-x_focal_deprecessed)**2
472 +(y_focal_icrs-y_focal_deprecessed)**2)
474 self.assertLess(dd.max(), 5.0e-8)
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))
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)])
494 data = np.genfromtxt(os.path.join(getPackageDir('sims_catUtils'),
495 'tests', 'testData',
496 'pixel_prediction_catalog.txt'),
497 dtype=dtype)
499 ra_obs, dec_obs = observedFromICRS(data['ra'], data['dec'],
500 obs_metadata=obs,
501 includeRefraction=False,
502 epoch=2000.0)
504 phosim_mixin = PhoSimAstrometryBase()
505 ra_dep, dec_dep = phosim_mixin._dePrecess(np.radians(ra_obs),
506 np.radians(dec_obs),
507 obs)
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)
513 def test_InstanceCatalog_against_catalog(self):
514 """
515 Test that we can reproduce the validated data using the
516 InstanceCatalog framework
517 """
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))
527 data_dir = os.path.join(getPackageDir('sims_catUtils'),'tests',
528 'testData')
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)])
536 data = np.genfromtxt(os.path.join(data_dir,
537 'pixel_prediction_catalog.txt'),
538 dtype=dtype)
540 data_txt_file = tempfile.mktemp(dir=data_dir,
541 prefix='ic_validation_cat',
542 suffix='.txt')
544 cat_dtype = np.dtype([('id', int),
545 ('raJ2000', float), ('decJ2000', float)])
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'])):
553 out_file.write('%d %.17f %.17f\n' % (ii, rr, dd))
555 db = fileDBObject(data_txt_file, idColKey='id', dtype=cat_dtype,
556 delimiter=' ')
558 class DeprecessionTestCatalog(PhoSimCatalogPoint):
559 def get_uniqueId(self):
560 return self.column_by_name('id')
562 def get_properMotionRa(self):
563 return np.zeros(len(self.column_by_name('raJ2000')))
565 def get_properMotionDec(self):
566 return np.zeros(len(self.column_by_name('raJ2000')))
568 def get_radialVelocity(self):
569 return np.zeros(len(self.column_by_name('raJ2000')))
571 def get_parallax(self):
572 return np.zeros(len(self.column_by_name('raJ2000')))
574 def get_galacticAv(self):
575 return np.zeros(len(self.column_by_name('raJ2000')))
577 def get_galacticRv(self):
578 return 3.1*np.ones(len(self.column_by_name('raJ2000')))
580 def get_sedFilepath(self):
581 return np.array(['sed_flat.txt.gz']*len(self.column_by_name('raJ2000')))
583 def get_phoSimMagNorm(self):
584 return np.ones(len(self.column_by_name('raJ2000')))
586 cat = DeprecessionTestCatalog(db, obs_metadata=obs)
587 cat.phoSimHeaderMap = DefaultPhoSimHeaderMap
589 id_list = []
590 ra_dep_list = []
591 dec_dep_list= []
593 phosim_cat_name = tempfile.mktemp(dir=data_dir,
594 prefix='phosim_dep',
595 suffix='.txt')
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]))
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)
612 dd = 3600.0*angularSeparation(data['ra_deprecessed'], data['dec_deprecessed'],
613 ra_dep_list, dec_dep_list)
615 self.assertLess(dd.max(), 1.0e-5)
617 if os.path.exists(data_txt_file):
618 os.unlink(data_txt_file)
620 if os.path.exists(phosim_cat_name):
621 os.unlink(phosim_cat_name)
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 """
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))
638 data_dir = os.path.join(getPackageDir('sims_catUtils'),'tests',
639 'testData')
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)])
647 data = np.genfromtxt(os.path.join(data_dir,
648 'pixel_prediction_catalog.txt'),
649 dtype=dtype)
651 data_txt_file = tempfile.mktemp(dir=data_dir,
652 prefix='ic_validation_cat',
653 suffix='.txt')
655 cat_dtype = np.dtype([('id', int),
656 ('raJ2000', float), ('decJ2000', float)])
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'])):
664 out_file.write('%d %.17f %.17f\n' % (ii, rr, dd))
666 db = fileDBObject(data_txt_file, idColKey='id', dtype=cat_dtype,
667 delimiter=' ')
669 class DeprecessionTestCatalog_chunks(PhoSimCatalogPoint):
670 def get_uniqueId(self):
671 return self.column_by_name('id')
673 def get_properMotionRa(self):
674 return np.zeros(len(self.column_by_name('raJ2000')))
676 def get_properMotionDec(self):
677 return np.zeros(len(self.column_by_name('raJ2000')))
679 def get_radialVelocity(self):
680 return np.zeros(len(self.column_by_name('raJ2000')))
682 def get_parallax(self):
683 return np.zeros(len(self.column_by_name('raJ2000')))
685 def get_galacticAv(self):
686 return np.zeros(len(self.column_by_name('raJ2000')))
688 def get_galacticRv(self):
689 return 3.1*np.ones(len(self.column_by_name('raJ2000')))
691 def get_sedFilepath(self):
692 return np.array(['sed_flat.txt.gz']*len(self.column_by_name('raJ2000')))
694 def get_phoSimMagNorm(self):
695 return np.ones(len(self.column_by_name('raJ2000')))
697 cat = DeprecessionTestCatalog_chunks(db, obs_metadata=obs)
698 cat.phoSimHeaderMap = DefaultPhoSimHeaderMap
700 id_list = []
701 ra_dep_list = []
702 dec_dep_list= []
704 phosim_cat_name = tempfile.mktemp(dir=data_dir,
705 prefix='phosim_dep',
706 suffix='.txt')
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]))
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)
723 dd = 3600.0*angularSeparation(data['ra_deprecessed'], data['dec_deprecessed'],
724 ra_dep_list, dec_dep_list)
726 self.assertLess(dd.max(), 1.0e-5)
728 if os.path.exists(data_txt_file):
729 os.unlink(data_txt_file)
731 if os.path.exists(phosim_cat_name):
732 os.unlink(phosim_cat_name)
735class MemoryTestClass(lsst.utils.tests.MemoryTestCase):
736 pass
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()