In [20]:
%run basics
import ast
import collections
import dateutil
import xlrd
In [23]:
def get_ustarthreshold_from_cpdresults(cf):
# do some stuff
cpd_path = cf["Files"]["file_path"]
cpd_name = "../"+cpd_path+cf["Files"]["cpd_filename"]
cpd_wb = xlrd.open_workbook(cpd_name)
annual_ws = cpd_wb.sheet_by_name("Annual")
header_list = [x for x in annual_ws.row_values(0)]
year_list = [str(int(x)) for x in annual_ws.col_values(0)[1:]]
ustar_dict = collections.OrderedDict()
for i,year in enumerate(year_list):
ustar_dict[year] = collections.OrderedDict()
for item in header_list:
xlcol = header_list.index(item)
val = annual_ws.col_values(xlcol)[i+1]
typ = annual_ws.col_types(xlcol)[i+1]
if typ==2:
ustar_dict[year][item] = float(val)
else:
ustar_dict[year][item] = float(c.missing_value)
return ustar_dict
In [34]:
def get_ustarthreshold_from_cf(cf,ldt):
ustar_dict = collections.OrderedDict()
ustar_threshold_list = []
if "ustar_threshold" in cf.keys():
for n in cf["ustar_threshold"].keys():
ustar_threshold_list.append(ast.literal_eval(cf["ustar_threshold"][str(n)]))
for item in ustar_threshold_list:
startdate = dateutil.parser.parse(item[0])
year = startdate.year
ustar_dict[str(year)] = {}
ustar_dict[str(year)]["ustar_mean"] = float(item[2])
else:
msg = " [ustar_threshold] section not found in control file, using 0.25 m/s"
print msg
startyear = ldt[0].year
endyear = ldt[-1].year
years = range(startyear,endyear+1)
for year in years:
ustar_dict[str(year)] = {}
ustar_dict[str(year)]["ustar_mean"] = float(0.25)
return ustar_dict
In [8]:
cf_name = qcio.get_filename_dialog(path="../controlfiles/")
cf = qcio.get_controlfilecontents(cf_name)
In [18]:
in_filename = "../"+qcio.get_infilenamefromcf(cf)
ds = qcio.nc_read_series(in_filename)
ldt = ds.series["DateTime"]["Data"]
In [35]:
ustar_dict1 = get_ustarthreshold_from_cpdresults(cf)
In [36]:
ustar_dict2 = get_ustarthreshold_from_cf(cf,ldt)
In [37]:
ustar_dict1["2010"]["ustar_mean"]
Out[37]:
In [38]:
ustar_dict2["2010"]["ustar_mean"]
Out[38]:
In [32]:
ustar_dict2
Out[32]:
In [ ]: