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

""" 

This file does not include the boilerplate memory leak tests. Those tests 

kept failing because the instantiations of the LSST Camera were not cleaned 

up before the tests were run. 

""" 

 

from __future__ import with_statement 

import os 

import numpy as np 

import unittest 

import lsst.utils.tests 

 

from lsst.utils import getPackageDir 

from lsst.sims.utils import radiansFromArcsec, ObservationMetaData 

from lsst.sims.catalogs.db import fileDBObject 

from lsst.sims.catalogs.definitions import InstanceCatalog 

from lsst.sims.catUtils.mixins import CameraCoords, CameraCoordsLSST 

from lsst.sims.catUtils.mixins import AstrometryStars 

from lsst.obs.lsstSim import LsstSimMapper 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

class CameraCoordLSST_testCase(unittest.TestCase): 

""" 

This class will test that the CameraCoordsLSST mixin returns 

the same results as the CameraCoords mixin with self.camera=lsst_camera 

""" 

 

def test_different_cameras(self): 

rng = np.random.RandomState(6512) 

 

pointing_ra = 15.0 

pointing_dec = 13.0 

 

n_obj = 100 

ra_list = pointing_ra + 2.0*rng.random_sample(n_obj) 

dec_list = pointing_dec + 2.0*rng.random_sample(n_obj) 

px_list = radiansFromArcsec(0.005)*rng.random_sample(n_obj) 

px_list += radiansFromArcsec(0.001) 

mura_list = radiansFromArcsec(0.005)*rng.random_sample(n_obj) 

mudec_list = radiansFromArcsec(0.005)*rng.random_sample(n_obj) 

vrad_list = 100.0*rng.random_sample(n_obj) 

 

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

with open(db_text_file, 'w') as out_file: 

for ix, (rdeg, ddeg, rrad, drad, px, mura, mudec, vrad) in \ 

enumerate(zip(ra_list, dec_list, 

np.radians(ra_list), np.radians(dec_list), 

px_list, mura_list, mudec_list, vrad_list)): 

 

out_file.write('%d %e %e %e %e %e %e %e %e\n' % (ix, rdeg, ddeg, 

rrad, drad, 

px, 

mura, mudec, 

vrad)) 

 

dtype = np.dtype([('id', int), ('raDeg', float), ('decDeg', float), 

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

('parallax', float), 

('properMotionRa', float), ('properMotionDec', float), 

('radialVelocity', float)]) 

 

db = fileDBObject(db_text_file, dtype=dtype, idColKey='id') 

db.raColName = 'raDeg' 

db.decColName = 'decDeg' 

 

 

class CameraCoordsCatalog(AstrometryStars, CameraCoords, 

InstanceCatalog): 

camera = LsstSimMapper().camera 

column_outputs = ['id', 'chipName'] 

 

 

class CameraCoordsLSSTCatalog(AstrometryStars, CameraCoordsLSST, 

InstanceCatalog): 

column_outputs = ['id', 'chipName'] 

 

obs = ObservationMetaData(pointingRA=pointing_ra, 

pointingDec=pointing_dec, 

boundLength=1.75, 

boundType='circle', 

rotSkyPos=23.0, 

mjd=59580.0) 

 

control_cat = CameraCoordsCatalog(db, obs_metadata=obs) 

test_cat = CameraCoordsLSSTCatalog(db, obs_metadata=obs) 

 

control_line_list = [] 

none_chips = 0 

for line in control_cat.iter_catalog(): 

if line[1] is None: 

none_chips += 1 

control_line_list.append(line) 

self.assertGreater(len(control_line_list), 0) 

self.assertLess(none_chips, len(control_line_list)/2) 

 

line_ct = 0 

for line in test_cat.iter_catalog(): 

line_ct += 1 

self.assertIn(line, control_line_list) 

self.assertEqual(line_ct, len(control_line_list)) 

 

 

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

lsst.utils.tests.init() 

unittest.main()