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

109

110

111

112

113

114

115

import numpy as np 

from lsst.sims.utils import cartesianFromSpherical 

from lsst.sims.utils import sphericalFromCartesian 

from lsst.sims.utils import rotationMatrixFromVectors 

 

__all__ = ["_FieldRotator"] 

 

class _FieldRotator(object): 

 

def __init__(self, ra0, dec0, ra1, dec1): 

""" 

Parameters 

---------- 

ra0, dec0 are the coordinates of the original field 

center in radians 

 

ra1, dec1 are the coordinates of the new field center 

in radians 

 

The transform() method of this class operates by first 

applying a rotation that carries the original field center 

into the new field center. Points are then transformed into 

a basis in which the unit vector defining the new field center 

is the x-axis. A rotation about the x-axis is applied so that 

a point that was due north of the original field center is still 

due north of the field center at the new location. Finally, 

points are transformed back into the original x,y,z bases. 

""" 

 

self._ra0 = ra0 

self._dec0 = dec0 

self._ra1 = ra1 

self._dec1 = dec1 

 

# find the rotation that carries the original field center 

# to the new field center 

xyz = cartesianFromSpherical(ra0, dec0) 

xyz1 = cartesianFromSpherical(ra1, dec1) 

39 ↛ 40line 39 didn't jump to line 40, because the condition on line 39 was never true if np.abs(1.0-np.dot(xyz, xyz1))<1.0e-10: 

self._transformation = np.identity(3, dtype=float) 

return 

 

first_rotation = rotationMatrixFromVectors(xyz, xyz1) 

 

# create a basis set in which the unit vector 

# defining the new field center is the x axis 

xx = np.dot(first_rotation, xyz) 

rng = np.random.RandomState(99) 

mag = np.NaN 

while np.abs(mag)<1.0e-20 or np.isnan(mag): 

random_vec = rng.random_sample(3) 

comp = np.dot(random_vec, xx) 

yy = random_vec - comp*xx 

mag = np.sqrt((yy**2).sum()) 

yy /= mag 

 

zz = np.cross(xx, yy) 

 

to_self_bases = np.array([xx, 

yy, 

zz]) 

 

out_of_self_bases =to_self_bases.transpose() 

 

# Take a point due north of the original field 

# center. Apply first_rotation to carry it to 

# the new field. Transform it to the [xx, yy, zz] 

# bases and find the rotation about xx that will 

# make it due north of the new field center. 

# Finally, transform back to the original bases. 

d_dec = np.radians(0.1) 

north = cartesianFromSpherical(ra0,dec0+d_dec) 

 

north = np.dot(first_rotation, north) 

 

#print(np.degrees(sphericalFromCartesian(north))) 

 

north_true = cartesianFromSpherical(ra1, dec1+d_dec) 

 

north = np.dot(to_self_bases, north) 

north_true = np.dot(to_self_bases, north_true) 

north = np.array([north[1], north[2]]) 

north /= np.sqrt((north**2).sum()) 

north_true = np.array([north_true[1], north_true[2]]) 

north_true /= np.sqrt((north_true**2).sum()) 

 

c = north_true[0]*north[0]+north_true[1]*north[1] 

s = north[0]*north_true[1]-north[1]*north_true[0] 

norm = np.sqrt(c*c+s*s) 

c = c/norm 

s = s/norm 

 

nprime = np.array([c*north[0]-s*north[1], 

s*north[0]+c*north[1]]) 

 

yz_rotation = np.array([[1.0, 0.0, 0.0], 

[0.0, c, -s], 

[0.0, s, c]]) 

 

second_rotation = np.dot(out_of_self_bases, 

np.dot(yz_rotation, 

to_self_bases)) 

 

self._transformation = np.dot(second_rotation, 

first_rotation) 

 

def transform(self, ra, dec): 

""" 

ra, dec are in radians; return the RA, Dec coordinates 

of the point about the new field center 

""" 

xyz = cartesianFromSpherical(ra, dec).transpose() 

xyz = np.dot(self._transformation, xyz).transpose() 

ra_out, dec_out = sphericalFromCartesian(xyz) 

return ra_out, dec_out