Skip to content
Snippets Groups Projects
Unverified Commit 066257d4 authored by David Hoese's avatar David Hoese
Browse files

Add wind direction specific plot maker and other fixes

parent 6ac0019f
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ import matplotlib.dates as md ...@@ -10,6 +10,7 @@ import matplotlib.dates as md
import math import math
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
FIGURE_TITLE_SIZE = 13
# names of the plots used in title (default is `.title()` of plot name) # names of the plots used in title (default is `.title()` of plot name)
TITLES = { TITLES = {
...@@ -86,10 +87,11 @@ class PlotMaker(object): ...@@ -86,10 +87,11 @@ class PlotMaker(object):
def _set_ylim(self, frame, ax): def _set_ylim(self, frame, ax):
ymin = np.floor(frame.min().min()) ymin = np.floor(frame.min().min())
ymax = np.ceil(frame.max().max()) ymax = np.ceil(frame.max().max())
delta = ymax - ymin
if ymin == ymax: if ymin == ymax:
ax.set_ylim(ymin, ymax + 0.1) ax.set_ylim(ymin - 0.1, ymax + 0.1)
else: else:
ax.set_ylim(ymin, ymax) ax.set_ylim(ymin - delta * 0.2, ymax + delta * 0.2)
return ymin, ymax return ymin, ymax
def _set_title(self, frame, fig, ax, start_time=None, end_time=None, title=None, is_subplot=None): def _set_title(self, frame, fig, ax, start_time=None, end_time=None, title=None, is_subplot=None):
...@@ -103,7 +105,7 @@ class PlotMaker(object): ...@@ -103,7 +105,7 @@ class PlotMaker(object):
if is_subplot: if is_subplot:
ax.set_title(title, x=0.5, y=get_subtitle_location(is_subplot[0]), fontsize=8) ax.set_title(title, x=0.5, y=get_subtitle_location(is_subplot[0]), fontsize=8)
else: else:
fig.suptitle(title, fontsize=13) fig.suptitle(title, fontsize=FIGURE_TITLE_SIZE)
def _get_axes(self, fig, is_subplot, shared_x=None): def _get_axes(self, fig, is_subplot, shared_x=None):
if is_subplot: if is_subplot:
...@@ -120,7 +122,7 @@ class PlotMaker(object): ...@@ -120,7 +122,7 @@ class PlotMaker(object):
def _set_yticks(self, ax, ymin, ymax, is_subplot): def _set_yticks(self, ax, ymin, ymax, is_subplot):
if is_subplot: if is_subplot:
new_ticks = self.get_yticks(ymin, ymax, is_subplot[0]) new_ticks = self.get_yticks(ymin, ymax, is_subplot[0])
ax.get_yaxis().get_major_ticks()[-1].set_visible(False) # ax.yaxis.get_major_ticks()[-1].set_visible(False)
ax.set_yticks(new_ticks) ax.set_yticks(new_ticks)
def create_plot(self, frame, fig, start_time=None, end_time=None, def create_plot(self, frame, fig, start_time=None, end_time=None,
...@@ -140,6 +142,8 @@ class PlotMaker(object): ...@@ -140,6 +142,8 @@ class PlotMaker(object):
# get the min for each column then combine them assuming we can # get the min for each column then combine them assuming we can
specific_frame = frame[[x for x in frame.columns if x in self.deps]] specific_frame = frame[[x for x in frame.columns if x in self.deps]]
# make ticks show up on top and bottom inside and out of the axis line
ax.xaxis.set_tick_params(left=True, right=True, direction='inout')
lines = self._call_plot(specific_frame, ax) lines = self._call_plot(specific_frame, ax)
ymin, ymax = self._set_ylim(specific_frame, ax) ymin, ymax = self._set_ylim(specific_frame, ax)
...@@ -150,11 +154,36 @@ class PlotMaker(object): ...@@ -150,11 +154,36 @@ class PlotMaker(object):
return ax return ax
class PrecipPlotMaker(PlotMaker):
def _set_ylim(self, frame, ax):
ymin = 0
ymax = np.ceil(frame.max().max())
delta = ymax - ymin
# 0 is the minimum y-min we want
if ymin == ymax:
ax.set_ylim(ymin, ymax + 0.2)
else:
ax.set_ylim(ymin, ymax + delta * 0.2)
return ymin, ymax
class TDPlotMaker(PlotMaker): class TDPlotMaker(PlotMaker):
def _call_plot(self, frame, ax): def _call_plot(self, frame, ax):
air_temp = self.deps[0] air_temp = self.deps[0]
dewpoint = self.deps[1] dewpoint = self.deps[1]
ax.plot(frame.index, frame[air_temp], 'r', frame.index, frame[dewpoint], 'g') return ax.plot(frame.index, frame[air_temp], 'r', frame.index, frame[dewpoint], 'g')
class WindDirPlotMaker(PlotMaker):
def _set_ylim(self, frame, ax):
return 0, 360
def _set_yticks(self, ax, ymin, ymax, is_subplot):
ax.yaxis.set_ticks([0, 90, 180, 270])
def _call_plot(self, frame, ax):
lines = ax.plot(frame.index, frame, 'k.', markersize=3, linewidth=0)
return lines
class MeteorogramPlotMaker(PlotMaker): class MeteorogramPlotMaker(PlotMaker):
...@@ -173,7 +202,7 @@ class MeteorogramPlotMaker(PlotMaker): ...@@ -173,7 +202,7 @@ class MeteorogramPlotMaker(PlotMaker):
end_time = frame.index[-1].to_pydatetime() end_time = frame.index[-1].to_pydatetime()
if title is None: if title is None:
title = self.get_title(frame, False, start_time, end_time) title = self.get_title(frame, False, start_time, end_time)
fig.suptitle(title, fontsize=13) fig.suptitle(title, fontsize=FIGURE_TITLE_SIZE)
num_plots = len(self.plot_deps) num_plots = len(self.plot_deps)
shared_x = None shared_x = None
...@@ -187,11 +216,13 @@ class MeteorogramPlotMaker(PlotMaker): ...@@ -187,11 +216,13 @@ class MeteorogramPlotMaker(PlotMaker):
if idx == 0: if idx == 0:
shared_x = ax shared_x = ax
if idx != num_plots - 1: if idx != num_plots - 1:
print("Disabling")
# Disable the x-axis ticks so we don't interfere with other subplots # Disable the x-axis ticks so we don't interfere with other subplots
ax.set_xticklabels([''] * len(ax.get_xticklabels())) kwargs = {'visible': False}
# ax.get_xaxis().get_major_ticks()[-1].set_visible(False) for l in ax.get_xticklabels():
# ax.get_xaxis().get_major_ticks()[0].set_visible(False) l.update(kwargs)
# make the top y-tick label invisible
# ax.yaxis.get_major_ticks()[-1].label1.update({'visible': False})
ax.set_xlabel('Time (UTC)') ax.set_xlabel('Time (UTC)')
fig.subplots_adjust(hspace=0, bottom=0.125) fig.subplots_adjust(hspace=0, bottom=0.125)
...@@ -204,13 +235,13 @@ PLOT_TYPES = { ...@@ -204,13 +235,13 @@ PLOT_TYPES = {
('air_temp', 'dewpoint', 'rh', 'wind_speed', 'wind_dir', 'accum_precip'), ('air_temp', 'dewpoint', 'rh', 'wind_speed', 'wind_dir', 'accum_precip'),
('td', 'rh', 'wind_speed', 'wind_dir', 'accum_precip')), ('td', 'rh', 'wind_speed', 'wind_dir', 'accum_precip')),
'td': TDPlotMaker('td', ('air_temp', 'dewpoint'), units="°C"), # air_temp and dewpoint in one plot 'td': TDPlotMaker('td', ('air_temp', 'dewpoint'), units="°C"), # air_temp and dewpoint in one plot
'wind_dir': PlotMaker('wind_dir', ('wind_dir',), units='°'), # special tick labels 'wind_dir': WindDirPlotMaker('wind_dir', ('wind_dir',), units='°'), # special tick labels
'rh': PlotMaker('rh', ('rh',), units='%'), 'rh': PlotMaker('rh', ('rh',), units='%'),
'air_temp': PlotMaker('air_temp', ('air_temp',), units='°C'), 'air_temp': PlotMaker('air_temp', ('air_temp',), units='°C'),
'pressure': PlotMaker('pressure', ('pressure',), units='hpa'), 'pressure': PlotMaker('pressure', ('pressure',), units='hpa'),
'dewpoint': PlotMaker('dewpoint', ('air_temp',), units='°C'), 'dewpoint': PlotMaker('dewpoint', ('air_temp',), units='°C'),
'wind_speed': PlotMaker('wind_speed', ('wind_speed',), units='m/s'), 'wind_speed': PlotMaker('wind_speed', ('wind_speed',), units='m/s'),
'accum_precip': PlotMaker('accum_precip', ('accum_precip',), units='mm'), 'accum_precip': PrecipPlotMaker('accum_precip', ('accum_precip',), units='mm'),
'solar_flux': PlotMaker('solar_flux', ('solar_flux',), units='W/m^2'), 'solar_flux': PlotMaker('solar_flux', ('solar_flux',), units='W/m^2'),
} }
...@@ -488,7 +519,7 @@ def full_plot(fig, axes, dates, data, ymin, ymax, ...@@ -488,7 +519,7 @@ def full_plot(fig, axes, dates, data, ymin, ymax,
# @param numSubPlots - number of subplots # @param numSubPlots - number of subplots
# @return y-coordinate of subtitle # @return y-coordinate of subtitle
def get_subtitle_location(numSubPlots): def get_subtitle_location(numSubPlots):
return 1 - 0.05*numSubPlots return 1 - 0.055*numSubPlots
def create_full_plot(plot_names, frame, output, start_time=None, end_time=None): def create_full_plot(plot_names, frame, output, start_time=None, end_time=None):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment