Skip to content

Commit fb49e7b

Browse files
committed
add nan rep for plot
* allow user to set null value for parameter plots for masking * update for pandas deprecation error for setting values to a dataframe
1 parent 31ae9c0 commit fb49e7b

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

prms_python/parameters.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ def write(self, out_name):
144144
['vartype']])])
145145

146146
def plot(self, nrows, which='all', out_dir=None, xlabel=None,\
147-
ylabel=None, cbar_label=None, title=None, mpl_style=None):
147+
ylabel=None, cbar_label=None, title=None, mpl_style=None,
148+
na_val=-99999):
148149
"""
149150
Versatile method that plots most parameters in a standard PRMS parameter
150151
file assuming the PRMS model was built on a uniform spatial grid.
@@ -177,6 +178,7 @@ def plot(self, nrows, which='all', out_dir=None, xlabel=None,\
177178
title (str): plot title
178179
mpl_style (str, list): name or list of names of matplotlib style sheets to
179180
use for plot(s).
181+
na_val (float, int): default -99999. Value to mask in plots.
180182
181183
Returns:
182184
None
@@ -235,7 +237,10 @@ def plot(self, nrows, which='all', out_dir=None, xlabel=None,\
235237
try:
236238
plt.figure()
237239
ax = plt.gca()
238-
im = ax.imshow(params['{}'.format(p)].reshape(nrows,ncols), origin='upper')
240+
241+
d = np.where(params[p] == na_val, np.nan, params[p])
242+
im = ax.imshow(d.reshape(nrows,ncols), origin='upper')
243+
239244
# origin upper- assumes indices of parameters starts in upper left
240245
divider = make_axes_locatable(ax)
241246
cax = divider.append_axes("right", size="5%", pad=0.05)
@@ -290,7 +295,7 @@ def plot(self, nrows, which='all', out_dir=None, xlabel=None,\
290295
df = pd.DataFrame()
291296
df.index.name = 'parameter'
292297
for p in p_names:
293-
df.set_value(p, 'value', params[p])
298+
df.at[p, 'value'] = params[p]
294299
df.to_html(OPJ(out_dir,'single_valued_params.html'))
295300
################################################################
296301
# plot single parameter, in case of nhru by monthly param,

prms_python/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def load_statvar(statvar_file):
192192
skiprows = n_statvars+1
193193
df = pd.read_csv(
194194
statvar_file, delim_whitespace=True, skiprows=skiprows,
195-
header=-1, na_values=[missing_value]
195+
header=None, na_values=[missing_value]
196196
)
197197

198198
# apply correct header names using metadata retrieved from file

0 commit comments

Comments
 (0)