Exemple #1
0
def scatter121Batch(xMat, yMat, cMat, labelLst, nXY,
                    optCb=1, cR=None, ticks=None, s=15,
                    figsize=None, titleLst=None, cmap='viridis'):
    # plot nx*nx 121 maps
    # xMat, yMat - [#data, #features]
    # optCb - 0 no colorbar; 1 shared color bar; 2 - individual colorbar
    figM = plt.figure(figsize=figsize)
    [nfx, nfy] = nXY
    rCb = 10  # colorbar will be of width 1/rCb of subplot
    if optCb == 0:
        gsM = gridspec.GridSpec(nfy, nfx)
    elif optCb == 1:
        gsM = gridspec.GridSpec(nfy*rCb, nfx*rCb+1)
        if cR is None:
            cR = [np.nanmin(cMat), np.nanmax(cMat)]
    elif optCb == 2:
        gsM = gridspec.GridSpec(nfy*rCb, nfx*(rCb+1))
    # plot scatter
    axM = list()
    for k, label in enumerate(labelLst):
        j, i = utils.index2d(k, nfy, nfx)
        if optCb == 0:
            ax = figM.add_subplot(gsM[j:j+1, i:i+1])
        elif optCb == 1:
            ax = figM.add_subplot(gsM[(j)*rCb:(j+1)*rCb, i*rCb:(i+1)*rCb])
        elif optCb == 2:
            ax = figM.add_subplot(
                gsM[(j)*rCb:(j+1)*rCb, i*(rCb+1):i*(rCb+1)+rCb])
        ax.set_label(label)
        axM.append(ax)
        c = cMat[:, k] if cMat.ndim == 2 else cMat
        sc = axplot.scatter121(
            ax, xMat[:, k], yMat[:, k], c, vR=cR, size=s, cmap=cmap)
        corr = utils.stat.calCorr(xMat[:, k], yMat[:, k])
        titleStr = '{} {:.2f}'.format(label, corr)
        axplot.titleInner(ax, titleStr)
        if ticks is not None:
            _ = ax.set_xlim([ticks[0], ticks[-1]])
            _ = ax.set_ylim([ticks[0], ticks[-1]])
            _ = ax.set_yticks(ticks)
            _ = ax.set_xticks(ticks)
            if i != 0:
                _ = ax.set_yticklabels([])
            if j != 4:
                _ = ax.set_xticklabels([])
            figM.subplots_adjust(wspace=0, hspace=0)
        if optCb == 2:
            cax = figM.add_subplot(
                gsM[(j)*rCb:(j+1)*rCb, (i+1)*(rCb+1)-1])
            figM.colorbar(sc, cax=cax)
    if optCb == 1:
        cax = figM.add_subplot(gsM[:, -1])
        figM.colorbar(sc, cax=cax)
    return figM, axM
Exemple #2
0
# WRTDS corr
dirWrtds = os.path.join(kPath.dirWQ, 'modelStat', 'WRTDS-D', 'All')
fileC = os.path.join(dirWrtds, 'corr')
dfCorr = pd.read_csv(fileC, dtype={'siteNo': str}).set_index('siteNo')

code = '00915'
codeName = usgs.codePdf.loc[code]['shortName']
# load WRTDS par
fileP = os.path.join(dirWrtds, 'params', code)
dfPar = pd.read_csv(fileP, dtype={'siteNo': str}).set_index('siteNo')
# select site by count
n = 40 * 2
dfParSel = dfPar[dfPar['count'] > n]
siteNoLst = dfParSel.index.tolist()
dfCorrSel = dfCorr.loc[siteNoLst][code]
dfCrd = gageII.readData(varLst=['LAT_GAGE', 'LNG_GAGE'], siteNoLst=siteNoLst)
dfCrd = gageII.updateCode(dfCrd)
lat = dfCrd['LAT_GAGE'].values
lon = dfCrd['LNG_GAGE'].values

# plot map
parLst = ['pQ', 'pSinT', 'pCosT', 'pYr', 'b']
figM, axM = plt.subplots(3, 2, figsize=(12, 16))
axplot.mapPoint(axM[0, 0], lat, lon, dfCorrSel.values, s=16)
axM[0, 0].set_title('WRTDS corr {}'.format(codeName))
for k, par in enumerate(parLst):
    iy, ix = utils.index2d(k + 1, 3, 2)
    axplot.mapPoint(axM[iy, ix], lat, lon, dfParSel[par].values, s=16)
    axM[iy, ix].set_title('WRTDS {} {}'.format(par, codeName))
figM.show()
Exemple #3
0
# cMat = np.log(cMat+1)

indC = [codeLst.index(code) for code in codeLst2]
# cMat = intMatC[:, indC, 2]
cMat = pMat[:, indC]
cVar = 'power'
# cR = [np.nanpercentile(cMat, 10), np.nanpercentile(cMat, 90)]
# cR = [np.nanmin(cMat), np.nanmax(cMat)]
# cR = [0, 100]
cR = [0, 0.5]
# cR = [0, 20]

# attr vs diff
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 = cMat[:, k] if cMat.ndim == 2 else cMat
    # y = corrMat[:, ic, 1]**2-corrMat[:, ic, 2]**2
    y = rmseMat[:, ic, 1]**2-rmseMat[:, ic, 2]**2
    ax.plot(x, y, '*')
    ax.plot([np.nanmin(x), np.nanmax(x)], [0, 0], 'k-')
    ax.set_ylim([-0.5, 0.5])
    # ax.set_xlim([0, 200])
    titleStr = '{} {} '.format(
        code, usgs.codePdf.loc[code]['shortName'])
    axplot.titleInner(ax, titleStr)
fig.show()

Exemple #4
0
cVar = 'power'
cR = [0, 0.6]

# plot 121
plt.close('all')
importlib.reload(axplot)
codeLst2 = [
    '00095', '00400', '00405', '00600', '00605', '00618', '00660', '00665',
    '00681', '00915', '00925', '00930', '00935', '00940', '00945', '00950',
    '00955', '70303', '71846', '80154'
]

# attr vs diff
fig, axes = plt.subplots(5, 4)
for k, code in enumerate(codeLst2):
    j, i = utils.index2d(k, 5, 4)
    ax = axes[j, i]
    ic = codeLst.index(code)
    x = cMat[:, ic]
    y = corrMat[:, ic, 1]**2 - corrMat[:, ic, 2]**2
    _ = ax.plot(x, y, '*')
    _ = ax.plot([np.nanmin(x), np.nanmax(x)], [0, 0], 'k-')
    ax.set_ylim([-0.3, 0.3])
    titleStr = '{} {} '.format(code, usgs.codePdf.loc[code]['shortName'])
    axplot.titleInner(ax, titleStr)
fig.show()

gsM = gridspec.GridSpec(50, 41)
figM = plt.figure(figsize=[10, 10])
ticks = [-0.5, 0, 0.5, 1]
axM = list()
Exemple #5
0
#     statPLst.append(stat.statError(ypTemp, obsTemp))
#     statFLst.append(stat.statError(yfTemp, obsTemp))

# plot maps forecast_diff
tLeg = ['0401-0701', '0701-1001', '1001-0101', '0101-0401']
[lat, lon] = df.getGeo()
fig, axes = plt.subplots(2, 2, figsize=[8, 5])
key = 'RMSE'
for k in range(4):
    s1 = statFLst[k][key]
    s2 = statPLst[k][key]
    data = s2 - s1
    cRange = [0, 0.03]
    keyLeg = 'RMSE(Proj)-RMSE(Fore)'
    titleStr = tLeg[k] + ' ' + keyLeg
    j, i = utils.index2d(k, 2, 2)
    grid, uy, ux = utils.grid.array2grid(data, lat=lat, lon=lon)
    plot.plotMap(grid,
                 ax=axes[j][i],
                 lat=uy,
                 lon=ux,
                 title=titleStr,
                 cRange=cRange)
# plt.tight_layout()
fig.show()
fig.savefig(os.path.join(saveDir, 'map_diff_RMSE_month'))

# plot map time series for each season / month
tM = [301, 501]
tRLst = [[20160000 + tM[0], 20160000 + tM[1]],
         [20170000 + tM[0], 20170000 + tM[1]]]
Exemple #6
0
fig = plot.plotBoxFig(dataBox[10:11],
                      label1=labMonth[10:11],
                      label2=labCrop,
                      sharey=True,
                      figsize=[8, 3],
                      colorLst='rgbk',
                      legOnly=True)
plt.tight_layout()
fig.show()
fig.savefig(os.path.join(saveDir, 'box_crop_leg.eps'))
fig.savefig(os.path.join(saveDir, 'box_crop_leg.png'))

# map crop
[lat, lon] = df.getGeo()
fig, axes = plt.subplots(2, 2, figsize=[8, 4])
dataLst = [cropRate[:, 0], cropRate[:, 22], cropRate[:, 23], cropRate[:, 2]]
cRangeLst = [[0, 40], [0, 10], [0, 20], [0, 2]]
for k in range(4):
    iy, ix = utils.index2d(k, 2, 2)
    grid, uy, ux = utils.grid.array2grid(dataLst[k], lat=lat, lon=lon)
    plot.plotMap(grid,
                 ax=axes[iy][ix],
                 lat=uy,
                 lon=ux,
                 title=labCrop[k] + ' fraction (%)',
                 cRange=cRangeLst[k])
plt.tight_layout()
fig.show()
fig.savefig(os.path.join(saveDir, 'map_crop.eps'))
fig.savefig(os.path.join(saveDir, 'map_crop.png'))