本文整理汇总了Python中WRCCUtils.get_element_list方法的典型用法代码示例。如果您正苦于以下问题:Python WRCCUtils.get_element_list方法的具体用法?Python WRCCUtils.get_element_list怎么用?Python WRCCUtils.get_element_list使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WRCCUtils
的用法示例。
在下文中一共展示了WRCCUtils.get_element_list方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_grid_data
# 需要导入模块: import WRCCUtils [as 别名]
# 或者: from WRCCUtils import get_element_list [as 别名]
def get_grid_data(form_input, program):
'''
Retrieves Grid 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 or smry (if data_summary)
lats -- lists of latitudes for grid points
lons -- lists of longitudes for grid points
'''
#datalist[date_idx] = [[date1,lat1, lon1, elev1, el1_val1, el2_val1, ...],
#[date2, lat2, ...], ...]
s_date, e_date = WRCCUtils.start_end_date_to_eight(form_input)
#grid data calls do not except list of elements, need to be string of comma separated values
el_list = WRCCUtils.get_element_list(form_input, program)
if 'data_summary' in form_input.keys() and form_input['data_summary'] == 'temporal_summary':
elements = [{'name':str(el),'smry':str(form_input['temporal_summary']),'smry_only':1} for el in el_list]
else:
elements = ','.join(el_list)
params = {
'sdate': s_date,
'edate': e_date,
'grid': form_input['grid'],
'elems': elements,
'meta': 'll,elev'
}
#Set area parameter
try:
key = WRCCData.GRID_AREA_FORM_TO_PARAM[form_input['select_grid_by']]
val = form_input[form_input['select_grid_by']]
except:
key = WRCCData.GRID_AREA_FORM_TO_PARAM[form_input['area_type']]
val = form_input[form_input['area_type']]
params[key] = val
#Override area parameter if needed
#Find bbox if custom shape
if 'shape' in form_input.keys():
#Need to find enclosing bbox
shape_type,bbox = WRCCUtils.get_bbox(form_input['shape'])
if shape_type == 'location':params['loc'] = form_input['shape']
else:params['bbox'] = bbox
#Find enclosing bbox via General ACIS call if climdiv, cwa, county, basin
#Note: gridACIS currently does not support direct calls for these options
#FIX me : when gridACIS supports calls for climdiv, cwa, county, basin
if form_input['select_grid_by'] in ['county_warning_area', 'climate_division', 'basin', 'county']:
try:
a = WRCCData.STN_AREA_FORM_TO_PARAM[form_input['select_grid_by']]
v = form_input[form_input['select_grid_by']]
except:
a = WRCCData.STN_AREA_FORM_TO_PARAM[form_input['area_type']]
v = form_input[form_input['area_type']]
bbox = get_acis_bbox_of_area(a,v)
params['bbox'] = bbox
request = {}
try:
request = GridData(params)
except Exception, e:
error = 'GridData request failed with ERROR: %s.' %(str(e))
request['error'] = error
示例2: get_sod_data
# 需要导入模块: import WRCCUtils [as 别名]
# 或者: from WRCCUtils import get_element_list [as 别名]
def get_sod_data(form_input, program):
'''
Data acquisition for Soddyrec, Soddynorm, Soddd, Sodpad, Sodsumm
Keyword arguments:
form_input -- parameter file for data request obtained from user of WRCC SOD pages
program -- specifies program that is making the request.
'''
s_date, e_date = WRCCUtils.start_end_date_to_eight(form_input)
'''
if program in ['Sodpiii']:
#get an extra year of data previos and after s_date, e_date
s_date = str(int(s_date[0:4]) - 1) + s_date[4:]
e_date = str(int(e_date[0:4]) + 1) + e_date[4:]
'''
dates = WRCCUtils.get_dates(s_date, e_date, program)
elements = WRCCUtils.get_element_list(form_input, program)
els = [dict(name='%s' % el) for el in elements]
if 'station_id' in form_input.keys():
station_ids =[form_input['station_id']]
elif 'station_ids' in form_input.keys():
station_ids = form_input['station_ids']
elif 'county' in form_input.keys():
station_ids = get_station_list('county', form_input['county'])
elif 'climate_division' in form_input.keys():
station_ids = get_station_list('climate_division', form_input['climate_division'])
elif 'county_warning_area' in form_input.keys():
station_ids = get_station_list('county_warning_area', form_input['county_warning_area'])
elif 'basin' in form_input.keys():
station_ids = get_station_list('basin', form_input['basin'])
elif 'state' in form_input.keys():
station_ids = get_station_list('state', form_input['state'])
elif 'bounding_box' in form_input.keys():
station_ids = get_station_list('bounding_box', form_input['bounding_box'])
else:
station_ids =[]
#sort station id in ascending order
#station_ids = WRCCUtils.strip_n_sort(station_ids)
station_names=['No Name found' for i in range(len(station_ids))]
#Since Acis may not return results for some stations, we need to initialize output dictionary
datadict = defaultdict(list)
for i, stn in enumerate(station_ids):
if program == 'Soddyrec':
#yr_list = [[['#', '#', '#', '#', '#', '#','#', '#'] for k in range(366)] for el in elements]
#yr_list = [[['#', '#', '#', '#', '#', '#','#', '#'] for k in range(366)] for i in range(3*len(elements))]
#datadict[i] = yr_list
datadict[i] = []
elif program in ['Sodrun', 'Sodrunr']:
datadict[i] = []
else:
datadict[i] = [[] for el in elements]
if program == 'Soddyrec':
smry_opts = [{'reduce':'mean', 'add':'date,mcnt'}, {'reduce':'max', 'add':'date,mcnt'}, {'reduce':'min', 'add':'date,mcnt'}]
elts = []
for el in elements:
for sry in smry_opts:
#elts.append(dict(name=str(el),smry=sry, groupby='year'))
elts.append(dict(vX=WRCCData.ACIS_ELEMENTS_DICT[el]['vX'],smry=sry, groupby='year'))
params = dict(sids=station_ids, sdate=s_date, edate=e_date, elems=elts)
elif program in ['Soddynorm', 'Soddd', 'Sodpad', 'Sodsumm', 'Sodpct', 'Sodthr', 'Sodxtrmts', 'Sodpiii']:
params = dict(sids=station_ids, sdate=s_date, edate=e_date, \
#elems=[dict(name=el,interval='dly',duration='dly',groupby='year')for el in elements])
elems=[dict(vX=WRCCData.ACIS_ELEMENTS_DICT[el]['vX'],interval='dly',duration='dly',groupby='year') for el in elements])
elif program in ['Sodlist', 'Sodcnv']:
params = dict(sids=station_ids, sdate=s_date, edate=e_date, \
#elems=[dict(name=el,add='t')for el in elements])
elems=[dict(vX=WRCCData.ACIS_ELEMENTS_DICT[el]['vX'],add='t') for el in elements])
else:
params = dict(sids=station_ids, sdate=s_date, edate=e_date, \
#elems=[dict(name=el)for el in elements])
elems=[dict(vX=WRCCData.ACIS_ELEMENTS_DICT[el]['vX']) for el in elements])
request = MultiStnData(params)
if not request:
request = {'error':'bad request, check params: %s' % str(params)}
try:
request['data']#list of data for the stations
except:
if request['error']:
return datadict, dates, elements, station_ids, station_names
#sys.exit(1)
else:
#Unknown error ocurred when getting data
#sys.exit(1)
return datadict, dates, elements, station_ids, station_names
for stn, stn_data in enumerate(request['data']):
if not 'meta' in stn_data.keys():continue
sids = stn_data['meta']['sids']
index = None
for sid in sids:
sid_split = sid.split(' ')
station_id = str(sid_split[0])
try:
index = station_ids.index(str(station_id))
break
except:
continue
#.........这里部分代码省略.........
示例3: get_station_data
# 需要导入模块: import WRCCUtils [as 别名]
# 或者: from WRCCUtils import get_element_list [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
elements = WRCCUtils.get_element_list(form_input, program)
elems_list = []
elems_list_short = []
resultsdict = {}
for el in elements:
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
[s_date, e_date] = WRCCUtils.find_valid_daterange(sid, start_date=s, end_date=e, el_list=l, max_or_min='max')
params['sdate'] = s_date; params['edate'] = e_date
if not params['sdate'] or not params['edate']:
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