Changeset 2160 in lmdz_wrf
- Timestamp:
- Oct 4, 2018, 3:46:14 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r2159 r2160 92 92 # is a given structure with a series of values, once the maximum is overpassed 93 93 # 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) 94 97 # DateTimeStr_date: Function to transform a string date-time ([YYYY][MM][DD][HH][MI][SS] format) to a date object 95 98 # datetimeStr_datetime: Function to transform a string date-time ([YYYY]-[MM]-[DD]_[HH]:[MI]:[SS] format) to a date object … … 14057 14060 return cycvar[rescyc] 14058 14061 14062 def 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 14059 14095 def time_slices(tv, tu, cal, per, amount): 14060 14096 """ Function to return temporal slices of a series of times for a given amount … … 14130 14166 print 'cyctimes:', cyctimes 14131 14167 14168 # First cycle time from first time 14132 14169 iit = 0 14133 itt = 014170 itt = index_vec(cyctimes,mattimes[0,imat]) 14134 14171 ip = cyctimes[itt] 14135 ep = cyc times[itt+amount]14172 ep = cyclevar(cyctimes, itt+amount) 14136 14173 for it in range(dimt): 14137 14174 # timeslice: [ini_slice, end_slice, freq_slice] … … 14139 14176 ttv = mattimes[it,imat] 14140 14177 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) 14142 14179 if not (ttv >= ip and ttv < ep): 14143 14180 slices.append(timeslice) … … 14191 14228 tv = [] 14192 14229 values = [] 14193 totT = 3 65.14194 dT = 100.14230 totT = 30. 14231 dT = 7. 14195 14232 for it in range(0,10): 14196 14233 for itt in range(3): … … 14201 14238 itdim = 0 14202 14239 tu = 'days since 1949-12-01 00:00:00' 14203 per = ' year'14240 per = 'month' 14204 14241 calend = 'standard' 14205 14242 amount = 1
Note: See TracChangeset
for help on using the changeset viewer.