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


Python Dataset.Title方法代码示例

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


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

示例1: tides2nc

# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import Title [as 别名]
    def tides2nc(self,outfile):
        """
        Saves the tidal harmonic data to netcdf
        """
        
        # Write the grid variables
        self.writeNC(outfile)

        nc = Dataset(outfile,'a')
        
        nc.Title = 'SUNTANS harmonic output'
        nc.Constituent_Names = ' '.join(self.frqnames)
        reftime = datetime.strftime(self.reftime,'%Y-%m-%d %H:%M:%S')
        nc.ReferenceDate = reftime
        nc.SimulationTime = '%s - %s'%(datetime.strftime(self.time[self.tstep[0]],'%Y-%m-%d %H:%M:%S'),datetime.strftime(self.time[self.tstep[-1]],'%Y-%m-%d %H:%M:%S'))
        # Add another dimension
        nc.createDimension('Ntide', self.Ntide)
        
        
        nc.close()
        
        # Create the output variables
        for vv in self.varnames:
            print 'Creating variable: %s'%vv

            ndim = self._returnDim(vv)
            if ndim == 2:
                dims = ('Ntide','Nc')
                coords = 'omega xv yv'
            elif ndim == 3:
                dims = ('Ntide','Nk','Nc')
                coords = 'omega z_r xv yv'	

            if vv in ['ubar','vbar']:
                units='m s-1'
            else:
                units = self.nc.variables[vv].units

            name = vv+'_amp'
            longname = '%s - harmonic amplitude'%vv
            self.create_nc_var(outfile, name, dims,\
                {'long_name':longname,'units':units,'coordinates':coords},\
                dtype='f8',zlib=1,complevel=1,fill_value=999999.0)
                
            name = vv+'_phs'
            longname = '%s - harmonic phase'%vv
            self.create_nc_var(outfile, name, dims,\
                {'long_name':longname,'units':'radians','coordinates':coords,'reference_time':reftime},\
                dtype='f8',zlib=1,complevel=1,fill_value=999999.0)
                
            ndim = self._returnDim(vv)
            if ndim == 2:
                dims = ('Nc')
                coords = 'omega xv yv'
            elif ndim == 3:
                dims = ('Nk','Nc')
                coords = 'omega z_r xv yv'
                
            name = vv+'_Mean'
            longname = '%s - Temporal mean'%vv
            self.create_nc_var(outfile, name, dims,\
                {'long_name':longname,'units':units,'coordinates':coords},\
                dtype='f8',zlib=1,complevel=1,fill_value=999999.0)
        
        self.create_nc_var(outfile,'omega', ('Ntide',), {'long_name':'frequency','units':'rad s-1'})
        
        nc = Dataset(outfile,'a')
        nc.variables['omega'][:]=self.frq
        
        for vv in self.varnames:
            name = vv+'_amp'
            nc.variables[name][:]=self.Amp[vv]
            name = vv+'_phs'
            nc.variables[name][:]=self.Phs[vv]
            name = vv+'_Mean'
            nc.variables[name][:]=self.Mean[vv]
        nc.close()        
        
        print 'Completed writing harmonic output to:\n   %s'%outfile
开发者ID:ofringer,项目名称:suntanspy,代码行数:81,代码来源:suntides.py

示例2: WriteNCCF

# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import Title [as 别名]
def WriteNCCF(FileName,Dates,Latitudes,Longitudes,ClimPoints,DataObject,DimObject,AttrObject,GlobAttrObject):
    ''' Sort out the date/times to write out and time bounds '''
    ''' Sort out clim bounds '''
    ''' Sort out lat and long bounds '''
    ''' Convert variables using the obtained scale_factor and add_offset: stored_var=int((var-offset)/scale) '''
    ''' Write to file, set up given dimensions, looping through all potential variables and their attributes, and then the provided dictionary of global attributes '''
    
    # Sort out date/times to write out
    print(Dates)
    TimPoints,TimBounds = MakeDaysSince(Dates['StYr'],Dates['StMon'],Dates['EdYr'],Dates['EdMon'])
    nTims = len(TimPoints)
	
    # Sort out clim bounds - paired strings
    ClimBounds = np.empty((12,2),dtype='|S10')
    for mm in range(12):
	ClimBounds[mm,0] = str(ClimPoints[0])+'-'+str(mm+1)+'-'+str(1)
	ClimBounds[mm,1] = str(ClimPoints[1])+'-'+str(mm+1)+'-'+str(MonthDays[mm])
		
    # Sort out LatBounds and LonBounds
    LatBounds = np.empty((len(Latitudes),2),dtype='float')
    LonBounds = np.empty((len(Longitudes),2),dtype='float')
	
    LatBounds[:,0] = Latitudes - ((Latitudes[1]-Latitudes[0])/2.)
    LatBounds[:,1] = Latitudes + ((Latitudes[1]-Latitudes[0])/2.)

    LonBounds[:,0] = Longitudes - ((Longitudes[1]-Longitudes[0])/2.)
    LonBounds[:,1] = Longitudes + ((Longitudes[1]-Longitudes[0])/2.)	
	
    #pdb.set_trace()
    
    # No need to convert float data using given scale_factor and add_offset to integers - done within writing program (packV = (V-offset)/scale
    # Not sure what this does to float precision though...
    # Change mdi into an integer -999 because these are stored as integers
    for vv in range(len(DataObject)):
        DataObject[vv][np.where(DataObject[vv] == OLDMDI)] = MDI

    # Create a new netCDF file - have tried zlib=True,least_significant_digit=3 (and 1) - no difference
    ncfw=Dataset(FileName,'w',format='NETCDF4_CLASSIC') # need to try NETCDF4 and also play with compression but test this first
    
    # Write out the global attributes
    if ('description' in GlobAttrObject):
        ncfw.description = GlobAttrObject['description']
	#print(GlobAttrObject['description'])
	
    if ('File_created' in GlobAttrObject):
        ncfw.File_created = GlobAttrObject['File_created']

    if ('Title' in GlobAttrObject):
        ncfw.Title = GlobAttrObject['Title']

    if ('Institution' in GlobAttrObject):
        ncfw.Institution = GlobAttrObject['Institution']

    if ('History' in GlobAttrObject):
        ncfw.History = GlobAttrObject['History']

    if ('Licence' in GlobAttrObject):
        ncfw.Licence = GlobAttrObject['Licence']

    if ('Project' in GlobAttrObject):
        ncfw.Project = GlobAttrObject['Project']

    if ('Processing_level' in GlobAttrObject):
        ncfw.Processing_level = GlobAttrObject['Processing_level']

    if ('Acknowledgement' in GlobAttrObject):
        ncfw.Acknowledgement = GlobAttrObject['Acknowledgement']

    if ('Source' in GlobAttrObject):
        ncfw.Source = GlobAttrObject['Source']

    if ('Comment' in GlobAttrObject):
        ncfw.Comment = GlobAttrObject['Comment']

    if ('References' in GlobAttrObject):
        ncfw.References = GlobAttrObject['References']

    if ('Creator_name' in GlobAttrObject):
        ncfw.Creator_name = GlobAttrObject['Creator_name']

    if ('Creator_email' in GlobAttrObject):
        ncfw.Creator_email = GlobAttrObject['Creator_email']

    if ('Version' in GlobAttrObject):
        ncfw.Version = GlobAttrObject['Version']

    if ('doi' in GlobAttrObject):
        ncfw.doi = GlobAttrObject['doi']

    if ('Conventions' in GlobAttrObject):
        ncfw.Conventions = GlobAttrObject['Conventions']

    if ('netcdf_type' in GlobAttrObject):
        ncfw.netcdf_type = GlobAttrObject['netcdf_type']
	
    # Loop through and set up the dimension names and quantities
    for vv in range(len(DimObject[0])):
        ncfw.createDimension(DimObject[0][vv],DimObject[1][vv])
	
    # Go through each dimension and set up the variable and attributes for that dimension if needed
#.........这里部分代码省略.........
开发者ID:Kate-Willett,项目名称:Climate_Explorer,代码行数:103,代码来源:WriteNetCDF_CEDAESGF_JAN2016.py

示例3: tides2nc

# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import Title [as 别名]
    def tides2nc(self, outfile):
        """
        Saves the tidal harmonic data to netcdf
        """

        # Write the grid variables
        self.writeNC(outfile)

        nc = Dataset(outfile, "a")

        nc.Title = "SUNTANS harmonic output"
        nc.Constituent_Names = " ".join(self.frqnames)
        reftime = datetime.strftime(self.reftime, "%Y-%m-%d %H:%M:%S")
        nc.ReferenceDate = reftime
        nc.SimulationTime = "%s - %s" % (
            datetime.strftime(self.time[self.tstep[0]], "%Y-%m-%d %H:%M:%S"),
            datetime.strftime(self.time[self.tstep[-1]], "%Y-%m-%d %H:%M:%S"),
        )
        # Add another dimension
        nc.createDimension("Ntide", self.Ntide)

        nc.close()

        # Create the output variables
        for vv in self.varnames:
            print "Creating variable: %s" % vv

            ndim = self._returnDim(vv)
            if ndim == 2:
                dims = ("Ntide", "Nc")
                coords = "omega xv yv"
            elif ndim == 3:
                dims = ("Ntide", "Nk", "Nc")
                coords = "omega z_r xv yv"

            if vv in ["ubar", "vbar"]:
                units = "m s-1"
            else:
                units = self.nc.variables[vv].units

            name = vv + "_amp"
            longname = "%s - harmonic amplitude" % vv
            self.create_nc_var(
                outfile,
                name,
                dims,
                {"long_name": longname, "units": units, "coordinates": coords},
                dtype="f8",
                zlib=1,
                complevel=1,
                fill_value=999999.0,
            )

            name = vv + "_phs"
            longname = "%s - harmonic phase" % vv
            self.create_nc_var(
                outfile,
                name,
                dims,
                {"long_name": longname, "units": "radians", "coordinates": coords, "reference_time": reftime},
                dtype="f8",
                zlib=1,
                complevel=1,
                fill_value=999999.0,
            )

            ndim = self._returnDim(vv)
            if ndim == 2:
                dims = "Nc"
                coords = "omega xv yv"
            elif ndim == 3:
                dims = ("Nk", "Nc")
                coords = "omega z_r xv yv"

            name = vv + "_Mean"
            longname = "%s - Temporal mean" % vv
            self.create_nc_var(
                outfile,
                name,
                dims,
                {"long_name": longname, "units": units, "coordinates": coords},
                dtype="f8",
                zlib=1,
                complevel=1,
                fill_value=999999.0,
            )

        self.create_nc_var(outfile, "omega", ("Ntide",), {"long_name": "frequency", "units": "rad s-1"})

        nc = Dataset(outfile, "a")
        nc.variables["omega"][:] = self.frq

        for vv in self.varnames:
            name = vv + "_amp"
            nc.variables[name][:] = self.Amp[vv]
            name = vv + "_phs"
            nc.variables[name][:] = self.Phs[vv]
            name = vv + "_Mean"
            nc.variables[name][:] = self.Mean[vv]
        nc.close()
#.........这里部分代码省略.........
开发者ID:mrayson,项目名称:soda,代码行数:103,代码来源:suntides.py

示例4: create_ncfile

# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import Title [as 别名]
 def create_ncfile(self,ncfile):
     nc = Dataset(ncfile, 'w', format='NETCDF4_CLASSIC')
     nc.Title = '%s model data'%(self.type)
     nc.url = '%s'%(self.ncurl)
     
     self._outnc=nc
开发者ID:pbranson,项目名称:soda,代码行数:8,代码来源:mythredds.py

示例5: write2netcdf

# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import Title [as 别名]
    def write2netcdf(self,outfile,trange):
        """
        Write all time steps in trange to an output file

        !! Note that all terms are converted to Wm-2 (multiplied by rho0) !!
        !! Divergent terms are divided by cell area (self.Ac) !!!
        """
        tstep = range(0,self.Nt)[trange[0]:trange[1]]
        # Write the output to netcdf
        print 'Writing the output to netcdf...'

        self.writeNC(outfile)

        nc = Dataset(outfile,'a')
        nc.Title = 'SUNTANS energy output'


        nc.close()

        # Create the new variable names
        self.create_nc_var(outfile, 'time', ('time',),\
            {'long_name':'time','units':'seconds since 1990-01-01 00:00:00'})

        self.create_nc_var(outfile, 'KEz', ('time','Nc'),\
            {'long_name':'Depth-integrated kinetic energy',\
            'units':'J m-2','coordinates':'yv xv'})
        self.create_nc_var(outfile, 'PEz', ('time','Nc'),\
            {'long_name':'Depth-integrated potential energy',\
            'units':'J m-2','coordinates':'yv xv'})
        self.create_nc_var(outfile, 'uP', ('time','Nc'),\
            {'long_name':'Depth-integrated pressure work divergence',\
            'units':'W m-2','coordinates':'yv xv'})
        self.create_nc_var(outfile, 'uKE', ('time','Nc'),\
            {'long_name':'Depth-integrated kinetic energy flux divergence',\
            'units':'W m-2','coordinates':'yv xv'})
        self.create_nc_var(outfile, 'uPE', ('time','Nc'),\
            {'long_name':'Depth-integrated potential energy flux divergence',\
            'units':'W m-2','coordinates':'yv xv'})
        self.create_nc_var(outfile, 'ueta', ('time','Nc'),\
            {'long_name':'Depth-integrated tidal energy flux divergence',\
            'units':'W m-2','coordinates':'yv xv'})

        self.create_nc_var(outfile, 'W_work', ('time','Nc'),\
            {'long_name':'Wind work',\
            'units':'W m-2','coordinates':'yv xv'})
        self.create_nc_var(outfile, 'B_flux', ('time','Nc'),\
            {'long_name':'Turbulent vertical buoyancy flux (KE->PE)',\
            'units':'W m-2','coordinates':'yv xv'})
        self.create_nc_var(outfile, 'diss', ('time','Nc'),\
            {'long_name':'Dissipation rate',\
            'units':'W m-2','coordinates':'yv xv'})
        
        # Testing variables
        self.create_nc_var(outfile, 'S2', ('time','Nk','Nc'),\
            {'long_name':'Shear squared',\
            'units':'s-2','coordinates':'yv xv'})
        self.create_nc_var(outfile, 'Pressure', ('time','Nk','Nc'),\
            {'long_name':'Pressure',\
            'units':'Pa','coordinates':'yv xv'})
 

 
        
        # Calculate the energy for each time step and write the output
        print 'Writing the variable data to netcdf...'
        nc = Dataset(outfile,'a')

        for ii, tt in enumerate(tstep):
            # Call the object to calculate the variables
            print 'Writing energy for timestep %d of %d...'%(tt,tstep[-1])
            self.__call__(tt)

            # Write the variable data out
            nc.variables['time'][ii]=self.timeraw[tt]

            nc.variables['KEz'][ii,:]=self.energy['KE']*RHO0
            nc.variables['PEz'][ii,:]=self.energy['PE']*RHO0
            nc.variables['uP'][ii,:]=self.energy['uP']/self.Ac*RHO0
            nc.variables['uKE'][ii,:]=self.energy['uKE']/self.Ac*RHO0
            nc.variables['uPE'][ii,:]=self.energy['uPE']/self.Ac*RHO0
            nc.variables['ueta'][ii,:]=self.energy['ueta']/self.Ac*RHO0
            nc.variables['W_work'][ii,:]=self.energy['W_work']*RHO0
            nc.variables['B_flux'][ii,:]=self.energy['B_flux']*RHO0
            nc.variables['diss'][ii,:]=self.energy['diss']*RHO0
            # Testing variables
            nc.variables['S2'][ii,:,:]=self.S2
            nc.variables['Pressure'][ii,:,:]=self.pressure*RHO0

        nc.close()
开发者ID:mrayson,项目名称:soda,代码行数:91,代码来源:sunanalysis.py

示例6: create_ncfile

# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import Title [as 别名]
    def create_ncfile(self, ncfile):
        nc = Dataset(ncfile, mode="w", data_model="NETCDF4_CLASSIC", format="NETCDF4_CLASSIC")
        nc.Title = "%s model data" % (self.type)
        nc.url = "%s" % (self.ncurl)

        self._outnc = nc
开发者ID:mrayson,项目名称:soda,代码行数:8,代码来源:mythredds.py

示例7: create_ncfile

# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import Title [as 别名]
 def create_ncfile(self,ncfile):
     nc = Dataset(ncfile,'w')
     nc.Title = '%s model data'%(self.type)
     nc.url = '%s'%(self.ncurl)
     
     self._outnc=nc
开发者ID:jadelson,项目名称:suntanspy,代码行数:8,代码来源:mythredds.py


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