Changeset 2230 in lmdz_wrf


Ignore:
Timestamp:
Nov 14, 2018, 9:47:26 PM (6 years ago)
Author:
lfita
Message:

Working version with 'aggregation' of `time_slices'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r2229 r2230  
    1461914619        if timesec != 'season':
    1462014620            for it in range(dimt):
    14621                 if timesec == 'year': print it, ':', mattimes[it,:]
    1462214621                for tvv in tvals:
    1462314622                    if mattimes[it,itsec] == tvv:
     
    1464614645                        tvsec[tvv] = vvv
    1464714646                        break
    14648                 print it, 'Lluis:', mattimes[it,:], tvv, mattimes[it,1]
    1464914647               
    1465014648        temporal_desc[timesec]=tvsec
     
    1469314691        quit(-1)
    1469414692
    14695 
    1469614693    mattimes = CFtimesvar_datetime(tv, tu, cal)
    1469714694
     
    1493114928        pern = per[3:Lper]
    1493214929        vtemp_desc = temp_desc[pern]
    14933         print vtemp_desc
    1493414930        vvtdesc = list(vtemp_desc.keys())
    1493514931        vvtdesc.sort()
     
    1493914935        for islc in range(Nslices):
    1494014936            vvtemp_desc = vtemp_desc[vvtdesc[islc]]
    14941             print 'islc,', islc, 'vtemp:', vvtemp_desc
    1494214937            Ltt = len(vvtemp_desc)
    1494314938            slices.append(vvtemp_desc)
     
    1497514970    return slices, Nslices
    1497614971
    14977 tv = []
    14978 values = []
    14979 totT = 24.
    14980 dT = 7.345
    14981 iTT = 29.
    14982 for it in range(0,10):
    14983    for itt in range(3):
    14984         days = iTT+it*totT+dT*itt
    14985         tv.append(days)
    14986         #values.append((it*3+itt)*1.)
    14987         Nyear = int((days-31)/365)
    14988         dyear = (days-31) - Nyear*365
    14989         if dyear < 59:
    14990             values.append(0.)
    14991         elif dyear >= 59 and dyear < 151:
    14992             values.append(1.)
    14993         elif dyear >= 151 and dyear < 243:
    14994             values.append(2.)
    14995         elif dyear >= 243 and dyear < 334:
    14996             values.append(3.)
    14997 
    14998 for it in range(len(values)):
    14999     print it, tv[it], values[it]
    15000 
    15001 vals = np.array(values)
    15002 itdim = 0
    15003 tu = 'days since 1949-12-01 00:00:00'
    15004 per = 'season'
    15005 calend = 'standard'
    15006 amount = 1
    15007 
    15008 tdes = temporal_desc(tv, tu, calend)
    15009 
    15010 tslc, Ntslc = time_slices(tv, tu, calend, per, amount, tdes)
    15011 
    15012 statn = 'mean'
    15013 tstat = np.ones((Ntslc), dtype=np.float)
    15014 for islc in range(Ntslc):
    15015     timeslcv = tslc[islc]
    15016     if per[0:3] != 'agg':
    15017         timeslc = [slice(timeslcv[0],timeslcv[1],timeslcv[2])]
    15018         tvals = vals[tuple(timeslc)]
    15019     else:
    15020         newshape = list(vals.shape)
    15021         aggslc = tslc[islc]
    15022         NNtslc = len(aggslc)
    15023         newshape[itdim] = NNtslc
    15024         tvals = np.zeros(tuple(newshape), dtype=vals.dtype)
    15025         origshape = list(vals.shape)
    15026         iishape = list(vals.shape)
    15027         for iislc in range(NNtslc):
    15028             origshape[itdim] = aggslc[iislc]
    15029             iishape[itdim] = iislc
    15030             print iislc, ':', iishape, '<>', origshape, vals[tuple(origshape)]
    15031             tvals[tuple(iishape)] = vals[tuple(origshape)]
    15032 
    15033     if statn == 'min':
    15034         tstat[islc] = np.min(tvals, axis=itdim)
    15035     elif statn == 'max':
    15036         tstat[islc] = np.max(tvals, axis=itdim)
    15037     elif statn == 'mean':
    15038         tstat[islc] = np.mean(tvals, axis=itdim)
    15039     elif statn == 'mean2':
    15040         tstat[islc] = np.mean(tvals**2, axis=itdim)
    15041     elif statn == 'std':
    15042         tstat[islc] = np.std(tvals, axis=itdim)
    15043 
    15044     timeslc = tslc[islc]
    15045     itime = tv[timeslc[0]]
    15046     etime = tv[timeslc[1]]
    15047     print islc, ':', itime, '-', etime, '<>', tvals, '=', tstat[islc]
    15048 quit()
    15049 
    15050 
     14972#quit()
     14973
     14974
Note: See TracChangeset for help on using the changeset viewer.