Skip to content

Commit

Permalink
Bug Fixes
Browse files Browse the repository at this point in the history
(1) In *gapfill_weather_postprocess*, rasterized the scatter plot because it was way to heavy to render in pdf.
(2)In module *hydrograph*, change the way saving and loading layout is done. It is now a for loop over a list instead of using a numpy array.
(3) Bug: There was a bug with the load/save functionality for graph layouts in Windows when there was unicode characters either in the path of the meteo data file, in the well name, or in the graph title.
(4) In *HydroPrint*, adding a feedback when the loading of a water level data file is started.
  • Loading branch information
jnsebgosselin committed Jan 15, 2016
1 parent aaac863 commit d27bee6
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 63 deletions.
7 changes: 0 additions & 7 deletions User_Manual/chapter10.tex

This file was deleted.

8 changes: 6 additions & 2 deletions WHAT/HydroPrint.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
"""
Copyright 2014-2015 Jean-Sebastien Gosselin
Copyright 2014-2016 Jean-Sebastien Gosselin
email: jnsebgosselin@gmail.com
This file is part of WHAT (Well Hydrograph Analysis Toolbox).
Expand Down Expand Up @@ -675,6 +674,11 @@ def load_waterlvl(self, filename): #=================== Load Water Level ==

#----- Load Data -----

self.ConsoleSignal.emit(
'''<font color=black>Loading water level data...</font>''')
for i in range(5):
QtCore.QCoreApplication.processEvents()

state = self.waterlvl_data.load(filename)
if state == False:
msg = ('WARNING: Waterlvl data file "%s" is not formatted ' +
Expand Down
2 changes: 1 addition & 1 deletion WHAT/WHAT.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
"""
Copyright 2014-2015 Jean-Sebastien Gosselin
Copyright 2014-2016 Jean-Sebastien Gosselin
email: jnsebgosselin@gmail.com
WHAT is free software: you can redistribute it and/or modify
Expand Down
7 changes: 4 additions & 3 deletions WHAT/database.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
"""
Copyright 2015 Jean-Sebastien Gosselin
Copyright 2014-2016 Jean-Sebastien Gosselin
email: jnsebgosselin@gmail.com
email: jnsebgosselin@gmail.com
Expand Down Expand Up @@ -29,8 +30,8 @@
from PySide.QtGui import QIcon, QFont, QFontDatabase
from PySide.QtCore import QSize

software_version = 'WHAT Beta 4.1.8'
last_modification = '07/07/2015'
software_version = 'WHAT Beta 4.1.9'
last_modification = '14/01/2016'

class Icons():

Expand Down
45 changes: 26 additions & 19 deletions WHAT/gapfill_weather_postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ def plot_est_err(Ymes, Ypre, varName, fname): #============= Est. Errors ==
#---- Estimation Error ----

hscat, = ax0.plot(Ymes, Ypre, '.', mec='k', mfc='k', ms=12, alpha=0.35)

hscat.set_rasterized(True)

#---- 1:1 Line ----

dl = 12 # dashes length
Expand Down Expand Up @@ -337,7 +338,7 @@ def plot_est_err(Ymes, Ypre, varName, fname): #============= Est. Errors ==

#-------------------------------------------------------------- Draw --

fig.savefig(fname)
fig.savefig(fname, dpi=300)

return canvas

Expand Down Expand Up @@ -539,23 +540,29 @@ def plot_rmse_vs_time(Ymes, Ypre, Time, Date, name):

dirname = '../Projects/Monteregie Est/Meteo/Output/'

# filename = dirname + 'BROME (7020840)/BROME (7020840)_1980-2009.err'
# pperr = PostProcessErr(filename)
# pperr.generates_graphs()

for root, directories, filenames in os.walk(dirname):
for filename in filenames:
if os.path.splitext(filename)[1] == '.err':
print('---- %s ----' % os.path.basename(root))
pperr = PostProcessErr(os.path.join(root, filename))
pperr.generates_graphs()
elif os.path.splitext(filename)[1] == '.out':
print('---- %s ----' % os.path.basename(root))
w = meteo.FigWeatherNormals()
w.plot_monthly_normals(os.path.join(root, filename))
savename = 'weather_normals.pdf'
print('Generating %s.' % savename)
w.figure.savefig(os.path.join(root, savename))
filename = dirname + 'GRANBY (7022800)/GRANBY (7022800)_1980-2009.err'
pperr = PostProcessErr(filename)
pperr.generates_graphs()

# for root, directories, filenames in os.walk(dirname):
# for filename in filenames:
# if os.path.splitext(filename)[1] == '.err':
# print('---- %s ----' % os.path.basename(root))
# pperr = PostProcessErr(os.path.join(root, filename))
# pperr.generates_graphs()
# elif os.path.splitext(filename)[1] == '.out':
# print('---- %s ----' % os.path.basename(root))
#
# METEO = meteo.MeteoObj()
# METEO.load_and_format(os.path.join(root, filename))
# NORMALS, _ = meteo.calculate_normals(METEO.DATA,
# METEO.datatypes)
#
# w = meteo.FigWeatherNormals()
# w.plot_monthly_normals(NORMALS)
# savename = 'weather_normals.pdf'
# print('Generating %s.' % savename)
# w.figure.savefig(os.path.join(root, savename))

# for root, directories, filenames in os.walk(dirname):
# for filename in filenames:
Expand Down
70 changes: 39 additions & 31 deletions WHAT/hydrograph3.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def __init__(self, *args, **kargs):

self.WLdatum = 0 # 0: mbgs; 1: masl
self.trend_line = 0
self.isLegend = True
self.isLegend = False
self.meteoOn = True # controls wether meteo data are plotted or not
self.gridLines = 2 # 0 -> None, 1 -> "-" 2 -> ":"
self.datemode = 'month' # 'month' or 'year'
Expand Down Expand Up @@ -643,60 +643,68 @@ def load_layout(self, name_well, filename): #==============================

# A <checkConfig> is supposed to have been carried before this method
# is called. So it can be supposed at this point that everything is
# fine with the graph layout for this well.
# fine with the graph layout for this well and that it does exist.

with open(filename, 'r') as f:
reader = list(csv.reader(f, delimiter='\t'))
reader = np.array(reader)

row = np.where(reader[:,0] == name_well)[0]

reader = reader[row][0]

for row in range(len(reader)):
if reader[row][0].decode('utf-8') == name_well:
break
else:
row +=1

reader = reader[row]

self.fmeteo = reader[1]
self.fmeteo = reader[1].decode('utf-8')
self.finfo = self.fmeteo[:-3] + 'log'

self.WLmin = reader[2].astype(float)
self.WLscale = reader[3].astype(float)
self.WLmin = float(reader[2])
self.WLscale = float(reader[3])

self.TIMEmin = reader[4].astype(float)
self.TIMEmax = reader[5].astype(float)
self.TIMEmin = float(reader[4])
self.TIMEmax = float(reader[5])

self.title_state = reader[6].astype(float)
self.title_state = float(reader[6])
if self.title_state != 0:
self.title_state = 1

self.title_text = reader[7].astype(str)
self.RAINscale = reader[8].astype(float)
self.WLdatum = reader[9].astype(int)
self.trend_line = reader[10].astype(int)

print('Trend Line', self.trend_line)

self.title_text = reader[7].decode('utf-8')
self.RAINscale = float(reader[8])
self.WLdatum = int(reader[9])
self.trend_line = int(reader[10])

def save_layout(self, name_well, filename): #==============================

#---- load file ----

with open(filename, 'r') as f:
reader = list(csv.reader(f, delimiter='\t'))
reader = np.array(reader)

#---- update content ----

rowx = np.where(reader[:,0] == name_well)[0]

new = [name_well, self.fmeteo, self.WLmin, self.WLscale,
self.TIMEmin, self.TIMEmax,self.title_state, self.title_text,
# this is necessary for Windows when there is an accented character
# in the path of the meteo data file, in the name of the well, or in
# the title of the graph.

name_well = name_well.encode('utf-8')
fmeteo = self.fmeteo.encode('utf-8')
graph_title = self.title_text.encode('utf-8')

new = [name_well, fmeteo, self.WLmin, self.WLscale,
self.TIMEmin, self.TIMEmax,self.title_state, graph_title,
self.RAINscale, self.WLdatum, self.trend_line]

if len(rowx) == 0:
reader = np.vstack((reader, new))
else:
reader = np.delete(reader, rowx, 0)
reader = np.vstack((reader, new))
for row in range(len(reader)):
if reader[row][0] == name_well:
del reader[row]
break
else:
row +=1

reader.append(new)
reader[0] = self.header[0]

#---- save file ----

with open(filename, 'w') as f:
Expand Down

0 comments on commit d27bee6

Please sign in to comment.