Changeset 1086 in lmdz_wrf for trunk


Ignore:
Timestamp:
Sep 9, 2016, 12:55:36 PM (9 years ago)
Author:
lfita
Message:

Moving `coincident_CFtimes' from 'drawing_tools.py' to 'generic_tools.py'

Location:
trunk/tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing.py

    r1084 r1086  
    16821682        [colns]= ',' list of color names ('None' for automatic, single value for all the same)
    16831683        [lines]= ',' list of style of lines ('None' for automatic, single value for all the same)
    1684         [points]= ',' list of style of points ('None' for automatic, single value for all the same)
     1684        [points]= '@' list of style of points ('None' for automatic, single value for all the same)
    16851685        [lwdths]= ',' list of withs of lines ('None' for automatic, single value for all the same)
    16861686        [psizes]= ',' list of size of points ('None' for automatic, single value for all the same)
     
    17101710    vartit = values.split(':')[4]
    17111711    title = values.split(':')[5].replace('|',' ')
    1712     locleg = values.split(':')[6]
     1712    locleg = int(values.split(':')[6])
    17131713    colns = gen.str_list(values.split(':')[7], ',')
    17141714    lines = gen.str_list(values.split(':')[8], ',')
    1715     points = gen.str_list(values.split(':')[9], ',')
     1715    points = gen.str_list(values.split(':')[9], '@')
    17161716    lwdths = gen.str_list(values.split(':')[10], ',')
    17171717    psizes = gen.str_list(values.split(':')[11], ',')
     
    18391839        [collines]: ',' list of colors for the lines, None for automatic, single
    18401840          value all the same
    1841         [points]: ',' list of type of points for the lines, None for automatic, single
     1841        [points]: '@' list of type of points for the lines, None for automatic, single
    18421842          value all the same
    18431843        [linewidths]: ',' list of widths for the lines, None for automatic, single
     
    19261926                points.append(points0)
    19271927        else:
    1928             points = points0.split(',')
     1928            points = points0.split('@')
    19291929    elif points0 == 'None':
    19301930        points = None
     
    20342034              "' has any variable '", varname, "' !!"
    20352035            quit(-1)
    2036         if vdobj.units.find('month') != 1:
     2036        if vdobj.units.find('month') != -1:
    20372037            print warnmsg
    2038             print '  ' + fname + ": tranforming time units from 'months' to 'days'!!"
     2038            print '  ' + fname + ": transforming time units from 'months' to 'days'!!"
    20392039            timevals0, tunits0 = gen.CFmonthU_daysU(vdobj[:], vdobj.units)
    20402040        else:
     
    20452045        if ifn > 0:
    20462046# Referring all times to the same reference time!
    2047             reftvals = drw.coincident_CFtimes(timevals0, timeunit, tunits0)
     2047            reftvals = gen.coincident_CFtimes(timevals0, timeunit, tunits0)
    20482048        else:
    20492049            reftvals = timevals0
     
    30463046            print warnmsg
    30473047            print '  ' + fname + ': different time units in the plot!!'
    3048             newtimes = drw.coincident_CFtimes(otim[:], tunits, otim.getncattr('units'))
     3048            newtimes = gen.coincident_CFtimes(otim[:], tunits, otim.getncattr('units'))
    30493049        else:
    30503050            newtimes = otim[:]
     
    44394439
    44404440    # Time axis taking time units in line A as reference
    4441     varvalsaxisB = drw.coincident_CFtimes(timevalsB, tunitsA, tunitsB)
     4441    varvalsaxisB = gen.coincident_CFtimes(timevalsB, tunitsA, tunitsB)
    44424442    trangeB = [np.min(varvalsaxisB), np.max(varvalsaxisB)]
    44434443
  • trunk/tools/drawing_tools.py

    r1077 r1086  
    26342634    return boolv
    26352635
    2636 def coincident_CFtimes(tvalB, tunitA, tunitB):
    2637     """ Function to make coincident times for two different sets of CFtimes
    2638     tvalB= time values B
    2639     tunitA= time units times A to which we want to make coincidence
    2640     tunitB= time units times B
    2641     >>> coincident_CFtimes(np.arange(10),'seconds since 1949-12-01 00:00:00',
    2642       'hours since 1949-12-01 00:00:00')
    2643     [     0.   3600.   7200.  10800.  14400.  18000.  21600.  25200.  28800.  32400.]
    2644     >>> coincident_CFtimes(np.arange(10),'seconds since 1949-12-01 00:00:00',
    2645       'hours since 1979-12-01 00:00:00')
    2646     [  9.46684800e+08   9.46688400e+08   9.46692000e+08   9.46695600e+08
    2647        9.46699200e+08   9.46702800e+08   9.46706400e+08   9.46710000e+08
    2648        9.46713600e+08   9.46717200e+08]
    2649     """
    2650     import datetime as dt
    2651     fname = 'coincident_CFtimes'
    2652 
    2653     tunitA = tunitA.replace('_',' ')
    2654     tunitB = tunitB.replace('_',' ')
    2655 
    2656     trefA = tunitA.split(' ')[2] + ' ' + tunitA.split(' ')[3]
    2657     trefB = tunitB.split(' ')[2] + ' ' + tunitB.split(' ')[3]
    2658     tuA = tunitA.split(' ')[0]
    2659     tuB = tunitB.split(' ')[0]
    2660 
    2661 #    if tuB == 'months':
    2662 #        tvalB, tunitB  = gen.CFmonthU_daysU(tvalB, tunitB)
    2663 #        tuB = tunitB.split(' ')[0]
    2664 
    2665     if tuA != tuB:
    2666         if tuA == 'microseconds':
    2667             if tuB == 'microseconds':
    2668                 tB = tvalB*1.
    2669             elif tuB == 'seconds':
    2670                 tB = tvalB*10.e6
    2671             elif tuB == 'minutes':
    2672                 tB = tvalB*60.*10.e6
    2673             elif tuB == 'hours':
    2674                 tB = tvalB*3600.*10.e6
    2675             elif tuB == 'days':
    2676                 tB = tvalB*3600.*24.*10.e6
    2677             else:
    2678                 print errormsg
    2679                 print '  ' + fname + ": combination of time untis: '" + tuA +        \
    2680                   "' & '" + tuB + "' not ready !!"
    2681                 quit(-1)
    2682         elif tuA == 'seconds':
    2683             if tuB == 'microseconds':
    2684                 tB = tvalB/10.e6
    2685             elif tuB == 'seconds':
    2686                 tB = tvalB*1.
    2687             elif tuB == 'minutes':
    2688                 tB = tvalB*60.
    2689             elif tuB == 'hours':
    2690                 tB = tvalB*3600.
    2691             elif tuB == 'days':
    2692                 tB = tvalB*3600.*24.
    2693             else:
    2694                 print errormsg
    2695                 print '  ' + fname + ": combination of time untis: '" + tuA +        \
    2696                   "' & '" + tuB + "' not ready !!"
    2697                 quit(-1)
    2698         elif tuA == 'minutes':
    2699             if tuB == 'microseconds':
    2700                 tB = tvalB/(60.*10.e6)
    2701             elif tuB == 'seconds':
    2702                 tB = tvalB/60.
    2703             elif tuB == 'minutes':
    2704                 tB = tvalB*1.
    2705             elif tuB == 'hours':
    2706                 tB = tvalB*60.
    2707             elif tuB == 'days':
    2708                 tB = tvalB*60.*24.
    2709             else:
    2710                 print errormsg
    2711                 print '  ' + fname + ": combination of time untis: '" + tuA +        \
    2712                   "' & '" + tuB + "' not ready !!"
    2713                 quit(-1)
    2714         elif tuA == 'hours':
    2715             if tuB == 'microseconds':
    2716                 tB = tvalB/(3600.*10.e6)
    2717             elif tuB == 'seconds':
    2718                 tB = tvalB/3600.
    2719             elif tuB == 'minutes':
    2720                 tB = tvalB/60.
    2721             elif tuB == 'hours':
    2722                 tB = tvalB*1.
    2723             elif tuB == 'days':
    2724                 tB = tvalB*24.
    2725             else:
    2726                 print errormsg
    2727                 print '  ' + fname + ": combination of time untis: '" + tuA +        \
    2728                   "' & '" + tuB + "' not ready !!"
    2729                 quit(-1)
    2730         elif tuA == 'days':
    2731             if tuB == 'microseconds':
    2732                 tB = tvalB/(24.*3600.*10.e6)
    2733             elif tuB == 'seconds':
    2734                 tB = tvalB/(24.*3600.)
    2735             elif tuB == 'minutes':
    2736                 tB = tvalB/(24.*60.)
    2737             elif tuB == 'hours':
    2738                 tB = tvalB/24.
    2739             elif tuB == 'days':
    2740                 tB = tvalB*1.
    2741             else:
    2742                 print errormsg
    2743                 print '  ' + fname + ": combination of time untis: '" + tuA +        \
    2744                   "' & '" + tuB + "' not ready !!"
    2745                 quit(-1)
    2746         else:
    2747             print errormsg
    2748             print '  ' + fname + ": time untis: '" + tuA + "' not ready !!"
    2749             quit(-1)
    2750     else:
    2751         tB = tvalB*1.
    2752 
    2753     if trefA != trefB:
    2754         trefTA = dt.datetime.strptime(trefA, '%Y-%m-%d %H:%M:%S')
    2755         trefTB = dt.datetime.strptime(trefB, '%Y-%m-%d %H:%M:%S')
    2756 
    2757         difft = trefTB - trefTA
    2758         diffv = difft.days*24.*3600.*10.e6 + difft.seconds*10.e6 + difft.microseconds
    2759         print '  ' + fname + ': different reference refA:',trefTA,'refB',trefTB
    2760         print '    difference:',difft,':',diffv,'microseconds'
    2761 
    2762         if tuA == 'microseconds':
    2763             tB = tB + diffv
    2764         elif tuA == 'seconds':
    2765             tB = tB + diffv/10.e6
    2766         elif tuA == 'minutes':
    2767             tB = tB + diffv/(60.*10.e6)
    2768         elif tuA == 'hours':
    2769             tB = tB + diffv/(3600.*10.e6)
    2770         elif tuA == 'days':
    2771             tB = tB + diffv/(24.*3600.*10.e6)
    2772         else:
    2773             print errormsg
    2774             print '  ' + fname + ": time untis: '" + tuA + "' not ready !!"
    2775             quit(-1)
    2776 
    2777     return tB
    2778 
    27792636####### ###### ##### #### ### ## #
    27802637
     
    57995656                print '  ' + fname + ': number of provided colors:', Ncols,          \
    58005657                  'and required:', Nstyles,'differ !!'
     5658                print '    provided:', colors
    58015659                quit(-1)
    58025660            usecolors = colors
     
    58195677                print '  ' + fname + ': number of provided lines:', Nklns,           \
    58205678                  'and required:', Nstyles,'differ !!'
     5679                print '    provided:', lines
    58215680                quit(-1)
    58225681            uselines = lines
     
    58395698                print '  ' + fname + ': number of provided points:', Nkpts,          \
    58405699                  'and required:', Nstyles,'differ !!'
     5700                print '    provided:', points
    58415701                quit(-1)
    58425702            usepoints = points
     
    58595719                print '  ' + fname + ': number of provided line widthss:', Nwlns,    \
    58605720                  'and required:', Nstyles, 'differ !!'
     5721                print '    provided:', lwidths
    58615722                quit(-1)
    58625723            usewlines = lwidths
     
    58795740                print '  ' + fname + ': number of provided point sizes:', Nspts,     \
    58805741                  'and required:', Nstyles, 'differ !!'
     5742                print '    provided:', psizes
    58815743                quit(-1)
    58825744            usespoints = psizes
  • trunk/tools/generic_tools.py

    r1076 r1086  
    3333# chainSnum_levnext: Function to provide the next value for a given level from a chainStrnum hirerarchy of numbers
    3434# chainSnum_num: Function to pass a `ChainStrNum' string to a number
     35# coincident_CFtimes: Function to make coincident times for two different sets of CFtimes
    3536# coldec_hex: Function to pas a decimal ([r,g,b]; [0.,1.]) color to hexadecimal (#[RR][GG][BB], 00-64, 0A-FF)
    3637# colhex_dec: Function to pas a hexadecimal (#[RR][GG][BB]; 00-64, 0A-FF) color to decimal ([0.,1.])
     
    84518452    return diffs, Bdiff
    84528453
     8454
     8455def coincident_CFtimes(tvalB, tunitA, tunitB):
     8456    """ Function to make coincident times for two different sets of CFtimes
     8457    tvalB= time values B
     8458    tunitA= time units times A to which we want to make coincidence
     8459    tunitB= time units times B
     8460    >>> coincident_CFtimes(np.arange(10),'seconds since 1949-12-01 00:00:00',
     8461      'hours since 1949-12-01 00:00:00')
     8462    [     0.   3600.   7200.  10800.  14400.  18000.  21600.  25200.  28800.  32400.]
     8463    >>> coincident_CFtimes(np.arange(10),'seconds since 1949-12-01 00:00:00',
     8464      'hours since 1979-12-01 00:00:00')
     8465    [  9.46684800e+08   9.46688400e+08   9.46692000e+08   9.46695600e+08
     8466       9.46699200e+08   9.46702800e+08   9.46706400e+08   9.46710000e+08
     8467       9.46713600e+08   9.46717200e+08]
     8468    """
     8469    import datetime as dt
     8470    fname = 'coincident_CFtimes'
     8471
     8472    tunitA = tunitA.replace('_',' ')
     8473    tunitB = tunitB.replace('_',' ')
     8474
     8475    trefA = tunitA.split(' ')[2] + ' ' + tunitA.split(' ')[3]
     8476    trefB = tunitB.split(' ')[2] + ' ' + tunitB.split(' ')[3]
     8477    tuA = tunitA.split(' ')[0]
     8478    tuB = tunitB.split(' ')[0]
     8479
     8480#    if tuB == 'months':
     8481#        tvalB, tunitB  = gen.CFmonthU_daysU(tvalB, tunitB)
     8482#        tuB = tunitB.split(' ')[0]
     8483
     8484    if tuA != tuB:
     8485        if tuA == 'microseconds':
     8486            if tuB == 'microseconds':
     8487                tB = tvalB*1.
     8488            elif tuB == 'seconds':
     8489                tB = tvalB*10.e6
     8490            elif tuB == 'minutes':
     8491                tB = tvalB*60.*10.e6
     8492            elif tuB == 'hours':
     8493                tB = tvalB*3600.*10.e6
     8494            elif tuB == 'days':
     8495                tB = tvalB*3600.*24.*10.e6
     8496            else:
     8497                print errormsg
     8498                print '  ' + fname + ": combination of time untis: '" + tuA +        \
     8499                  "' & '" + tuB + "' not ready !!"
     8500                quit(-1)
     8501        elif tuA == 'seconds':
     8502            if tuB == 'microseconds':
     8503                tB = tvalB/10.e6
     8504            elif tuB == 'seconds':
     8505                tB = tvalB*1.
     8506            elif tuB == 'minutes':
     8507                tB = tvalB*60.
     8508            elif tuB == 'hours':
     8509                tB = tvalB*3600.
     8510            elif tuB == 'days':
     8511                tB = tvalB*3600.*24.
     8512            else:
     8513                print errormsg
     8514                print '  ' + fname + ": combination of time untis: '" + tuA +        \
     8515                  "' & '" + tuB + "' not ready !!"
     8516                quit(-1)
     8517        elif tuA == 'minutes':
     8518            if tuB == 'microseconds':
     8519                tB = tvalB/(60.*10.e6)
     8520            elif tuB == 'seconds':
     8521                tB = tvalB/60.
     8522            elif tuB == 'minutes':
     8523                tB = tvalB*1.
     8524            elif tuB == 'hours':
     8525                tB = tvalB*60.
     8526            elif tuB == 'days':
     8527                tB = tvalB*60.*24.
     8528            else:
     8529                print errormsg
     8530                print '  ' + fname + ": combination of time untis: '" + tuA +        \
     8531                  "' & '" + tuB + "' not ready !!"
     8532                quit(-1)
     8533        elif tuA == 'hours':
     8534            if tuB == 'microseconds':
     8535                tB = tvalB/(3600.*10.e6)
     8536            elif tuB == 'seconds':
     8537                tB = tvalB/3600.
     8538            elif tuB == 'minutes':
     8539                tB = tvalB/60.
     8540            elif tuB == 'hours':
     8541                tB = tvalB*1.
     8542            elif tuB == 'days':
     8543                tB = tvalB*24.
     8544            else:
     8545                print errormsg
     8546                print '  ' + fname + ": combination of time untis: '" + tuA +        \
     8547                  "' & '" + tuB + "' not ready !!"
     8548                quit(-1)
     8549        elif tuA == 'days':
     8550            if tuB == 'microseconds':
     8551                tB = tvalB/(24.*3600.*10.e6)
     8552            elif tuB == 'seconds':
     8553                tB = tvalB/(24.*3600.)
     8554            elif tuB == 'minutes':
     8555                tB = tvalB/(24.*60.)
     8556            elif tuB == 'hours':
     8557                tB = tvalB/24.
     8558            elif tuB == 'days':
     8559                tB = tvalB*1.
     8560            else:
     8561                print errormsg
     8562                print '  ' + fname + ": combination of time untis: '" + tuA +        \
     8563                  "' & '" + tuB + "' not ready !!"
     8564                quit(-1)
     8565        else:
     8566            print errormsg
     8567            print '  ' + fname + ": time untis: '" + tuA + "' not ready !!"
     8568            quit(-1)
     8569    else:
     8570        tB = tvalB*1.
     8571
     8572    if trefA != trefB:
     8573        trefTA = dt.datetime.strptime(trefA, '%Y-%m-%d %H:%M:%S')
     8574        trefTB = dt.datetime.strptime(trefB, '%Y-%m-%d %H:%M:%S')
     8575
     8576        difft = trefTB - trefTA
     8577        diffv = difft.days*24.*3600.*10.e6 + difft.seconds*10.e6 + difft.microseconds
     8578        print '  ' + fname + ': different reference refA:',trefTA,'refB',trefTB
     8579        print '    difference:',difft,':',diffv,'microseconds'
     8580
     8581        if tuA == 'microseconds':
     8582            tB = tB + diffv
     8583        elif tuA == 'seconds':
     8584            tB = tB + diffv/10.e6
     8585        elif tuA == 'minutes':
     8586            tB = tB + diffv/(60.*10.e6)
     8587        elif tuA == 'hours':
     8588            tB = tB + diffv/(3600.*10.e6)
     8589        elif tuA == 'days':
     8590            tB = tB + diffv/(24.*3600.*10.e6)
     8591        else:
     8592            print errormsg
     8593            print '  ' + fname + ": time untis: '" + tuA + "' not ready !!"
     8594            quit(-1)
     8595
     8596    return tB
     8597
    84538598#quit()
    84548599
Note: See TracChangeset for help on using the changeset viewer.