if(dfx.isnull().values.sum() != 0 or dfy.isnull().values.sum() != 0\ or dfz.isnull().values.sum() != 0): print("missing value exists in interpolation") else: xdtc = xd_interp.values.reshape(nlat, nlon) ydtc = yd_interp.values.reshape(nlat, nlon) zdtc = zd_interp.values.reshape(nlat, nlon) xdnp, ydnp, zdnp = librotate.tc2np(lonc, latc, xdtc, ydtc, zdtc) #missing value if(np.isnan(xdnp).sum() != 0 or np.isnan(ydnp).sum() != 0 or \ np.isnan(zdnp).sum() != 0): print("missing value exists in tc2np") else: lonnp = lonin.reshape(1, -1) unp, vnp = librotate.xyzd2uv(xdnp, ydnp, zdnp, lonnp) #missing value if (np.isnan(unp).sum() != 0 or np.isnan(vnp).sum() != 0): print("missing value exists in xyzd2uv") else: udata = xr.DataArray(unp.reshape(1,nlat,nlon),\ [('time',pd.date_range(date,periods=1)),\ ('latitude',latin),('longitude',lonin)],\ attrs=attrs_u,name=var_sfc[0]) vdata = xr.DataArray(vnp.reshape(1,nlat,nlon),\ [('time',pd.date_range(date,periods=1)),\ ('latitude',latin),('longitude',lonin)],\ attrs=attrs_v,name=var_sfc[1]) print(udata) print(vdata) daout.append(udata)
#sfc u = data[var_sfc[0]].values v = data[var_sfc[1]].values attrs_u = data[var_sfc[0]].attrs attrs_v = data[var_sfc[1]].attrs #missing values need to be searched dfu = data[var_sfc[0]].to_pandas() dfv = data[var_sfc[1]].to_pandas() if (dfu.isnull().values.sum() != 0 or dfv.isnull().values.sum() != 0): logging.warning("missing value exists in input") continue lon2d = lon.reshape(1, -1) lat2d = lat.reshape(-1, 1) xd, yd, zd = librotate.uv2xyzd(u, v, lon2d, lat2d) #debug ud, vd = librotate.xyzd2uv(xd, yd, zd, lon2d, lat2d) logging.debug(f"uv2xyzd u {np.max(np.abs(u-ud))}") logging.debug(f"uv2xyzd v {np.max(np.abs(v-vd))}") da_xd = xr.DataArray(xd.reshape(1,len(lat),len(lon)),\ [('time',pd.date_range(date,periods=1)),('latitude',lat),('longitude',lon)],\ name='xd') da_yd = xr.DataArray(yd.reshape(1,len(lat),len(lon)),\ [('time',pd.date_range(date,periods=1)),('latitude',lat),('longitude',lon)],\ name='yd') da_zd = xr.DataArray(zd.reshape(1,len(lat),len(lon)),\ [('time',pd.date_range(date,periods=1)),('latitude',lat),('longitude',lon)],\ name='zd') xd_interp = da_xd.interp(longitude=newlon, latitude=newlat) yd_interp = da_yd.interp(longitude=newlon, latitude=newlat)
logging.debug(dataout) daout.append(dataout) #exit() #u, v attrs_u = data['u'].attrs attrs_v = data['v'].attrs #missing values need to be searched if (np.isnan(u).sum() != 0 or np.isnan(v).sum() != 0): logging.warning("missing value exists in input") continue lon3d = lonin[None, None, :] lat3d = latin[None, :, None] xd, yd, zd = librotate.uv2xyzd(u, v, lon3d, lat3d) #debug ud, vd = librotate.xyzd2uv(xd, yd, zd, lon3d, lat3d) logging.debug(f"uv2xyzd u {np.max(np.abs(u-ud))}") logging.debug(f"uv2xyzd v {np.max(np.abs(v-vd))}") xb, yb, zb = librotate.uv2xyzd(ud, vd, lon3d, lat3d) logging.debug(f"xyzd2uv x {np.max(np.abs(xd-xb))}") logging.debug(f"xyzd2uv y {np.max(np.abs(yd-yb))}") logging.debug(f"xyzd2uv z {np.max(np.abs(zd-zb))}") da_xd = xr.DataArray(xd[None,:],\ [('time',pd.date_range(date,periods=1)),\ ('level',level),\ ('latitude',latin),('longitude',lonin)],\ name='xd') da_yd = xr.DataArray(yd[None,:],\ [('time',pd.date_range(date,periods=1)),\ ('level',level),