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# LSST Data Management System 

3# Copyright 2012-2017 LSST Corporation. 

4# 

5# This product includes software developed by the 

6# LSST Project (http://www.lsst.org/). 

7# 

8# This program is free software: you can redistribute it and/or modify 

9# it under the terms of the GNU General Public License as published by 

10# the Free Software Foundation, either version 3 of the License, or 

11# (at your option) any later version. 

12# 

13# This program is distributed in the hope that it will be useful, 

14# but WITHOUT ANY WARRANTY; without even the implied warranty of 

15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

16# GNU General Public License for more details. 

17# 

18# You should have received a copy of the LSST License Statement and 

19# the GNU General Public License along with this program. If not, 

20# see <http://www.lsstcorp.org/LegalNotices/>. 

21# 

22 

23 

24import unittest 

25 

26import numpy as np 

27 

28from numpy.testing import assert_allclose 

29 

30import lsst.utils 

31from lsst.validate.drp.calcsrd.amx import matchVisitComputeDistance 

32 

33 

34def test_basic_matchVisitComputeDistance(): 

35 visit_obj1 = [1, 2, 3, 4] 

36 visit_obj2 = [1, 2, 3, 4] 

37 ra_obj1 = np.deg2rad(np.array([10.0010, 10.0005, 10.0000, 10.0005])) 

38 ra_obj2 = np.deg2rad(np.array([10.0008, 10.0003, 10.0005, 10.0006])) 

39 dec_obj1 = np.deg2rad(np.array([20.001, 20.006, 20.002, 20.004])) 

40 dec_obj2 = np.deg2rad(np.array([20.010, 20.030, 20.004, 20.003])) 

41 

42 exp = [0.0001571138, 0.000418891, 3.58568e-05, 1.75301e-05] 

43 obs = matchVisitComputeDistance(visit_obj1, ra_obj1, dec_obj1, 

44 visit_obj2, ra_obj2, dec_obj2) 

45 # matchVisitComputeDistance doesn't preserve order 

46 # Sort to compare 

47 exp = np.sort(exp) 

48 obs = np.sort(obs) 

49 

50 assert_allclose(exp, obs, atol=1e-7) # 1e-7 rad == 5.73e-6 deg == 0.00036 arcsec 

51 

52 

53def test_missing_matchVisitComputeDistance(): 

54 visit_obj1 = [1, 2, 3, 4] 

55 visit_obj2 = [4, 1] 

56 ra_obj1 = np.deg2rad(np.array([10.0010, 10.0005, 10.0000, 10.0005])) 

57 ra_obj2 = np.deg2rad(np.array([10.0006, 10.0008])) 

58 dec_obj1 = np.deg2rad(np.array([20.001, 20.006, 20.002, 20.004])) 

59 dec_obj2 = np.deg2rad(np.array([20.003, 20.010])) 

60 

61 exp = [1.75301e-05, 0.0001571138] 

62 obs = matchVisitComputeDistance(visit_obj1, ra_obj1, dec_obj1, 

63 visit_obj2, ra_obj2, dec_obj2) 

64 

65 # matchVisitComputeDistance doesn't preserve order 

66 # Sort to compare 

67 exp = np.sort(exp) 

68 obs = np.sort(obs) 

69 assert_allclose(exp, obs, atol=1e-7) # 1e-7 rad == 5.73e-6 deg == 0.00036 arcsec 

70 

71 

72def test_speed_matchVisitComputeDistance(n=5000): 

73 # Explicitly convert n to int to ensure consistent behavior in indexing and numpy 

74 n = int(n) 

75 visits = np.arange(2*n) 

76 

77 np.random.shuffle(visits) 

78 visit_obj1 = visits[:n] 

79 np.random.shuffle(visits) 

80 visit_obj2 = visits[:n] 

81 

82 mu, sigma = 0, 3e-4 # mean 0, ~1 arcsec width 

83 mean_ra = 10 # degrees 

84 mean_dec = 20 # degrees 

85 

86 ra_obj1 = mean_ra + np.random.normal(mu, sigma, n) * np.cos(np.deg2rad(mean_dec)) 

87 ra_obj2 = mean_ra + np.random.normal(mu, sigma, n) * np.cos(np.deg2rad(mean_dec)) 

88 dec_obj1 = mean_dec + np.random.normal(mu, sigma, n) 

89 dec_obj2 = mean_dec + np.random.normal(mu, sigma, n) 

90 

91 matchVisitComputeDistance(visit_obj1, ra_obj1, dec_obj1, 

92 visit_obj2, ra_obj2, dec_obj2) 

93 

94 

95if __name__ == "__main__": 95 ↛ 96line 95 didn't jump to line 96, because the condition on line 95 was never true

96 lsst.utils.tests.init() 

97 unittest.main()