def funcMap(): figM, axM = plt.subplots(1, 1, figsize=(12, 4)) axplot.mapPoint(axM, lat, lon, matMap, vRange=[-0.3, 0.3], s=16) axM.set_title('testing corr LSTM - corr WRTDS') figP = plt.figure(figsize=[16, 6]) figP, axP = plt.subplots(1, 1, figsize=(12, 4)) return figM, axM, figP, axP, lon, lat
def funcMap(): figM, axM = plt.subplots(1, nc, figsize=(12, 4)) for k in range(nc): axplot.mapPoint(axM[k], lat, lon, mapLst[k], s=16) axM[k].set_title('WRTDS corr {}'.format(codeNameLst[k])) figP, axP = plt.subplots(len(codeLst), 1, figsize=[16, 6]) return figM, axM, figP, axP, lon, lat
def funcM(): figM = plt.figure(figsize=[12, 3]) gsM = gridspec.GridSpec(1, 5) axM = list() axM.append(figM.add_subplot(gsM[0, 0])) axM.append(figM.add_subplot(gsM[0, 1:3])) axM.append(figM.add_subplot(gsM[0, 3:5])) axM = np.array(axM) x = corrMat[indS, codeLst.index(codeM[0]), 1] y = corrMat[indS, codeLst.index(codeM[1]), 1] sc = axplot.scatter121(axM[0], x, y, cMat) figM.colorbar(sc, ax=axM[0]) axM[0].set_label('scatter') axplot.mapPoint(axM[1], lat, lon, x, s=24) axM[1].set_label('map1') axplot.mapPoint(axM[2], lat, lon, y, s=24) axM[2].set_label('map2') labelLst = ['scatter', 'map1', 'map2'] xMat = np.stack([x, lon, lon], axis=1) yMat = np.stack([y, lat, lat], axis=1) figP = plt.figure(figsize=[12, 3]) gsP = gridspec.GridSpec(2, 4) axP = list() axP.append(figP.add_subplot(gsP[0, :-1])) axP.append(figP.add_subplot(gsP[0, -1])) axP.append(figP.add_subplot(gsP[1, :-1])) axP.append(figP.add_subplot(gsP[1, -1])) axP = np.array(axP) return figM, axM, figP, axP, xMat, yMat, labelLst
def plotNode(nodeId, indInput, indLeft, indRight, title): gs = gridspec.GridSpec(1, 3) fig = plt.figure(figsize=[9, 3]) # cdf ax = fig.add_subplot(gs[0, 0]) cLst = 'gbr' y0 = y[indInput] y1 = y[indLeft] y2 = y[indRight] labLst = [ 'parent {:.2f}'.format(np.nanmean(y0)), 'left {:.2f} (*)'.format(np.nanmean(y1)), 'right {:.2f} (o)'.format(np.nanmean(y2)) ] dataLst = [y0, y1, y2] for kk, data in enumerate(dataLst): xSort = np.sort(data[~np.isnan(data)]) yRank = np.arange(1, len(xSort) + 1) / float(len(xSort)) ax.plot(xSort, yRank, color=cLst[kk], label=labLst[kk]) ax.set_xlim([0, 1]) ax.legend(loc='best', frameon=False) # map ax = fig.add_subplot(gs[0, 1:]) for indTemp, sty in zip([indLeft, indRight], '*o'): lat = dfG['LAT_GAGE'][indTemp].values lon = dfG['LNG_GAGE'][indTemp].values data = y[indTemp] axplot.mapPoint(ax, lat, lon, data, vRange=[0, 1], marker=sty, s=20) # fig.suptitle(title) ax.set_title(title, fontsize=16) plt.tight_layout() figName = 'node{}.png'.format(nodeId) plt.savefig(os.path.join(saveFolder, figName)) return fig
def funcP(axP, iP, iM): rr = xMat[:, iM]**2-yMat[:, iM]**2 cc = cMat[:, iM] if cMat.ndim == 2 else cMat dfCrd = gageII.readData( varLst=['LAT_GAGE', 'LNG_GAGE'], siteNoLst=siteNoLst) lat = dfCrd['LAT_GAGE'].values lon = dfCrd['LNG_GAGE'].values # maps axplot.mapPoint(axP[0], lat, lon, rr, vRange=[-0.3, 0.3], s=16, cb=False) circle = plt.Circle([lon[iP], lat[iP]], 2, color='black', fill=False) axP[0].add_patch(circle) axplot.mapPoint(axP[1], lat, lon, cc, vRange=cR, s=16, cb=False) circle = plt.Circle([lon[iP], lat[iP]], 2, color='black', fill=False) axP[1].add_patch(circle) siteNo = siteNoLst[iP] # ts code = codeLst2[iM] print(code, siteNo) print(iP, iM) v0 = dictObs[siteNo][code].values v1 = dictLSTM[siteNo][code].values v2 = dictWRTDS[siteNo][code].values t = dictObs[siteNo].index.values legLst = ['LSTM', 'WRTDS', 'Obs'] axplot.plotTS(axP[2], t[ind1], [v1[ind1], v2[ind1], v0[ind1]], styLst='--*', cLst='rbk', legLst=legLst) axplot.plotTS(axP[3], t[ind2], [v1[ind2], v2[ind2], v0[ind2]], styLst='--*', cLst='rbk', legLst=legLst) # cq q = dictObs[siteNo]['00060'].values c = dictObs[siteNo][code].values td = dictObs[siteNo].index.dayofyear sc = axP[4].scatter(np.log(q), c, c=td, cmap='hsv', vmin=0, vmax=365)
def funcMap(): figM, axM = plt.subplots(1, 1, figsize=(12, 4)) axplot.mapPoint(axM, lat, lon, rmseLSTM, s=24) axM.set_title('Testing corr LSTM ') figP = plt.figure(figsize=[16, 4]) figP, axP = plt.subplots(1, 1, figsize=(12, 4)) return figM, axM, figP, axP, lon, lat
def funcMap(): figM, axM = plt.subplots(1, 1, figsize=(6, 4)) axplot.mapPoint(axM, lat, lon, corrMat[:, 1], vRange=[0.5, 1], s=16) shortName = usgs.codePdf.loc[code]['shortName'] axM.set_title('Testing correlation of {}'.format(shortName)) figP, axP = plt.subplots(1, 1, figsize=(12, 4)) return figM, axM, figP, axP, lon, lat
def funcMap(): figM, axM = plt.subplots(1, 2, figsize=(12, 6)) axplot.mapPoint(axM[0], lat, lon, matR, s=16) axplot.mapPoint(axM[1], lat, lon, mat2, s=16) shortName = usgs.codePdf.loc[code]['shortName'] figP, axP = plt.subplots(2, 1, figsize=(16, 4)) return figM, axM, figP, axP, lon, lat
def funcMap(): figM, axM = plt.subplots(1, 1, figsize=(12, 4)) axplot.mapPoint(axM, lat, lon, corr2, vRange=[0.5, 1], s=16) axM.set_title('corr LSTM streamflow') figP = plt.figure(figsize=[16, 6]) figP, axP = plt.subplots(1, 1, figsize=(12, 4)) return figM, axM, figP, axP, lon, lat
def funcMap(): figM, axM = plt.subplots(2, 1, figsize=(8, 6)) # shortName = codePdf.loc[code]['shortName'] # title = 'RMSE of {} {}'.format(shortName, code) axplot.mapPoint(axM[0], lat, lon, errMat1[:, 0, 0], s=12) axplot.mapPoint(axM[1], lat, lon, errMatL2[:, 0, 0], s=12) figP, axP = plt.subplots(2, 1, figsize=(8, 6)) return figM, axM, figP, axP, lon, lat
def funcMap(): figM, axM = plt.subplots(2, 1, figsize=(8, 6)) # shortName = codePdf.loc[code]['shortName'] axplot.mapPoint(axM[0], lat, lon, dwMat2[:,0], s=12) axplot.mapPoint(axM[1], lat, lon, dwMat2[:,1], s=12) # axM[k].set_title(modLst[k]) figP, axP = plt.subplots(2, 2, figsize=(8, 6)) return figM, axM, figP, axP, lon, lat
def funcM(): figM, axM = plt.subplots(2, 1, figsize=(6, 4)) axplot.mapPoint(axM[0], lat, lon, np.mean( errL[:, :, 1], axis=1), s=16, cb=True) axplot.mapPoint(axM[1], lat, lon, np.mean( errW[:, :, 1], axis=1), s=16, cb=True) figP, axP = plt.subplots(nc, 1, figsize=(12, 8)) figP.subplots_adjust(hspace=0) return figM, axM, figP, axP, lon, lat
def funcMap(): figM, axM = plt.subplots(len(codeSel), 1, figsize=(8, 6)) for k, code in enumerate(codeSel): ic = wqData.varC.index(code) shortName = codePdf.loc[code]['shortName'] title = 'D(R) of {} {}'.format(shortName, code) axplot.mapPoint(axM[k], lat, lon, errMat[:, ic, 1], s=12, title=title) figP, axP = plt.subplots(len(codeSel) + 1, 1, figsize=(8, 6)) return figM, axM, figP, axP, lon, lat
def funcMap(): figM, axM = plt.subplots(1, 2, figsize=(12, 3)) axplot.mapPoint(axM[0], lat, lon, corrMat[:, 1], vRange=[0, 1], s=16) axplot.mapPoint(axM[1], lat, lon, corrMat[:, 3], vRange=[0, 1], s=16) shortName = usgs.codePdf.loc[code]['shortName'] axM[0].set_title('LSTM testing corr of {}'.format(shortName)) axM[1].set_title('WRTDS testing corr of {}'.format(shortName)) figP, axP = plt.subplots(2, 1, figsize=(20, 6)) return figM, axM, figP, axP, lon, lat
def funcMap(): figM, axM = plt.subplots(nc, 1, figsize=(8, 6)) for k in range(nc): axplot.mapPoint(axM[k], lat, lon, rMat[:, k], s=12) figP = plt.figure(constrained_layout=True) spec = gridspec.GridSpec(ncols=3, nrows=2, figure=figP) axLst = [figP.add_subplot(spec[0, :])] +\ [figP.add_subplot(spec[1, k]) for k in range(3)] axP = np.array(axLst) return figM, axM, figP, axP, lon, lat
def funcMap(): figM, axM = plt.subplots(2, 1, figsize=(8, 6)) # shortName = codePdf.loc[code]['shortName'] for k in range(2): mapData = corrMat[:, 0, k] - corrMat[:, 1, k] axplot.mapPoint(axM[k], lat, lon, mapData, s=12) # axM[k].set_title(modLst[k]) figP, axP = plt.subplots(nM, 1, figsize=(8, 6)) axP = np.array([axP]) if nM == 1 else axP return figM, axM, figP, axP, lon, lat
def funcMap(): figM, axM = plt.subplots(1, 2, figsize=(10, 4)) axplot.mapPoint(axM[0], lat, lon, corrMat[:, 1], vRange=[0.5, 1], s=16) axM[0].set_title('correlation with Q') diff = corrMat[:, 1]**2 / corrMat[:, 0]**2 axplot.mapPoint(axM[1], lat, lon, diff, s=16) axM[1].set_title('Rsq Q target / Rsq Q input') shortName = usgs.codePdf.loc[code]['shortName'] # axM.set_title('Testing correlation of {}'.format(shortName)) figP, axP = plt.subplots(1, 1, figsize=(16, 4)) return figM, axM, figP, axP, lon, lat
def funcMap(): figM, axM = plt.subplots(len(codeSel), 1, figsize=(8, 6)) for k, code in enumerate(codeSel): ic = wqData.varC.index(code) shortName = codePdf.loc[code]['shortName'] title = 'correlation of {} {}'.format(shortName, code) ind = indLst[k] axplot.mapPoint(axM[k], lat[ind], lon[ind], errMatC2[ind, ic, 1], s=12) axM[k].set_title(title) figP, axP = plt.subplots(len(codeSel), 1, figsize=(8, 6)) return figM, axM, figP, axP, lon[indAll], lat[indAll]
def plotLeaf(nodeId, indInput, title): fig, ax = plt.subplots(1, 1, figsize=[6, 3]) lat = dfG['LAT_GAGE'][indInput].values lon = dfG['LNG_GAGE'][indInput].values data = y[indInput] axplot.mapPoint(ax, lat, lon, data, vRange=[0, 1], s=20) ax.set_title(title) # fig.show() figName = 'node{}.png'.format(nodeId) plt.savefig(os.path.join(saveFolder, figName)) return fig
def funcMap(): figM, axM = plt.subplots(nM, 1, figsize=(8, 6)) axM = np.array([axM]) if nM == 1 else axM shortName = codePdf.loc[code]['shortName'] title = '{} {}'.format(shortName, code) for k in range(nM): axplot.mapPoint(axM[k], lat, lon, corrMat[:, k, 1], s=12) axM[k].set_title(modLst[k]) figP, axP = plt.subplots(nM, 1, figsize=(8, 6)) axP = np.array([axP]) if nM == 1 else axP return figM, axM, figP, axP, lon, lat
def funcMap(): nM = len(codeLst) figM, axM = plt.subplots(nM, 1, figsize=(8, 6)) for k in range(0, nM): code = codeLst[k] ic = wqData.varC.index(code) shortName = codePdf.loc[code]['shortName'] title = '{} {}'.format(shortName, code) axplot.mapPoint(axM[k], lat, lon, errMat2[:, ic, 1], s=12) axM[k].set_title(title) figP, axP = plt.subplots(nM + 1, 1, figsize=(8, 6)) return figM, axM, figP, axP, lon, lat
def funcMap(): figM, axM = plt.subplots(1, nc, figsize=(12, 4)) for k in range(nc): axplot.mapPoint(axM[k], lat, lon, mapLst[k], s=16) axM[k].set_title('WRTDS corr {}'.format(codeNameLst[k])) figP = plt.figure(figsize=[16, 6]) gs = gridspec.GridSpec(nc, 41) axP = np.ndarray([nc, 4], dtype=object) for k in range(nc): axP[k, 0] = figP.add_subplot(gs[k, :28]) axP[k, 1] = axP[k, 0].twinx() axP[k, 2] = figP.add_subplot(gs[k, 32:40]) axP[k, 3] = figP.add_subplot(gs[k, 40]) return figM, axM, figP, axP, lon, lat
def funcMap(): figM, axM = plt.subplots(1, 1, figsize=(12, 4)) axplot.mapPoint(axM, lat, lon, matMap, vRange=[-0.3, 0.3], s=16) axM.set_title('testing corr LSTM - corr WRTDS') figP = plt.figure(figsize=[16, 6]) gs = gridspec.GridSpec(3, 12) axTS = figP.add_subplot(gs[0, :]) axH1 = figP.add_subplot(gs[1, :4]) axH2 = figP.add_subplot(gs[1, 4:8]) axH3 = figP.add_subplot(gs[1, 8:]) axP1 = figP.add_subplot(gs[2, :6]) axP2 = figP.add_subplot(gs[2, 6:]) axP = np.array([axTS, axH1, axH2, axH3, axP1, axP2]) return figM, axM, figP, axP, lon, lat
def funcMap(): nM = len(codeLst) + 1 figM, axM = plt.subplots(nM, 1, figsize=(8, 6)) axplot.mapPoint(axM[0], lat, lon, errMatQ[:, 0, 0], s=12) axM[0].set_title('streamflow') for k in range(1, nM): code = codeLst[k - 1] ic = wqData.varC.index(code) shortName = codePdf.loc[code]['shortName'] title = '{} {}'.format(shortName, code) axplot.mapPoint(axM[k], lat, lon, errMatC[:, ic, 0], s=12) axM[k].set_title(title) figP, axP = plt.subplots(3, 1, figsize=(8, 6)) return figM, axM, figP, axP, lon, lat
def funcMap(): nM = len(plotVar) figM, axM = plt.subplots(nM, 1, figsize=(8, 6)) axM = np.array([axM]) if nM == 1 else axM for k, var in enumerate(plotVar): if var == '00060': axplot.mapPoint(axM[k], lat, lon, errMatQ2[:, 0, 1], s=12) axM[k].set_title('streamflow') else: ic = master['varYC'].index(var) shortName = codePdf.loc[var]['shortName'] title = '{} {}'.format(shortName, var) axplot.mapPoint(axM[k], lat, lon, errMatC2[:, ic, 1], s=12) axM[k].set_title(title) figP, axP = plt.subplots(nM, 1, figsize=(8, 6)) axP = np.array([axP]) if nM == 1 else axP return figM, axM, figP, axP, lon, lat
def funcMap(): figM, axM = plt.subplots(1, 3, figsize=(12, 4)) for k in range(3): axplot.mapPoint(axM[k], lat, lon, matMapLst[k], vRange=[0, 1], s=16) axM[0].set_title('corr(LSTM, WRTDS)') axM[1].set_title('corr(LSTM, obs)') axM[2].set_title('corr(WRTDS, obs)') figP = plt.figure(figsize=[16, 6]) gs = gridspec.GridSpec(3, 12) axTS = figP.add_subplot(gs[0, :]) axH1 = figP.add_subplot(gs[1, :4]) axH2 = figP.add_subplot(gs[1, 4:8]) axH3 = figP.add_subplot(gs[1, 8:]) axP1 = figP.add_subplot(gs[2, :6]) axP2 = figP.add_subplot(gs[2, 6:]) axP = np.array([axTS, axH1, axH2, axH3, axP1, axP2]) return figM, axM, figP, axP, lon, lat
def funcM(): dfCrd = gageII.readData(varLst=['LAT_GAGE', 'LNG_GAGE'], siteNoLst=siteNoLst) lat = dfCrd['LAT_GAGE'].values lon = dfCrd['LNG_GAGE'].values lat[np.isnan(xMat)] = 9999 lon[np.isnan(xMat)] = 9999 figM, axM = plt.subplots(1, 1, figsize=(12, 4)) axplot.mapPoint(axM, lat, lon, xMat**2 - yMat**2, vRange=[-0.3, 0.3], s=16) axM.set_title('testing Rsq LSTM - Rsq WRTDS') figP = plt.figure(figsize=[16, 6]) axP = list() gsP = gridspec.GridSpec(2, 3) axP.append(figP.add_subplot(gsP[0, :2])) axP.append(figP.add_subplot(gsP[1, :2])) axP.append(figP.add_subplot(gsP[0:, 2])) axP = np.array(axP) return figM, axM, figP, axP, lon, lat
def funcM(): figM = plt.figure(figsize=[12, 3]) gsM = gridspec.GridSpec(1, 3) axM = list() axM.append(figM.add_subplot(gsM[0, 0])) axM.append(figM.add_subplot(gsM[0, 1:])) axM = np.array(axM) sc = axplot.scatter121(axM[0], corrMat[indS, ic, 1], corrMat[indS, ic, 2], cMat) figM.colorbar(sc, ax=axM[0]) axplot.mapPoint(axM[1], lat, lon, corrMat[indS, ic, 1], s=24) axM[0].set_label('scatter') axM[1].set_label('map') figM.show() figP, axP = plt.subplots(2, 1) labelLst = ['scatter', 'map'] xMat = np.stack([corrMat[indS, ic, 1], lon], axis=1) yMat = np.stack([corrMat[indS, ic, 2], lat], axis=1) return figM, axM, figP, axP, xMat, yMat, labelLst
def plotP(xx, yy, cc, iP, code): dfCrd = gageII.readData( varLst=['LAT_GAGE', 'LNG_GAGE'], siteNoLst=siteNoLst) lat = dfCrd['LAT_GAGE'].values lon = dfCrd['LNG_GAGE'].values # maps axplot.mapPoint(axP[0], lat, lon, xx, vRange=[-0.5, 1], s=16) circle = plt.Circle([lon[iP], lat[iP]], 2, color='black', fill=False) axP[0].add_patch(circle) axplot.mapPoint(axP[1], lat, lon, yy, vRange=[-0.5, 1], s=16) circle = plt.Circle([lon[iP], lat[iP]], 2, color='black', fill=False) axP[1].add_patch(circle) axplot.mapPoint(axP[2], lat, lon, cc, vRange=cR, s=16) circle = plt.Circle([lon[iP], lat[iP]], 2, color='black', fill=False) axP[2].add_patch(circle) siteNo = siteNoLst[iP] # ts v0 = dictObs[siteNo][code].values v1 = dictLSTM[siteNo][code].values v2 = dictWRTDS[siteNo][code].values t = dictObs[siteNo].index.values legLst = ['LSTM', 'WRTDS', 'Obs'] axplot.plotTS(axP[3], t[ind1], [v1[ind1], v2[ind1], v0[ind1]], styLst='--*', cLst='rbk', legLst=legLst) axplot.plotTS(axP[4], t[ind2], [v1[ind2], v2[ind2], v0[ind2]], styLst='--*', cLst='rbk', legLst=legLst) # cq q = dictObs[siteNo]['00060'].values c = dictObs[siteNo][code].values td = dictObs[siteNo].index.dayofyear sc = axP[5].scatter(np.log(q), c, c=td, cmap='hsv', vmin=0, vmax=365) # figP.colorbar(sc, ax=axP[5]) figP.suptitle('code {} {}; siteNo {} \n corrLSTM {:.2f}; corrWRTDS {:.2f}; {} {}'.format( code, usgs.codePdf.loc[code]['shortName'], siteNo, xx[iP], yy[iP], cVar, cc[iP])) figP.show()
def funcMap(): figM, axM = plt.subplots(1, 3, figsize=(6, 12)) mat1 = dfR1['corr'].values mat2 = dfR2['corr'].values axplot.mapPoint(axM[0], lat, lon, mat1, vRange=[0, 1], s=16) axplot.mapPoint(axM[1], lat, lon, mat2, vRange=[0, 1], s=16) axplot.mapPoint(axM[2], lat, lon, mat1**2/mat2**2, vRange=[0.5, 1.5], s=16) shortName = usgs.codePdf.loc[code]['shortName'] axM[0].set_title('WRTDS corr, {}'.format(shortName)) axM[1].set_title('T only corr, {}'.format(shortName)) axM[2].set_title('R2 ratio, {}'.format(shortName)) figP, axP = plt.subplots(1, 1, figsize=(16, 4)) return figM, axM, figP, axP, lon, lat