当前位置: 首页>>代码示例>>Python>>正文


Python Dataset.Notes方法代码示例

本文整理汇总了Python中netCDF4.Dataset.Notes方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.Notes方法的具体用法?Python Dataset.Notes怎么用?Python Dataset.Notes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在netCDF4.Dataset的用法示例。


在下文中一共展示了Dataset.Notes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import Notes [as 别名]
  def run(self):
	if type(self.fnsi) == type('abc'):
		self.fnsi = glob(self.fnsi)
		  
	if not exists(self.fnsi[0]):
		print 'mergeNC:\tERROR:\tinputfile name does not exists:', self.fnsi[0]
		return
	if self.debug: print 'mergeNC:\tINFO:\topening dataset:\t', self.fnsi[0]	
	nci = Dataset(self.fnsi[0],'r')#Quiet =True)
	
	if self.timeAverage:
		print 'mergeNC:\tWARNING:\ttimeAverage is not yet debugged. '# are no use:', self.vars
		#return		
	if not self.vars:
		if self.debug: print 'mergeNC:\tINFO:\tvariables to save are empty, saving all.'
		self.vars = nci.variables.keys()

	if self.vars == 'all':
		if self.debug: print 'mergeNC:\tINFO:\tvariables to save:  \'all\' requested. '
		self.vars = nci.variables.keys()
				
	if self.cal != 'standard':
		if self.debug: print 'mergeNC:\tINFO:\tUsing non-standard calendar:', self.cal
				
	
	#check that there are some overlap between input vars and nci:
	for v in self.vars:
		if v in nci.variables.keys():continue
		print 'mergeNC:\tERROR:\tvariable,' ,v,', not found in ',self.fnsi[0]
		return
		
	#create dataset and header.
	if self.debug: print 'mergeNC:\tINFO:\tCreating a new dataset:\t', self.fno
	nco = Dataset(self.fno,'w')
	for a in nci.ncattrs():
		try:
		    if self.debug: print 'mergeNC:\tINFO:\tcopying attribute: \t\"'+str(a)+'\":\t', str(nci.getncattr(a))
		    nco.setncattr(a,nci.getncattr(a))
		except:
		    if self.debug: print 'changeNC:\twarning:\tThat attribute probably isn\'t using ASCII characters!'			
	appendToDesc= 'Reprocessed on '+todaystr()+' by '+getuser()+' using mergeNC.py'
	try: nco.Notes = nci.Notes + '\n\t\t'+appendToDesc
	except: nco.Notes = appendToDesc
	
	# list of variables to save, assuming some conventions
	alwaysInclude = ['time', 'lat','lon', 'latbnd', 'lonbnd', 'latitude', 'longitude', 't','nav_lat','nav_lon', 'time_counter', 'deptht','depth','depthu','depthv','depthw','z','month',]
	alwaysInclude = intersection(nci.variables.keys(),alwaysInclude) 
	save = list(set(sorted(alwaysInclude + self.vars)))
	time = intersection(['time', 't','time_counter','month',], alwaysInclude)
	if len(time) ==1: tvar=time[0]
	else: tvar = 'time'
	
	missing = {}
	if self.fullCheck:
	    if self.debug: print 'mergeNC:\tINFO:\tPerforming full check for missing entries'
	    for t,fni in enumerate(self.fnsi):
		#if self.debug: print 'mergeNC:\tINFO:\tOpening ', fni, ' ...', t   
		nci = Dataset(fni,'r')
		keys =nci.variables.keys()
		for s in save:
			if s in alwaysInclude:continue
			if s not in keys:
				print 'mergeNC:\tWARNING:\tFull check: ',s,' is missing from ', fni
				try: missing[s].append(fni)
				except:missing[s] = [fni,]
	    	nci.close()

 	    for s in missing.keys():
	        #remove key: 	    
	    	#print 'mergeNC:\tWARNING:\tFull check:\tremoving',s,' from ',save
	    	#save.remove(s)
	        
	        #remove missing files:
	    	for fn in missing[s]: 
		    	print 'mergeNC:\tWARNING:\tFull check:\tremoving',fni,' from files'	    	
	    		try:self.fnsi.remove(fn)
	    		except: print 'mergeNC:\tWARNING:\tFull check:\t',fni,' already removed from files'


  
	
	# create dimensions:
	nci = Dataset(self.fnsi[0],'r')#Quiet =True)	
	for d in nci.dimensions.keys():
	  if nci.dimensions[d].isunlimited() or d.lower() in ['time','time_counter',time]: dimSize = None
	  else:	  dimSize=len(nci.dimensions[d])
	  nco.createDimension(d, dimSize)	
	  if self.debug: print 'mergeNC:\tINFO:\tCreating Dimension:', d,dimSize

	# create Variables:
	for var in save:
		dt = nci.variables[var].dtype
		
		if self.debug: 
				print 'mergeNC:\tINFO:\tCreating Variable:',var,nci.variables[var].dtype,nci.variables[var].dimensions,
				print "zlib=True,complevel=5,fill_value=",default_fillvals['f8']

	  	nco.createVariable(var, nci.variables[var].dtype, nci.variables[var].dimensions,zlib=True,complevel=5,fill_value=default_fillvals['f8'])

	# Long Names:
#.........这里部分代码省略.........
开发者ID:ledm,项目名称:NetCDF_manip,代码行数:103,代码来源:mergeNC.py

示例2: run

# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import Notes [as 别名]
  def run(self):	
	if not self.vars:
		print 'depthProfileNC:\tERROR:\tvariables to save are no use:', self.vars
		return
	if not exists(self.fni):
		print 'depthProfileNC:\tERROR:\tinputfile name does not exists:', self.fni
		return
				
	nci = Dataset(self.fni,'r')#Quiet =True)
	
	#check for location in the map.
	# if the values are integers, it assumes them to be a grid location.
	# if the values are doubles, it assumes them to be lon-lat coords.
	if isinstance(self.loc[0], int) and isinstance(self.loc[1], int):
		self.slice = self.loc
	else:
		if len(nci.variables['latbnd'].shape) == 2:
			#ORCA grid
			la,lo = getNemoIndex(self.loc[0],self.loc[1], nci.variables['latbnd'], nci.variables['lonbnd'])
		else:	
			#1D latbnd,lonbnd 
			la = getIndex(self.loc[0], nci.variables['latbnd'])
			lo = getIndex(self.loc[1], nci.variables['lonbnd'])		
		self.slice = [la,lo]
	if self.debug: print 'Saving the location: ',self.slice

	# special key word to save all the variables
	if self.vars == 'all':
		self.vars = nci.variables.keys()
		
	#check that there are some overlap between input vars and nci:
	for v in self.vars:
		if v in nci.variables.keys():continue
		print 'depthProfileNC:\tERROR:\tvariable,' ,v,', not found in ',self.fni
		nci.close()
		return
	
	
	
	#create dataset and header.
	if self.debug: print 'depthProfileNC:\tINFO:\tCreating a new dataset:\t', self.fno
	nco = Dataset(self.fno,'w')
	for a in nci.ncattrs():
		if self.debug: print 'depthProfileNC:\tINFO:\tcopying attribute: \t\"'+a+'\":\t', nci.getncattr(a)
		nco.setncattr(a,nci.getncattr(a))	
	appendToDesc= 'Reprocessed on '+todaystr()+' by '+getuser()+' using depthProfileNC.py'
	try: nco.Notes = nci.Notes + '\n\t\t'+appendToDesc
	except: nco.Notes = appendToDesc
	
	# list of variables to save, assuming some conventions
	alwaysInclude = ['time', 'lat','lon', 'latbnd', 'lonbnd', 'nav_lat','nav_lat', 'time_counter', 'deptht',]
	timeNames = ['time', 'time_counter', 't']
	latNames = ['lat', 'latbnd','nav_lat','x']
	lonNames = ['lon', 'lonbnd','nav_lon','y']
	save =   list(set(nci.variables.keys()).intersection(set(alwaysInclude) ) ) 
	save = list(set(sorted(save + self.vars)))
	
	# create dimensions:
	for d in nci.dimensions.keys():
	  if d in timeNames:  nco.createDimension(d, None)
	  elif d in latNames: nco.createDimension(d, 1)
	  elif d in lonNames: nco.createDimension(d, 1)	  
	  else:		      nco.createDimension(d, len(nci.dimensions[d]))

	# create Variables:
	for var in save:  nco.createVariable(var, nci.variables[var].dtype, nci.variables[var].dimensions,zlib=True,complevel=5)

	# Long Names:
	for var in save: 
		try:  	long_name=nci.variables[var].long_name
		except:	
		  if self.debug: print 'depthProfileNC:\tWarning:\tNo long_name for ', var
		  long_name = var
		  
		#if self.timemean: long_name.replace('Daily', 'Monthly')	
		nco.variables[var].long_name=long_name
		if self.debug: print 'depthProfileNC:\t Adding long_name for ', var, long_name
		  
	# Units:
	for var in save: 
		try:  	nco.variables[var].units=nci.variables[var].units
		except: print 'depthProfileNC:\tWarning:\tNo units for ', var	
		
	# Fill Values:
	for var in save:
		if self.debug: print 'depthProfileNC:\tINFO:\tCopying ', var, ' ...'
		shape  = nci.variables[var].shape
		if len(shape) == 4:
			arr = nci.variables[var][:,:,self.slice[0],self.slice[1]]
			arr = arr[:,:,None,None] #add extra empty dimensions:
		elif len(nci.variables[var].shape) == 3:
			try:
				arr = nci.variables[var][:,self.slice[0],self.slice[1]]
				arr = arr[:,None,None] #add extra empty dimensions:
			except: 
				print 'depthProfileNC:\tERROR:\tCoping failed due to unusual shape', var,shape, self.slice
				return
		elif var in latNames or var in lonNames:
			arr = nci.variables[var][self.slice[0],self.slice[1]]
			arr = arr[None,None]
#.........这里部分代码省略.........
开发者ID:pwcazenave,项目名称:NetCDF_manip,代码行数:103,代码来源:depthProfileNC.py

示例3: run

# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import Notes [as 别名]
  def run(self):
	if not exists(self.fni):
		print 'convertToOneDNC:\tERROR:\tinputfile name does not exists:', self.fni
		return
		  
	nci = Dataset(self.fni,'r')
	
	if not self.vars:
		self.vars = nci.variables.keys() # save all


	#check that there are some overlap between input vars and nci:
	for v in self.vars:
		if v in nci.variables.keys():continue
		print 'convertToOneDNC:\tERROR:\tvariable,' ,v,', not found in ',self.fni
		return
		
	#create dataset and header.
	if self.debug: print 'convertToOneDNC:\tINFO:\tCreating a new dataset:\t', self.fno
	nco = Dataset(self.fno,'w')
	for a in nci.ncattrs():
		if self.debug: print 'convertToOneDNC:\tINFO:\tcopying attribute: \t\"'+a+'\":\t', nci.getncattr(a)
		nco.setncattr(a,nci.getncattr(a))
	
	appendToDesc= 'Reprocessed on '+todaystr()+' by '+getuser()+' using convertToOneDNC.py'
	try: nco.Notes = nci.Notes + '\n\t\t'+appendToDesc
	except: nco.Notes = appendToDesc
	


	save =   list(set(nci.variables.keys()).intersection(set(alwaysInclude) ) ) 
	save = sorted(list(set(sorted(save + self.vars))))
	

	# test to find out which coordinates should be saved.	
	if not self.dictToKeep:
		CoordsToKeep,save=getCoordsToKeep(nci,save,newMask=self.newMask,debug = self.debug)
	else:
		CoordsToKeep = self.dictToKeep


	
		
	# create dimensions:
	#for d in nci.dimensions.keys():
	#  if d in ['time',]: nco.createDimension(d, None)
	#  else:		     nco.createDimension(d, len(nci.dimensions[d]))
	nco.createDimension('index', None)

	# create Variables:

	nco.createVariable('index', int64, ['index',],zlib=True,complevel=5)#,chunksizes=10000)	
	nco.createVariable('index_t', int64, ['index',],zlib=True,complevel=5)#,chunksizes=10000)		
	nco.createVariable('index_z', int64, ['index',],zlib=True,complevel=5)#,chunksizes=10000)		
	nco.createVariable('index_y', int64, ['index',],zlib=True,complevel=5)#,chunksizes=10000)		
	nco.createVariable('index_x', int64, ['index',],zlib=True,complevel=5)#,chunksizes=10000)
	for var in save:
		nco.createVariable(var, nci.variables[var].dtype, ['index',],zlib=True,complevel=5)#,chunksizes=10000)
	
	# Long Names:
	nco.variables['index'].long_name='index'
	nco.variables['index_t'].long_name='index - time'	
	nco.variables['index_z'].long_name='index - depth'
	nco.variables['index_y'].long_name='index - latitude'
	nco.variables['index_x'].long_name='index - longitude'
			
	for var in save: 
		try:  	long_name=nci.variables[var].long_name
		except:	
		  if self.debug: print 'convertToOneDNC:\tWarning:\tNo long_name for ', var
		  long_name = var
		  
		nco.variables[var].long_name=long_name
		if self.debug: print 'convertToOneDNC:\t Adding long_name for ', var, long_name
		  
	# Units:
	nco.variables['index'].units=''
	nco.variables['index_t'].units=''
	nco.variables['index_z'].units=''
	nco.variables['index_y'].units=''
	nco.variables['index_x'].units=''
					
	for var in save: 
		try:  	nco.variables[var].units=nci.variables[var].units
		except: print 'convertToOneDNC:\tWarning:\tNo units for ', var	
		
	# Fill Values:
	sorted_Coords = sorted(CoordsToKeep.iteritems(), key=itemgetter(1))

	data={}
	if self.debug: print 'convertToOneDNC:\tINFO:\tCopying index  ...' , len(sorted_Coords)	
#	nco.variables['index'][:] = [ int(a[1]) for a in sorted_Coords]	
	nco.variables['index'][:] = array([ a[1] for a in sorted_Coords])
	nco.sync()	
	if self.debug: print 'convertToOneDNC:\tINFO:\tCopying index t ...' 	
	nco.variables['index_t'][:] = array([a[0][0] for a in sorted_Coords])
	nco.sync()
	if self.debug: print 'convertToOneDNC:\tINFO:\tCopying index z ...' 			
	nco.variables['index_z'][:] = array([a[0][1] for a in sorted_Coords])
	nco.sync()		
#.........这里部分代码省略.........
开发者ID:pwcazenave,项目名称:NetCDF_manip,代码行数:103,代码来源:convertToOneDNC.py

示例4: run

# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import Notes [as 别名]
  def run(self):	
	if not self.vars:
		print 'depthManipNC:\tERROR:\tvariables to save are no use:', self.vars
		return
	if not exists(self.fni):
		print 'depthManipNC:\tERROR:\tinputfile name does not exists:', self.fni
		return
	
	if self.depthFlags =='':
		print 'depthManipNC:\tWARNING:\tNo depth flags given, assuming surface values only.'
		self.depthFlags = zeros(len(self.vars),  dtype=int)
		
	if len(self.vars)!= len(self.depthFlags):
		print 'depthManipNC:\tERROR:\tVariables do not match depth flags:', len(self.vars), '!=', len(self.depthFlags)
		return
	self.varflag={}
	for var,flag in zip(self.vars, self.depthFlags):self.varflag[var] = flag
	
	if self.debug: print 'depthManipNC:\tINFO:\topening dataset:\t', self.fni	
	nci = Dataset(self.fni,'r')#Quiet =True)
	#if self.depthFlags and 'zbnd' not in nci.variables.keys():
	#	print 'depthManipNC:\tERROR:\tdepthFlags is ',self.depthFlags,'but inputfile name does contain \'zbnd\''
	#	return
	
	#check that there are some overlap between input vars and nci:
	for v in self.vars:
		if v in nci.variables.keys():continue
		print 'depthManipNC:\tERROR:\tvariable,' ,v,', not found in ',self.fni
		return
		
	#create dataset and header.
	if self.debug: print 'depthManipNC:\tINFO:\tCreating a new dataset:\t', self.fno
	nco = Dataset(self.fno,'w')
	for a in nci.ncattrs():
		if self.debug: print 'depthManipNC:\tINFO:\tcopying attribute: \t\"'+a+'\":\t', nci.getncattr(a)
		nco.setncattr(a,nci.getncattr(a))	
	appendToDesc= 'Reprocessed on '+todaystr()+' by '+getuser()+' using depthManipNC.py'
	try: nco.Notes = nci.Notes + '\n\t\t'+appendToDesc
	except: nco.Notes = appendToDesc
	
	# list of variables to save, assuming some conventions
	alwaysInclude = ['time', 'lat','lon', 'latbnd', 'lonbnd']
	save = list(set(nci.variables.keys()).intersection(set(alwaysInclude) ) ) 
	save = list(set(sorted(save + self.vars)))
	
	# create dimensions:
	for d in nci.dimensions.keys():
	  if d in ['time',]: nco.createDimension(d, None)
	  elif d in ['depth', 'z',]: nco.createDimension(d, 1)
	  else:		     nco.createDimension(d, len(nci.dimensions[d]))

	# create Variables:
	for var in save:  nco.createVariable(var, nci.variables[var].dtype, nci.variables[var].dimensions,zlib=True,complevel=5)

	
	# Long Names:
	for var in save:
		varln = ''
		long_name = ''
		try:  	long_name=nci.variables[var].long_name
		except:	
			if self.debug: print 'depthManipNC:\tWarning:\tNo long_name for ', var
		if var in self.vars:
			long_name += ' '+self.depthStrings[str(self.varflag[var])]
		if self.timemean: long_name.replace('Daily', '')
		if self.timemean: long_name.replace('Monthly', '')
		nco.variables[var].long_name = long_name
		if self.debug: print 'depthManipNC:\tInfo:\tAdding long_name:',var,long_name
	# Units:
	for var in save: 
		units = ''
		try:  	units=nci.variables[var].units
		except: 
			if self.debug: print 'depthManipNC:\tWarning:\tNo units for ', var
		if var in self.vars:
		  if  self.varflag[var] == 1: units = units.replace('m^3', 'm^2')
		  
		nco.variables[var].units=units
		if self.debug: print 'depthManipNC:\tInfo:\tAdding units:',var,units

	if 'zbnd' in nci.variables.keys(): self.zbnd =nci.variables['zbnd'][:]
	if 'bathymetry' in nci.variables.keys(): self.bathy =nci.variables['bathymetry'][:]	
	
	# Fill Values:
	for var in save:
		if var not in self.vars: #no change
			 arr=nci.variables[var][:] 
		else: 
			flag = self.varflag[var]
			if self.debug: print 'depthManipNC:\tInfo:\tFilling var:',var, 'flag:', flag
			if flag == 1:	
				arr = (nci.variables[var][:] * abs((self.zbnd[:,:,:,:,1]-self.zbnd[:,:,:,:,0]))).sum(1)			
				arr= arr[:,None,:,:]
			elif flag in [-2,-1,0]: arr =nci.variables[var][:,flag,:,:]
			elif flag in [-15,]:	arr =self.bottomLayer(nci, var)
			else: 	
				arr =nci.variables[var][:,flag,:,:].mean(1)
				arr= arr[:,None,:,:]
			
			#while len(arr.shape) < len(nci.variables[var].dimensions): arr = marray(arr[None,:])
#.........这里部分代码省略.........
开发者ID:ledm,项目名称:NetCDF_manip,代码行数:103,代码来源:depthManipNC.py

示例5: run

# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import Notes [as 别名]
  def run(self):	
	if not self.vars:
		print 'pruneNC:\tERROR:\tvariables to save are no use:', self.vars
		return
	if not exists(self.fni):
		print 'pruneNC:\tERROR:\tinputfile name does not exists:', self.fni
		return
				
	nci = Dataset(self.fni,'r')#Quiet =True)
	
	if self.depthInt: 
		print 'FAIL: maybe you should look at the depthManip.py class instead. This one only removes variables from a netcdf.'
		return
		
	
	#check that there are some overlap between input vars and nci:
	for v in self.vars:
		if v in nci.variables.keys():continue
		print 'pruneNC:\tERROR:\tvariable,' ,v,', not found in ',self.fni
		return
		
	#create dataset and header.
	if self.debug: print 'pruneNC:\tINFO:\tCreating a new dataset:\t', self.fno
	nco = Dataset(self.fno,'w')
	for a in nci.ncattrs():
		if self.debug: print 'pruneNC:\tINFO:\tcopying attribute: \t\"'+a+'\":\t', nci.getncattr(a)
		nco.setncattr(a,nci.getncattr(a))	
	appendToDesc= 'Reprocessed on '+todaystr()+' by '+getuser()+' using pruneNC.py'
	try: nco.Notes = nci.Notes + '\n\t\t'+appendToDesc
	except: nco.Notes = appendToDesc
	
	# list of variables to save, assuming some conventions
	alwaysInclude = ['time', 'lat','lon', 'latbnd', 'lonbnd']
	save =   list(set(nci.variables.keys()).intersection(set(alwaysInclude) ) ) 
	save = list(set(sorted(save + self.vars)))
	
	# create dimensions:
	for d in nci.dimensions.keys():
	  if d in ['time',]: nco.createDimension(d, None)
	  else:		     nco.createDimension(d, len(nci.dimensions[d]))

	# create Variables:
	for var in save:  nco.createVariable(var, nci.variables[var].dtype, nci.variables[var].dimensions,zlib=True,complevel=5)

	# Long Names:
	for var in save: 
		try:  	long_name=nci.variables[var].long_name
		except:	
		  print 'pruneNC:\tWarning:\tNo long_name for ', var
		  long_name = var
		  
		if self.timemean: long_name.replace('Daily', 'Monthly')	
		nco.variables[var].long_name=long_name
		if self.debug: print 'pruneNC:\t Adding long_name for ', var, long_name
		  
	# Units:
	for var in save: 
		try:  	nco.variables[var].units=nci.variables[var].units
		except: print 'pruneNC:\tWarning:\tNo units for ', var	
		
	# Fill Values:
	for var in save:
		if self.debug: print 'pruneNC:\tINFO:\tCopying ', var, ' ...' 
		arr = nci.variables[var][:]
		
		if self.timemean and len(intersection(['time','t'], nci.variables[var].dimensions)):
			if self.debug: print 'pruneNC:\tInfo:\tSaving time averaged var:',var
			arr = marray([arr.mean(0),])
			while len(arr.shape) < len(nci.variables[var].dimensions): arr = marray(arr[None,:])
			
		if self.debug: print 'pruneNC:\tInfo:\tSaving var:',var, arr.shape, '\tdims:', nci.variables[var].dimensions
		nco.variables[var][:] =arr

	# Close netcdfs:
	nco.close()
	nci.close()
	if self.debug: print 'pruneNC:\tINFO:\tsuccessfully created:\t', self.fno
	return
开发者ID:ledm,项目名称:NetCDF_manip,代码行数:80,代码来源:pruneNC.py


注:本文中的netCDF4.Dataset.Notes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。