Coverage for tests/testCameraCoordsLSST.py : 25%

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"""
2This file does not include the boilerplate memory leak tests. Those tests
3kept failing because the instantiations of the LSST Camera were not cleaned
4up before the tests were run.
5"""
7from __future__ import with_statement
8import os
9import numpy as np
10import unittest
11import lsst.utils.tests
13from lsst.utils import getPackageDir
14from lsst.sims.utils import radiansFromArcsec, ObservationMetaData
15from lsst.sims.catalogs.db import fileDBObject
16from lsst.sims.catalogs.definitions import InstanceCatalog
17from lsst.sims.catUtils.mixins import CameraCoords, CameraCoordsLSST
18from lsst.sims.catUtils.mixins import AstrometryStars
19from lsst.obs.lsstSim import LsstSimMapper
21def setup_module(module):
22 lsst.utils.tests.init()
25class CameraCoordLSST_testCase(unittest.TestCase):
26 """
27 This class will test that the CameraCoordsLSST mixin returns
28 the same results as the CameraCoords mixin with self.camera=lsst_camera
29 """
31 def test_different_cameras(self):
32 rng = np.random.RandomState(6512)
34 pointing_ra = 15.0
35 pointing_dec = 13.0
37 n_obj = 100
38 ra_list = pointing_ra + 2.0*rng.random_sample(n_obj)
39 dec_list = pointing_dec + 2.0*rng.random_sample(n_obj)
40 px_list = radiansFromArcsec(0.005)*rng.random_sample(n_obj)
41 px_list += radiansFromArcsec(0.001)
42 mura_list = radiansFromArcsec(0.005)*rng.random_sample(n_obj)
43 mudec_list = radiansFromArcsec(0.005)*rng.random_sample(n_obj)
44 vrad_list = 100.0*rng.random_sample(n_obj)
46 with lsst.utils.tests.getTempFilePath('.txt') as db_text_file:
47 with open(db_text_file, 'w') as out_file:
48 for ix, (rdeg, ddeg, rrad, drad, px, mura, mudec, vrad) in \
49 enumerate(zip(ra_list, dec_list,
50 np.radians(ra_list), np.radians(dec_list),
51 px_list, mura_list, mudec_list, vrad_list)):
53 out_file.write('%d %e %e %e %e %e %e %e %e\n' % (ix, rdeg, ddeg,
54 rrad, drad,
55 px,
56 mura, mudec,
57 vrad))
59 dtype = np.dtype([('id', int), ('raDeg', float), ('decDeg', float),
60 ('raJ2000', float), ('decJ2000', float),
61 ('parallax', float),
62 ('properMotionRa', float), ('properMotionDec', float),
63 ('radialVelocity', float)])
65 db = fileDBObject(db_text_file, dtype=dtype, idColKey='id')
66 db.raColName = 'raDeg'
67 db.decColName = 'decDeg'
70 class CameraCoordsCatalog(AstrometryStars, CameraCoords,
71 InstanceCatalog):
72 camera = LsstSimMapper().camera
73 column_outputs = ['id', 'chipName']
76 class CameraCoordsLSSTCatalog(AstrometryStars, CameraCoordsLSST,
77 InstanceCatalog):
78 column_outputs = ['id', 'chipName']
80 obs = ObservationMetaData(pointingRA=pointing_ra,
81 pointingDec=pointing_dec,
82 boundLength=1.75,
83 boundType='circle',
84 rotSkyPos=23.0,
85 mjd=59580.0)
87 control_cat = CameraCoordsCatalog(db, obs_metadata=obs)
88 test_cat = CameraCoordsLSSTCatalog(db, obs_metadata=obs)
90 control_line_list = []
91 none_chips = 0
92 for line in control_cat.iter_catalog():
93 if line[1] is None:
94 none_chips += 1
95 control_line_list.append(line)
96 self.assertGreater(len(control_line_list), 0)
97 self.assertLess(none_chips, len(control_line_list)/2)
99 line_ct = 0
100 for line in test_cat.iter_catalog():
101 line_ct += 1
102 self.assertIn(line, control_line_list)
103 self.assertEqual(line_ct, len(control_line_list))
106if __name__ == "__main__": 106 ↛ 107line 106 didn't jump to line 107, because the condition on line 106 was never true
107 lsst.utils.tests.init()
108 unittest.main()