Changeset 1918 in lmdz_wrf


Ignore:
Timestamp:
Jun 18, 2018, 4:09:24 PM (7 years ago)
Author:
lfita
Message:

Adding:

  • 'ASCIIfile_stats': Function to provide the statistics of a series of values from an ASCII file
Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic.py

    r1897 r1918  
    2121import re
    2222
     23# ASCIIfile_stats: Function to provide the statistics of a series of values from an ASCII file
    2324# coincident_CFtimes: Function to make coincident times for two different sets of CFtimes
    2425# count_cond: Function to count values of a variable which attain a condition
     
    4950
    5051# List of available operations
    51 operations=['coincident_CFtimes', 'count_cond', 'datetimeStr_conversion',            \
     52operations=['ASCIIfile_stats', 'coincident_CFtimes', 'count_cond',                   \
     53  'datetimeStr_conversion',                                                          \
    5254  'grid_combinations',                                                               \
    5355  'interpolate_locs', 'latex_fig_array', 'list_operations', 'PolyArea',              \
     
    423425        print gen.WRFsetup(vals0, vals1, vals2)
    424426
     427elif oper == 'ASCIIfile_stats':
     428    Nvals = 3
     429    vals = opts.values.split(cS)
     430    if vals[0] == 'h':
     431        print gen.ASCIIfile_stats.__doc__
     432        quit(-1)
     433    else:
     434        if len(vals) != Nvals:
     435            print errormsg
     436            print '  ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \
     437              len(vals), ' has passed!!'
     438            print gen.ASCIIfile_stats.__doc__
     439            quit(-1)
     440        vals0 = vals[0]
     441        vals1 = vals[1]
     442        vals2 = vals[2]
     443       
     444        print gen.ASCIIfile_stats(vals0, vals1, vals2)
     445
  • trunk/tools/generic_tools.py

    r1917 r1918  
    5252# advance_matDate: Function to advance matrix-date with a matrix-increment
    5353# angle_DegMinSec: Function to transform an angle to Degrees Minutes Seconds
     54# ASCIIfile_stats: Function to provide the statistics of a series of values from an ASCII file
    5455# ASCII_HTML: Function to transform from an ASCII line to HTML codification
    5556# ASCII_LaTeX: Function to transform from an ASCII character to LaTeX codification
     
    1326413265    return minNCvalues
    1326513266
     13267def ASCIIfile_stats(filen, comment='#', kind='R'):
     13268    """ Function to provide the statistics of a series of values from an ASCII file
     13269      filen= name of the file
     13270      comment= ':' separated list of comment characters
     13271      kind= kind of values
     13272        'I': integer
     13273        'R': float
     13274        'D': double
     13275    """
     13276    fname = 'ACIIfile_stats'
     13277
     13278    if not os.path.isfile(filen):
     13279        print errormsg
     13280        print '  ' + fname + ": ASCII file '" + filen + "' does not exist !!"
     13281        quit(-1)
     13282
     13283    comments = str_list(comment, ':')
     13284
     13285    objf = open(filen, 'r')
     13286    values = []
     13287    for line in objf:
     13288        linev = line.replace('\n','').replace('\t','').replace('\r','')
     13289        if len(linev) >= 1:
     13290            ch1 = linev[0:1]
     13291            if not searchInlist(comments, ch1):
     13292                print "'" + linev + "'"
     13293                values.append(typemod(linev,kind))
     13294
     13295    objf.close()
     13296
     13297    matv = np.array(values)
     13298    # Statistics
     13299    minv = np.min(matv)
     13300    maxv = np.max(matv)
     13301    meanv = np.mean(matv)
     13302    stdv = np.std(matv)
     13303    quantv = Quantiles(matv, 20)
     13304   
     13305    print "# Statistics of '" + filen + "' _______"
     13306    print '#@# min:', minv
     13307    print '#@# max:', maxv
     13308    print '#@# mean:', meanv
     13309    print '#@# stddev:', stdv
     13310    print '#@# quantiles:', quantv.quantilesv
     13311
     13312    quantS = []
     13313    for iq in quantv.quantilesv: quantS.append(str(iq))
     13314
     13315    print '#@# allvalues; min:' + str(minv) + ';max:' + str(maxv) + ';mean:' +       \
     13316      str(meanv) + ';stddev:' + str(stdv) + ';quant:' + ','.join(quantS)
     13317
     13318    return
     13319
     13320#ASCIIfile_stats('times_NOCDXWRF2.dat')
     13321
    1326613322#quit()
    1326713323
Note: See TracChangeset for help on using the changeset viewer.