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


Python Dataset.__setattr__方法代码示例

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


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

示例1: write

# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import __setattr__ [as 别名]
def write(filename,data,dtype='f',varname="data",dims=None,units=None,attributes=None, record_dim=None,
          lat=None,lon=None,extravars=None,history="",global_attributes=None, format="NETCDF4"):
    """write a netcdf file

    filename = name of output netcdf file (.nc will be appended automatically)
    data = data to write to file
    dtype = data type of data (see below)
    varname = name of variable to create in the netcdf file
    units = units for the data
    lat = a latitude variable to add (here for legacy reasons, use extravars)
    lon = ditto
    attribues: bunch/dictionary with key/values pairs to be added as attributes
    extravars is a list of variables to add
        each variable is a bunch or other class with attribues:
            data = data to write
            name = name of variable
            dims = dimensions to use: i.e. [[[[t],z],y],x] matching dimensions in primary data
            dtype= data type of output variable
                'd': 64 bit float
                'f': 32 bit float
                'l': long
                'i': 32 bit integer
                'h': 16 bit integer
                'b': 8 bit integer
                'S1': character
            attribues: bunch/dictionary with key/values pairs to be added as attributes
    """
    history = 'Created : ' + time.ctime() +'\nusing simple io.write by:'+os.environ['USER']+"  "+history


    if dims is None:
        if len(data.shape)==1:
            dims=('x',)
        if len(data.shape)==2:
            dims=('y','x')
        if len(data.shape)==3:
            dims=('z','y','x')
        if len(data.shape)==4:
            dims=('t','z','y','x')
        if len(data.shape)>4:
            dims=tuple([chr(dimname) for dimname in range(97,97+len(data.shape))])
    if nclib==NIO:
        return _write_nio(filename,data,dtype,varname,dims,units,attributes,lat,lon,extravars,history,global_attributes)
    else:
        NCfile=Dataset(filename,mode="w",format=format)
        _write_one_var(NCfile,data,varname=varname,units=units,dtype=dtype,dims=dims,attributes=attributes,record_dim=record_dim)

    if not (lat is None):
        print("WARNING: explicitly passing lat is deprecated, use extravars")
        if len(lat.shape)>1:
            NCfile.createVariable("lat",'f',(dims[-2],dims[-1]))
        else:
            NCfile.createVariable("lat",'f',(dims[-2],))
        NCfile.variables["lat"][:]=lat.astype('f')
    if not (lon is None):
        print("WARNING: explicitly passing lon is deprecated, use extravars")
        if len(lon.shape)>1:
            NCfile.createVariable("lon",'f',(dims[-2],dims[-1]))
        else:
            NCfile.createVariable("lon",'f',(dims[-1],))
        NCfile.variables["lon"][:]=lon.astype('f')

    if extravars:
        for e in extravars:
            if 'record_dim' in e.keys():
                this_record_dim=e.record_dim
            else:
                this_record_dim=None
            addvar(NCfile,e.data,e.name,e.dims,e.dtype,e.attributes, this_record_dim)

    if not (global_attributes is None):
        for k in global_attributes.keys():
            if k=="history":
                NCfile.__setattr__(k,history+global_attributes[k])
            else:
                NCfile.__setattr__(k,global_attributes[k])
    else:
        NCfile.history=history
    NCfile.close()
开发者ID:gutmann,项目名称:scripted_sufferin_succotash,代码行数:81,代码来源:mygis.py

示例2: __setattr__

# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import __setattr__ [as 别名]
 def __setattr__(self, name, value):
     try:
         Dataset.__setattr__(self, name, value)
     except TypeError:
         self.__dict__[name] = value
开发者ID:yeyuguo,项目名称:metamet,代码行数:7,代码来源:m3_file.py

示例3: open

# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import __setattr__ [as 别名]
# global attributes
fields = ["data_type", "parameter"]

with open("global_attributes_profile.txt", "rb") as f:

    reader = csv.DictReader(f, delimiter=",", fieldnames=fields)
    global_v = {}
    for row in reader:
        D = row.pop("data_type")
        if D == "S":
            P = row.pop("parameter")
            K = P.strip().split(":")
            if K[0] in result:
                # implement your duplicate row handling here
                pass
            ncfile.__setattr__(K[0].strip(), K[1].strip())
        if D == "N":
            P = row.pop("parameter")
            K = P.strip().split(":")
            if K[0] in result:
                # implement your duplicate row handling here
                pass
            ncfile.__setattr__(K[0].strip(), eval(K[1].strip()))

ncfile.Metadata_Conventions = "Unidata Dataset Discovery v1.0"
ncfile.nodc_template_version = "NODC_NetCDF_Profile_Template_v1.1"
# setattr(ncfile, 'wmo_platform_code', 'University of Cape Town')
# setattr(ncfile, 'summary', 'University of Cape Town CTD data')
# setattr(ncfile, 'id', 'University of Cape Town')

setattr(ncfile, "uuid", prof.attributes["md5"])
开发者ID:cpt-rroman,项目名称:ocean-netcdf,代码行数:33,代码来源:cnv_netcdf.py

示例4: L2_Process

# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import __setattr__ [as 别名]

#.........这里部分代码省略.........

    def read_uwka_flight(self):
        '''Read in processed NetCDF file.'''

        # Read the NetCDF
        self.ncFile = Dataset(self.infilepath,'r')

        # Read in Dimensions
        self.nc_dims = self.ncFile.dimensions
        self.nc_dimnames = [dim for dim in self.ncFile.dimensions]

        # Read in Variable names
        self.ncvars = self.ncFile.variables

        # Grab the metadata stored in global attributes as a dictionary
        self.metadata = self.ncFile.__dict__  # Gets entire attribute info
        self.globattr = self.ncFile.ncattrs() # Gets only attribute names

    ############################
    ##  WRITE GLOBAL METHODS  ##
    ############################

    def write_dimensions(self):
        # Write the dimension information
        for dimname in self.ncFile.dimensions:
            self.outfile.createDimension(dimname, len(self.ncFile.dimensions[dimname]))

    def write_glob_attr(self):
        '''Write the global attributes.'''
        self.outfile.description = "UWKA Level 2 Data"

        self.outfile.documentation = "http://flights.uwyo.edu/n2uw/users/"
        for attname in GLOB_ATTS:
            self.outfile.__setattr__(attname, getattr(self.ncFile, attname))
        self.outfile.created_UTC = datetime.datetime.utcnow().isoformat()
        self.coordinates = "lon lat alt time"
        self.latitude_coordinate = "lat"
        self.longitude_coordinate = "lon"
        self.zaxis_coordinate = "alt"
        self.time_coordinate = "time"
        self.wind_field = "wind_dir wind_spd w_wind"

    def add_glob_attr(self, attname, attval):
        '''Add a global attribute from setup file.'''
        self.outfile.__setattr__(attname, attval)

    ##########################
    ##  WRITE FILE METHODS  ##
    ##########################       
    def write_time_var(self, tIn, tOut):
        '''Create a time variable for user file'''
        self.outfile.createVariable(tOut, \
                                    self.ncvars[tIn].datatype, \
                                    self.ncvars[tIn].dimensions)
        self.outfile.variables[tOut].long_name = "time of measurement"
        self.outfile.variables[tOut].standard_name = "time"
        self.outfile.variables[tOut].units = self.ncvars['time'].units
        self.outfile.variables[tOut].strptime_format = "seconds since %F %T %z"
        self.outfile.variables[tOut][:] = self.ncvars[tIn][:]

    def write_var(self, VarIn, VarOut):
        '''Create output variable'''
        # Get the attributes associated with a variable
        InputVaratts = self.ncFile.variables[VarIn].ncattrs()

        # Check for _FillValue
开发者ID:jaysulk,项目名称:uwkingair,代码行数:70,代码来源:make_uwka_l2_flight.py


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