def netcdf_netcdf(ncfile1,ncfile2):
    nc1_ids, nc1_pos = MOM.read_netcdf_drifters(ncfile1)
    nc2_ids, nc2_pos = MOM.read_netcdf_drifters(ncfile2)

    dist = np.zeros(nc1_ids.shape)
    for i in range(0,nc1_ids.shape[0]):
        for j in range(0,nc2_ids.shape[0]):
            if nc1_ids[i] == nc2_ids[j]:
                dist[i] = great_circle(nc1_pos[i,0:2],nc2_pos[i,0:2]).km

    return nc1_ids,dist
def txt_netcdf(txtfile,ncfile):
    txt_ids,txt_pos = MOM.read_txt_drifters(txtfile)
    nc_ids,nc_pos = MOM.read_netcdf_drifters(ncfile)

    dist = np.zeros(txt_ids.shape)
    for i in range(0,txt_ids.shape[0]):
        for j in range(0,nc_ids.shape[0]):
            if txt_ids[i] == nc_ids[j]:
                dist[i] = great_circle(txt_pos[i,0:2],nc_pos[j,0:2]).km
                
            
    return txt_ids, dist
예제 #3
0
lons,lats,levs = MOM.read_netcdf_grids(gfile)
nlon = np.size(lons)
nlat = np.size(lats)
nlev = np.size(levs)


dr_id = 32
dpos_ens_g = np.zeros([2,num_ens])
dpos_ens_g2 = np.zeros([2,num_ens])

# read drifter ensemble data based on the given drifter id
for k in range(1,num_ens+1):
    ens_dir = os.path.dirname(root_dir + '/OUTPUT/' + date_str + '/model/' + '%03.d'%(k) + '/RESTART/')
    edrfile_g = os.path.join(ens_dir,'drifters_inp.nc')

    tmp1,tmp2 = MOM.read_netcdf_drifters(edrfile_g)  
    dpos_ens_g[:,k-1] = tmp2[dr_id-1,0:2]

    #ens_dir2 = os.path.dirname(root_dir + '/OUTPUT/' + date_str + '/model/' + '%03.d'%(k) + '/INPUT/')
    #edrfile_g = os.path.join(ens_dir2,'drifters_inp.nc')

    #tmp1,tmp2 = MOM.read_netcdf_drifters(edrfile_g)  
    #dpos_ens_g2[:,k-1] = tmp2[dr_id-1,0:2]

    #dpos_ens_g[:,k-1] = dpos_ens_g[:,k-1] - dpos_ens_g2[:,k-1]



# read true drifter position as mean
tdrfile = os.path.join(true_dir,'drifters_inp.nc')
tmp1,tmp2 = MOM.read_netcdf_drifters(tdrfile)
  # code the andr_sp and gsdr_sp later 
  for j in range(1,num_ens+1):
    an_ens = os.path.join(letkf_dir,'anal' + '{:03d}'.format(j) + '.drifters_inp.nc')
    gs_ens = os.path.join(letkf_dir,'gs'+ '{:02d}'.format(iday)  + '{:03d}'.format(j) + '.drifters_inp.txt')   

    tmp_id,tmp_an_dist = txt_netcdf(anal,an_ens) 
    tmp_id,tmp_gs_dist = txt_gstxt(gues,gs_ens)

    tmp_an_sp[:,0] = tmp_an_sp[:,0] + np.square(tmp_an_dist[:])
    tmp_gs_sp[:,0] = tmp_gs_sp[:,0] + np.square(tmp_gs_dist[:])

  spa_dist[:,i-1] = np.sqrt(tmp_an_sp[:,0]/(num_ens-1))
  spg_dist[:,i-1] = np.sqrt(tmp_gs_sp[:,0]/(num_ens-1))

  # code for plotting drifter trajectories: true, gues_me and anal_me
  tid, tpos[:,:,i-1] = MOM.read_netcdf_drifters(true)
  gid, gpos[:,:,i-1] = MOM.read_txt_drifters(gues)
  aid, apos[:,:,i-1] = MOM.read_txt_drifters(anal)
  cid, cpos[:,:,i-1] = MOM.read_netcdf_drifters(ctrl)

  f.write(str(np.mean(tmg_dist[:,i-1])) + " " +  str(np.mean(tma_dist[:,i-1])) + " " + str(np.mean(spg_dist[:,i-1])) + " " + str(np.mean(spa_dist[:,i-1])) + " " + str(np.mean(tmc_dist[:,i-1])) + "\n")

f.close()

  

# plotting the average drifters distance error in the testing time interval
plt.figure(1)
plt.plot(time,np.mean(tmg_dist[:,:],axis=0),label='true - forecast',c='b')
plt.plot(time,np.mean(tma_dist[:,:],axis=0),label='true - analysis',c='r')
plt.plot(time,np.mean(tmc_dist[:,:],axis=0),label='true - control', c='g')