def plot_val_table(fsp, func, freq, quantile, stationlist): # freq = climpy.check_freq(freq) if freq == _c.FR_MTH: (periodtype, periodnames) = ("monthly", hdf5io.monthenum._names.keys()) periodnames = ['Dec', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov'] elif (freq // _c.FR_QTR == 1): (periodtype, periodnames) = ("quarterly", fqtr2names[freq]) else: raise NotImplementedError, "Unrecognized frequency %s" % freq # funcdict = dict(med='median', mean='mean', ) funcname = funcdict[func] qtlname = '%03i' % (100 * quantile) qtlleg = {'000':'Minimum', '025':'Lower Quartile'}['%03i' % (100 * quantile)] # freq = climpy.check_freq(freq) if freq == _c.FR_MTH: (periodtype, periodnames) = ("monthly", hdf5io.monthenum._names.keys()) periodnames = ['Dec', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov'] elif (freq // _c.FR_QTR == 1): (periodtype, periodnames) = ("quarterly", fqtr2names[freq]) else: raise NotImplementedError, "Unrecognized frequency %s" % freq # # flow_basename = "USGS_Q%s_%s%s.hdf5" % (qtlname, fqname, func) # Define the HDF5 files .................................... hdf5flow_filename = os.path.join(hdf5_archive_dir, flow_basename) file = hdf5io.openFile(hdf5flow_filename, 'r+') hdf5flow = hdf5io.remove_duplicates(file) # val = hdf5flow.getNode("/".join(['', 'values', 'modified', 'noenso'])).read() for (marker, color, station) in zip(['o'] * 3 + ['s'] * 4, ['k'] * 3 + ['r'] * 4, stationlist): locval = val[val['id'] == station] fsp.plot(range(12), [locval[p] for p in periodnames], marker=marker, label=station, c=color) fsp.set_yscale('log') fsp.xaxis.set_major_locator(pylab.MultipleLocator(1)) fsp.set_xticklabels(periodnames) fsp.set_ylabel("Flows (cfs)", fontweight='bold') fsp.set_title("%s flows - %s" % (qtlleg, funcname), fontweight='bold') pylab.show()
def plot_val(fsp, station, func, quantile, group='modified'): # freq = _c.FR_MTH freq = climpy.check_freq(freq) if freq == _c.FR_MTH: # (periodtype, periodnames) = ("monthly", hdf5io.monthenum._names.keys()) periodnames = ['Dec', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov'] elif (freq // _c.FR_QTR == 1): (periodtype, periodnames) = ("quarterly", fqtr2names[freq]) else: raise NotImplementedError, "Unrecognized frequency %s" % freq # funcdict = dict(med='median', mean='mean', ) funcname = funcdict[func] qtlname = '%03i' % (100 * quantile) qtlleg = {'000':'Minimum', '025':'Lower Quartile'}['%03i' % (100 * quantile)] # # flow_basename = "USGS_Q%s_%s%s.hdf5" % (qtlname, fqname, func) # Define the HDF5 files .................................... hdf5flow_filename = os.path.join(hdf5_archive_dir, flow_basename) file = hdf5io.openFile(hdf5flow_filename, 'r+') hdf5flow = hdf5io.remove_duplicates(file) # if fsp.is_first_col(): labels = {'G':u"Global", 'C':u"La Ni\xf1a", 'N':u"Neutral", 'W':u"El Ni\xf1o", 'NS':"N/S", '90': '_nolabel_', '95': '_nolabel_', '99': '_nolabel_'} else: labels = {'G':'_nolabel_', 'C':'_nolabel_', 'N':'_nolabel_', 'W':'_nolabel_', 'NS':"N/S", '90': "90%", '95': "95%", '99': "99%"} # val = hdf5flow.getNode("/".join(['', 'values', group, 'noenso'])).read() val = val[val['id'] == station] fsp.plot(range(12), [val[p] for p in periodnames], marker='^', ms=6, label=labels['G'], c=ENSOlines['G']) # val = hdf5flow.getNode("/".join(['', 'values', group, 'cold'])).read() val = val[val['id'] == station] val = numpy.array([val[p] for p in periodnames]) apx = hdf5flow.getNode("/".join(['', 'apxpvalues', group, 'CN'])).read() apx = apx[apx['id'] == station] apx = numpy.array([apx[p] for p in periodnames]) col_C = ENSOlines['C'] fsp.plot(range(12), val, marker='', label='_nolabel_', c=col_C) fsp.plot(range(12), ma.array(val, mask=(apx < 0.1)), marker='^', label=labels['C'], c=col_C) fsp.plot(range(12), ma.array(val, mask=(apx >= 0.1) | (apx < 0.05)) , marker='d', label='_nolabel_', ls='', c=col_C, ms=10) fsp.plot(range(12), ma.array(val, mask=(apx >= 0.05) | (apx < 0.01)) , marker='s', label='_nolabel_', ls='', c=col_C, ms=10) fsp.plot(range(12), ma.array(val, mask=(apx > 0.01)) , marker='o', label='_nolabel_', ls='', c=col_C, ms=10) # val = hdf5flow.getNode("/".join(['', 'values', group, 'neutral'])).read() val = val[val['id'] == station] fsp.plot(range(12), [val[p] for p in periodnames], marker='o', ms=6, label=labels['N'], c=ENSOlines['N']) # val = hdf5flow.getNode("/".join(['', 'values', group, 'warm'])).read() val = val[val['id'] == station] val = numpy.array([val[p] for p in periodnames]) apx = hdf5flow.getNode("/".join(['', 'apxpvalues', group, 'WN'])).read() apx = apx[apx['id'] == station] apx = numpy.array([apx[p] for p in periodnames]) col_W = ENSOlines['W'] fsp.plot(range(12), val, marker='', label='_nolabel_', c=col_W) fsp.plot(range(12), ma.array(val, mask=(apx < 0.1)), marker='^', label=labels['W'], c=col_W) fsp.plot(range(12), ma.array(val, mask=(apx >= 0.1) | (apx < 0.05)) , marker='d', label=labels['90'], ls='', c=col_W, ms=10) fsp.plot(range(12), ma.array(val, mask=(apx >= 0.05) | (apx < 0.01)) , marker='s', label=labels['95'], ls='', c=col_W, ms=10) fsp.plot(range(12), ma.array(val, mask=(apx > 0.01)) , marker='o', label=labels['99'], ls='', c=col_W, ms=10) # #fsp.set_yscale('log') # fsp.xaxis.set_major_locator(pylab.MultipleLocator(1)) if fsp.is_last_row(): fsp.set_xticklabels(periodnames, fontsize=10) else: fsp.set_xticklabels([]) fsp.set_ylabel("Flows (cfs)", fontweight='bold', fontsize=10) fsp.yaxis.major.formatter.set_powerlimits((-3, 3)) # fsp.set_title("%s Q%02i flows - %s" % (funcname.capitalize(), # 100.*quantile, # station), fontweight='bold') fsp.set_title("%s" % (station), fontweight='bold', fontsize=10) if fsp.is_last_row(): fsp.legend(numpoints=1, prop=dict(size='x-small')) hdf5flow.close() return