Changeset 1849 in lmdz_wrf
- Timestamp:
- Mar 25, 2018, 3:00:18 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r1848 r1849 22689 22689 given axis 22690 22690 [globattrfilen]: name of ASCII file with the given metadata to be added as global attributes 22691 with a line per attribute [attrname] [value] it has to have at least (underparenthesis for description) 22692 use '#' for comments (use '[unknown]' for that values set-up according to content from file: 22693 institute_id [value, use '!' for spaces] (CV) 22691 with a line per attribute [attrname] [value](use '!' for spaces] (underparenthesis for description) 22692 use '#' for comments 22693 File has to have at least: 22694 institute_id [value] (CV) 22694 22695 institution [value] 22695 22696 model_id [value] (CORDEX starts with <institute_id>-) … … 22715 22716 basetime [value] (reference time "1949-12-01T00:00:00Z" formatted acording to UNIDATA conventions) 22716 22717 calendar [value] (CF conventions as in driving model) 22717 grid [value] (according to CF conventions 22718 grid [value] (according to CF conventions) 22718 22719 [projectfile]: ASCII file with all the CF-mandatory projection information. A line for each attribute. Name of 22719 22720 the variable to be used to refer the projection inside the file will be the same as global attribute `grid' … … 22785 22786 quit(-1) 22786 22787 22787 p inf= {}22788 pattr = {} 22788 22789 opinff = open(projfilen, 'r') 22789 22790 for line in opinff: 22790 22791 if line[0:1] != '#' and len(line) > 1: 22791 22792 linevals = line.replace('\n','').replace('\t','').split(' ') 22792 pinf[linevals[0]] = [linevals[1].replace('!',' '), linevals[2]] 22793 if len(linevals) != 3: 22794 print errormsg 22795 print ' ' + fname + ": wrong values in file '" + projfilen + "' !!" 22796 print ' each line has to have three words (space separated values)' 22797 print " from line: '" + line + "'" 22798 print " values found:", linevals 22799 print " remember to use '!' for spaces" 22800 quit(-1) 22801 pattr[linevals[0]] = [linevals[1].replace('!',' '), linevals[2]] 22793 22802 opinff.close() 22794 22803 … … 22858 22867 tunitsval='minutes') 22859 22868 oaxisv = tvals 22860 22869 22861 22870 # CF values of axis 22862 22871 CFdimvalues = gen.CFcorValues(axn) … … 22894 22903 CFvardimvalues.append(dn) 22895 22904 varslice.append(slice(0,len(onc.dimensions[dn]))) 22896 if dn == dimn and CFdimvalues['length'] != -1: 22905 if dn == dimn and CFdimvalues['length'] != -1: 22897 22906 CFdimvalues['length'] = len(onc.dimensions[dn]) 22898 22907 axsiv = oaxisv[tuple(varslice)] … … 22927 22936 'Y-m-dTH:M:SZ') 22928 22937 secfreq = gen.CFtime_freq(axisv[0], axisv[1], tunits) 22929 Sfreq = -122930 22938 # Labelling frequency 22931 if np.mod(secfreq, 100 * 365 * 24 * 3600.) == 0.: 22932 Sfreq = str(int(secfreq/(100 * 365 * 24 * 3600.))) + 'C' 22933 elif Sfreq == -1 and np.mod(secfreq, 365 * 24 * 3600.) == 0.: 22934 Sfreq = str(int(secfreq/(365 * 24 * 3600.))) + 'Y' 22935 elif Sfreq == -1 and np.mod(secfreq, 7 * 24 * 3600.) == 0.: 22936 Sfreq = str(int(secfreq/(7 * 24 * 3600.))) + 'W' 22937 elif Sfreq == -1 and np.mod(secfreq, 24 * 3600.) == 0.: 22938 Sfreq = str(int(secfreq/(24.*3600.))) + 'D' 22939 elif Sfreq == -1 and np.mod(secfreq,3600.) == 0.: 22940 Sfreq = str(int(secfreq/3600.)) + 'H' 22941 elif Sfreq == -1 and np.mod(secfreq,60.) == 0.: 22942 Sfreq = str(int(secfreq/60.)) + 'M' 22943 else: 22944 # Getting frequency from the global attributes 22939 if gattr['frequency'] == '[unknown]': 22940 if np.mod(secfreq, 100 * 365 * 24 * 3600.) == 0.: 22941 Sfreq = str(int(secfreq/(100 * 365 * 24 * 3600.))) + 'C' 22942 elif np.mod(secfreq, 365 * 24 * 3600.) == 0.: 22943 Sfreq = str(int(secfreq/(365 * 24 * 3600.))) + 'Y' 22944 elif np.mod(secfreq, 7 * 24 * 3600.) == 0.: 22945 Sfreq = str(int(secfreq/(7 * 24 * 3600.))) + 'W' 22946 elif np.mod(secfreq, 24 * 3600.) == 0.: 22947 Sfreq = str(int(secfreq/(24.*3600.))) + 'D' 22948 elif np.mod(secfreq,3600.) == 0.: 22949 Sfreq = str(int(secfreq/3600.)) + 'H' 22950 elif np.mod(secfreq,60.) == 0.: 22951 Sfreq = str(int(secfreq/60.)) + 'M' 22952 else: 22953 print errormsg 22954 print ' ' + fname + ": no frequency has been provided '" + \ 22955 gattr['frequency'] + "' but, data from file does not conform "+\ 22956 "any know time-units!!" 22957 print ' frequency from file:', secfreq, ' seconds _______' 22958 print ' century:', secfreq/(100 * 365 * 24 * 3600.) 22959 print ' year (365d):', secfreq/(365 * 24 * 3600.) 22960 print ' week:', secfreq/(7 * 24 * 3600.) 22961 print ' day:', secfreq/(24 * 3600.) 22962 print ' hour:', secfreq/(3600.) 22963 print ' minute:', secfreq/(60.) 22964 print ' second:', secfreq 22965 print " provide a frequency value in the global attributes " + \ 22966 "file '" + globalattrfilen + "' as frequency [value]" 22967 quit(-1) 22968 gattr['frequency'] = Sfreq 22969 else: 22945 22970 Sfreq = gattr['frequency'] 22946 if gattr['frequency'] == '[unknown]': gattr['frequency'] = Sfreq22947 print ' frquency in file:', secfreq, 's', Sfreq22948 22971 22949 22972 # Renaming dimensions for 2D lon,lat variable-dimensions … … 22978 23001 axinf = axisinf[axn1] 22979 23002 cfaxinf = CFdimvals[axn1] 22980 if axinf[0] == fdn: 23003 if axinf[0] == fdn: 22981 23004 cfdimaxes.append(cfaxinf['dimn']) 22982 23005 if filecfdimn[fdn] is None: filecfdimn[fdn] = cfaxinf['dimn'] … … 22990 23013 22991 23014 CFaxisvardimvals[axn] = cfdimaxes 22992 23015 22993 23016 print 'file --> CF equivalencies of dimensions _______' 22994 23017 print filecfdimn … … 23036 23059 '_' + gattr['rcm_version_id'] + '_' + Sfreq + '_' + Sinit + '-' + Sendt + \ 23037 23060 '.nc' 23061 23038 23062 onewnc = NetCDFFile(filen,'w') 23039 23063 now = dt.datetime.now()
Note: See TracChangeset
for help on using the changeset viewer.