Changeset 2160 in lmdz_wrf


Ignore:
Timestamp:
Oct 4, 2018, 3:46:14 PM (6 years ago)
Author:
lfita
Message:

Adding:

  • `cyclevar_within': Function to tell if a given value is within a period of a cycle variable. A cycle variable is a given structure with a series of values, once the maximum is overpassed it restarts from the beginning (e.g.: 12 months of a year)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r2159 r2160  
    9292#   is a given structure with a series of values, once the maximum is overpassed
    9393#   it restarts from the beginning (e.g.: 12 months of a year)
     94# cyclevar_within: Function to tell if a given value is within a period of a cycle variable.
     95#   A cycle variable is a given structure with a series of values, once the
     96#   maximum is overpassed it restarts from the beginning (e.g.: 12 months of a year)
    9497# DateTimeStr_date: Function to transform a string date-time ([YYYY][MM][DD][HH][MI][SS] format) to a date object
    9598# datetimeStr_datetime: Function to transform a string date-time ([YYYY]-[MM]-[DD]_[HH]:[MI]:[SS] format) to a date object
     
    1405714060    return cycvar[rescyc]
    1405814061
     14062def cyclevar_within(cycvar,bper, eper, val):
     14063    """ Function to tell if a given value is within a period of a cycle variable.
     14064        A cycle variable is a given structure with a series of values, once the
     14065        maximum is overpassed it restarts from the beginning (e.g.: 12 months of a
     14066        year)
     14067      cycvar: array of values
     14068      ind: index to provide the value from
     14069    >>> cyclevar(np.arange(12)+1, 3, 6, 4)
     14070    True
     14071    >>> cyclevar(np.arange(12)+1, 12, 3, 2)
     14072    True
     14073    >>> cyclevar(np.arange(12)+1, 12, 3, 5)
     14074    False
     14075    """
     14076    fname = 'cyclevar_within'
     14077
     14078    dcyc = cycvar.shape[0]
     14079    # Indices of the beginning and end of the period
     14080    bind = index_vec(cycvar,bper)
     14081    eind = index_vec(cycvar,eper)
     14082
     14083    # Index of the value
     14084    vind = index_vec(cycvar,val)
     14085
     14086    if eind < bind:
     14087        eind = eind + dcyc
     14088        vind = vind + dcyc
     14089
     14090    if vind >= bind and vind < eind: within = True
     14091    else: within = False
     14092
     14093    return within
     14094
    1405914095def time_slices(tv, tu, cal, per, amount):
    1406014096    """ Function to return temporal slices of a series of times for a given amount
     
    1413014166        print 'cyctimes:', cyctimes
    1413114167
     14168        # First cycle time from first time
    1413214169        iit = 0
    14133         itt = 0
     14170        itt = index_vec(cyctimes,mattimes[0,imat])
    1413414171        ip = cyctimes[itt]
    14135         ep = cyctimes[itt+amount]
     14172        ep = cyclevar(cyctimes, itt+amount)
    1413614173        for it in range(dimt):
    1413714174            # timeslice: [ini_slice, end_slice, freq_slice]
     
    1413914176            ttv = mattimes[it,imat]
    1414014177            timeslice[1] = it
    14141             print it, ttv, 'ip:', ip, 'ep:', ep, '<>', (ttv >= ip and ttv < ep)
     14178            print it, '.', itt, '|', ttv, 'ip:', ip, 'ep:', ep, '<>', (ttv >= ip and ttv < ep)
    1414214179            if not (ttv >= ip and ttv < ep):
    1414314180                slices.append(timeslice)
     
    1419114228tv = []
    1419214229values = []
    14193 totT = 365.
    14194 dT = 100.
     14230totT = 30.
     14231dT = 7.
    1419514232for it in range(0,10):
    1419614233    for itt in range(3):
     
    1420114238itdim = 0
    1420214239tu = 'days since 1949-12-01 00:00:00'
    14203 per = 'year'
     14240per = 'month'
    1420414241calend = 'standard'
    1420514242amount = 1
Note: See TracChangeset for help on using the changeset viewer.