【问题标题】:Write long netCDF attribute using python使用 python 编写长 netCDF 属性
【发布时间】:2021-11-28 16:19:26
【问题描述】:

我正在尝试编写一个 netCDF 文件,其中一个属性是对该文件中内容的详细描述。

假设开头是:

ds = nc.Dataset(filename, 'w', format='NETCDF4')

那么属性将是:

ds.Data_Attribution = "This netCDF files contains all the data recovered from different sources: Source one: Description and url Source one: Description and url "

而且我想将每个来源放在不同的行中。

提前致谢。

【问题讨论】:

    标签: python attributes netcdf4


    【解决方案1】:

    我认为你可以这样做:

    ds.Data_Attribution = "This netCDF files contains all the data recovered from different sources"
    ds.Source1 = "Description and url  Source one: Description and url"
    ds.Source2 = "Description and url  Source two: Description and url"
    

    您也可以尝试xarray 来处理 netcdf 文件。它将 netcdf 文件读取为“xarray dataarray”,然后它也可以很容易地保存为 netcdf 文件。它可以生成非常简洁的属性,如下所示:

    import xarray as xr
    
    # create a sample xarray data array
    ds = xr.Dataset({'var': [1, 2,3,4,5]})
    
    # edit attributes
    ds.attrs['Short name']  = "a short name"
    ds.attrs['Long name']   = "a long name"
    ds.attrs['Description'] = "full description"
    
    # check the results
    display(ds)
    
    # save out as a netcdf file
    ds.to_netcdf("my_netcdffile.nc")
    

    【讨论】:

      猜你喜欢
      • 2013-06-12
      • 2023-03-30
      • 1970-01-01
      • 2021-08-09
      • 1970-01-01
      • 2021-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多