def load_std(E,std_mode = 'NODA',hostname='taurus',verbose=False): """ This subroutine returns the standard deviation of whatever variable is given in E['variable'], for each time given in E['daterange']. There are several ways to compute the standard deviation, and that's determined by the input 'std_mode': std_mode='ensemble' simply computes the standard deviation of the DART ensemble at each time if you set std_mode to any other string, it looks up the multi-year experiment corresponding to that string using the subroutine 'std_runs' in the user module experiment_settings. In this case, the standard deviation is computed for each time over several years, rather than an ensemble """ if std_mode == 'ensemble' : # cycle over the dates in the experiment dictionary # and load the ensemble mean of the corresponding No-assimilation case # TODO: a subroutine that returns the corresponding NODA experiment for each case Xlist = [] ECLIM = E.copy() ECLIM['copystring'] = 'ensemble std' Xclim,lat,lon,lev,DRnew = DSS.DART_diagn_to_array(ECLIM,hostname=hostname,debug=verbose) if len(DRnew) != len(ECLIM['daterange']): print('NOTE: not all requested data were found; returning a revised datarange') if Xclim is None: print('Cannot find data for experiment '+E['exp_name']) return None, None, None, None if std_mode == 'F_W4_L66' : # find the corresponding dataset ff = es.std_runs(std_mode,hostname=hostname,debug=verbose) # load the desired variables from netCDF4 import Dataset f = Dataset(ff,'r') lat = f.variables['lat'][:] lon = f.variables['lon'][:] lev = f.variables['lev'][:] time = f.variables['time'][:] variable = E['variable'] if E['variable'] == 'US': variable = 'U' if E['variable'] == 'VS': variable = 'V' if E['variable'] == 'OLR': variable = 'FLUT' VV = f.variables[variable][:] f.close() # choose the times corresponding to the daterange in E d0 = E['daterange'][0].timetuple().tm_yday # day in the year where we start nT = len(E['daterange']) df = E['daterange'][nT-1].timetuple().tm_yday # day in the year where we start # if df<d0, we have to cycle back to the beginning of the year if df < d0: day_indices = list(range(d0-1,365))+list(range(0,df)) else: day_indices = list(range(d0-1,df)) # also choose the lat, lon, and level ranges corresponding to those in E if E['levrange'] is not None: if E['levrange'][0] == E['levrange'][1]: ll = E['levrange'][0] idx = (np.abs(lev-ll)).argmin() lev2 = lev[idx] k1 = idx k2 = idx else: highest_level_index = (np.abs(lev-E['levrange'][1])).argmin() lowest_level_index = (np.abs(lev-E['levrange'][0])).argmin() # which index is k1 or k2 depends on the direction of lev if highest_level_index > lowest_level_index: k2 = highest_level_index k1 = lowest_level_index if highest_level_index < lowest_level_index: k1 = highest_level_index k2 = lowest_level_index lev2 = lev[k1:k2+1] j2 = (np.abs(lat-E['latrange'][1])).argmin() j1 = (np.abs(lat-E['latrange'][0])).argmin() lat2 = lat[j1:j2+1] i2 = (np.abs(lon-E['lonrange'][1])).argmin() i1 = (np.abs(lon-E['lonrange'][0])).argmin() lon2 = lon[i1:i2+1] if len(VV.shape) == 4: Xclim = VV[day_indices,k1:k2+1,j1:j2+1,i1:i2+1] else: Xclim = VV[day_indices,j1:j2+1,i1:i2+1] # in this case, we don't need to change the daterange DRnew = E['daterange'] return Xclim,lat,lon,lev,DRnew
def load_climatology(E,climatology_option = 'NODA',hostname='taurus',verbose=False): """ Load a climatology option for a given DART experiment. The choice of climatology is given by 'climatology_option'. Choices are: 'NODA' (default): take the ensemble mean of the corresponding no-DA experiment as a N-year climatology 'F_W4_L66': CESM-WACCM simulation with observed forcings, 1951-2010 (perfomed by Wuke Wang) """ climatology_option_not_found = True if climatology_option == 'NODA' : climatology_option_not_found = False # cycle over the dates in the experiment dictionary # and load the ensemble mean of the corresponding No-assimilation case # TODO: a subroutine that returns the corresponding NODA experiment for each case Xlist = [] ECLIM = E.copy() ECLIM['exp_name'] = 'W0910_NODA' ECLIM['diagn'] = 'Prior' ECLIM['copystring'] = 'ensemble mean' Xclim,lat,lon,lev,DRnew = DSS.DART_diagn_to_array(ECLIM,hostname=hostname,debug=verbose) if len(DRnew) != len(ECLIM['daterange']): print('NOTE: not all requested data were found; returning a revised datarange') if Xclim is None: print('Cannot find data for climatology option '+climatology_option+' and experiment '+E['exp_name']) return None, None, None, None if climatology_option == 'F_W4_L66' : from netCDF4 import Dataset climatology_option_not_found = False # in this case, load a single daily climatology calculated from this CESM-WACCM simulation ff = '/data/c1/lneef/CESM/F_W4_L66/atm/climatology/F_W4_L66.cam.h1.1951-2010.daily_climatology.nc' f = Dataset(ff,'r') lat = f.variables['lat'][:] lon = f.variables['lon'][:] lev = f.variables['lev'][:] time = f.variables['time'][:] # load climatology of the desired model variable variable = E['variable'] if E['variable'] == 'US': variable = 'U' if E['variable'] == 'VS': variable = 'V' if E['variable'] == 'OLR': variable = 'FLUT' VV = f.variables[variable][:] f.close() # choose the times corresponding to the daterange in E d0 = E['daterange'][0].timetuple().tm_yday # day in the year where we start nT = len(E['daterange']) df = E['daterange'][nT-1].timetuple().tm_yday # day in the year where we start # if df<d0, we have to cycle back to the beginning of the year if df < d0: day_indices = list(range(d0-1,365))+list(range(0,df)) else: day_indices = list(range(d0-1,df)) # also choose the lat, lon, and level ranges corresponding to those in E if E['levrange'] is not None: if E['levrange'][0] == E['levrange'][1]: ll = E['levrange'][0] idx = (np.abs(lev-ll)).argmin() lev2 = lev[idx] k1 = idx k2 = idx else: highest_level_index = (np.abs(lev-E['levrange'][1])).argmin() lowest_level_index = (np.abs(lev-E['levrange'][0])).argmin() # which index is k1 or k2 depends on the direction of lev if highest_level_index > lowest_level_index: k2 = highest_level_index k1 = lowest_level_index if highest_level_index < lowest_level_index: k1 = highest_level_index k2 = lowest_level_index lev2 = lev[k1:k2+1] j2 = (np.abs(lat-E['latrange'][1])).argmin() j1 = (np.abs(lat-E['latrange'][0])).argmin() lat2 = lat[j1:j2+1] i2 = (np.abs(lon-E['lonrange'][1])).argmin() i1 = (np.abs(lon-E['lonrange'][0])).argmin() lon2 = lon[i1:i2+1] if len(VV.shape) == 4: Xclim = VV[day_indices,k1:k2+1,j1:j2+1,i1:i2+1] else: Xclim = VV[day_indices,j1:j2+1,i1:i2+1] # in this case, we don't need to change the daterange DRnew = E['daterange'] if climatology_option_not_found: print('Climatology option '+climatology_option+' has not been coded yet. Returning None for climatology.') return None, None, None, None return Xclim,lat,lon,lev,DRnew