简体   繁体   English

如何使用python从netcdf文件的标题中获取特定信息?

[英]How to get a specific information from the header of a netcdf file using python?

I have several necdf files and I need to read the value of "aod550:scale_factor" and "aod550:add_offset" because they are different for different files. 我有几个necdf文件,我需要读取"aod550:scale_factor""aod550:add_offset"因为它们对于不同的文件而言是不同的。 They are located in the header of my netcdf files and are additional information of "short aod550" (the variable which I'm interested). 它们位于我的netcdf文件的标头中,并且是"short aod550" (我感兴趣的变量)的附加信息。 The part of the netcdf header looks like this: netcdf标头的部分如下所示:

variables: 变量:

short aod550(time, latitude, longitude) ;
    aod550:scale_factor = 1.44701502281421e-05 ;
    aod550:add_offset = 0.474128942375304 ;
    aod550:_FillValue = -32767s ;

Is there any command to read this information in python? 是否有任何命令可以在python中读取此信息? I'm thinking in something similar to read variables. 我在想类似读取变量的东西。 I can read the values of variable aod550 using aod = 'my_netcdf_file'.variables['aod550'] but it doesn't work with 'aod550:scale_factor' or 'aod550:add_offset' because they aren't variables. 我可以使用aod550 aod = 'my_netcdf_file'.variables['aod550']读取变量aod550的值,但不适用于'aod550:scale_factor''aod550:add_offset'因为它们不是变量。

Anyone have any ideas??? 有人有想法么???

Thank you N1B4 for your suggestion, however I'm using Scientific.IO.NetCDF. 谢谢N1B4的建议,但是我正在使用Scientific.IO.NetCDF。 Finally I solved my problem: 终于我解决了我的问题:

Read variable "aod": 读取变量“ aod”:

aod = 'my_netcdf_file'.variables['aod550'] aod ='my_netcdf_file'.variables ['aod550']

Read "scale_factor" and "add_offset" values: 读取“ scale_factor”和“ add_offset”值:

scale_factor = aod.scale_factor[0] add_offset = aod.add_offset[0] scale_factor = aod.scale_factor [0] add_offset = aod.add_offset [0]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM