From 066257d4ffe2d110d9a48c1138351e6829b0302f Mon Sep 17 00:00:00 2001 From: davidh-ssec <david.hoese@ssec.wisc.edu> Date: Thu, 13 Jul 2017 16:23:48 -0500 Subject: [PATCH] Add wind direction specific plot maker and other fixes --- .../tower_quicklooks/create_quicklook.py | 57 ++++++++++++++----- 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/aosstower/tower_quicklooks/create_quicklook.py b/aosstower/tower_quicklooks/create_quicklook.py index c1d8712..1a877da 100644 --- a/aosstower/tower_quicklooks/create_quicklook.py +++ b/aosstower/tower_quicklooks/create_quicklook.py @@ -10,6 +10,7 @@ import matplotlib.dates as md import math LOG = logging.getLogger(__name__) +FIGURE_TITLE_SIZE = 13 # names of the plots used in title (default is `.title()` of plot name) TITLES = { @@ -86,10 +87,11 @@ class PlotMaker(object): def _set_ylim(self, frame, ax): ymin = np.floor(frame.min().min()) ymax = np.ceil(frame.max().max()) + delta = ymax - ymin if ymin == ymax: - ax.set_ylim(ymin, ymax + 0.1) + ax.set_ylim(ymin - 0.1, ymax + 0.1) else: - ax.set_ylim(ymin, ymax) + ax.set_ylim(ymin - delta * 0.2, ymax + delta * 0.2) return ymin, ymax 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): if is_subplot: ax.set_title(title, x=0.5, y=get_subtitle_location(is_subplot[0]), fontsize=8) else: - fig.suptitle(title, fontsize=13) + fig.suptitle(title, fontsize=FIGURE_TITLE_SIZE) def _get_axes(self, fig, is_subplot, shared_x=None): if is_subplot: @@ -120,7 +122,7 @@ class PlotMaker(object): def _set_yticks(self, ax, ymin, ymax, is_subplot): if is_subplot: 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) def create_plot(self, frame, fig, start_time=None, end_time=None, @@ -140,6 +142,8 @@ class PlotMaker(object): # 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]] + # 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) ymin, ymax = self._set_ylim(specific_frame, ax) @@ -150,11 +154,36 @@ class PlotMaker(object): 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): def _call_plot(self, frame, ax): air_temp = self.deps[0] 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): @@ -173,7 +202,7 @@ class MeteorogramPlotMaker(PlotMaker): end_time = frame.index[-1].to_pydatetime() if title is None: 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) shared_x = None @@ -187,11 +216,13 @@ class MeteorogramPlotMaker(PlotMaker): if idx == 0: shared_x = ax if idx != num_plots - 1: - print("Disabling") # Disable the x-axis ticks so we don't interfere with other subplots - ax.set_xticklabels([''] * len(ax.get_xticklabels())) - # ax.get_xaxis().get_major_ticks()[-1].set_visible(False) - # ax.get_xaxis().get_major_ticks()[0].set_visible(False) + kwargs = {'visible': False} + for l in ax.get_xticklabels(): + 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)') fig.subplots_adjust(hspace=0, bottom=0.125) @@ -204,13 +235,13 @@ PLOT_TYPES = { ('air_temp', 'dewpoint', '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 - '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='%'), 'air_temp': PlotMaker('air_temp', ('air_temp',), units='°C'), 'pressure': PlotMaker('pressure', ('pressure',), units='hpa'), 'dewpoint': PlotMaker('dewpoint', ('air_temp',), units='°C'), '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'), } @@ -488,7 +519,7 @@ def full_plot(fig, axes, dates, data, ymin, ymax, # @param numSubPlots - number of subplots # @return y-coordinate of subtitle 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): -- GitLab