当前位置: 首页>>代码示例>>Python>>正文


Python WRCCUtils.get_dates方法代码示例

本文整理汇总了Python中WRCCUtils.get_dates方法的典型用法代码示例。如果您正苦于以下问题:Python WRCCUtils.get_dates方法的具体用法?Python WRCCUtils.get_dates怎么用?Python WRCCUtils.get_dates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WRCCUtils的用法示例。


在下文中一共展示了WRCCUtils.get_dates方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_sod_data

# 需要导入模块: import WRCCUtils [as 别名]
# 或者: from WRCCUtils import get_dates [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)
    variables = WRCCUtils.get_variable_list(form_input, program)
    els = [dict(name='%s' % el) for el in variables]
    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 variables]
            #yr_list = [[['#', '#', '#', '#', '#', '#','#', '#'] for k in range(366)] for i in range(3*len(variables))]
            #datadict[i] = yr_list
            datadict[i] = []
        elif program in ['Sodrun', 'Sodrunr']:
            datadict[i] = []
        else:
            datadict[i] = [[] for el in variables]

    if program == 'Soddyrec':
        smry_opts = [{'reduce':'mean', 'add':'date,mcnt'}, {'reduce':'max', 'add':'date,mcnt'}, {'reduce':'min', 'add':'date,mcnt'}]
        elts = []
        for el in variables:
            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 variables])
        elems=[dict(vX=WRCCData.ACIS_ELEMENTS_DICT[el]['vX'],interval='dly',duration='dly',groupby='year') for el in variables])
    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 variables])
        elems=[dict(vX=WRCCData.ACIS_ELEMENTS_DICT[el]['vX'],add='t') for el in variables])
    else:
        params = dict(sids=station_ids, sdate=s_date, edate=e_date, \
        #elems=[dict(name=el)for el in variables])
        elems=[dict(vX=WRCCData.ACIS_ELEMENTS_DICT[el]['vX']) for el in variables])
    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, variables, station_ids, station_names
            #sys.exit(1)
        else:
            #Unknown error ocurred when getting data
            #sys.exit(1)
            return datadict, dates, variables, 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
#.........这里部分代码省略.........
开发者ID:bdaudert,项目名称:my-python-lib,代码行数:103,代码来源:AcisWS.py


注:本文中的WRCCUtils.get_dates方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。