- Timestamp:
- Oct 25, 2019, 5:27:18 PM (6 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/OBSstations.csv
r2731 r2732 1 # WMOid,station_name,longitude,latitude,lon_deg,lon_min,lon_sec,lat_deg,lat_min,lat_sec,height,country,prov,nice_name,add1,add21 #station_name,WMOid,longitude,lon_deg,lon_min,lon_sec,latitude,lat_deg,lat_min,lat_sec,height,prov,country,nice_name,add1,add2 2 2 AEROPARQUE BUENOS AIRES,87582,34.566667,34,34,0.00,58.416667,58,25,0.00,6,CAPITAL FEDERAL,Argentina,Aeroparque Airport Buenos Aires,, 3 3 BUENOS AIRES,87585,34.583333,34,35,0.00,58.483333,58,29,0.00,25,CAPITAL FEDERAL,Argentina,Buenos Aires,, -
trunk/tools/generic_tools.py
r2730 r2732 233 233 # snr_K08: Function to compute the signal-to-noise-ratio after Kendon et al., 2008 234 234 # stagger_unstagger: Function to de-stagger a variable 235 # stations_values: Function to provide information from a given station from one of its values 236 # from ASCII file 'OBStations.csv' 235 237 # stats_Slist: Function to provide extremes from a string as a list separated by a given character 236 238 # std_stats2Val: two variables standard Statistics class … … 5864 5866 elif typeval == 'str' or typeval == 'S': 5865 5867 return str(value) 5868 elif typeval == 'unicode' or typeval == 'U': 5869 return value.decode("utf-8", "strict") 5866 5870 elif typeval == 'bool': 5867 5871 return bool(value) … … 17254 17258 17255 17259 newlist = [] 17256 for iv in range(Nin): newlist.append(typemod(inlist[iv], Klist[iv])) 17260 for iv in range(Nin): 17261 if len(inlist[iv]) > 0: 17262 newlist.append(typemod(inlist[iv], Klist[iv])) 17263 else: 17264 newlist.append(' ') 17257 17265 17258 17266 return newlist 17259 17267 17260 print list_listKs(['2.2333', 'Hola', '231.21', '231.21'], ['F', 'S', 'F-I', 'D']) 17261 17262 quit() 17263 17264 def stations_values(stcrit,stval): 17268 def stations_values(stcrit,stval,Nexpctst='all'): 17265 17269 """ Function to provide information from a given station from one of its values 17266 17270 from ASCII file 'OBStations.csv' 17267 17271 variables_values([values]) 17268 17272 [stcrit]: name of the criteria from OBStations.csv 17269 one of: 'WMOid', 'station_name', 'longitude', 'latitude', 'lon_deg', 17270 'lon_min', 'lon_sec', 'lat_deg', 'lat_min', 'lat_sec', 'height', 'country', 17271 'prov', 'nice_name', 'add1', 'add2' 17273 one of: 'station_name', 'WMOid', 'longitude', 'lon_deg', 'lon_min', 17274 'lon_sec', 'latitude', 'lat_deg', 'lat_min', 'lat_sec', 'height', 17275 'prov', 'country', 'nice_name', 'add1', 'add2' 17276 [station_name]: station raw name 17272 17277 [WMOid]: WMO id value 17273 [station_name]: station raw name17274 17278 [longitude]: longitude of the station in degrees 17275 [latitude]: latitude of the stations in degrees17276 17279 [lon_deg]: longitude degree of the station 17277 17280 [lon_min]: longitude minute of the station 17278 17281 [lon_sec]: longitude second of the station 17282 [latitude]: latitude of the stations in degrees 17279 17283 [lat_deg]: latitude degree of the station 17280 17284 [lat_min]: latitude mniute of the station 17281 17285 [lat_sec]: latitude second of the station 17282 17286 [height]: height of the station 17287 [prov]: province/state/... 17283 17288 [country]: country of the station 17284 [prov]: province/state/...17285 17289 [nice_name]: Complete nice name of the station 17286 17290 [add1]: additional value 1 17287 17291 [add2]: additional value 2 17288 17292 [stval]: value of [stcrit] to be matched 17289 return: [WMOid], [station_name], [longitude], [latitude], [lon_deg], 17290 [lon_min], [lon_sec], [lat_deg], [lat_min], [lat_sec], [height], [country], 17291 [prov], [nice_name], [add1], [add2] 17292 >>> variables_values('WMOid','87582') 17293 17293 [Nexpctst]: expected quantity of stations to retrieve 17294 'all': all matching entries. It will return a dictionary 17295 'one': only one entry. It will return a list 17296 return: [station_name], [WMOid], [longitude], [lon_deg], [lon_min], [lon_sec], 17297 [latitude], [lat_deg], [lat_min], [lat_sec], [height], [prov], [country], 17298 [nice_name], [add1], [add2] 17299 >>> stations_values('WMOid','87582','all') 17300 {0: ['AEROPARQUE BUENOS AIRES', 87582, 34.566667, 34, 34, 0.0, 58.416667, 58, 17301 25, 0.0, 6.0, u'CAPITAL FEDERAL', u'Argentina', 17302 u'Aeroparque Airport Buenos Aires', ' ', ' ']} 17303 >>> stations_values('WMOid','87582','one') 17304 ['AEROPARQUE BUENOS AIRES', 87582, 34.566667, 34, 34, 0.0, 58.416667, 58, 17305 25, 0.0, 6.0, u'CAPITAL FEDERAL', u'Argentina', 17306 u'Aeroparque Airport Buenos Aires', ' ', ' '] 17294 17307 """ 17295 17308 import subprocess as sub 17296 17309 fname='stations_values' 17297 17310 17298 criteriavail = ['WMOid', 'station_name', 'longitude', 'latitude', 'lon_deg', \ 17299 'lon_min', 'lon_sec', 'lat_deg', 'lat_min', 'lat_sec', 'height', 'country',\ 17300 'prov', 'nice_name', 'add1', 'add2'] 17311 criteriavail = ['station_name', 'WMOid', 'longitude', 'lon_deg', 'lon_min', \ 17312 'lon_sec', 'latitude', 'lat_deg', 'lat_min', 'lat_sec', 'height', 'prov', \ 17313 'country', 'nice_name', 'add1', 'add2'] 17314 stKs = ['S', 'I', 'F', 'I', 'I', 'F', 'F', 'I', 'I', 'F', 'F', 'U', 'U', 'U', \ 17315 'U', 'U'] 17301 17316 17302 17317 if stcrit == 'h': … … 17324 17339 quit(-1) 17325 17340 icrit = criteriavail.index(stcrit) 17341 stv = typemod(stval,stKs[icrit]) 17342 Nst = 0 17326 17343 stations = {} 17327 Nst = 017328 17344 for line in ncf: 17329 17345 if line[0:1] != '#' and len(line) > 10: … … 17335 17351 quit(-1) 17336 17352 17337 if values[icrit] == stval: 17338 stations[Nst] = [int(values[0]), values[1]] 17339 17340 print errormsg 17341 print ' ' + fname + ": variable '" + varn + "' not defined !!!" 17342 ncf.close() 17343 quit(-1) 17344 17345 return 17353 stvalues = list_listKs(values, stKs) 17354 print stvalues[icrit], stv, stvalues[icrit] == stv 17355 if stvalues[icrit] == stv: 17356 stations[Nst] = stvalues 17357 Nst = Nst + 1 17358 17359 if Nst == 0: 17360 print errormsg 17361 print ' ' + fname + ": station with criteria '" + stcrit + "'= '", stval, \ 17362 "' not found !!!" 17363 ncf.close() 17364 quit(-1) 17365 17366 if Nexpctst == 'all': return stations 17367 else: 17368 if Nst > 1: 17369 print errormsg 17370 print ' ' + fname + ': too many stations found ', Nst, '!!' 17371 print ' ', Nst, 'stations found _______' 17372 printing_dictionary(stations) 17373 else: 17374 stfound = stations[0] 17375 return stfound 17376 17377 17378 return stations 17346 17379 17347 17380 #quit()
Note: See TracChangeset
for help on using the changeset viewer.