def rcs_model(winlen, modfile): from grid_tools import trim_time_jandec from netCDF4 import num2date from netCDF4 import date2num from scipy import ndimage from netcdf_tools import ncextractall from convert import mmd_mmm #Extract the model data and clip to the required start and end months modnc = ncextractall(modfile) mdata = modnc['pr'] mdata = mdata*86400. #convert to same units as obs mlon = modnc['lon'] mlat = modnc['lat'] mtime = modnc['time'] time_u = modnc['time_units'] if 'time_calendar' in modnc.keys(): cal = modnc['time_calendar'] mtime = num2date(mtime,units = time_u, calendar=cal) else: mtime = num2date(mtime,units = time_u) mdata, mtime = trim_time_jandec(mdata, mtime) mdata = mmd_mmm(mdata) mdata = ndimage.filters.uniform_filter(mdata,size=[winlen,1,1]) #Trim first or last values if required as they are unrepresentative trim = int(winlen/2) mdata = mdata[trim:,:,:] if winlen % 2 == 0: trim = trim - 1 mdata = mdata[:-trim,:,:] return, mdata, mlat, mlon
def rcs_gpcp(winlen): from grid_tools import trim_time_jandec from netCDF4 import num2date from netCDF4 import date2num from scipy import ndimage from netcdf_tools import ncextractall from convert import mmd_mmm #Extract the observed data and clip to the required start and end months obfile = '/Users/ailieg/Data/drought_model_eval_data/data/obs/GPCP/precip.mon.mean.nc' obsnc = ncextractall(obfile) odata = obsnc['precip'] olon = obsnc['lon'] olat = obsnc['lat'] olat = olat[::-1] odata = odata[:,::-1,:] otime = obsnc['time'] obsmiss = obsnc['precip_missing_value'] odata[np.where(odata == obsmiss)] = np.nan time_u = obsnc['time_units'] if 'time_calendar' in obsnc.keys(): cal = obsnc['time_calendar'] otime = num2date(otime,units = time_u, calendar=cal) else: otime = num2date(otime,units = time_u) odata, otime = trim_time_jandec(odata, otime) odata = mmd_mmm(odata) odata = ndimage.filters.uniform_filter(odata,size=[winlen,1,1]) #Trim first or last values if required as they are unrepresentative trim = int(winlen/2) odata = odata[trim:,:,:] if winlen % 2 == 0: trim = trim - 1 odata = odata[:-trim,:,:] return, odata, olat, olon