本文整理汇总了Python中WRCCUtils.strip_n_sort方法的典型用法代码示例。如果您正苦于以下问题:Python WRCCUtils.strip_n_sort方法的具体用法?Python WRCCUtils.strip_n_sort怎么用?Python WRCCUtils.strip_n_sort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WRCCUtils
的用法示例。
在下文中一共展示了WRCCUtils.strip_n_sort方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_sodsum_data
# 需要导入模块: import WRCCUtils [as 别名]
# 或者: from WRCCUtils import strip_n_sort [as 别名]
def get_sodsum_data(form_input):
'''
Data acquisition for sodsum
Keyword arguments:
form_input -- parameter file for data request obtained from user of WRCC SOD pages
'''
if 'variable' not in form_input.keys() or 'station_ids' not in form_input.keys():
print 'variable and station_id options required!'
sys.exit(0)
if not form_input['variable'] or not form_input['station_ids']:
print 'variable and station_id options required!'
sys.exit(0)
s_date, e_date = WRCCUtils.start_end_date_to_eight(form_input)
station_ids = form_input['station_ids'] #list of stn ids (converted to list in form)
#sort coop ids in ascending order, strip left zeros first, sort and reattach zeros
station_ids = WRCCUtils.strip_n_sort(station_ids)
datadict = defaultdict(list)
station_names=[' ' for i in range(len(station_ids))]
if form_input['variable']!= 'multi':
variables = [form_input['variable']]
#evap, wdmv, wesf not fully implemented into Acis_WS yet
if form_input['variable'] in ['evap', 'wdmv', 'wesf']:
print 'Evaporation, wind and water equivalent not implemented yet. Please chose another variable!'
sys.exit(0)
else:
variables = ['pcpn', 'snow', 'snwd', 'maxt', 'mint', 'obst']
#request data on a station by station basis
for i, stn_id in enumerate(station_ids):
if form_input['variable']!= 'multi':
params = dict(sid=stn_id, sdate=s_date, edate=e_date, elems=[dict(name='%s' % form_input['variable'])])
else:
params = dict(sid=stn_id, sdate=s_date, edate=e_date, elems=[dict(name='pcpn'), \
dict(name='snow'), dict(name='snwd'), dict(name='maxt'), dict(name='mint'), dict(name='obst')])
request = StnData(params)
if not request:
request = {'error':'Bad request, check parameters.'}
try:
request['meta']
station_names[i] = request['meta']['name']
except:
station_names[i] = ' '
try:
request['data']
datadict[i] = request['data']
except:
datadict[i]=[]
return datadict, variables, station_ids, station_names