當前位置: 首頁>>代碼示例>>Python>>正文


Python WRCCUtils.strip_n_sort方法代碼示例

本文整理匯總了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
開發者ID:bdaudert,項目名稱:my-python-lib,代碼行數:55,代碼來源:AcisWS.py


注:本文中的WRCCUtils.strip_n_sort方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。