out = os.path.join(cDir, 'output', 'CONUSv4f1') rootDB = os.path.join(cDir, 'data') nEpoch = 100 tRange = [20160401, 20170401] # load data df, yp, yt = master.test( out, tRange=[20160401, 20170401], subset='CONUSv4f1', epoch=100, reTest=True) yp = yp.squeeze() yt = yt.squeeze() # calculate stat statErr = stat.statError(yp, yt) dataGrid = [statErr['RMSE'], statErr['Corr']] dataTs = [yp, yt] t = df.getT() crd = df.getGeo() mapNameLst = ['RMSE', 'Correlation'] tsNameLst = ['LSTM', 'SMAP'] # plot map and time series plot.plotTsMap( dataGrid, dataTs, lat=crd[0], lon=crd[1], t=t, mapNameLst=mapNameLst, tsNameLst=tsNameLst, isGrid=True)
ax=None, lat=gagelat, lon=gagelon, title='Delta NSE', shape=None) # plot TS map t = utils.time.tRange2Array(tRange) tsdata = list() tsdata.append(obs.squeeze()) npred = 2 for ii in range(npred): tsdata.append(predLst[ii].squeeze()) plot.plotTsMap(dataMap=deltaNSE, dataTs=tsdata, t=t, lat=gagelat, lon=gagelon, tsNameLst=['USGS', 'LSTM', 'DA-1']) # plot multiple NSE maps plt.rcParams['font.size'] = 13 gageinfo = camels.gageDict gagelat = gageinfo['lat'] gagelon = gageinfo['lon'] fig, axs = plt.subplots(3, 2, figsize=(12, 8), constrained_layout=True) axs = axs.flat for ii in range(len(axs)): data = statDictLst[ii]['NSE'] ax = axs[ii] if ii == 0: subtitle = 'LSTM'
yp = train.testModel(model, x, batchSize=100).squeeze() ypLst.append( dbCsv.transNorm(yp, rootDB=rootDB, fieldName='SMAP_AM', fromRaw=False)) modelName = 'LSTM-DA' model = train.loadModel(outFolder, nEpoch, modelName=modelName) yp = train.testModel(model, x, z=y, batchSize=100).squeeze() ypLst.append( dbCsv.transNorm(yp, rootDB=rootDB, fieldName='SMAP_AM', fromRaw=False)) ## statErr1 = stat.statError(ypLst[0], yt) statErr2 = stat.statError(ypLst[1], yt) dataGrid = [statErr2['RMSE'], statErr2['RMSE'] - statErr1['RMSE']] dataTs = [ypLst[0], ypLst[1], yt] t = df.getT() crd = df.getGeo() mapNameLst = ['DA', 'DA-LSTM'] tsNameLst = ['LSTM', 'DA', 'SMAP'] colorMap = None colorTs = None plot.plotTsMap( dataGrid, dataTs, crd, t, colorMap=colorMap, mapNameLst=mapNameLst, tsNameLst=tsNameLst)
statPLst[0]['RMSE'] - statFLst[0]['RMSE'], statPLst[1]['RMSE'] - statFLst[1]['RMSE'], statPLst[2]['RMSE'] - statFLst[2]['RMSE'] ] prcp = df.getDataTs('APCP_FORA').squeeze() dataTs = [[obs, ypLst[0], yfLst[0]], [obs, ypLst[1], yfLst[1]], [obs, ypLst[2], yfLst[2]], [prcp]] crd = df.getGeo() t = df.getT() mapNameLst = ['dRMSE 2015', 'dRMSE 2016', 'dRMSE 2017'] tsNameLst = ['obs', 'prj', 'fore'] plot.plotTsMap(dataGrid, dataTs, lat=crd[0], lon=crd[1], t=t, tBar=[utils.time.t2dt(20160401), utils.time.t2dt(20170401)], mapNameLst=mapNameLst, isGrid=True, multiTS=True) # plot pixel time series import importlib importlib.reload(plot) matplotlib.rcParams.update({'font.size': 12}) matplotlib.rcParams.update({'lines.linewidth': 1}) matplotlib.rcParams.update({'lines.markersize': 6}) matplotlib.rcParams.update({'legend.fontsize': 12}) indLst = [1442, 1023] indYLst = [0, 2] nts = len(indLst)
dataGrid = [ statPtemp['RMSE'] / statFtemp['RMSE'], statPtemp['Corr'] / statFtemp['Corr'] ] prcp = df.getDataTs('APCP_FORA') dataTs = [obs, yp, yf] dataTs2 = [prcp] crd = df.getGeo() t = df.getT() mapNameLst = ['ratio RMSE', 'ratio Correlation'] tsNameLst = ['obs', 'prj', 'fore'] plot.plotTsMap(dataGrid, dataTs, dataTs2=dataTs2, lat=crd[0], lon=crd[1], t=t, mapNameLst=mapNameLst, tsNameLst=tsNameLst, isGrid=True) # plot map and time series # obsL4 = df.getDataTs('SMAP_L4', doNorm=False, rmNan=False).squeeze() dataGrid = [ statPLst[0]['RMSE'] - statFLst[0]['RMSE'], # statPLst[1]['RMSE'] / statFLst[1]['RMSE'], statPLst[2]['RMSE'] - statFLst[2]['RMSE'], # statPLst[3]['RMSE'] / statFLst[3]['RMSE'], ] prcp = df.getDataTs('APCP_FORA') dataTs = [obs, yp, yf]
] prcp = df.getDataTs('APCP_FORA').squeeze() dataTs = [[obs, ypLst[0], yfLst[0]], [obs, ypLst[1], yfLst[1]], [obs, ypLst[2], yfLst[2]], [prcp]] crd = df.getGeo() t = df.getT() mapNameLst = ['dRMSE 2015', 'dRMSE 2016', 'dRMSE 2017'] tsNameLst = ['obs', 'prj', 'fore'] tBar = [utils.time.t2dt(20160401), utils.time.t2dt(20170401)] #plt.tight_layout() plot.plotTsMap(dataGrid, dataTs, lat=crd[0], lon=crd[1], t=t, mapNameLst=mapNameLst, isGrid=True, multiTS=True, linewidth=1, figsize=(10, 10), tBar=tBar) # see result for different seasons tRangeLst = [[20180101, 20180201], [20180201, 20180301], [20180301, 20180401], [20160401, 20160501], [20160501, 20160601], [20160601, 20160701], [20160701, 20160801], [20160801, 20160901], [20160901, 20161001], [20161001, 20161101], [20161101, 20161201], [20161201, 20170101], [20170101, 20170201], [20170201, 20170301], [20170301, 20170401], [20170401, 20170501], [20170501, 20170601], [20170601, 20170701], [20170701, 20170801], [20170801, 20170901], [20170901, 20171001], [20171001, 20171101], [20171101, 20171201], [20171201, 20180101]]
statErr2 = stat.statError(yp2, yt2) dataMap = [statErr2['Corr'], statErr1['Corr'] - statErr2['Corr']] dataTs = [yt2, yp2] t = df2.getT() crd = df2.getGeo() mapNameLst = ['Test Corr', 'Train Corr - Test Corr'] tsNameLst = ['USGS', 'LSTM'] colorMap = None colorTs = None import imp imp.reload(plot) plot.plotTsMap(dataMap, dataTs, lat=crd[:, 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,