Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

PR: Add a year range option to the weather normals viewer #142

Merged
merged 30 commits into from
Jan 15, 2018
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ac72614
:recycle: Renamed WeatherAvgGraph to WeatherViewer
jnsebgosselin Jan 9, 2018
eed2bce
:art: Code style changes
jnsebgosselin Jan 9, 2018
578364f
Added a new RangeSpinBoxes class
jnsebgosselin Jan 9, 2018
5ca22c9
Added a year range widget to the weather viewer
jnsebgosselin Jan 9, 2018
89424e7
:book: Added some docstrings to functions
jnsebgosselin Jan 10, 2018
fd34b4f
:art: Some code style changes
jnsebgosselin Jan 10, 2018
fff15a1
:recycle: Added year range for normals calc
jnsebgosselin Jan 10, 2018
b7914bd
Removed annoying prints
jnsebgosselin Jan 11, 2018
e891eb3
:art: Code style changes
jnsebgosselin Jan 11, 2018
2b3b3df
Improved the RangeSpinBoxes implementation
jnsebgosselin Jan 11, 2018
d7460cb
Update the graph and table when year range change.
jnsebgosselin Jan 11, 2018
dd9141f
:art: More code style changes
jnsebgosselin Jan 11, 2018
cd3cba6
Updated the save normals to file functionality
jnsebgosselin Jan 11, 2018
c29d119
Merge remote-tracking branch 'refs/remotes/origin/master' into add_ye…
jnsebgosselin Jan 11, 2018
3f4994c
:wrench: Clean imports
jnsebgosselin Jan 11, 2018
7f65f89
:art: Some code style changes
jnsebgosselin Jan 11, 2018
ad2fabc
:recycle: Refactoring of how language is handled.
jnsebgosselin Jan 11, 2018
96fb2c4
Added the year range as a label of the x-axis
jnsebgosselin Jan 11, 2018
1907c8a
Tweaked bottom margin and fixed set_lang
jnsebgosselin Jan 11, 2018
2c0cfee
Show buttons by default in the SmartSpinBox
jnsebgosselin Jan 11, 2018
6d73c2a
Added a button in toolbar to expand year range
jnsebgosselin Jan 12, 2018
a17733b
Make table more pretty
jnsebgosselin Jan 12, 2018
e53207c
Updated tooltip and made window non resizable
jnsebgosselin Jan 12, 2018
5fad844
Imports
jnsebgosselin Jan 12, 2018
d78a159
Stretch the columns and rows
jnsebgosselin Jan 12, 2018
baf66c8
Remove the call to resize to contents
jnsebgosselin Jan 12, 2018
f8cd8e1
Make the height of the table not hard coded
jnsebgosselin Jan 12, 2018
ec94d74
:art: Some code style changes
jnsebgosselin Jan 13, 2018
9e8054f
Added 'Period' key to WXDataFrame
jnsebgosselin Jan 13, 2018
08d3da9
:wrench: clean imports
jnsebgosselin Jan 13, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
🎨 Code style changes
  • Loading branch information
jnsebgosselin committed Jan 11, 2018
commit e891eb361d5ea95af91152e346272aaa9eb5171f
76 changes: 22 additions & 54 deletions gwhat/meteo/weather_viewer.py
Original file line number Diff line number Diff line change
@@ -8,15 +8,15 @@

from __future__ import division, unicode_literals

# ---- Standard library imports
# ---- Imports: Standard Libraries

import sys
import os
import csv
from time import strftime
from datetime import datetime

# ---- Third party imports
# ---- Imports: Third Parties

import xlsxwriter
import numpy as np
@@ -28,7 +28,7 @@
QFileDialog, QApplication, QTableWidget,
QTableWidgetItem, QLabel, QHBoxLayout)

# ---- Local imports
# ---- Imports: Local

from gwhat.colors2 import ColorsReader
from gwhat.common import StyleDB, QToolButtonNormal
@@ -201,8 +201,6 @@ def show_monthly_grid(self):
# self.setFixedWidth(self.size().width()-75)
self.sender().setAutoRaise(True)

# =========================================================================

def set_lang(self, lang):
"""Sets the language of all the labels in the figure."""
self.language = lang
@@ -218,7 +216,6 @@ def generate_graph(self, wxdset):

self.grid_weather_normals.populate_table(wxdset['normals'])

# ---------------------------------------------------------------------

def save_graph(self):
yrmin = np.min(self.wxdset['Year'])
@@ -400,9 +397,6 @@ def export_series_tofile(self, filename, time_frame):
QApplication.restoreOverrideCursor()


# :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


class FigWeatherNormals(FigureCanvasQTAgg):
"""
This is the class that does all the plotting of the weather normals.
@@ -636,7 +630,7 @@ def plot_monthly_normals(self, normals):

self.normals = normals

# ------------------------------------------- assign local variables --
# Assign local variables :

Tmax_norm = normals['Tmax']
Tmin_norm = normals['Tmin']
@@ -645,18 +639,9 @@ def plot_monthly_normals(self, normals):
Rain_norm = normals['Rain']
Snow_norm = Ptot_norm - Rain_norm

print('Tmax Yearly Avg. = %0.1f' % np.mean(Tmax_norm))
print('Tmin Yearly Avg. = %0.1f' % np.mean(Tmin_norm))
print('Tavg Yearly Avg. = %0.1f' % np.mean(Tavg_norm))
print('Ptot Yearly Acg. = %0.1f' % np.sum(Ptot_norm))

# ------------------------------------------------ DEFINE AXIS RANGE --

if np.sum(Ptot_norm) < 500:
Yscale0 = 10 # Precipitation (mm)
else:
Yscale0 = 20
# Define the range of the axis :

Yscale0 = 10 if np.sum(Ptot_norm) < 500 else 20 # Precipitation (mm)
Yscale1 = 5 # Temperature (deg C)

SCA0 = np.arange(0, 10000, Yscale0)
@@ -701,7 +686,7 @@ def plot_monthly_normals(self, normals):
Ymin1 = -20
# ----

# ------------------------------------------------- YTICKS FORMATING --
# Define the fomatting of the yticks :

ax0 = self.figure.axes[1]
ax1 = self.figure.axes[2]
@@ -723,7 +708,7 @@ def plot_monthly_normals(self, normals):
yticks1_minor = np.arange(yticks1[0], yticks1[-1], Yscale1/5.)
ax1.set_yticks(yticks1_minor, minor=True)

# --------------------------------------------------- SET AXIS RANGE --
# Set the range of the axis :

ax0.set_ylim(Ymin0, Ymax0)
ax1.set_ylim(Ymin1, Ymax1)
@@ -768,82 +753,65 @@ def set_axes_labels(self):
ax1.set_ylabel(labelDB.Tlabel, va='bottom', fontsize=16)
ax1.yaxis.set_label_coords(-0.09, 0.5)

# =========================================================================
# ---- Plot the Data

def plot_precip(self, PNORM, SNORM):

# ---- define vertices manually ----
# Define the vertices manually :

Xmid = np.arange(0.5, 12.5, 1)
n = 0.5 # Controls the width of the bins
f = 0.65 # Controls the spacing between the bins
f = 0.75 # Controls the spacing between the bins

Xpos = np.vstack((Xmid - n * f,
Xmid - n * f,
Xmid + n * f,
Xmid + n * f)).transpose().flatten()
Xpos = np.vstack((Xmid - n * f, Xmid - n * f,
Xmid + n * f, Xmid + n * f)).transpose().flatten()

Ptot = np.vstack((PNORM * 0,
PNORM,
PNORM,
PNORM * 0)).transpose().flatten()
Ptot = np.vstack((PNORM * 0, PNORM,
PNORM, PNORM * 0)).transpose().flatten()

Snow = np.vstack((SNORM * 0,
SNORM,
SNORM,
SNORM * 0)).transpose().flatten()
Snow = np.vstack((SNORM * 0, SNORM,
SNORM, SNORM * 0)).transpose().flatten()

# -- plot data --
# Plot the data :

ax = self.figure.axes[1]

for collection in reversed(ax.collections):
collection.remove()

colors = ColorsReader()
colors.load_colors_db()

ax.fill_between(Xpos, 0., Ptot, edgecolor='none',
ax.fill_between(Xpos, 0, Ptot, edgecolor='none',
color=colors.rgb['Rain'])
ax.fill_between(Xpos, 0., Snow, edgecolor='none',
ax.fill_between(Xpos, 0, Snow, edgecolor='none',
color=colors.rgb['Snow'])

# ---------------------------------------------------------------------

def plot_air_temp(self, Tmax_norm, Tavg_norm, Tmin_norm):
for i, Tnorm in enumerate([Tmax_norm, Tavg_norm, Tmin_norm]):
T0 = (Tnorm[-1]+Tnorm[0])/2
T = np.hstack((T0, Tnorm, T0))
self.figure.axes[2].lines[i].set_ydata(T)
self.figure.axes[2].lines[3].set_ydata(Tavg_norm)

# =========================================================================

def update_yearly_avg(self):

Tavg_norm = self.normals['Tavg']
Ptot_norm = self.normals['Ptot']

ax = self.figure.axes[0]

# ---- update position ----
# Update the position of the labels :

bbox = ax.texts[0].get_window_extent(self.get_renderer())
bbox = bbox.transformed(ax.transAxes.inverted())

ax.texts[1].set_position((0, bbox.y0))

# ---- update labels ----
# Update the text of the labels :

labelDB = LabelDB(self.lang)

ax.texts[0].set_text(labelDB.Tyrly % np.mean(Tavg_norm))
ax.texts[1].set_text(labelDB.Pyrly % np.sum(Ptot_norm))


# :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


class GridWeatherNormals(QTableWidget):

def __init__(self, parent=None):