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 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
for code in dictPlot.keys(): siteNoCode = dictSite[code] siteNoP = dictPlot[code] indS = [siteNoLst.index(siteNo) for siteNo in siteNoCode] ic = codeLst.index(code) dfCrd = gageII.readData(varLst=['LAT_GAGE', 'LNG_GAGE'], siteNoLst=siteNoCode) lat = dfCrd['LAT_GAGE'].values lon = dfCrd['LNG_GAGE'].values shortName = usgs.codePdf.loc[code]['shortName'] fig = plt.figure(figsize=[12, 9]) gsM = gridspec.GridSpec(4, 5) ax = fig.add_subplot(gsM[0, 0]) sc = axplot.scatter121(ax, corrMat[indS, ic, 1], corrMat[indS, ic, 2], pMat[indS, ic]) fig.colorbar(sc, ax=ax) ax.set_xlabel('LSTM correlation') ax.set_ylabel('WRTDS correlation') ax.set_title('power of seasonal signal') for siteNo in siteNoP: iS = siteNoLst.index(siteNo) circle = plt.Circle([corrMat[iS, ic, 1], corrMat[iS, ic, 2]], 0.05, color='red', fill=False) ax.add_patch(circle) ax = fig.add_subplot(gsM[0, 1:3]) axplot.mapPoint(ax, lat, lon, corrMat[indS, ic, 1], s=24, cmap='viridis') ax.set_title('map of LSTM correlation')
ticks = [-0.5, 0, 0.5, 1] axM = list() for k, code in enumerate(codeLst2): j, i = utils.index2d(k, 5, 4) axM.append( figM.add_subplot(gsM[(j) * 10:(j + 1) * 10, i * 10:(i + 1) * 10])) for k, code in enumerate(codeLst2): j, i = utils.index2d(k, 5, 4) ax = axM[k] ic = codeLst.index(code) x = corrMat[:, ic, 1] y = corrMat[:, ic, 2] c = cMat[:, ic] # c = np.argsort(countMat2[:, ind]) sc = axplot.scatter121(ax, x, y, c, vR=cR, size=15) rmse, corr = utils.stat.calErr(x, y) titleStr = '{} {} {:.2f}'.format(code, usgs.codePdf.loc[code]['shortName'], corr) _ = ax.set_xlim([ticks[0], ticks[-1]]) _ = ax.set_ylim([ticks[0], ticks[-1]]) _ = ax.set_yticks(ticks) _ = ax.set_xticks(ticks) axplot.titleInner(ax, titleStr) ax.set_label(code) # print(i, j) if i != 0: _ = ax.set_yticklabels([]) if j != 4: _ = ax.set_xticklabels([]) # _ = ax.set_aspect('equal')
code, usgs.codePdf.loc[code]['shortName']) axplot.titleInner(ax, titleStr) fig.show() dfG = gageII.readData(siteNoLst=siteNoLst) dfG = gageII.updateRegion(dfG) dfG = gageII.updateCode(dfG) cMat= fig, axes = plt.subplots(nfy, nfx) for k, code in enumerate(codeLst2): j, i = utils.index2d(k, nfy, nfx) ax = axes[j, i] ic = codeLst.index(code) x = rMat[:, ic, 1] y = rMat[:, ic, 0] axplot.scatter121(ax, x, y, cvR=[0, 1]) titleStr = '{} {} '.format( code, usgs.codePdf.loc[code]['shortName']) axplot.titleInner(ax, titleStr) fig.show() # Cart dfA = pd.DataFrame(index=range(10), columns=codeLst) dfV = pd.DataFrame(index=range(10), columns=codeLst) for code in codeLst: ic = codeLst.index(code) matAll = rMat[] [mat], indS = utils.rmNan([matAll]) siteNoCode = [siteNoLst[ind] for ind in indS] dfGC = dfG.loc[siteNoCode]
x = qMat y = rMat[:, ic, 0] axplot.plot121(ax, x, y, vR=[0, 1]) titleStr = '{} {} '.format(code, usgs.codePdf.loc[code]['shortName']) axplot.titleInner(ax, titleStr) fig.show() cMat = qMat fig, axes = plt.subplots(nfy, nfx) for k, code in enumerate(codeLst2): j, i = utils.index2d(k, nfy, nfx) ax = axes[j, i] ic = codeLst.index(code) x = rMat[:, ic, 1] y = rMat[:, ic, 0] axplot.scatter121(ax, x, y, qMat, vR=[0, 0.5]) titleStr = '{} {} '.format(code, usgs.codePdf.loc[code]['shortName']) axplot.titleInner(ax, titleStr) fig.show() indC = [codeLst.index(code) for code in codeLst2] labelLst = [ '{} {}'.format(code, usgs.codePdf.loc[code]['shortName']) for code in codeLst2 ] xMat = rMat[:, indC, 1] yMat = rMat[:, indC, 0] nXY = [nfx, nfy] figM, axM = figplot.scatter121Batch(xMat, yMat, qMat,
importlib.reload(axplot) figM, figP = figplot.clickMap(funcMap, funcPoint) # 121 plot # tempLst = ['09163500', '05465500', '02175000', '09171100'] tempLst = ['10343500', '05465500', '02175000', '09171100'] code = '00915' fig, ax = plt.subplots(1, 1, figsize=[8, 6]) ic = codeLst.index(code) x = corrMat[:, ic, 0] y = corrMat[:, ic, 1] c = corrMat[:, ic, 2] out = axplot.scatter121(ax, x, y, c) # for siteNo in tempLst: # indS = siteNoLst.index(siteNo) # circle = plt.Circle([x[indS], y[indS]], 0.05, # color='black', fill=False) # ax.add_patch(circle) ax.set_xlabel('LSTM correlation') ax.set_ylabel('WRTDS correlation') ax.set_title('Performance on Calcium') fig.colorbar(out, ax=ax) fig.show() figM, axM = plt.subplots(1, 2, figsize=(12, 4)) indS = [siteNoLst.index(siteNo) for siteNo in dictSite[code]] siteNoLstCode = dictSite[code] dfCrd = gageII.readData(
fileGlim = os.path.join(kPath.dirData, 'USGS', 'GLiM', 'tab_1KM') tabGlim = pd.read_csv(fileGlim, dtype={'siteNo': str}).set_index('siteNo') matV = np.argmax(tabGlim.values, axis=1) labelLst = [ '{} {}'.format(code, usgs.codePdf.loc[code]['shortName']) for code in codeLst2 ] icLst = [codeLst.index(code) for code in codeLst2] figM, axM = figplot.scatter121Batch(rMat[:, icLst, 1], rMat[:, icLst, 0], matV, labelLst, [nfx, nfy], optCb=1, ticks=[0, 0.5, 1]) figM.show() temp = ['00930', '00940'] ic1 = codeLst.index(temp[0]) ic2 = codeLst.index(temp[1]) nameLst = [usgs.codePdf.loc[code]['shortName'] for code in temp] fig, axes = plt.subplots(1, 2) axplot.scatter121(axes[0], rMat[:, ic1, 0], rMat[:, ic2, 0], qMat, vR=[0, .6]) axes[0].set_xlabel('Linearity of {}'.format(nameLst[0])) axes[0].set_ylabel('Linearity of {}'.format(nameLst[1])) axplot.scatter121(axes[1], rMat[:, ic1, 1], rMat[:, ic2, 1], qMat, vR=[0, .6]) axes[1].set_xlabel('Seasonality of {}'.format(nameLst[0])) axes[1].set_ylabel('Seasonality of {}'.format(nameLst[1])) fig.show()
v3 = dictObs[siteNo][code].iloc[ind2].values vv1, vv2, vv3 = utils.rmNan([v1, v2, v3], returnInd=False) rmse1, corr1 = utils.stat.calErr(vv1, vv2) rmse2, corr2 = utils.stat.calErr(vv1, vv3) rmse3, corr3 = utils.stat.calErr(vv2, vv3) corrMat[indS, ic, 0] = corr1 corrMat[indS, ic, 1] = corr2 corrMat[indS, ic, 2] = corr3 # load basin attributes regionLst = [ 'ECO2_BAS_DOM', 'NUTR_BAS_DOM', 'HLR_BAS_DOM_100M', 'PNV_BAS_DOM' ] dfG = gageII.readData(siteNoLst=siteNoLst) fileT = os.path.join(gageII.dirTab, 'lookupPNV.csv') tabT = pd.read_csv(fileT).set_index('PNV_CODE') for code in range(1, 63): siteNoTemp = dfG[dfG['PNV_BAS_DOM'] == code].index dfG.at[siteNoTemp, 'PNV_BAS_DOM2'] = tabT.loc[code]['PNV_CLASS_CODE'] dfG = gageII.updateCode(dfG) var = 'PLANTNLCD06' codePlot = ['00618', '00660'] fig, ax = plt.subplots(1, 1) c = dfG[var].values x = corrMat[:, codeLst.index(codePlot[0]), 1] y = corrMat[:, codeLst.index(codePlot[1]), 1] sc = axplot.scatter121(ax, x, y, c=c, vR=[0, 1]) fig.colorbar(sc, ax=ax) fig.show()
cVar = 'Estimated Travel time' cR = [np.nanmin(cMat), np.nanmax(cMat)] cR = [np.nanpercentile(cMat, 10), np.nanpercentile(cMat, 90)] code = '00660' cVar = 'DEVOPENNLCD06' th = 4.755000114 cMat = dfG[cVar].values # attr vs diff cMatLog = np.log(cMat + 1) fig, axes = plt.subplots(1, 2, figsize=(10, 4)) ic = codeLst.index(code) sc = axplot.scatter121(axes[0], corrMat[:, ic, 1], corrMat[:, ic, 2], cMatLog, size=30) axes[0].set_xlabel('Corr LSTM') axes[0].set_ylabel('Corr WRTDS') fig.colorbar(sc, ax=axes[0]) x = cMat y = corrMat[:, ic, 1]**2 - corrMat[:, ic, 2]**2 axes[1].plot(x, y, '*') axes[1].plot([np.nanmin(x), np.nanmax(x)], [0, 0], 'k-') axes[1].set_ylim([-0.5, 0.5]) axes[1].set_xlabel(cVar) axes[1].set_ylabel('Rsq LSTM - Rsq WRTDS') fig.suptitle('affect of {} on {} {}'.format( cVar, code, usgs.codePdf.loc[code]['shortName'])) fig.show()
j, i = utils.index2d(k, nfy, nfx) axM.append( figM.add_subplot(gsM[(j) * 10:(j + 1) * 10, i * 10:(i + 1) * 10])) for k, code in enumerate(codeLst2): j, i = utils.index2d(k, nfy, nfx) ax = axM[k] ic = codeLst.index(code) x = corrMat[:, ic, 1] y = corrMat[:, ic, 2] if cMat.ndim > 1: c = cMat[:, ic] else: c = cMat # c = np.argsort(countMat2[:, ind]) sc = axplot.scatter121(ax, x, y, c, vR=cR) rmse, corr = utils.stat.calErr(x, y) titleStr = '{} {} {:.2f}'.format(code, usgs.codePdf.loc[code]['shortName'], corr) _ = ax.set_xlim([ticks[0], ticks[-1]]) _ = ax.set_ylim([ticks[0], ticks[-1]]) _ = ax.set_yticks(ticks) _ = ax.set_xticks(ticks) axplot.titleInner(ax, titleStr) ax.set_label(code) # print(i, j) if i != 0: _ = ax.set_yticklabels([]) if j != 4: _ = ax.set_xticklabels([]) # _ = ax.set_aspect('equal')
yMat = rMat[:, indC, 0] cMat = bMat2[:, indC] nXY = [nfx, nfy] figM, axM = figplot.scatter121Batch( xMat, yMat, cMat, labelLst, nXY, optCb=1, ticks=[0, 0.5, 1], s=20, cmap='jet') figM.show() ############### ic1 = codeLst.index('00915') ic2 = codeLst.index('00955') fig, axes = plt.subplots(1, 2) # axplot.plot121(axes[0], rMat[:, ic1, 0], rMat[:, ic2, 0], vR=[0, 1]) # axplot.plot121(axes[1], rMat[:, ic1, 1], rMat[:, ic2, 1], vR=[0, 1]) axplot.scatter121(axes[0], rMat[:, ic1, 0], rMat[:, ic2, 0], qMat, vR=[0, .5]) axplot.scatter121(axes[1], rMat[:, ic1, 1], rMat[:, ic2, 1], qMat, vR=[0, .5]) fig.show() temp = ['00915', '00955'] ic1 = codeLst.index(temp[0]) ic2 = codeLst.index(temp[1]) nameLst = [usgs.codePdf.loc[code]['shortName'] for code in temp] fig, axes = plt.subplots(1, 2) sc1 = axplot.scatter121(axes[0], rMat[:, ic1, 1], rMat[:, ic1, 0], qMat, vR=[0, 0.5]) axes[0].set_xlabel('Seasonality of {}'.format(nameLst[0])) axes[0].set_ylabel('Linearity of {}'.format(nameLst[0])) sc2 = axplot.scatter121(axes[1], rMat[:, ic2, 1], rMat[:, ic2, 0], qMat, vR=[0, 0.5]) axes[1].set_xlabel('Seasonality of {}'.format(nameLst[1]))