def get_data(station, tag, syear=2000, eyear=2020, egm08=0.0, egm96=0.0):
    time = -9999.0
    data = -9999.0
    if tag == "HydroWeb":
        time, data = hweb.HydroWeb_WSE(station,
                                       syear=syear,
                                       eyear=eyear,
                                       egm08=egm08,
                                       egm96=egm96)
    elif tag == "HydroSat":
        time, data = hsat.HydroSat_WSE(station,
                                       syear=syear,
                                       eyear=eyear,
                                       egm08=egm08,
                                       egm96=egm96)
    elif tag == "ICESat":
        time, data = isat.ICESat_WSE(station,
                                     syear=syear,
                                     eyear=eyear,
                                     egm08=egm08,
                                     egm96=egm96)
    elif tag == "CGLS":
        time, data = cgls.CGLS_WSE(station,
                                   syear=syear,
                                   eyear=eyear,
                                   egm08=egm08,
                                   egm96=egm96)
    elif tag == "GRRATS":
        time, data = grt.GRRATS_WSE(station,
                                    syear=syear,
                                    eyear=eyear,
                                    egm08=egm08,
                                    egm96=egm96)
    return time, data
Exemple #2
0
def get_data(station, tag):
    time = -9999.0
    data = -9999.0
    if tag == "HydroWeb":
        time, data = hweb.HydroWeb_WSE(station, syear=1992)
    elif tag == "HydroSat":
        time, data = hsat.HydroSat_WSE(station, syear=1992)
    elif tag == "ICESat":
        time, data = isat.ICESat_WSE(station, syear=1992)
    elif tag == "CGLS":
        time, data = cgls.CGLS_WSE(station, syear=1992)
    elif tag == "GRRATS":
        time, data = grt.GRRATS_WSE(station, syear=1992)
    return time, data
Exemple #3
0
def make_fig(point):
    plt.close()
    labels = ["HydroWeb", "corrupted", "assimilated"]
    #    print org[:,point]
    #    print "----------------"
    #    print np.mean(asm[:,:,point],axis=1)
    #    for i in np.arange(start,last):
    #        print opn[i,:,point]
    #        print asm[i,:,point]

    fig, ax1 = plt.subplots()
    #ax1.plot(np.arange(start,last),org[:,point],label="true",color="black",linewidth=0.7,zorder=101,marker = "o",markevery=swt[point])
    time, org = hweb.HydroWeb_WSE(pname[point], syear, eyear)
    # alti=hweb.altimetry(pname[point]) - EGM08[point] + EGM96[point]
    data = np.array(org) - np.array(EGM08[point]) + np.array(
        EGM96[point])  #- alti
    #====================================
    if conflag == 1:
        data0 = data
    elif conflag == 2:
        data0 = data - np.mean(
            data
        )  #(data-mean_obs[ylist[point],xlist[point]])+mean_sfcelv[ylist[point],xlist[point]]
    elif conflag == 3:
        data0 = (data - np.mean(data)) / (
            np.std(data) + 1e-20
        )  #((data-mean_obs[ylist[point],xlist[point]])/(std_obs[ylist[point],xlist[point]]+1.0e-20))*std_sfcelv[ylist[point],xlist[point]]+mean_sfcelv[ylist[point],xlist[point]]
    #====================================
    lines = [
        ax1.plot(time,
                 data0,
                 label="obs",
                 marker="o",
                 color="#34495e",
                 linewidth=0.0,
                 zorder=101)[0]
    ]
    #    ax1.plot(np.arange(start,last),org[:,point],label="true",color="black",linewidth=0.7,zorder=101)
    #    ax1.plot(np.arange(start,last),m_sf[:,point],label="mean sfcelv",color="black",linewidth=0.7,linestyle="--",zorder=107)
    #    plt.plot(np.arange(start,last),org[:,point],label="true",color="black",linewidth=0.7)

    for num in np.arange(0, int(pm.ens_mem())):
        if conflag == 1:
            opn0 = opn[:, num, point]
            asm0 = asm[:, num, point]
        elif conflag == 2:
            opn0 = opn[:, num, point] - mean_obss[num, ylist[point],
                                                  xlist[point]]
            asm0 = asm[:, num, point] - mean_obss[num, ylist[point],
                                                  xlist[point]]
        elif conflag == 3:
            opn0 = (opn[:, num, point] -
                    mean_obss[num, ylist[point], xlist[point]]) / (
                        std_obss[num, ylist[point], xlist[point]] + 1e-20)
            asm0 = (asm[:, num, point] -
                    mean_obss[num, ylist[point], xlist[point]]) / (
                        std_obss[num, ylist[point], xlist[point]] + 1e-20)
        #------------------------
        ax1.plot(np.arange(start, last),
                 opn0,
                 label="corrupted",
                 color="#4dc7ec",
                 linewidth=0.2,
                 alpha=0.5,
                 zorder=102)
        ax1.plot(np.arange(start, last),
                 asm0,
                 label="assimilated",
                 color="#ff8021",
                 linewidth=0.3,
                 alpha=0.5,
                 zorder=103)
#        ax1.plot(np.arange(start,last),em_sf[:,num,point],label="mean sfcelv",color="blue",linewidth=0.3,linestyle="--",alpha=0.5,zorder=103)
#        plt.plot(np.arange(start,last),opn[:,num,point],label="corrupted",color="blue",linewidth=0.3,alpha=0.5)
#        plt.plot(np.arange(start,last),asm[:,num,point],label="assimilated",color="red",linewidth=0.3,alpha=0.5)
    if conflag == 1:
        opn1 = np.mean(opn[:, :, point], axis=1)
        asm1 = np.mean(asm[:, :, point], axis=1)
    elif conflag == 2:
        opn1 = np.mean(opn[:, :, point], axis=1) - np.mean(
            mean_obss[:, ylist[point], xlist[point]], axis=0)
        asm1 = np.mean(asm[:, :, point], axis=1) - np.mean(
            mean_obss[:, ylist[point], xlist[point]], axis=0)
    elif conflag == 3:
        opn1 = (np.mean(opn[:, :, point], axis=1) - np.mean(
            mean_obss[:, ylist[point], xlist[point]], axis=0)) / (np.mean(
                std_obss[:, ylist[point], xlist[point]], axis=0) + 1e-20)
        asm1 = (np.mean(asm[:, :, point], axis=1) - np.mean(
            mean_obss[:, ylist[point], xlist[point]], axis=0)) / (np.mean(
                std_obss[:, ylist[point], xlist[point]], axis=0) + 1e-20)

    lines.append(
        ax1.plot(np.arange(start, last),
                 opn1,
                 label="corrupted",
                 color="#4dc7ec",
                 linewidth=0.8,
                 alpha=0.8,
                 zorder=102)[0])
    lines.append(
        ax1.plot(np.arange(start, last),
                 asm1,
                 label="assimilated",
                 color="#ff8021",
                 linewidth=0.8,
                 alpha=0.8,
                 zorder=103)[0])
    #    ax1.plot(np.arange(start,last),np.mean(em_sf[:,:,point],axis=1),label="mean sfelv",color="blue",linewidth=0.5,linestyle="--",alpha=0.5,zorder=103)
    #    plt.ylim(ymin=)
    meanch = "mean (long-term): %5.2f" % (np.mean(
        mean_obss[:, ylist[point], xlist[point]], axis=0))
    stdch = "std (long-term):%5.2f" % (np.mean(
        std_obss[:, ylist[point], xlist[point]], axis=0))
    omch = "mean (obs): %5.2f" % (np.mean(data))
    osch = "std (obs): %5.2f" % (np.std(data))
    cmch = "mean (cor): %5.2f" % (np.mean(opn[:, :, point]))
    csch = "std (cor): %5.2f" % (np.std(opn[:, :, point]))
    ax1.text(0.02,
             0.9,
             meanch,
             ha="left",
             va="center",
             transform=ax1.transAxes,
             fontsize=10)
    ax1.text(0.02,
             0.8,
             stdch,
             ha="left",
             va="center",
             transform=ax1.transAxes,
             fontsize=10)
    ax1.text(0.02,
             0.7,
             omch,
             ha="left",
             va="center",
             transform=ax1.transAxes,
             fontsize=10)
    ax1.text(0.02,
             0.6,
             osch,
             ha="left",
             va="center",
             transform=ax1.transAxes,
             fontsize=10)
    ax1.text(0.02,
             0.5,
             cmch,
             ha="left",
             va="center",
             transform=ax1.transAxes,
             fontsize=10)
    ax1.text(0.02,
             0.4,
             csch,
             ha="left",
             va="center",
             transform=ax1.transAxes,
             fontsize=10)

    # Make the y-axis label, ticks and tick labels match the line color.
    ax1.set_ylabel('anomaly WSE (m)', color='k')
    #ax1.set_ylim(ymin=0,ymax=250.)
    ax1.set_xlim(xmin=0, xmax=last + 1)
    ax1.tick_params('y', colors='k')
    # xxlist=np.linspace(15,N-15,int(N/30))
    # xxlab=[calendar.month_name[i][:3] for i in range(1,13)]
    # ax1.set_xticks(xxlist)
    # ax1.set_xticklabels(xxlab,fontsize=10)

    if eyear - syear > 5:
        dtt = 5
        dt = int(math.ceil(((eyear - syear) + 1) / 5.0))
    else:
        dtt = 1
        dt = (eyear - syear) + 1
    xxlist = np.linspace(0, N, dt, endpoint=True)
    #xxlab=[calendar.month_name[i][:3] for i in range(1,13)]
    xxlab = np.arange(syear, eyear + 1, dtt)
    ax1.set_xticks(xxlist)
    ax1.set_xticklabels(xxlab, fontsize=10)

    #    ax2 = ax1.twinx()
    #    aiv = stat.AI(asm[:,:,point],opn[:,:,point],org[:,point])
    #    aivn,error= stat.AI_new(asm[:,:,point],opn[:,:,point],org[:,point])#[0]
    #    fmax = np.finfo(np.float32).max
    #    aivn[aivn>fmax]=0
    #    aivn[aivn<-fmax]=0
    #    print np.mean(aivn)
    #    #--
    #    pBias,pB_c = stat.pBias(asm[:,:,point],opn[:,:,point],org[:,point])
    #    ai_mean = np.mean(ma.masked_less_equal(aivn,0.0)) #np.nanmean(ma.masked_less_equal(aivn,0.0))
    #    mai = "meanAI:%1.2f"%(ai_mean)
    #    pB  = "pBIAS:%1.1f%%"%(pBias)
    #    print  mai # pB, "pB_c", pB_c, "%"
    #    #pB  = pB + r'{1.1f}\%'.format(pBias)
    #    ax1.text(0.02,0.9,mai,ha="left",va="center",transform=ax1.transAxes,fontsize=10)
    #    ax1.text(0.02,0.8,pB,ha="left",va="center",transform=ax1.transAxes,fontsize=10)
    ##    ax2.plot(np.arange(start,last),aiv,color="green",zorder=104,marker = "o",alpha=0.3, markevery=swt[point])
    #    ax2.plot(np.arange(start,last),ma.masked_less_equal(aivn,1.0e-20),color="green",zorder=104,marker = "o", alpha=0.5,linewidth=0.5,markevery=swt[point])
    #    ax2.set_ylabel('AI', color='green')
    #    ax2.tick_params('y', colors='green')
    #    ax2.set_ylim(ymin=0.,ymax=1.)
    plt.legend(lines, labels, ncol=1, loc='upper right'
               )  #, bbox_to_anchor=(1.0, 1.0),transform=ax1.transAxes)
    #    fig.legend(lines,labels,ncol=1,loc='lower left', bbox_to_anchor=(1.0, 1.0))
    print(
        'save', river[point],
        re.split("_", pname[point])[2] + "_" + re.split("_", pname[point])[3]
    )  #,ylist[point],xlist[point],mean_obs[ylist[point],xlist[point]],std_obs[ylist[point],xlist[point]]
    # print (asm[:,num,point])
    #plt.savefig(assim_out+"/figures/sfcelv/"+river[point]+"_"+re.split("_",pname[point])[2]+"_"+re.split("_",pname[point])[3]+".png",dpi=300)
    plt.savefig(assim_out + "/figures/anomaly/" + pname[point][2::] + ".png",
                dpi=300)
    return 0