Changeset 508 in lmdz_wrf for trunk/tools
- Timestamp:
- Jun 17, 2015, 4:14:44 PM (10 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var.py
r507 r508 84 84 85 85 # Operations which file name is not a real file 86 NotCheckingFile = ['file_creation', 'list_operations', 'netcdf_concatenation', 'netcdf_fold_concatenation'] 86 NotCheckingFile = ['DatesFiles', 'file_creation', 'list_operations', \ 87 'netcdf_concatenation', 'netcdf_fold_concatenation'] 87 88 88 89 ####### ###### ##### #### ### ## # -
trunk/tools/nc_var_tools.py
r507 r508 15875 15875 """ 15876 15876 import subprocess as sub 15877 import datetime as dt 15877 15878 fname='DatesFiles' 15878 15879 … … 15884 15885 arguments = '[dates],[fold]' 15885 15886 check_arguments(fname, len(values.split(',')), arguments, ',', \ 15886 len(argumen st.split(',')))15887 15888 dates = values.split(',')[0].split(' ,')15887 len(arguments.split(','))) 15888 15889 dates = values.split(',')[0].split(':') 15889 15890 fold = values.split(',')[1] 15890 15891 … … 15893 15894 15894 15895 print ' ' + fname +': looking on:',Nfiles,'files' 15895 print confiles15896 15896 15897 15897 # Opening all files and getting times 15898 15898 ncobjs = {} 15899 15899 for filen in confiles: 15900 print 'charging: ',filen15901 15900 filename = fold + '/' + filen 15902 ncf = NetCDFFile(fname, 'r') 15901 ncf = NetCDFFile(filename, 'r') 15902 datesv = [] 15903 15903 if varn == 'WRFt': 15904 15904 fdates = ncf.variables['Times'][:] 15905 datesv = datetimeStr_conversion(fdates, 'WRFdatetime', 'YmdHMS') 15905 for it in range(fdates.shape[0]): 15906 datesv.append(datetimeStr_conversion(fdates[it,:], 'WRFdatetime', \ 15907 'YmdHMS')) 15906 15908 else: 15907 15909 tunits = ncf.variables[varn].getncattr('units') 15908 15910 fdates = ncf.variables[varn][:] 15909 datesv = datetimeStr_conversion(fdates, 'cfTime,' + tunits , 'YmdHMS') 15910 15911 ncobjs[fname] = datesv 15912 15913 founddates = {} 15914 for dt in dates: 15911 for it in range(fdates.shape[0]): 15912 datesv.append(datetimeStr_conversion(fdates[it], 'cfTime,' + tunits ,\ 15913 'YmdHMS')) 15914 15915 ncobjs[filename] = datesv 15916 ncf.close() 15917 15918 # Computing time-step inside files (assuming regular) 15919 if filen == confiles[0]: 15920 ini=datesv[0] 15921 end=datesv[1] 15922 15923 iniT = dt.datetime.strptime(ini,'%Y%m%d%H%M%S') 15924 endT = dt.datetime.strptime(end,'%Y%m%d%H%M%S') 15925 15926 DT = endT - iniT 15927 diffT = DT.total_seconds() 15928 print ' ' + fname + ': seconds between time-steps in files:', diffT 15929 15930 Efounddates = {} 15931 Cfounddates = {} 15932 for dtv in dates: 15933 foundclosest = False 15915 15934 for fn in ncobjs.keys(): 15916 if searchInlist(ncobjs[fn], dt): 15917 founddates[dt] = fn 15918 istep = ncobjs[fn].index(dt) 15919 15920 print fname + ':',dt,fn,istep 15921 15935 if searchInlist(ncobjs[fn], dtv): 15936 founddates[dtv] = fn 15937 istep = ncobjs[fn].index(dtv) 15938 15939 print fname + 'Exact:',dtv,fn,istep,'(date, filname, time-step)' 15940 Efounddates[dtv] = [dtv,fn,istep] 15941 15942 for it in ncobjs[fn]: 15943 iniT = dt.datetime.strptime(it,'%Y%m%d%H%M%S') 15944 endT = dt.datetime.strptime(dtv,'%Y%m%d%H%M%S') 15945 15946 DT = endT - iniT 15947 diffitv = DT.total_seconds() 15948 15949 if diffT > DT.total_seconds(): 15950 istep = ncobjs[fn].index(it) 15951 print fname + 'Closest:',dtv,fn,it,diffitv,'(date, filname, ' + \ 15952 'time-step, distance in seconds)' 15953 Cfounddates[dtv] = [dtv,fn,istep,diffitv] 15954 foundclosest = True 15955 break 15956 15957 if foundclosest: break 15922 15958 return 15923 15959
Note: See TracChangeset
for help on using the changeset viewer.