Coverage for python/lsst/sims/maf/plots/neoDistancePlotter.py : 15%

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
1from builtins import zip
2import numpy as np
3import matplotlib.pyplot as plt
4from .plotHandler import BasePlotter
5from matplotlib.patches import Ellipse
7__all__ = ['NeoDistancePlotter']
10class NeoDistancePlotter(BasePlotter):
11 """
12 Special plotter to calculate and plot the maximum distance an H=22 NEO could be observable to,
13 in any particular particular opsim observation.
14 """
15 def __init__(self, step=.01, eclipMax=10., eclipMin=-10.):
16 """
17 eclipMin/Max: only plot observations within X degrees of the ecliptic plane
18 step: Step size to use for radial bins. Default is 0.01 AU.
19 """
20 self.plotType = 'neoxyPlotter'
21 self.objectPlotter = True
22 self.defaultPlotDict = {'title': None, 'xlabel': 'X (AU)',
23 'ylabel': 'Y (AU)', 'xMin': -1.5, 'xMax': 1.5,
24 'yMin': -.25, 'yMax': 2.5, 'units': 'Count'}
25 self.filter2color = {'u': 'purple', 'g': 'blue', 'r': 'green',
26 'i': 'cyan', 'z': 'orange', 'y': 'red'}
27 self.filterColName = 'filter'
28 self.step = step
29 self.eclipMax = np.radians(eclipMax)
30 self.eclipMin = np.radians(eclipMin)
32 def __call__(self, metricValue, slicer, userPlotDict, fignum=None):
33 """
34 Parameters
35 ----------
36 metricValue : numpy.ma.MaskedArray
37 Metric values calculated by lsst.sims.maf.metrics.PassMetric
38 slicer : lsst.sims.maf.slicers.UniSlicer
39 userPlotDict: dict
40 Dictionary of plot parameters set by user (overrides default values).
41 fignum : int
42 Matplotlib figure number to use (default = None, starts new figure).
44 Returns
45 -------
46 int
47 Matplotlib figure number used to create the plot.
48 """
49 fig = plt.figure(fignum)
50 ax = fig.add_subplot(111)
52 inPlane = np.where((metricValue[0]['eclipLat'] >= self.eclipMin) &
53 (metricValue[0]['eclipLat'] <= self.eclipMax))
55 plotDict = {}
56 plotDict.update(self.defaultPlotDict)
57 plotDict.update(userPlotDict)
59 planetProps = {'Earth': 1., 'Venus': 0.72, 'Mars': 1.52, 'Mercury': 0.39}
61 planets = []
62 for prop in planetProps:
63 planets.append(Ellipse((0, 0), planetProps[prop] * 2, planetProps[prop] * 2, fill=False))
65 for planet in planets:
66 ax.add_artist(planet)
68 # Let's make a 2-d histogram in polar coords, then convert and display in cartisian
70 rStep = self.step
71 Rvec = np.arange(0, plotDict['xMax'] + rStep, rStep)
72 thetaStep = np.radians(3.5)
73 thetavec = np.arange(0, 2 * np.pi + thetaStep, thetaStep) - np.pi
75 # array to hold histogram values
76 H = np.zeros((thetavec.size, Rvec.size), dtype=float)
78 Rgrid, thetagrid = np.meshgrid(Rvec, thetavec)
80 xgrid = Rgrid * np.cos(thetagrid)
81 ygrid = Rgrid * np.sin(thetagrid)
83 for dist, x, y in zip(metricValue[0]['MaxGeoDist'][inPlane], metricValue[0]['NEOHelioX'][inPlane],
84 metricValue[0]['NEOHelioY'][inPlane]):
86 theta = np.arctan2(y - 1., x)
87 diff = np.abs(thetavec - theta)
88 thetaToUse = thetavec[np.where(diff == diff.min())]
89 # This is a slow where-clause, should be possible to speed it up using
90 # np.searchsorted+clever slicing or hist2d to build up the map.
91 good = np.where((thetagrid == thetaToUse) & (Rgrid <= dist))
92 H[good] += 1
94 # Set the under value to white
95 myCmap = plt.cm.get_cmap('jet')
96 myCmap.set_under('w')
97 blah = ax.pcolormesh(xgrid, ygrid + 1, H, cmap=myCmap, vmin=.001)
98 cb = plt.colorbar(blah, ax=ax)
99 cb.set_label(plotDict['units'])
101 ax.set_xlabel(plotDict['xlabel'])
102 ax.set_ylabel(plotDict['ylabel'])
103 ax.set_title(plotDict['title'])
104 ax.set_ylim([plotDict['yMin'], plotDict['yMax']])
105 ax.set_xlim([plotDict['xMin'], plotDict['xMax']])
107 ax.plot([0], [1], marker='o', color='b')
108 ax.plot([0], [0], marker='o', color='y')
110 return fig.number