- Timestamp:
- Mar 31, 2017, 5:51:21 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r1474 r1480 10592 10592 [fold]: folder with the location of the netCDF files 10593 10593 [dimname]: dimension along which files should be concatenated 10594 [ tail]: tail of the files to concatenate (optional)10594 [vardimname]: name of the dimension variable with the values 10595 10595 [ncfile]= [header],[middle],[tail] 10596 10596 [header] = header of the name of the files to concatenate [ncfile]*[middle]*[tail] … … 10613 10613 fold = values.split(',')[0] 10614 10614 condim = values.split(',')[1] 10615 vardimname = values.split(',')[2] 10615 10616 10616 10617 HMT = ncfile.split(',') … … 10639 10640 print errormsg 10640 10641 print ' ' + fname + ": files do not have dimensions '" + condim + "' !!!" 10642 quit(-1) 10643 if not ncobjs[0].variables.has_key(vardimname): 10644 print errormsg 10645 print ' ' + fname + ": files do not have variable '" + vardimname + "' !!!" 10641 10646 quit(-1) 10642 10647 … … 10677 10682 newvar = newnc.createVariable('int' + condim, 'i4', tuple(dims)) 10678 10683 newvar[:] = range(totcondim) 10684 10685 # Dimension variable for the concatenation 10686 10687 odimvar = ncobjs[0].variables[vardimname] 10688 odimvardims = odimvar.dimensions 10689 odimattrs = odimvar.ncattrs 10690 for dimn in odimvardims: 10691 if not gen.searchInlist(newnc.dimensions,dimn): 10692 Ldim = len(odimvar.dimensions[dimn]) 10693 newvar = newnc.crateVarieble(vardimname, odimvar.dtype, odimvardims) 10694 for attrn in odimattrs: 10695 attrv = odimvar.getncattr(attrn) 10696 newattr = set_attribute(newvar, attrn, attrv) 10697 if attrn == 'units': urefvals = attrv 10698 10699 # Checking units of condimvar 10700 uvalsecs = urefvals.split(' ') 10701 if uvalsecs[1] == 'since': 10702 tunits = True 10703 if len(uvalsecs) == 4: 10704 date=uvalsecs[2] 10705 time=uvalsecs[3] 10706 else: 10707 if uvalsecs[2].find('_') != -1: 10708 date=uvalsecs[2] 10709 time='00:00:00' 10710 else: 10711 date=uvalsecs[2].split('_')[0] 10712 time=uvalsecs[2].split('_')[1] 10713 refdate = gen.datetimeStr_datetime(date+'_'+time) 10714 print warnmsg 10715 print ' ' + fname + ': concatenating dimension-variable has time units!' 10716 print ' shifting temporal-values since the date of the first file', refdate 10717 10718 for ifile in range(Nfiles): 10719 slicevartot = [] 10720 objvar = ncobjs[ifile].variables[vardimname] 10721 for dimn in objvar.dimensions: 10722 ldimfile = len(ncobjs[ifile].dimensions[dimn]) 10723 if dimn == condim: 10724 slicevartot.append(slice(begslicetot,begslicetot+ldimfile)) 10725 begslicetot = begslicetot + ldimfile 10726 else: 10727 slicevartot.append(slice(0,ldimfile)) 10728 if tunits: 10729 uvals = objvar.getncattr('units') 10730 newtimes = gen.coincident_CFtimes(objvar[:], uvals, urefvals) 10731 newvar[tuple(slicevartot)] = objvar[:] 10732 else: 10733 newvar[tuple(slicevartot)] = objvar[:] 10734 newnc.sync() 10679 10735 10680 10736 # Looping variables
Note: See TracChangeset
for help on using the changeset viewer.