相关疑难解决方法(0)

如何在Python中复制文件?

如何在Python中复制文件?

我找不到任何东西os.

python filesystems copy file file-copying

2171
推荐指数
18
解决办法
174万
查看次数

python netcdf:制作所有变量和属性的副本,但只有一个

我需要在netcdf文件中处理一个实际包含许多属性和变量的变量.我认为无法更新netcdf文件(请参阅如何删除Scientific.IO.NetCDF.NetCDFFile中的变量的问题)

我的方法如下:

  1. 获取要从原始文件处理的变量
  2. 处理变量
  3. 从原始netcdf复制所有数据但将处理过的变量复制到最终文件
  4. 将处理过的变量复制到最终文件中

我的问题是编码第3步.我开始使用以下内容:

def  processing(infile, variable, outfile):
        data = fileH.variables[variable][:]

        # do processing on data...

        # and now save the result
        fileH = NetCDFFile(infile, mode="r")
        outfile = NetCDFFile(outfile, mode='w')
        # build a list of variables without the processed variable
        listOfVariables = list( itertools.ifilter( lamdba x:x!=variable , fileH.variables.keys() ) )
        for ivar in listOfVariables:
             # here I need to write each variable and each attribute
Run Code Online (Sandbox Code Playgroud)

如何在不需要重建整个数据结构的情况下将所有数据和属性保存在一小撮代码中?

python netcdf

11
推荐指数
3
解决办法
9407
查看次数

标签 统计

python ×2

copy ×1

file ×1

file-copying ×1

filesystems ×1

netcdf ×1