Changeset 2161 in lmdz_wrf


Ignore:
Timestamp:
Oct 4, 2018, 4:27:23 PM (6 years ago)
Author:
lfita
Message:

Fixing `cyclevar_within', assuming independently overpassing cycles

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r2160 r2161  
    23532353    fname = 'index_vec'
    23542354
    2355     vecv = np.array(vec)
    2356 
    2357     valpos = -1
    2358     for i in range(vecv.shape[0]):
    2359         if vecv[i] == val:
    2360             valpos = i
    2361             break
     2355    if type(vec) == type(np.arange(2)):
     2356        valpos = -1
     2357        for i in range(vec.shape[0]):
     2358            if vec[i] == val:
     2359                valpos = i
     2360                break
     2361    elif type(vec) == type(range(2)):
     2362        valpos = vec.index(val)
    23622363
    23632364    return valpos
     
    1406014061    return cycvar[rescyc]
    1406114062
    14062 def cyclevar_within(cycvar,bper, eper, val):
     14063def cyclevar_within(cycvar, bper, eper, val):
    1406314064    """ Function to tell if a given value is within a period of a cycle variable.
    1406414065        A cycle variable is a given structure with a series of values, once the
     
    1406614067        year)
    1406714068      cycvar: array of values
    14068       ind: index to provide the value from
    14069     >>> cyclevar(np.arange(12)+1, 3, 6, 4)
     14069      bper: beginning period
     14070      eper: end period (if eper < bper, assuming period overpassing cycle)
     14071      val: value to look for (if val < bper, assuming value next cycle)
     14072    >>> cyclevar_within(np.arange(12)+1, 3, 6, 4)
    1407014073    True
    14071     >>> cyclevar(np.arange(12)+1, 12, 3, 2)
     14074    >>> cyclevar_within(np.arange(12)+1, 12, 3, 2)
    1407214075    True
    14073     >>> cyclevar(np.arange(12)+1, 12, 3, 5)
     14076    >>> cyclevar_within(np.arange(12)+1, 12, 3, 5)
    1407414077    False
    1407514078    """
     
    1407814081    dcyc = cycvar.shape[0]
    1407914082    # Indices of the beginning and end of the period
     14083    print 'cycvar:', cycvar
     14084    print 'bper:', bper, 'eper:', eper, 'val:', val
     14085
    1408014086    bind = index_vec(cycvar,bper)
    1408114087    eind = index_vec(cycvar,eper)
     
    1408414090    vind = index_vec(cycvar,val)
    1408514091
    14086     if eind < bind:
     14092    print 'bind:', bind, 'eind:', eind, 'vind:', vind
     14093
     14094    if eind < bind:
    1408714095        eind = eind + dcyc
     14096
     14097    if vind < bind:
    1408814098        vind = vind + dcyc
    1408914099
     
    1417614186            ttv = mattimes[it,imat]
    1417714187            timeslice[1] = it
    14178             print it, '.', itt, '|', ttv, 'ip:', ip, 'ep:', ep, '<>', (ttv >= ip and ttv < ep)
    14179             if not (ttv >= ip and ttv < ep):
     14188            print it, '.', itt, '|', ttv, 'ip:', ip, 'ep:', ep, '<>', cyclevar_within(cyctimes, ip, ep, ttv)
     14189            if not (cyclevar_within(cyctimes, ip, ep, ttv)):
    1418014190                slices.append(timeslice)
    1418114191                iit = it + 0
Note: See TracChangeset for help on using the changeset viewer.