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
10from lsst.sims.catalogs.db import fileDBObject
11from lsst.sims.utils import _angularSeparation
12from lsst.sims.utils import angularSeparation
13from lsst.sims.utils import arcsecFromRadians
14from lsst.sims.catalogs.definitions import InstanceCatalog
15from lsst.sims.catUtils.utils import makePhoSimTestDB
16from lsst.sims.catUtils.utils import testStarsDBObj, testGalaxyDiskDBObj
17from lsst.sims.catUtils.mixins import PhoSimAstrometryBase
18from lsst.sims.catUtils.mixins import PhoSimAstrometryStars
19from lsst.sims.catUtils.mixins import PhoSimAstrometryGalaxies
21from lsst.sims.utils import _observedFromICRS
22from lsst.sims.utils import _observedFromAppGeo
24from lsst.sims.utils import observedFromICRS
25from lsst.sims.utils import observedFromAppGeo
27from lsst.sims.utils import Site, ObservationMetaData
28from lsst.sims.utils import distanceToSun
29from lsst.sims.utils import raDecFromAltAz
30from lsst.sims.utils import pupilCoordsFromRaDec
31from lsst.sims.coordUtils import focalPlaneCoordsFromPupilCoords
32from lsst.sims.coordUtils import lsst_camera
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
43from lsst.sims.coordUtils import clean_up_lsst_camera
45ROOT = os.path.abspath(os.path.dirname(__file__))
48def setup_module(module):
49 lsst.utils.tests.init()
52def _naivePupilCoordsFromObserved(ra_obs, dec_obs, ra0, dec0, rotSkyPos):
53 """
54 Convert Observed RA, Dec into pupil coordinates
56 Parameters
57 ----------
58 ra_obs is the observed RA in radians
60 dec_obs is the observed Dec in radians
62 obs_metadata is an ObservationMetaData characterizing the telescope location and pointing
64 epoch is the epoch of the mean RA and Dec in julian years (default=2000.0)
66 includeRefraction is a boolean controlling the application of refraction.
68 Returns
69 --------
70 A numpy array whose first row is the x coordinate on the pupil in
71 radians and whose second row is the y coordinate in radians
72 """
74 are_arrays = _validate_inputs([ra_obs, dec_obs], ['ra_obs', 'dec_obs'],
75 "pupilCoordsFromObserved")
77 theta = -1.0*rotSkyPos
79 ra_pointing = ra0
80 dec_pointing = dec0
82 # palpy.ds2tp performs the gnomonic projection on ra_in and dec_in
83 # with a tangent point at (pointingRA, pointingDec)
84 #
85 if not are_arrays:
86 try:
87 x, y = palpy.ds2tp(ra_obs, dec_obs, ra_pointing, dec_pointing)
88 except:
89 x = np.NaN
90 y = np.NaN
91 else:
92 try:
93 x, y = palpy.ds2tpVector(ra_obs, dec_obs, ra_pointing, dec_pointing)
94 except:
95 # apparently, one of your ra/dec values was improper; we will have to do this
96 # element-wise, putting NaN in the place of the bad values
97 x = []
98 y = []
99 for rr, dd in zip(ra_obs, dec_obs):
100 try:
101 xx, yy = palpy.ds2tp(rr, dd, ra_pointing, dec_pointing)
102 except:
103 xx = np.NaN
104 yy = np.NaN
105 x.append(xx)
106 y.append(yy)
107 x = np.array(x)
108 y = np.array(y)
110 # rotate the result by rotskypos (rotskypos being "the angle of the sky relative to
111 # camera coordinates" according to phoSim documentation) to account for
112 # the rotation of the focal plane about the telescope pointing
114 x_out = x*np.cos(theta) - y*np.sin(theta)
115 y_out = x*np.sin(theta) + y*np.cos(theta)
117 return np.array([x_out, y_out])
120class StarTestCatalog(PhoSimAstrometryStars, InstanceCatalog):
121 column_outputs = ['raICRS', 'decICRS', 'raPhoSim', 'decPhoSim',
122 'raJ2000', 'decJ2000',
123 'properMotionRa','properMotionDec', 'parallax',
124 'radialVelocity']
126 transformations = {'raICRS': np.degrees, 'decICRS': np.degrees,
127 'raPhoSim': np.degrees, 'decPhoSim': np.degrees}
129 default_formats = {'f': '%.12g'}
131 delimiter = ' '
134class GalaxyTestCatalog(PhoSimAstrometryGalaxies, InstanceCatalog):
135 column_outputs = ['raICRS', 'decICRS', 'raPhoSim', 'decPhoSim']
136 transformations = {'raICRS': np.degrees, 'decICRS': np.degrees,
137 'raPhoSim': np.degrees, 'decPhoSim': np.degrees}
139 override_formats = {'raICRS': '%.12g', 'decICRS': '%.12g',
140 'raPhoSim': '%.12g', 'decPhoSim': '%.12g'}
142 delimiter = ' '
145class PhoSimAstrometryTestCase(unittest.TestCase):
147 @classmethod
148 def setUpClass(cls):
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 clean_up_lsst_camera()
161 def test_stellar_astrometry_radians(self):
162 """
163 Test that we can go from raPhoSim, decPhoSim to ICRS coordinates
164 in the case of stars (in radians)
165 """
166 db = testStarsDBObj(driver='sqlite', database=self.db_name)
167 cat = StarTestCatalog(db, obs_metadata=self.obs)
168 with lsst.utils.tests.getTempFilePath('.txt') as cat_name:
169 cat.write_catalog(cat_name)
170 dtype = np.dtype([('raICRS', float), ('decICRS', float),
171 ('raPhoSim', float), ('decPhoSim', float),
172 ('raJ2000', float), ('decJ2000', float),
173 ('pmRA', float), ('pmDec', float),
174 ('parallax', float), ('vRad', float)])
175 data = np.genfromtxt(cat_name, dtype=dtype)
176 self.assertGreater(len(data), 100)
177 ra_pho_rad = np.radians(data['raPhoSim'])
178 dec_pho_rad = np.radians(data['decPhoSim'])
180 # verify that, when transforming back to ICRS, we are within
181 # 10^-3 arcsec
182 ra_icrs, dec_icrs = PhoSimAstrometryBase._icrsFromPhoSim(ra_pho_rad,
183 dec_pho_rad,
184 self.obs)
185 dist = _angularSeparation(np.radians(data['raICRS']),
186 np.radians(data['decICRS']),
187 ra_icrs, dec_icrs)
189 dist = arcsecFromRadians(dist)
190 self.assertLess(dist.max(), 0.001)
192 # verify that the distance between raPhoSim, decPhoSim and
193 # raICRS, decICRS is greater than the distance between
194 # the original raICRS, decICRS and the newly-calculated
195 # raICRS, decICRS
196 dist_bad = _angularSeparation(ra_pho_rad, dec_pho_rad,
197 np.radians(data['raICRS']),
198 np.radians(data['decICRS']))
200 dist_bad = arcsecFromRadians(dist_bad)
201 self.assertGreater(dist_bad.min(), dist.max())
203 del db
205 def test_stellar_astrometry_degrees(self):
206 """
207 Test that we can go from raPhoSim, decPhoSim to ICRS coordinates
208 in the case of stars (in degrees)
209 """
210 db = testStarsDBObj(driver='sqlite', database=self.db_name)
211 cat = StarTestCatalog(db, obs_metadata=self.obs)
212 with lsst.utils.tests.getTempFilePath('.txt') as cat_name:
213 cat.write_catalog(cat_name)
214 dtype = np.dtype([('raICRS', float), ('decICRS', float),
215 ('raPhoSim', float), ('decPhoSim', float),
216 ('raJ2000', float), ('decJ2000', float),
217 ('pmRA', float), ('pmDec', float),
218 ('parallax', float), ('vRad', float)])
219 data = np.genfromtxt(cat_name, dtype=dtype)
220 self.assertGreater(len(data), 100)
222 # verify that, when transforming back to ICRS, we are within
223 # 10^-3 arcsec
224 ra_icrs, dec_icrs = PhoSimAstrometryBase.icrsFromPhoSim(data['raPhoSim'],
225 data['decPhoSim'],
226 self.obs)
227 dist = angularSeparation(data['raICRS'], data['decICRS'],
228 ra_icrs, dec_icrs)
230 dist = 3600.0*dist
231 self.assertLess(dist.max(), 0.001)
233 # verify that the distance between raPhoSim, decPhoSim and
234 # raICRS, decICRS is greater than the distance between
235 # the original raICRS, decICRS and the newly-calculated
236 # raICRS, decICRS
237 dist_bad = angularSeparation(data['raPhoSim'], data['decPhoSim'],
238 data['raICRS'], data['decICRS'])
240 dist_bad = 3600.0*dist_bad
241 self.assertGreater(dist_bad.min(), dist.max())
243 del db
245 def test_stellar_observed_radians(self):
246 """
247 Test ability to go all the way to observed RA, Dec
248 from PhoSim (this is necessary for the ImSim software
249 that DESC is working on)
250 """
251 db = testStarsDBObj(driver='sqlite', database=self.db_name)
252 cat = StarTestCatalog(db, obs_metadata=self.obs)
253 with lsst.utils.tests.getTempFilePath('.txt') as cat_name:
254 cat.write_catalog(cat_name)
255 dtype = np.dtype([('raICRS', float), ('decICRS', float),
256 ('raPhoSim', float), ('decPhoSim', float),
257 ('raJ2000', float), ('decJ2000', float),
258 ('pmRA', float), ('pmDec', float),
259 ('parallax', float), ('vRad', float)])
260 data = np.genfromtxt(cat_name, dtype=dtype)
261 self.assertGreater(len(data), 100)
263 (ra_obs,
264 dec_obs) = _observedFromICRS(data['raJ2000'],
265 data['decJ2000'],
266 obs_metadata=self.obs,
267 pm_ra=data['pmRA'],
268 pm_dec=data['pmDec'],
269 parallax=data['parallax'],
270 v_rad=data['vRad'],
271 includeRefraction=True,
272 epoch=2000.0)
274 (ra_appGeo,
275 dec_appGeo) = PhoSimAstrometryBase._appGeoFromPhoSim(np.radians(data['raPhoSim']),
276 np.radians(data['decPhoSim']),
277 self.obs)
279 (ra_obs_2,
280 dec_obs_2) = _observedFromAppGeo(ra_appGeo, dec_appGeo,
281 obs_metadata=self.obs,
282 includeRefraction=True)
284 dd = arcsecFromRadians(_angularSeparation(ra_obs, dec_obs, ra_obs_2, dec_obs_2))
285 self.assertLess(dd.max(), 1.0e-5)
287 def test_stellar_observed_degrees(self):
288 """
289 Test ability to go all the way to observed RA, Dec
290 from PhoSim (this is necessary for the ImSim software
291 that DESC is working on)
292 """
293 db = testStarsDBObj(driver='sqlite', database=self.db_name)
294 cat = StarTestCatalog(db, obs_metadata=self.obs)
295 with lsst.utils.tests.getTempFilePath('.txt') as cat_name:
296 cat.write_catalog(cat_name)
297 dtype = np.dtype([('raICRS', float), ('decICRS', float),
298 ('raPhoSim', float), ('decPhoSim', float),
299 ('raJ2000', float), ('decJ2000', float),
300 ('pmRA', float), ('pmDec', float),
301 ('parallax', float), ('vRad', float)])
302 data = np.genfromtxt(cat_name, dtype=dtype)
303 self.assertGreater(len(data), 100)
305 (ra_obs,
306 dec_obs) = observedFromICRS(np.degrees(data['raJ2000']),
307 np.degrees(data['decJ2000']),
308 obs_metadata=self.obs,
309 pm_ra=arcsecFromRadians(data['pmRA']),
310 pm_dec=arcsecFromRadians(data['pmDec']),
311 parallax=arcsecFromRadians(data['parallax']),
312 v_rad=data['vRad'],
313 includeRefraction=True,
314 epoch=2000.0)
316 (ra_appGeo,
317 dec_appGeo) = PhoSimAstrometryBase.appGeoFromPhoSim(data['raPhoSim'],
318 data['decPhoSim'],
319 self.obs)
321 (ra_obs_2,
322 dec_obs_2) = observedFromAppGeo(ra_appGeo, dec_appGeo,
323 obs_metadata=self.obs,
324 includeRefraction=True)
326 dd = 3600.0*angularSeparation(ra_obs, dec_obs, ra_obs_2, dec_obs_2)
327 self.assertLess(dd.max(), 1.0e-5)
329 def test_galaxy_astrometry_radians(self):
330 """
331 Test that we can go from raPhoSim, decPhoSim to ICRS coordinates
332 in the case of galaxies (in radians)
333 """
334 db = testGalaxyDiskDBObj(driver='sqlite', database=self.db_name)
335 cat = GalaxyTestCatalog(db, obs_metadata=self.obs)
336 with lsst.utils.tests.getTempFilePath('.txt') as cat_name:
337 cat.write_catalog(cat_name)
338 dtype = np.dtype([('raICRS', float), ('decICRS', float),
339 ('raPhoSim', float), ('decPhoSim', float)])
340 data = np.genfromtxt(cat_name, dtype=dtype)
341 self.assertGreater(len(data), 100)
342 ra_pho_rad = np.radians(data['raPhoSim'])
343 dec_pho_rad = np.radians(data['decPhoSim'])
345 # verify that, when transforming back to ICRS, we are within
346 # 10^-3 arcsec
347 ra_icrs, dec_icrs = PhoSimAstrometryBase._icrsFromPhoSim(ra_pho_rad,
348 dec_pho_rad,
349 self.obs)
350 dist = _angularSeparation(np.radians(data['raICRS']),
351 np.radians(data['decICRS']),
352 ra_icrs, dec_icrs)
354 dist = arcsecFromRadians(dist)
355 self.assertLess(dist.max(), 0.001)
357 # verify that the distance between raPhoSim, decPhoSim and
358 # raICRS, decICRS is greater than the distance between
359 # the original raICRS, decICRS and the newly-calculated
360 # raICRS, decICRS
361 dist_bad = _angularSeparation(ra_pho_rad, dec_pho_rad,
362 np.radians(data['raICRS']),
363 np.radians(data['decICRS']))
365 dist_bad = arcsecFromRadians(dist_bad)
366 self.assertGreater(dist_bad.min(), dist.max())
368 del db
370 def test_galaxy_astrometry_degrees(self):
371 """
372 Test that we can go from raPhoSim, decPhoSim to ICRS coordinates
373 in the case of galaxies (in degrees)
374 """
375 db = testGalaxyDiskDBObj(driver='sqlite', database=self.db_name)
376 cat = GalaxyTestCatalog(db, obs_metadata=self.obs)
377 with lsst.utils.tests.getTempFilePath('.txt') as cat_name:
378 cat.write_catalog(cat_name)
379 dtype = np.dtype([('raICRS', float), ('decICRS', float),
380 ('raPhoSim', float), ('decPhoSim', float)])
381 data = np.genfromtxt(cat_name, dtype=dtype)
382 self.assertGreater(len(data), 100)
384 # verify that, when transforming back to ICRS, we are within
385 # 10^-3 arcsec
386 ra_icrs, dec_icrs = PhoSimAstrometryBase.icrsFromPhoSim(data['raPhoSim'],
387 data['decPhoSim'],
388 self.obs)
389 dist = angularSeparation(data['raICRS'], data['decICRS'],
390 ra_icrs, dec_icrs)
392 dist = 3600.0*dist
393 self.assertLess(dist.max(), 0.001)
395 # verify that the distance between raPhoSim, decPhoSim and
396 # raICRS, decICRS is greater than the distance between
397 # the original raICRS, decICRS and the newly-calculated
398 # raICRS, decICRS
399 dist_bad = angularSeparation(data['raPhoSim'], data['decPhoSim'],
400 data['raICRS'], data['decICRS'])
402 dist_bad = 3600.0*dist_bad
403 self.assertGreater(dist_bad.min(), dist.max())
405 del db
407 def test_naive_focal_plane_position(self):
408 """
409 Test deprecession of PhoSim coordinates by comparing
410 the focal plane position predicted by CatSim from ICRS
411 with the focal plane position predicted by CatSim from deprecessed
412 coordinates.
413 """
415 phosim_mixin = PhoSimAstrometryBase()
417 mjd = 59587.2
419 # create site with no atmosphere so that we can avoid
420 # refraction
421 site = Site(name="LSST", pressure=0.0, humidity=0.0)
423 obs = ObservationMetaData(mjd=mjd, site=site)
424 ra, dec = raDecFromAltAz(31.0, 112.0, obs)
426 d_sun = distanceToSun(ra, dec, obs.mjd)
427 self.assertGreater(d_sun, 45.0)
429 obs = ObservationMetaData(pointingRA=ra, pointingDec=dec,
430 rotSkyPos=27.3, mjd=mjd,
431 site=site)
432 ra_icrs = np.arange(obs.pointingRA-2.0, obs.pointingRA+2.0, 0.05)
433 dec_icrs = np.arange(obs.pointingDec-2.0, obs.pointingDec+2.0, 0.05)
435 coord_grid = np.meshgrid(ra_icrs, dec_icrs)
436 ra_icrs = coord_grid[0].flatten()
437 dec_icrs = coord_grid[1].flatten()
439 (xpup_icrs,
440 ypup_icrs) = pupilCoordsFromRaDec(ra_icrs, dec_icrs,
441 obs_metadata=obs,
442 epoch=2000.0,
443 includeRefraction=False)
445 (x_focal_icrs,
446 y_focal_icrs) = focalPlaneCoordsFromPupilCoords(xpup_icrs,
447 ypup_icrs,
448 camera=lsst_camera())
450 ra_obs, dec_obs = observedFromICRS(ra_icrs, dec_icrs, obs_metadata=obs,
451 epoch=2000.0,
452 includeRefraction=False)
454 ra_obs_rad = np.radians(ra_obs)
455 dec_obs_rad = np.radians(dec_obs)
457 (ra_deprecessed_rad,
458 dec_deprecessed_rad) = phosim_mixin._dePrecess(ra_obs_rad,
459 dec_obs_rad, obs)
461 (xpup_deprecessed,
462 ypup_deprecessed) = _naivePupilCoordsFromObserved(ra_deprecessed_rad,
463 dec_deprecessed_rad,
464 obs._pointingRA,
465 obs._pointingDec,
466 obs._rotSkyPos)
468 (x_focal_deprecessed,
469 y_focal_deprecessed) = focalPlaneCoordsFromPupilCoords(xpup_deprecessed,
470 ypup_deprecessed,
471 camera=lsst_camera())
473 dd = np.sqrt((x_focal_icrs-x_focal_deprecessed)**2
474 +(y_focal_icrs-y_focal_deprecessed)**2)
476 self.assertLess(dd.max(), 5.0e-8)
478 def test_against_catalog(self):
479 """
480 Compare deprecession results to a catalog that was validated
481 with PhoSim.
482 """
483 obs = ObservationMetaData(pointingRA=53.00913847303155535,
484 pointingDec=-27.43894880881512321,
485 rotSkyPos=256.75075318193080420,
486 mjd=59580.13955500000156462,
487 site=Site(name="LSST", pressure=0.0,
488 humidity=0.0))
490 dtype = np.dtype([('id', int), ('ra', float), ('dec', float),
491 ('ra_deprecessed', float), ('dec_deprecessed', float),
492 ('x_dm', float), ('y_dm', float),
493 ('x_focal', float), ('y_focal', float),
494 ('x_cam', float), ('y_cam', float)])
496 data = np.genfromtxt(os.path.join(getPackageDir('sims_catUtils'),
497 'tests', 'testData',
498 'pixel_prediction_catalog.txt'),
499 dtype=dtype)
501 ra_obs, dec_obs = observedFromICRS(data['ra'], data['dec'],
502 obs_metadata=obs,
503 includeRefraction=False,
504 epoch=2000.0)
506 phosim_mixin = PhoSimAstrometryBase()
507 ra_dep, dec_dep = phosim_mixin._dePrecess(np.radians(ra_obs),
508 np.radians(dec_obs),
509 obs)
511 dd = 3600.0*angularSeparation(data['ra_deprecessed'], data['dec_deprecessed'],
512 np.degrees(ra_dep), np.degrees(dec_dep))
513 self.assertLess(dd.max(), 1.0e-5)
515 def test_InstanceCatalog_against_catalog(self):
516 """
517 Test that we can reproduce the validated data using the
518 InstanceCatalog framework
519 """
521 obs = ObservationMetaData(pointingRA=53.00913847303155535,
522 pointingDec=-27.43894880881512321,
523 rotSkyPos=256.75075318193080420,
524 mjd=59580.13955500000156462,
525 bandpassName='r',
526 site=Site(name="LSST", pressure=0.0,
527 humidity=0.0))
529 data_dir = os.path.join(getPackageDir('sims_catUtils'),'tests',
530 'testData')
532 dtype = np.dtype([('id', int), ('ra', float), ('dec', float),
533 ('ra_deprecessed', float), ('dec_deprecessed', float),
534 ('x_dm', float), ('y_dm', float),
535 ('x_focal', float), ('y_focal', float),
536 ('x_cam', float), ('y_cam', float)])
538 data = np.genfromtxt(os.path.join(data_dir,
539 'pixel_prediction_catalog.txt'),
540 dtype=dtype)
542 data_txt_file = tempfile.mktemp(dir=data_dir,
543 prefix='ic_validation_cat',
544 suffix='.txt')
546 cat_dtype = np.dtype([('id', int),
547 ('raJ2000', float), ('decJ2000', float)])
549 with open(data_txt_file, 'w') as out_file:
550 out_file.write('# a header\n')
551 for ii, rr, dd in zip(data['id'],
552 np.radians(data['ra']),
553 np.radians(data['dec'])):
555 out_file.write('%d %.17f %.17f\n' % (ii, rr, dd))
557 db = fileDBObject(data_txt_file, idColKey='id', dtype=cat_dtype,
558 delimiter=' ')
560 class DeprecessionTestCatalog(PhoSimCatalogPoint):
561 def get_uniqueId(self):
562 return self.column_by_name('id')
564 def get_properMotionRa(self):
565 return np.zeros(len(self.column_by_name('raJ2000')))
567 def get_properMotionDec(self):
568 return np.zeros(len(self.column_by_name('raJ2000')))
570 def get_radialVelocity(self):
571 return np.zeros(len(self.column_by_name('raJ2000')))
573 def get_parallax(self):
574 return np.zeros(len(self.column_by_name('raJ2000')))
576 def get_galacticAv(self):
577 return np.zeros(len(self.column_by_name('raJ2000')))
579 def get_galacticRv(self):
580 return 3.1*np.ones(len(self.column_by_name('raJ2000')))
582 def get_sedFilepath(self):
583 return np.array(['sed_flat.txt.gz']*len(self.column_by_name('raJ2000')))
585 def get_phoSimMagNorm(self):
586 return np.ones(len(self.column_by_name('raJ2000')))
588 cat = DeprecessionTestCatalog(db, obs_metadata=obs)
589 cat.phoSimHeaderMap = DefaultPhoSimHeaderMap
591 id_list = []
592 ra_dep_list = []
593 dec_dep_list= []
595 phosim_cat_name = tempfile.mktemp(dir=data_dir,
596 prefix='phosim_dep',
597 suffix='.txt')
599 cat.write_catalog(phosim_cat_name)
600 with open(phosim_cat_name, 'r') as input_file:
601 for line in input_file:
602 params = line.strip().split()
603 if len(params) < 3:
604 continue
605 id_list.append(int(params[1]))
606 ra_dep_list.append(float(params[2]))
607 dec_dep_list.append(float(params[3]))
609 id_list = np.array(id_list)
610 np.testing.assert_array_equal(id_list, data['id'])
611 ra_dep_list = np.array(ra_dep_list)
612 dec_dep_list = np.array(dec_dep_list)
614 dd = 3600.0*angularSeparation(data['ra_deprecessed'], data['dec_deprecessed'],
615 ra_dep_list, dec_dep_list)
617 self.assertLess(dd.max(), 1.0e-5)
619 if os.path.exists(data_txt_file):
620 os.unlink(data_txt_file)
622 if os.path.exists(phosim_cat_name):
623 os.unlink(phosim_cat_name)
625 def test_InstanceCatalog_against_catalog_chunks(self):
626 """
627 Test that we can reproduce the validated data using the
628 InstanceCatalog framework when the catalog must be written
629 in multiple chunks
630 """
632 obs = ObservationMetaData(pointingRA=53.00913847303155535,
633 pointingDec=-27.43894880881512321,
634 rotSkyPos=256.75075318193080420,
635 mjd=59580.13955500000156462,
636 bandpassName='r',
637 site=Site(name="LSST", pressure=0.0,
638 humidity=0.0))
640 data_dir = os.path.join(getPackageDir('sims_catUtils'),'tests',
641 'testData')
643 dtype = np.dtype([('id', int), ('ra', float), ('dec', float),
644 ('ra_deprecessed', float), ('dec_deprecessed', float),
645 ('x_dm', float), ('y_dm', float),
646 ('x_focal', float), ('y_focal', float),
647 ('x_cam', float), ('y_cam', float)])
649 data = np.genfromtxt(os.path.join(data_dir,
650 'pixel_prediction_catalog.txt'),
651 dtype=dtype)
653 data_txt_file = tempfile.mktemp(dir=data_dir,
654 prefix='ic_validation_cat',
655 suffix='.txt')
657 cat_dtype = np.dtype([('id', int),
658 ('raJ2000', float), ('decJ2000', float)])
660 with open(data_txt_file, 'w') as out_file:
661 out_file.write('# a header\n')
662 for ii, rr, dd in zip(data['id'],
663 np.radians(data['ra']),
664 np.radians(data['dec'])):
666 out_file.write('%d %.17f %.17f\n' % (ii, rr, dd))
668 db = fileDBObject(data_txt_file, idColKey='id', dtype=cat_dtype,
669 delimiter=' ')
671 class DeprecessionTestCatalog_chunks(PhoSimCatalogPoint):
672 def get_uniqueId(self):
673 return self.column_by_name('id')
675 def get_properMotionRa(self):
676 return np.zeros(len(self.column_by_name('raJ2000')))
678 def get_properMotionDec(self):
679 return np.zeros(len(self.column_by_name('raJ2000')))
681 def get_radialVelocity(self):
682 return np.zeros(len(self.column_by_name('raJ2000')))
684 def get_parallax(self):
685 return np.zeros(len(self.column_by_name('raJ2000')))
687 def get_galacticAv(self):
688 return np.zeros(len(self.column_by_name('raJ2000')))
690 def get_galacticRv(self):
691 return 3.1*np.ones(len(self.column_by_name('raJ2000')))
693 def get_sedFilepath(self):
694 return np.array(['sed_flat.txt.gz']*len(self.column_by_name('raJ2000')))
696 def get_phoSimMagNorm(self):
697 return np.ones(len(self.column_by_name('raJ2000')))
699 cat = DeprecessionTestCatalog_chunks(db, obs_metadata=obs)
700 cat.phoSimHeaderMap = DefaultPhoSimHeaderMap
702 id_list = []
703 ra_dep_list = []
704 dec_dep_list= []
706 phosim_cat_name = tempfile.mktemp(dir=data_dir,
707 prefix='phosim_dep',
708 suffix='.txt')
710 cat.write_catalog(phosim_cat_name, chunk_size=10)
711 with open(phosim_cat_name, 'r') as input_file:
712 for line in input_file:
713 params = line.strip().split()
714 if len(params) < 3:
715 continue
716 id_list.append(int(params[1]))
717 ra_dep_list.append(float(params[2]))
718 dec_dep_list.append(float(params[3]))
720 id_list = np.array(id_list)
721 np.testing.assert_array_equal(id_list, data['id'])
722 ra_dep_list = np.array(ra_dep_list)
723 dec_dep_list = np.array(dec_dep_list)
725 dd = 3600.0*angularSeparation(data['ra_deprecessed'], data['dec_deprecessed'],
726 ra_dep_list, dec_dep_list)
728 self.assertLess(dd.max(), 1.0e-5)
730 if os.path.exists(data_txt_file):
731 os.unlink(data_txt_file)
733 if os.path.exists(phosim_cat_name):
734 os.unlink(phosim_cat_name)
737class MemoryTestClass(lsst.utils.tests.MemoryTestCase):
738 pass
741if __name__ == "__main__": 741 ↛ 742line 741 didn't jump to line 742, because the condition on line 741 was never true
742 lsst.utils.tests.init()
743 unittest.main()