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)
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
def run_station_finder(self, form_cleaned): vX_list = [] for el_idx, element in enumerate(form_cleaned["elements"]): el, base_temp = WRCCUtils.get_el_and_base_temp(element) 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["elements_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
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 variables = WRCCUtils.get_variable_list(form_input, program) elems_list = [] elems_list_short = [] resultsdict = {} for el in variables: 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 vd, no_vd_els = WRCCUtils.find_valid_daterange(sid, start_date=s, end_date=e, el_list=l, max_or_min='max') params['sdate'] = v[0]; params['edate'] = v[1] if params['sdate'] == '9999-99-99' or params['edate'] == '9999-99-99': 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