本文整理汇总了Python中WRCCUtils.find_valid_daterange方法的典型用法代码示例。如果您正苦于以下问题:Python WRCCUtils.find_valid_daterange方法的具体用法?Python WRCCUtils.find_valid_daterange怎么用?Python WRCCUtils.find_valid_daterange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WRCCUtils
的用法示例。
在下文中一共展示了WRCCUtils.find_valid_daterange方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_min_max_dates
# 需要导入模块: import WRCCUtils [as 别名]
# 或者: from WRCCUtils import find_valid_daterange [as 别名]
def set_min_max_dates(initial):
sd = '9999-99-99';ed = '9999-99-99'
sd_fut = sd; ed_fut = ed
data_type = 'station'
if 'location' in initial.keys():
data_type = 'grid'
if initial['app_name'] in ['monthly_spatial_summary', 'temporal_summary']:
data_type = 'grid'
if 'data_type' in initial.keys() and initial['data_type'] == 'grid':
data_type = 'grid'
if 'station_id' in initial.keys():
stn_json = settings.MEDIA_DIR + '/json/US_station_id.json'
stn_id, stn_name = WRCCUtils.find_id_and_name(initial['station_id'],stn_json)
els = []
if 'variable' in initial.keys():
els = [initial['variable']]
if 'variables' in initial.keys():
els = initial['variables']
vd, no_vd_els = WRCCUtils.find_valid_daterange(stn_id,el_list=els,max_or_min='min')
sd = vd[0];ed = vd[1]
#sd_fut = sd;ed_fut = ed
elif data_type == 'grid':
sd = WRCCData.GRID_CHOICES[str(initial['grid'])][3][0][0]
#ed = WRCCUtils.advance_date(sd,10*365,'forward')
ed = WRCCData.GRID_CHOICES[str(initial['grid'])][3][0][1]
#sd_fut = sd;ed_fut = ed
if len(WRCCData.GRID_CHOICES[initial['grid']][3]) == 2:
sd_fut = WRCCData.GRID_CHOICES[initial['grid']][3][1][0]
#ed_fut = WRCCUtils.advance_date(sd,10*365,'forward')
ed_fut = WRCCData.GRID_CHOICES[initial['grid']][3][1][1]
else:
if 'data_type' in initial.keys() and initial['data_type'] == 'station':
sd = '1850-01-01'
ed = today
return sd, ed, sd_fut, ed_fut
示例2: set_min_max_dates
# 需要导入模块: import WRCCUtils [as 别名]
# 或者: from WRCCUtils import find_valid_daterange [as 别名]
def set_min_max_dates(initial):
sd = '9999-99-99';ed = '9999-99-99'
sd_fut = sd; ed_fut = ed
if 'station_id' in initial.keys():
stn_json = settings.MEDIA_DIR + '/json/US_station_id.json'
stn_id, stn_name = WRCCUtils.find_id_and_name(initial['station_id'],stn_json)
els = []
if 'element' in initial.keys():
els = [initial['element']]
if initial['element'] in ['dtr','pet']:els = ['maxt','mint']
if 'elements' in initial.keys():
els = initial['elements']
if 'dtr' in els and 'maxt' not in els:
els.append('maxt')
if 'dtr' in els and 'mint' not in els:
els.append('mint')
if 'dtr' in els and 'maxt' not in els:
els.append('maxt')
if 'dtr' in els and 'mint' not in els:
els.append('mint')
vd = WRCCUtils.find_valid_daterange(stn_id,el_list=els,max_or_min='min')
if vd and len(vd) >=1:sd = vd[0]
if vd and len(vd) >1:ed = vd[1]
sd_fut = sd;ed_fut = ed
if 'location' in initial.keys() or initial['app_name'] == 'monthly_spatial_summary':
sd = WRCCData.GRID_CHOICES[str(initial['grid'])][3][0][0]
ed = WRCCData.GRID_CHOICES[str(initial['grid'])][3][0][1]
sd_fut = sd;ed_fut = ed
if len(WRCCData.GRID_CHOICES[initial['grid']][3]) == 2:
sd_fut = WRCCData.GRID_CHOICES[initial['grid']][3][1][0]
ed_fut = WRCCData.GRID_CHOICES[initial['grid']][3][1][1]
return sd, ed, sd_fut, ed_fut
示例3: set_wrapper_params
# 需要导入模块: import WRCCUtils [as 别名]
# 或者: from WRCCUtils import find_valid_daterange [as 别名]
def set_wrapper_params(stn_id):
'''
yesterday = WRCCUtils.set_back_date(1)
w_params = [stn_id, 'all','18000101',yesterday]
'''
vd = WRCCUtils.find_valid_daterange(stn_id)
if len(vd) == 2 and vd[0] and vd[1]:
return [stn_id, 'all',vd[0],vd[1]]
return []
示例4: set_form
# 需要导入模块: import WRCCUtils [as 别名]
# 或者: from WRCCUtils import find_valid_daterange [as 别名]
#.........这里部分代码省略.........
del form['csrfmiddlewaretoken']
if 'formData' in form.keys():
del form['formData']
if 'form_options' in form.keys():
del form['form_options']
if not clean:
return form
#Clean up form for submission
#Clean Dates and windows
vd = None
for key in ['start_date', 'end_date', 'start_year', 'end_year','start_window','end_window']:
if key not in form.keys():
continue
if form[key].lower() == 'por':
if str(key) in ['start_date']:
k=key; idx = 0;sd = 'por'; ed = form['end_date']
if str(key) in ['end_date']:
k=key; idx = 1;ed = 'por'; sd = form['start_date']
if str(key) in ['start_year']:
k='start_date'; idx = 0;sd = 'por'
if form['end_year'].lower() == 'por':ed = 'por'
else:ed = str(int(form['end_year']) -1) + '-12-31'
if str(key) in ['end_year']:
k='end_date'; idx = 1;ed = 'por'
if form['start_year'].lower() == 'por':sd = 'por'
else:sd = form['start_year'] + '-01-01'
if 'element' in form.keys() and not 'elements' in form.keys():
if form['element'] in ['dtr']:
el_list = ['maxt','mint']
if form['element'] in ['pet']:
el_list = ['maxt','mint','pcpn']
if 'elements' in form.keys() and not 'element' in form.keys():
if isinstance(form['elements'],basestring):
el_list = form['elements'].replace(' ','').split(',')
else:
el_list = form['elements']
else:
el_list = None
if 'station_id' in form.keys():
if vd is None:
stn_id, stn_name = WRCCUtils.find_id_and_name(str(form['station_id']),settings.MEDIA_DIR +'json/US_station_id.json')
vd = WRCCUtils.find_valid_daterange(stn_id, start_date=sd, end_date=ed, el_list=el_list, max_or_min='max')
form[k] = vd[idx]
if key == 'start_year' and form['start_year'].lower() == 'por':
form['start_year'] = vd[0][0:4]
if key == 'end_year' and form['end_year'].lower() == 'por':
form['end_year'] = vd[1][0:4]
else:
form[str(key)] = str(form[key]).replace('-','').replace(':','').replace('/','').replace(' ','')
else:
form[str(key)] = str(form[key]).replace('-','').replace(':','').replace('/','').replace(' ','')
#Convert user input of area names to ids
for key in ['station_id','county', 'basin', 'county_warning_area', 'climate_division']:
if not key in form.keys():
continue
ID,name = WRCCUtils.find_id_and_name(form[key],settings.MEDIA_DIR +'json/US_' + key + '.json')
form[key] = ID
form['user_area_id'] = str(name) + ', ' + str(ID)
if not 'user_area_id' in form.keys():
try:
form['user_area_id'] = form[form['area_type']]
except:
try:
form['user_area_id'] = form[form['data_type']]
except:
pass
#station_ids is special case
if 'station_ids' in form.keys():
stn_ids = ''
stn_list = form['station_ids'].rstrip(',').split(',')
#Remove leading spaces from list items
stn_list = [v.lstrip(' ').rstrip(' ') for v in stn_list]
stn_ids, stn_names = WRCCUtils.find_ids_and_names(stn_list,settings.MEDIA_DIR +'json/US_' + 'station_id' + '.json')
form['station_ids'] = stn_ids
uai = ''
stn_names_list = stn_names.split(',')
for idx, stn_id in enumerate(stn_ids.split(',')):
uai+=str(stn_names[idx]) + ', ' + str(stn_id) + ';'
form['user_area_id'] = uai
#set data summary if needed
if 'data_summary' not in form.keys():
if 'temporal_summary' in form.keys():
form['data_summary'] = 'temporal_summary'
if 'spatial_summary' in form.keys():
form['data_summary'] = 'spatial_summary'
#Combine elements
if 'add_degree_days' in form.keys() and form['add_degree_days'] == 'T':
for dd in form['degree_days'].replace(' ','').split(','):
'''
if form['units'] == 'metric':
el_strip, base_temp = WRCCUtils.get_el_and_base_temp(dd)
form['elements'].append(el_strip + str(WRCCUtils.convert_to_english('base_temp',base_temp)))
else:
form['elements'].append(dd)
'''
form['elements'].append(dd)
return form
示例5: sods
# 需要导入模块: import WRCCUtils [as 别名]
# 或者: from WRCCUtils import find_valid_daterange [as 别名]
def sods(request, app_name):
units = {'pcpn':'Hundredths of Inches', 'snow':'Tenths of Inches', 'snwd': 'Inches', 'maxt':'Whole Degrees', 'mint':'Whole Degrees',\
'avgt':'Whole Degrees', 'dtr':'Whole Degrees', 'hdd':'Days', 'cdd':'Days','gdd':'Days'}
months = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']
context = {
'title': '%s' % app_name,
}
#Form 1 dealing with station selection and for some apps, preliminary information
form1 = set_as_form(request, 'Sod0', init={'app_name': app_name})
context['form1'] = form1
if 'stn_selection' in request.POST:
#if app_name == 'Soddd':
# form1 = set_as_form(request, 'Sod0', init={'app_name': app_name, 'skip_days':False})
#elif app_name == 'Sodthr':
# form1 = set_as_form(request, 'Sod0', init={'app_name': app_name, 'custom_tables':False, 'number_of_threholds':1})
#else:
form1 = set_as_form(request, 'Sod0', init={'app_name': app_name})
context['form1'] = form1
if form1.is_valid():
context['form_2_ready'] = '2ready'
station_selection = form1.cleaned_data['station_selection']
if app_name == 'Soddd':
initial = {'app_name':app_name, 'station_selection':station_selection, \
'skip_days':form1.cleaned_data['skip_days'], 'truncate':form1.cleaned_data['truncate'] }
elif app_name == 'Sodpct':
initial = {'app_name':app_name, 'station_selection':station_selection,\
'threshold':form1.cleaned_data['threshold'], 'element':form1.cleaned_data['element'], \
'individual_averages': form1.cleaned_data['individual_averages'] }
elif app_name == 'Sodthr':
initial = {'app_name':app_name, 'station_selection':station_selection,\
'custom_tables':form1.cleaned_data['custom_tables'],'number_of_thresholds': form1.cleaned_data['number_of_thresholds']}
elif app_name == 'Sodxtrmts':
initial = {'app_name':app_name, 'station_selection':station_selection,\
'statistic':form1.cleaned_data['statistic'], 'element':form1.cleaned_data['element'], \
'frequency_analysis':form1.cleaned_data['frequency_analysis'],'statistic_period':'monthly'}
elif app_name == 'Sodpiii':
initial = {'app_name':app_name, 'station_selection':station_selection,\
'skew':form1.cleaned_data['skew'], 'cv':form1.cleaned_data['cv'], 'mean':form1.cleaned_data['mean'], \
'pct_average':form1.cleaned_data['pct_average'], 'days':form1.cleaned_data['days']}
else:
initial = {'app_name':app_name, 'station_selection':station_selection}
form2 = set_as_form2(init=initial)
context['form2'] = form2
else:
station_selection=None
#Form2 Application parameters
if 'app_form' in request.POST:
form2 = set_as_form(request, 'Sod')
context['form2'] = form2
#import pdb; pdb.set_trace()
if form2.is_valid():
context['cleaned'] = form2.cleaned_data
#Check for POR
vd = None
if 'station_id' in form2.cleaned_data.keys() or 'stnid' in form2.cleaned_data.keys():
if 'station_id' in form2.cleaned_data.keys():
stn_id = form2.cleaned_data['station_id']
if 'stnid' in form2.cleaned_data.keys():
stn_id = form2.cleaned_data['stn_id']
if 'start_date' in form2.cleaned_data.keys() and form2.cleaned_data['start_date'].upper() == 'POR':
vd = WRCCUtils.find_valid_daterange(stn_id, max_or_min='max')
if 'end_date' in form2.cleaned_data.keys() and form2.cleaned_data['end_date'].upper() == 'POR' and vd is None:
vd = WRCCUtils.find_valid_daterange(stn_id, max_or_min='max')
if vd is not None and len(vd) == 2:
form2.cleaned_data['start_date'] = vd[0]
form2.cleaned_data['end_date'] = vd[1]
(data, dates, elements, station_ids, station_names) = AcisWS.get_sod_data(form2.cleaned_data, app_name)
#get contexts for the different apps and run data application
if app_name in ['Sodrun', 'Sodrunr']:
if elements == ['maxt', 'mint']:
context['el'] = 'range'
else:
context['el'] = str(elements[0])
if form2.cleaned_data['aeb'] == 'A':
context['op'] = '>'
elif form2.cleaned_data['aeb'] == 'B':
context['op'] = '<'
else:
context['op'] = '='
context['thresh'] = form2.cleaned_data['threshold']
context['dur'] = form2.cleaned_data['minimum_run']
app_args = {'app_name': app_name, 'data':data,'dates':dates,'elements':elements,\
'station_ids':station_ids,'station_names':station_names,'op':context['op'],\
'thresh':context['thresh'], 'verbose': form2.cleaned_data['verbose'], 'minimum_run': form2.cleaned_data['minimum_run']}
results = WRCCDataApps.Sodrun(**app_args)
elif app_name == 'Soddynorm':
app_args = {'app_name': app_name, 'data':data,'dates':dates,'elements':elements,\
'station_ids':station_ids,'station_names':station_names,\
'filter_type':form2.cleaned_data['filter_type'],\
'filter_days':form2.cleaned_data['number_of_days']}
results = WRCCDataApps.Soddynorm(**app_args)
'''
results = run_data_app(app_name, data, dates, elements, station_ids, station_names, \
form2.cleaned_data['filter_type'], form2.cleaned_data['number_of_days'])
'''
elif app_name == 'Soddyrec':
app_args = {'app_name': app_name, 'data':data,'dates':dates,'elements':elements,\
'station_ids':station_ids,'station_names':station_names}
results = WRCCDataApps.Soddyrec(**app_args)
#.........这里部分代码省略.........
示例6: set_wrapper_params
# 需要导入模块: import WRCCUtils [as 别名]
# 或者: from WRCCUtils import find_valid_daterange [as 别名]
def set_wrapper_params(stn_id, table_name):
vd, no_vd_els = WRCCUtils.find_valid_daterange(stn_id)
if len(vd) == 2 and vd[0] != '9999-99-99' and vd[1] != '9999-99-99':
return [stn_id, table_name,vd[0][0:4],vd[1][0:4],5]
return []
示例7: get_station_data
# 需要导入模块: import WRCCUtils [as 别名]
# 或者: from WRCCUtils import find_valid_daterange [as 别名]
def get_station_data(form_input, program):
'''
Retrieves Station Data from ACIS.
Keyword arguments:
form_input -- parameter file for data request obtained from user of CSC pages
program -- specifies program that is making the request.
Returns python dictionary with keys:
meta
data
'''
request = {'data':[]}
s_date, e_date = WRCCUtils.start_end_date_to_eight(form_input)
#Sanity check for valid date input:
if (s_date.lower() == 'por' or e_date.lower() == 'por') and ('station_id' not in form_input.keys()):
error = 'Parameter error. Start/End date ="por" not supported for multi station call.'
resultsdict['error'] = error
return resultsdict
variables = WRCCUtils.get_variable_list(form_input, program)
elems_list = []
elems_list_short = []
resultsdict = {}
for el in variables:
el_strip, base_temp = WRCCUtils.get_el_and_base_temp(el)
elems_list_short.append(el_strip)
if el_strip in ['gdd', 'hdd', 'cdd'] and base_temp is not None:
d = dict(vX=WRCCData.ACIS_ELEMENTS_DICT[el_strip]['vX'], base=int(base_temp), add='f,t')
elems_list.append(d)
else:
d = dict(vX=WRCCData.ACIS_ELEMENTS_DICT[el]['vX'],add='f,t')
elems_list.append(d)
params = {
'sdate':s_date,
'edate':e_date,
'meta':'name,state,sids,ll,elev,uid,valid_daterange',
'elems':elems_list
}
shape_type = None
#Deal with POR input dates
if 'station_id' in form_input.keys():
sid = form_input['station_id']
s = s_date.lower()
e = e_date.lower()
l = elems_list_short
vd, no_vd_els = WRCCUtils.find_valid_daterange(sid, start_date=s, end_date=e, el_list=l, max_or_min='max')
params['sdate'] = v[0]; params['edate'] = v[1]
if params['sdate'] == '9999-99-99' or params['edate'] == '9999-99-99':
error = 'No start/end date could be found for this station in the metadata database.'
resultsdict['error'] = error
return resultsdict
#Set area parameter
try:
key = WRCCData.STN_AREA_FORM_TO_PARAM[form_input['select_stations_by']]
val = form_input[form_input['select_stations_by']]
except:
key = WRCCData.STN_AREA_FORM_TO_PARAM[form_input['area_type']]
val = form_input[form_input['area_type']]
params[key] = val
#Find bbox if custom shape and update params['bbox']
if 'shape' in form_input.keys():
shape_type,bbox = WRCCUtils.get_bbox(form_input['shape'])
params['bbox'] = bbox
#Data request
try:
req = MultiStnData(params)
except Exception, e:
request['error'] = 'StnData request failed. Error: %s. Pameters: %s.' %(str(e), params)
return request