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

from __future__ import division 

from builtins import zip 

from builtins import range 

import unittest 

import numpy as np 

import lsst.utils.tests 

import lsst.sims.utils as utils 

import healpy as hp 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

class ApproxCoordTests(unittest.TestCase): 

""" 

Test the fast approximate ra,dec to alt,az transforms 

""" 

 

def test_degrees(self): 

nside = 64 

hpids = np.arange(hp.nside2npix(nside)) 

ra, dec = utils.hpid2RaDec(nside, hpids) 

mjd = 59852. 

obs = utils.ObservationMetaData(mjd=mjd) 

 

alt1, az1, pa1 = utils.altAzPaFromRaDec(ra, dec, obs) 

 

alt2, az2 = utils.approx_RaDec2AltAz(ra, dec, obs.site.latitude, 

obs.site.longitude, mjd) 

 

# Check that the fast is similar to the more precice transform 

tol = 2 # Degrees 

tol_mean = 1. 

separations = utils.angularSeparation(az1, alt1, az2, alt2) 

self.assertLess(np.max(separations), tol) 

self.assertLess(np.mean(separations), tol_mean) 

 

# Check that the fast can nearly round-trip 

ra_back, dec_back = utils.approx_altAz2RaDec(alt2, az2, obs.site.latitude, 

obs.site.longitude, mjd) 

separations = utils.angularSeparation(ra, dec, ra_back, dec_back) 

self.assertLess(np.max(separations), tol) 

self.assertLess(np.mean(separations), tol_mean) 

 

def test_rad(self): 

nside = 64 

hpids = np.arange(hp.nside2npix(nside)) 

ra, dec = utils._hpid2RaDec(nside, hpids) 

mjd = 59852. 

obs = utils.ObservationMetaData(mjd=mjd) 

 

alt1, az1, pa1 = utils._altAzPaFromRaDec(ra, dec, obs) 

 

alt2, az2 = utils._approx_RaDec2AltAz(ra, dec, obs.site.latitude_rad, 

obs.site.longitude_rad, mjd) 

 

# Check that the fast is similar to the more precice transform 

tol = np.radians(2) 

tol_mean = np.radians(1.) 

separations = utils._angularSeparation(az1, alt1, az2, alt2) 

 

self.assertLess(np.max(separations), tol) 

self.assertLess(np.mean(separations), tol_mean) 

 

# Check that the fast can nearly round-trip 

ra_back, dec_back = utils._approx_altAz2RaDec(alt2, az2, obs.site.latitude_rad, 

obs.site.longitude_rad, mjd) 

separations = utils._angularSeparation(ra, dec, ra_back, dec_back) 

self.assertLess(np.max(separations), tol) 

self.assertLess(np.mean(separations), tol_mean) 

 

 

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

pass 

 

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

lsst.utils.tests.init() 

unittest.main()