def bias_matrix(domain, interpolate, save): if interpolate == True: if domain == 'pcse': fname = 'pcse-domain_bias' lon_new, lat_new = lonp, latp elif domain == 'rio': fname = 'rio-domain_bias' lon_new, lat_new = lonr, latr NEinterp = griddata(lonc.flatten(), latc.flatten(), NEbias.flatten(), lon_new, lat_new) SEinterp = griddata(lonc.flatten(), latc.flatten(), SEbias.flatten(), lon_new, lat_new) SWinterp = griddata(lonc.flatten(), latc.flatten(), SWbias.flatten(), lon_new, lat_new) NWinterp = griddata(lonc.flatten(), latc.flatten(), NWbias.flatten(), lon_new, lat_new) ds = xray.Dataset( variables={'NE_bias': (['y','x'], NEinterp), 'SE_bias': (['y','x'], SEinterp), 'SW_bias': (['y','x'], SWinterp), 'NW_bias': (['y','x'], NWinterp)}, coords={'lat': (['y','x'], lat_new), 'lon': (['y','x'], lon_new)}, attrs={'Name' : 'CFSR - WRF regional averaged-bias for January 2013', 'Description' : 'Bias values were calculated by\ subtratcting WRF regional model from CFSR product.\ WRF model results used here has a spatial resolution\ of 9km while CFSR is ~25km. The computation regards\ the MEDIAN over January 2013'} ) if save == True: ds.to_netcdf( ROOTDIR + fname + '.nc' ) elif interpolate == False: fname = 'cfs-domain_bias' ds = xray.Dataset( variables={'NE_bias': (['y','x'], NEbias), 'SE_bias': (['y','x'], SEbias), 'SW_bias': (['y','x'], SWbias), 'NW_bias': (['y','x'], NWbias)}, coords={'lat': (['y','x'], latc), 'lon': (['y','x'], lonc)}, attrs={'Name' : 'CFSR - WRF regional averaged-bias for January 2013', 'Description' : 'Bias values were calculated by\ subtratcting WRF regional model from CFSR product.\ WRF model results used here has a spatial resolution\ of 9km while CFSR is ~25km. The computation regards\ the MEDIAN over January 2013'} ) if save == True: ds.to_netcdf( ROOTDIR + fname + '.nc' )
wrf['west_east'].values = wrf['XLONG'][0,0,:].values u = wrf['U10'].sel(south_north=slice(Glims[2],Glims[3]), west_east=slice(Glims[0], Glims[1])) v = wrf['V10'].sel(south_north=slice(Glims[2],Glims[3]), west_east=slice(Glims[0], Glims[1])) lonw = u.coords['XLONG'][0,...].values latw = u.coords['XLAT'][0,...].values U = np.ones( (u.shape[0], latc.shape[0], lonc.shape[1]) ) V = U.copy() for k in range(u.shape[0]): U[k] = griddata(lonw.flatten(), latw.flatten(), u[k].values.flatten(), lonc, latc) V[k] = griddata(lonw.flatten(), latw.flatten(), v[k].values.flatten(), lonc, latc) WRFint, WRFdir = uv2intdir(-U, -V) NEwrf, SEwrf, SWwrf, NWwrf = wind_quadrant(WRFdir, WRFint, type='median') ############################################################################ # Computing BIAS (CFSv2 - WRF) ############################################################################ NEbias = NEcfs - NEwrf SEbias = SEcfs - SEwrf SWbias = SWcfs - SWwrf NWbias = NWcfs - NWwrf