Changeset 2161 in lmdz_wrf
- Timestamp:
- Oct 4, 2018, 4:27:23 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r2160 r2161 2353 2353 fname = 'index_vec' 2354 2354 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) 2362 2363 2363 2364 return valpos … … 14060 14061 return cycvar[rescyc] 14061 14062 14062 def cyclevar_within(cycvar, bper, eper, val):14063 def cyclevar_within(cycvar, bper, eper, val): 14063 14064 """ Function to tell if a given value is within a period of a cycle variable. 14064 14065 A cycle variable is a given structure with a series of values, once the … … 14066 14067 year) 14067 14068 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) 14070 14073 True 14071 >>> cyclevar (np.arange(12)+1, 12, 3, 2)14074 >>> cyclevar_within(np.arange(12)+1, 12, 3, 2) 14072 14075 True 14073 >>> cyclevar (np.arange(12)+1, 12, 3, 5)14076 >>> cyclevar_within(np.arange(12)+1, 12, 3, 5) 14074 14077 False 14075 14078 """ … … 14078 14081 dcyc = cycvar.shape[0] 14079 14082 # Indices of the beginning and end of the period 14083 print 'cycvar:', cycvar 14084 print 'bper:', bper, 'eper:', eper, 'val:', val 14085 14080 14086 bind = index_vec(cycvar,bper) 14081 14087 eind = index_vec(cycvar,eper) … … 14084 14090 vind = index_vec(cycvar,val) 14085 14091 14086 if eind < bind: 14092 print 'bind:', bind, 'eind:', eind, 'vind:', vind 14093 14094 if eind < bind: 14087 14095 eind = eind + dcyc 14096 14097 if vind < bind: 14088 14098 vind = vind + dcyc 14089 14099 … … 14176 14186 ttv = mattimes[it,imat] 14177 14187 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)): 14180 14190 slices.append(timeslice) 14181 14191 iit = it + 0
Note: See TracChangeset
for help on using the changeset viewer.