Example #1
0
    statStr = keyLst[iS]
    temp = list()
    for k in range(len(statDictLst)):
        data = statDictLst[k][statStr]
        data = data[~np.isnan(data)]
        temp.append(data)
    dataBox.append(temp)
fig = plot.plotBoxFig(dataBox, keyLst, ['LSTM', 'DA-1', 'DA-7'], sharey=False)
fig.show()

# plot time series
t = utils.time.tRange2Array([20050101, 20150101])
fig, axes = plt.subplots(5, 1, figsize=(12, 8))
# iLst = [54, 219, 298, 325, 408]
for k in range(5):
    iGrid = np.random.randint(0, 671)
    # iGrid = iLst[k]
    yPlot = list()
    for y in yLst:
        yPlot.append(y[iGrid, :])
    if k == 0:
        plot.plotTS(
            t,
            yPlot,
            ax=axes[k],
            cLst='kbrg',
            markerLst='----',
            legLst=['USGS', 'LSTM', 'DA-1', 'DA-7'])
    else:
        plot.plotTS(t, yPlot, ax=axes[k], cLst='kbrg', markerLst='----')
fig.show()
Example #2
0
siteNoLst = dictData['siteNoLst']
varC = dictData['varC']
bb = True
while bb is True:
    iS = randint(0, len(siteNoLst))
    iC = randint(0, 20)
    iS = 0
    iC = 1
    t = dfT[dfT['siteNo'] == siteNoLst[iS]]['date']
    a = dfT[dfT['siteNo'] == siteNoLst[iS]][varC[iC]]
    b = dfP[dfP['siteNo'] == siteNoLst[iS]][varC[iC]]
    if not a.isna().all():
        fig, ax = plt.subplots(1, 1)
        fig, ax = plot.plotTS(t=t,
                              y=[a, b],
                              legLst=[varC[iC] + ' obs', varC[iC] + ' pred'])
        fig.show()
        bb = False
pass

# time series map
siteNoLst = dictData['siteNoLst']
varC = dictData['varC']
nP = len(siteNoLst)
nC = len(varC)
matRho1 = np.ndarray([nP, nC])
matRho2 = np.ndarray([nP, nC])
matRmse1 = np.ndarray([nP, nC])
matRmse2 = np.ndarray([nP, nC])
matN1 = np.ndarray([nP, nC])
Example #3
0
 ylabel = "Flow rate ($\mathregular{m^3}$/s)"
 for k in range(len(gageindex)):
     iGrid = gageindex[k]
     yPlot = [obs[iGrid, :]]
     for y in predLst[0:npred]:
         yPlot.append(y[iGrid, :])
     # get the NSE value of LSTM and DI(1) model
     NSE_LSTM = str(round(statDictLst[0]["NSE"][iGrid], 2))
     NSE_DI1 = str(round(statDictLst[1]["NSE"][iGrid], 2))
     # plot time series
     plot.plotTS(
         t,
         yPlot,
         ax=axes[k],
         cLst="kbrmg",
         markerLst="---",
         legLst=["USGS", "LSTM: " + NSE_LSTM, "DI(1): " + NSE_DI1],
         title=subtitle[k],
         linespec=["-", ":", ":"],
         ylabel=ylabel,
     )
 # plot gage location
 plot.plotlocmap(
     plat,
     plon,
     ax=axes[-1],
     baclat=gagelat,
     baclon=gagelon,
     title=subtitle[-1],
     txtlabel=txt,
 )
Example #4
0
# plot
# training loss
fig, ax = plt.subplots(1, 1)
plt.plot(np.arange(nEpoch), lossEpLst)
ax.set_xlabel('epoch')
ax.set_ylabel('loss')
fig.show()
# forcing
fig, axes = plt.subplots(len(varFcLst) + 1, 1)
titleLst = ['discharge', 'precipitation', 'temperature']
cLst = 'gbr'
for i, title in enumerate(titleLst):
    plot.plotTS(t,
                x[:, i],
                ax=axes[i],
                cLst=cLst[i],
                lsLst=['-'],
                tBar=t[-1] - np.timedelta64(nTest, 'D'),
                title=title)
    if i + 1 < len(varWqLst): axes[i].set_xticks([])
fig.show()
# water quality
dfCode = usgs.readUsgsText(os.path.join(workDir, 'usgs_parameter_code'))
fig, axes = plt.subplots(len(varWqLst), 1)
for i, code in enumerate(varWqLst):
    title = code + ' ' + \
        dfCode['parameter_nm'].loc[dfCode['parameter_cd'] ==code].values[0]
    plot.plotTS(t, [y[:, i], yOut[:, i]],
                ax=axes[i],
                cLst='kr',
                lsLst=['-', '-'],
Example #5
0
# pct = [10, 25, 50, 75, 90]
# indLst = list()
# diff = (statP['RMSE'] - statF['RMSE']) / statP['RMSE']
# for p in pct:
#     indLst.append(abs(diff - np.percentile(diff, p)).argmin())

nts = len(indLst)
fig, axes = plt.subplots(nts, 1, figsize=[8, 6])
t = df.getT()
for k in range(nts):
    ind = indLst[k]
    ax = axes[k]
    legLst = ['SMAP', 'project', 'forecast'] if k == 2 else None
    plot.plotTS(
        t, [obs[ind, :], yp[ind, :], yf[ind, :]],
        ax=ax,
        cLst='krb',
        linewidth=1)
    if k != nts - 1:
        ax.set_xticklabels([])
plt.tight_layout()
plt.subplots_adjust(hspace=0)
plt.subplots_adjust(vspace=0)
fig.show()
fig.savefig(os.path.join(saveDir, 'ts_pixel.eps'))
fig.savefig(os.path.join(saveDir, 'ts_pixel'))

fig, ax = plt.subplots(1, 1, figsize=[8, 6])
plot.plotTS(
    t, [obs[ind, :], yp[ind, :], yf[ind, :]],
    ax=ax,
Example #6
0
t = df.getT()
prcp = df.getDataTs('APCP_FORA').squeeze()
tBarLst = [20160401, [20160401, 20170401], 20170401]
for k in range(nts):
    ind = indLst[k]
    indY = indYLst[k]
    ax = fig.add_subplot(gs[k * 3, 0])
    tBar = utils.time.t2dt(tBarLst[indY])
    if k == 0:
        legLst1 = ['project', 'forecast', 'SMAP']
        legLst2 = ['prcp']
    else:
        legLst1 = None
        legLst2 = None
    plot.plotTS(t, [ypLst[indY][ind, :], yfLst[indY][ind, :], obs[ind, :]],
                ax=ax,
                tBar=tBar,
                legLst=legLst1,
                linewidth=1)
    ax.set_xticklabels([])
    ax = fig.add_subplot(gs[k * 3 + 1, 0])
    plot.plotTS(t, [prcp[ind, :]],
                ax=ax,
                cLst='c',
                legLst=legLst2,
                tBar=tBar,
                linewidth=1)
fig.show()
fig.savefig(os.path.join(saveDir, 'ts_extreme.eps'))
fig.savefig(os.path.join(saveDir, 'ts_extreme'))
Example #7
0
# plot time series
indLst = [1023]
strLst = ['east Texas']
tBar = [utils.time.t2dt(20160401)]
t = df.getT()
[lat, lon] = df.getGeo()
prcp = df.getDataTs('APCP_FORA')
tsNameLst = ['obs', 'prj', 'fore']
for k in range(len(indLst)):
    fig, axes = plt.subplots(2, 1, figsize=[16, 6])
    ind = indLst[k]
    titleStr = 'typical {} pixel, lat {:.3}, lon {:.3}'.format(
        strLst[k], lat[ind], lon[ind])
    tsLst = [obs[ind, :], yp[ind, :], yf[ind, :]]
    tsLst2 = [prcp[ind, :]]
    plot.plotTS(t, tsLst, ax=axes[1], legLst=tsNameLst, cLst='krb', tBar=tBar)
    plot.plotTS(t,
                tsLst2,
                ax=axes[0],
                legLst=['prcp'],
                title=titleStr,
                cLst='c',
                tBar=tBar)
    axes[0].set_xticks([])
    plt.tight_layout()
    plt.subplots_adjust(wspace=0, hspace=0)
    fig.show()

# maps for argriculture
trLst = [[20160801, 20161101], [20170801, 20171101]]
trLab = '1001-1201'
Example #8
0
saveFile = os.path.join(workDir, 'data', 'dailyTS', siteNo)
usgs.downloadDaily(siteNo, nwisCode, saveFile)
saveFile = os.path.join(workDir, 'data', 'sample', siteNo)
usgs.downloadSample(siteNo, saveFile)

# read data
dfDaily = usgs.readUsgsText(os.path.join(workDir, 'data', 'dailyTS', siteNo),
                            dataType='dailyTS')
dfSample = usgs.readUsgsText(os.path.join(workDir, 'data', 'sample', siteNo),
                             dataType='sample')
# forcing data
# see extractForcing.py 

# plot time series
dfCode = usgs.readUsgsText(os.path.join(workDir, 'usgs_parameter_code'))
fig, axes = plt.subplots(len(nwisCode)-1, 1)
for i, code in enumerate(nwisCode[1:]):
    t1 = dfDaily['datetime'].values
    y1 = dfDaily[code].values
    t2 = dfSample['datetime'].values
    y2 = dfSample[code].values
    title = code + ' ' + \
        dfCode['parameter_nm'].loc[dfCode['parameter_cd'] ==code].values[0]
    plot.plotTS([t1, t2], [y1, y2],
                ax=axes[i],
                cLst='rb',
                mLst=[None, '*'],
                lsLst=['-', ':'],
                title=title)
    if i + 1 < len(nwisCode): axes[i].set_xticks([])
fig.show()
Example #9
0
               lon=crd[:, 1],
               t=t,
               colorMap=colorMap,
               mapNameLst=mapNameLst,
               tsNameLst=tsNameLst)

# plot time series
t = utils.time.tRange2Array([20100101, 20150101])
fig, axes = plt.subplots(5, 1, figsize=(12, 8))
iLst = [10, 52, 178, 404, 620]
for k in range(5):
    iGrid = np.random.randint(0, 671)
    iGrid = iLst[k]
    yPlot = [yt2[iGrid, :], yp2[iGrid, :]]
    gageId = camels.gageDict['id'][iGrid]
    if k == 0:
        plot.plotTS(t,
                    yPlot,
                    ax=axes[k],
                    cLst='br',
                    markerLst='--',
                    legLst=['USGS', 'LSTM'])

    else:
        plot.plotTS(t, yPlot, ax=axes[k], cLst='br', markerLst='--')
    axes[k].set_ylabel('streamflow(cfs)')
    if k == 4:
        axes[k].set_xlabel('time')
plt.tight_layout()
fig.show()