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


Python WRCCUtils類代碼示例

本文整理匯總了Python中WRCCUtils的典型用法代碼示例。如果您正苦於以下問題:Python WRCCUtils類的具體用法?Python WRCCUtils怎麽用?Python WRCCUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了WRCCUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: set_min_max_dates

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
開發者ID:,項目名稱:,代碼行數:33,代碼來源:

示例2: station_invalid

    def station_invalid(el_list, vX_list, time_range, stn, contraints):
        #Check if constraints are met for element list and date range
        if constraints in ['any_any', 'any_all']:
            flag_invalid_station = True
        elif constraints in ['all_all', 'all_any']:
            flag_invalid_station = False

        for el_idx, el_vX in enumerate(el_list):
            #Find correct index in vX_list
            try:
                idx = vX_list.index(el_vX)
            except:
                if constraints in ['all_all', 'all_any']:
                    flag_invalid_station = True
                    break
                elif constraints in ['any_any', 'any_all']:
                    continue
            #Sanity Check
            if not stn['valid_daterange'][idx] and (constraints == 'all_all'  or constraints == 'all_any' or constraints is None):
                #data for this element does not exist at station
                flag_invalid_station = True
                break
            elif not stn['valid_daterange'][idx] and (constraints == 'any_any' or constraints == 'any_all'):
                continue

            #Find period of record for this element and station
            por_start = WRCCUtils.date_to_datetime(stn['valid_daterange'][idx][0])
            por_end = WRCCUtils.date_to_datetime(stn['valid_daterange'][idx][1])
            if time_range[0].lower() != 'por':
                user_start = WRCCUtils.date_to_datetime(time_range[0])
            else:
                user_start = por_start
            if time_range[1].lower() != 'por':
                user_end = WRCCUtils.date_to_datetime(time_range[1])
            else:
                user_end = por_end
            #Check constraints logic for this element and station
            if constraints == 'all_all' or constraints is None:
                #all  elements have data records for all dates within start and end date given by user
                if user_start < por_start or user_end > por_end:
                    flag_invalid_station =  True
                    break
            elif constraints == 'any_any':
                #At least one element has one data record within user given time_range
                if (user_end >= por_start and user_start <= por_end) or (user_start <= por_end and user_end >=por_start):
                    flag_invalid_station = False
                    break
            elif constraints == 'all_any':
                #All elements have at least one data record within user given time_range
                if (user_end >= por_start and user_start <= por_end) or (user_start <= por_end and user_end >=por_start):
                    continue
                else:
                    flag_invalid_station =  True
                    break
            elif constraints == 'any_all':
                #At least one elements has data records for all dates within given date_range
                if user_start >= por_start and user_end <= por_end:
                    flag_invalid_station = False
                    break
        return flag_invalid_station
開發者ID:,項目名稱:,代碼行數:60,代碼來源:

示例3: set_min_max_dates

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
開發者ID:bdaudert,項目名稱:my-python-lib,代碼行數:35,代碼來源:DJANGOUtils.py

示例4: get_sodsum_data

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,代碼行數:53,代碼來源:AcisWS.py

示例5: stn_in_poly

 def stn_in_poly(by_type, shape_type, shape,stn_meta):
     #convert to floats
     s = [float(s) for s in shape]
     if shape_type == 'circle':
         poly = s
         stn_in = WRCCUtils.point_in_circle(stn_meta['ll'][0], stn_meta['ll'][1], poly)
     else:
         if shape_type in ['bbox','location']:
             poly = [(s[0],s[1]), (s[0],s[3]),(s[2],s[3]),(s[2],s[1])]
         else:
             poly = [(s[2*idx],s[2*idx+1]) for idx in range(len(s)/2)]
         stn_in = WRCCUtils.point_in_poly(stn_meta['ll'][0], stn_meta['ll'][1], poly)
     if not stn_in:return False
     else:return True
開發者ID:bdaudert,項目名稱:my-python-lib,代碼行數:14,代碼來源:AcisWS.py

示例6: check_end_window

def check_end_window(form):
    #Backbutton sanity check
    if 'start_window' not in form.keys() or 'end_window' not in form.keys():
        return 'Start and/or End Window field not valid. You may have pressed the backbutton. Please reset the windowed data button.'
    err = None
    s_w = form['start_window'].replace('-','').replace('/','').replace(':','')
    e_w = form['end_window'].replace('-','').replace('/','').replace(':','')
    if len(e_w) != 4:
        return 'Start Window must be of form mmdd/mm-dd or mm:dd. You entered %s' % form['start_window']
    mm = e_w[0:2]
    dd= e_w[2:4]
    #Check month
    if int(mm) < 1 or int(mm) > 12:
        return 'Not a valid month.'
    #Check day
    if int(dd) < 1 or int(dd) > 31:
        return 'Not a valid day.'
    ml = WRCCData.MONTH_LENGTHS[int(mm) - 1]
    if int(dd) > ml:
        if mm == '02' and dd == '29':
            if 'end_date' in form.keys() and WRCCUtils.is_leap_year(form['end_date'][0:4]):
                return err
            else:
                return 'Month %s only has %s days. You entered: %s' %(WRCCData.NUMBER_TO_MONTH_NAME[mm],ml,dd)
        else:
            return 'Month %s only has %s days. You entered: %s' %(WRCCData.NUMBER_TO_MONTH_NAME[mm],ml,dd)
    return err
開發者ID:bdaudert,項目名稱:my-python-lib,代碼行數:27,代碼來源:WRCCFormCheck.py

示例7: create_kml_file

def create_kml_file(area_type, overlay_state):
    kml_file_name = overlay_state + '_' + area_type + '.kml'
    kml_file_path = settings.TMP_URL +  kml_file_name
    status = WRCCUtils.generate_kml_file(area_type, overlay_state, kml_file_name, settings.TEMP_DIR)
    if status != 'Success':
        return 'ERROR: ' + status
    return kml_file_path
開發者ID:,項目名稱:,代碼行數:7,代碼來源:

示例8: set_wrapper_params

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 []
開發者ID:,項目名稱:,代碼行數:9,代碼來源:

示例9: test_find_id_and_name

 def test_find_id_and_name(self):
     for area_type, area_val in self.test_areas.iteritems():
         if area_type in ['station_id','basin','county','county_warning_area','climate_division']:
             json_file_path = '/www/apps/csc/dj-projects/my_acis/media/json/US_' + area_type + '.json'
             ID, name = WRCCUtils.find_id_and_name(area_val, json_file_path)
             try:
                 self.assertNotEqual('ID','')
             except AssertionError as err:
                 logger.error('AssertionError' + str(err))
開發者ID:bdaudert,項目名稱:my-python-lib,代碼行數:9,代碼來源:UnitTestSCENIC.py

示例10: test_get_el_and_base_temp

 def test_get_el_and_base_temp(self):
     for unit in self.units:
         for el in self.variables:
             el, base_temp = WRCCUtils.get_el_and_base_temp(el,units=unit)
             self.assertIsInstance(el, basestring)
             self.assertIn(el,WRCCData.ACIS_ELEMENTS_DICT.keys())
             try:
                 int(base_temp)
             except:
                 self.assertEqual(base_temp,None)
開發者ID:bdaudert,項目名稱:my-python-lib,代碼行數:10,代碼來源:UnitTestSCENIC.py

示例11: run_multi_lister

 def run_multi_lister(self,params):
     results = {};err = None
     initial, err = self.setInitial(params)
     if err is not None:return results, err
     form, err = self.setForm(initial)
     if err is not None:return results, err
     form_cleaned, err = self.setFormCleaned(initial)
     if err is not None:return results, err
     try:
         results = WRCCUtils.request_and_format_data(form_cleaned)
     except Exception, e:
         err = 'FAIL request_and_format_data. ERROR: ' + str(e) + ' PARAMS: ' + str(params)
         return results, err
開發者ID:bdaudert,項目名稱:my-python-lib,代碼行數:13,代碼來源:FunctionalTestSCENIC.py

示例12: test_find_ids_and_names

 def test_find_ids_and_names(self):
     area_type = 'station_ids'
     area_val = self.test_areas[area_type]
     json_file_path = '/www/apps/csc/dj-projects/my_acis/media/json/US_station_id.json'
     IDs, names = WRCCUtils.find_ids_and_names(area_val, json_file_path)
     try:
         self.assertIsInstance(IDs, str)
     except AssertionError as err:
         logger.error('AssertionError' + str(err))
     try:
         self.assertNotEqual(IDs.split(','),[])
     except AssertionError as err:
         logger.error('AssertionError' + str(err))
開發者ID:bdaudert,項目名稱:my-python-lib,代碼行數:13,代碼來源:UnitTestSCENIC.py

示例13: run_seasonal_summary

 def run_seasonal_summary(self,params):
     results = {};err = None
     initial, err = self.setInitial(params)
     if err is not None:return results, err
     form, err = self.setForm(initial)
     if err is not None:return results, err
     form_cleaned, err = self.setFormCleaned(initial)
     if err is not None:return results, err
     try:
         year_data, hc_data = WRCCUtils.get_single_seasonal_summary_data(form_cleaned)
     except Exception, e:
         err = 'FAIL get_single_seasonal_summary_data. ERROR: ' + \
         str(e) + ' PARAMS: ' + str(params)
         return results, err
開發者ID:bdaudert,項目名稱:my-python-lib,代碼行數:14,代碼來源:FunctionalTestSCENIC.py

示例14: run_station_finder

    def run_station_finder(self, form_cleaned):
        vX_list = []
        for el_idx, variable in enumerate(form_cleaned['variables']):
            el,base_temp = WRCCUtils.get_el_and_base_temp(variable)
            vX_list.append(str(WRCCData.ACIS_ELEMENTS_DICT[el]['vX']))

        by_type = WRCCData.ACIS_TO_SEARCH_AREA[form_cleaned['area_type']]
        val = form_cleaned[WRCCData.ACIS_TO_SEARCH_AREA[form_cleaned['area_type']]]
        dr = [form_cleaned['start_date'],form_cleaned['end_date']]
        ec = form_cleaned['variables_constraints']
        dc = form_cleaned['dates_constraints']
        edc  = ec + '_' + dc
        station_json, f_name = AcisWS.station_meta_to_json(by_type, val, el_list=vX_list,time_range=dr, constraints=edc)
        return station_json, f_name
開發者ID:bdaudert,項目名稱:my-python-lib,代碼行數:14,代碼來源:FunctionalTestSCENIC.py

示例15: run_single_year

 def run_single_year(self,params):
     results = {};err = None
     initial, err = self.setInitial(params)
     if err is not None:return results, err
     form, err = self.setForm(initial)
     if err is not None:return results, err
     form_cleaned, err = self.setFormCleaned(initial)
     if err is not None:return results, err
     try:
         year_txt_data, year_graph_data, climoData, percentileData =\
         WRCCUtils.get_single_single_year_data(form_cleaned)
     except Exception, e:
         err = 'FAIL get_single_intraanual_data. ERROR: ' + \
         str(e) + ' PARAMS: ' + str(params)
         return results, err
開發者ID:bdaudert,項目名稱:my-python-lib,代碼行數:15,代碼來源:FunctionalTestSCENIC.py


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