Changeset 2732 in lmdz_wrf for trunk


Ignore:
Timestamp:
Oct 25, 2019, 5:27:18 PM (6 years ago)
Author:
lfita
Message:

Adding:

  • `stations_values': Function to provide information from a given station from one of its values from ASCII file 'OBStations.csv'
  • Adding 'U': unicode into `typemod'
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,add2
     1#station_name,WMOid,longitude,lon_deg,lon_min,lon_sec,latitude,lat_deg,lat_min,lat_sec,height,prov,country,nice_name,add1,add2
    22AEROPARQUE BUENOS AIRES,87582,34.566667,34,34,0.00,58.416667,58,25,0.00,6,CAPITAL FEDERAL,Argentina,Aeroparque Airport Buenos Aires,,
    33BUENOS 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  
    233233# snr_K08: Function to compute the signal-to-noise-ratio after Kendon et al., 2008
    234234# 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'
    235237# stats_Slist: Function to provide extremes from a string as a list separated by a given character
    236238# std_stats2Val: two variables standard Statistics class
     
    58645866        elif typeval == 'str' or typeval == 'S':
    58655867            return str(value)
     5868        elif typeval == 'unicode' or typeval == 'U':
     5869            return value.decode("utf-8", "strict")
    58665870        elif typeval == 'bool':
    58675871            return bool(value)
     
    1725417258
    1725517259    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(' ')
    1725717265
    1725817266    return newlist
    1725917267
    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):
     17268def stations_values(stcrit,stval,Nexpctst='all'):
    1726517269    """ Function to provide information from a given station from one of its values
    1726617270      from ASCII file 'OBStations.csv'
    1726717271    variables_values([values])
    1726817272        [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
    1727217277          [WMOid]: WMO id value
    17273           [station_name]: station raw name
    1727417278          [longitude]: longitude of the station in degrees
    17275           [latitude]: latitude of the stations in degrees
    1727617279          [lon_deg]: longitude degree of the station
    1727717280          [lon_min]: longitude minute of the station
    1727817281          [lon_sec]: longitude second of the station
     17282          [latitude]: latitude of the stations in degrees
    1727917283          [lat_deg]: latitude degree of the station
    1728017284          [lat_min]: latitude mniute of the station
    1728117285          [lat_sec]: latitude second of the station
    1728217286          [height]: height of the station
     17287          [prov]: province/state/...
    1728317288          [country]: country of the station
    17284           [prov]: province/state/...
    1728517289          [nice_name]: Complete nice name of the station
    1728617290          [add1]: additional value 1
    1728717291          [add2]: additional value 2
    1728817292        [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', ' ', ' ']
    1729417307    """
    1729517308    import subprocess as sub
    1729617309    fname='stations_values'
    1729717310
    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']
    1730117316
    1730217317    if stcrit == 'h':
     
    1732417339        quit(-1)
    1732517340    icrit = criteriavail.index(stcrit)
     17341    stv = typemod(stval,stKs[icrit])
     17342    Nst = 0
    1732617343    stations = {}
    17327     Nst = 0
    1732817344    for line in ncf:
    1732917345        if line[0:1] != '#' and len(line) > 10:
     
    1733517351                quit(-1)
    1733617352
    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
    1734617379
    1734717380#quit()
Note: See TracChangeset for help on using the changeset viewer.