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

from builtins import zip 

import numpy as np 

import matplotlib.pyplot as plt 

from .plotHandler import BasePlotter 

from matplotlib.patches import Ellipse 

 

__all__ = ['NeoDistancePlotter'] 

 

 

class NeoDistancePlotter(BasePlotter): 

""" 

Special plotter to calculate and plot the maximum distance an H=22 NEO could be observable to, 

in any particular particular opsim observation. 

""" 

def __init__(self, step=.01, eclipMax=10., eclipMin=-10.): 

""" 

eclipMin/Max: only plot observations within X degrees of the ecliptic plane 

step: Step size to use for radial bins. Default is 0.01 AU. 

""" 

self.plotType = 'neoxyPlotter' 

self.objectPlotter = True 

self.defaultPlotDict = {'title': None, 'xlabel': 'X (AU)', 

'ylabel': 'Y (AU)', 'xMin': -1.5, 'xMax': 1.5, 

'yMin': -.25, 'yMax': 2.5, 'units': 'Count'} 

self.filter2color = {'u': 'purple', 'g': 'blue', 'r': 'green', 

'i': 'cyan', 'z': 'orange', 'y': 'red'} 

self.filterColName = 'filter' 

self.step = step 

self.eclipMax = np.radians(eclipMax) 

self.eclipMin = np.radians(eclipMin) 

 

def __call__(self, metricValue, slicer, userPlotDict, fignum=None): 

""" 

Parameters 

---------- 

metricValue : numpy.ma.MaskedArray 

Metric values calculated by lsst.sims.maf.metrics.PassMetric 

slicer : lsst.sims.maf.slicers.UniSlicer 

userPlotDict: dict 

Dictionary of plot parameters set by user (overrides default values). 

fignum : int 

Matplotlib figure number to use (default = None, starts new figure). 

 

Returns 

------- 

int 

Matplotlib figure number used to create the plot. 

""" 

fig = plt.figure(fignum) 

ax = fig.add_subplot(111) 

 

inPlane = np.where((metricValue[0]['eclipLat'] >= self.eclipMin) & 

(metricValue[0]['eclipLat'] <= self.eclipMax)) 

 

plotDict = {} 

plotDict.update(self.defaultPlotDict) 

plotDict.update(userPlotDict) 

 

planetProps = {'Earth': 1., 'Venus': 0.72, 'Mars': 1.52, 'Mercury': 0.39} 

 

planets = [] 

for prop in planetProps: 

planets.append(Ellipse((0, 0), planetProps[prop] * 2, planetProps[prop] * 2, fill=False)) 

 

for planet in planets: 

ax.add_artist(planet) 

 

# Let's make a 2-d histogram in polar coords, then convert and display in cartisian 

 

rStep = self.step 

Rvec = np.arange(0, plotDict['xMax'] + rStep, rStep) 

thetaStep = np.radians(3.5) 

thetavec = np.arange(0, 2 * np.pi + thetaStep, thetaStep) - np.pi 

 

# array to hold histogram values 

H = np.zeros((thetavec.size, Rvec.size), dtype=float) 

 

Rgrid, thetagrid = np.meshgrid(Rvec, thetavec) 

 

xgrid = Rgrid * np.cos(thetagrid) 

ygrid = Rgrid * np.sin(thetagrid) 

 

for dist, x, y in zip(metricValue[0]['MaxGeoDist'][inPlane], metricValue[0]['NEOHelioX'][inPlane], 

metricValue[0]['NEOHelioY'][inPlane]): 

 

theta = np.arctan2(y - 1., x) 

diff = np.abs(thetavec - theta) 

thetaToUse = thetavec[np.where(diff == diff.min())] 

# This is a slow where-clause, should be possible to speed it up using 

# np.searchsorted+clever slicing or hist2d to build up the map. 

good = np.where((thetagrid == thetaToUse) & (Rgrid <= dist)) 

H[good] += 1 

 

# Set the under value to white 

myCmap = plt.cm.get_cmap('jet') 

myCmap.set_under('w') 

blah = ax.pcolormesh(xgrid, ygrid + 1, H, cmap=myCmap, vmin=.001) 

cb = plt.colorbar(blah, ax=ax) 

cb.set_label(plotDict['units']) 

 

ax.set_xlabel(plotDict['xlabel']) 

ax.set_ylabel(plotDict['ylabel']) 

ax.set_title(plotDict['title']) 

ax.set_ylim([plotDict['yMin'], plotDict['yMax']]) 

ax.set_xlim([plotDict['xMin'], plotDict['xMax']]) 

 

ax.plot([0], [1], marker='o', color='b') 

ax.plot([0], [0], marker='o', color='y') 

 

return fig.number