NetCDF中scale_factor和add_offset的使用

參考連接:http://ferret.wrc.noaa.gov/noaa_coop/coop_cdf_profile.html

  • scale_factor - If present for a variable, the data are to be multiplied by this factor after the data are read by the application that accesses the data. (see further discussion under the add_offset attribute)
  • add_offset - If present for a variable, this number is to be added to the data after it is read by the application that accesses the data. If both scale_factor and add_offset attributes are present, the data are first scaled before the offset is added. The attributes scale_factor and add_offset can be used together to provide simple data compression to store low-resolution floating-point data as small integers in a netCDF file. When scaled data are written, the application should first subtract the offset and then divide by the scale factor.
    The NOAA cooperative standard is more restrictive than the netCDF Users Guide with respect to the use of the scale_factor and add_offset attributes; ambiguities and precision problems related to data type conversions are resolved by these restrictions. If the scale_factor and add_offset attributes are of the same data type as the associated variable no restrictions apply; the unpacked data is assumed to be of the same data type as the packed data. However, if the scale_factor and add_offset attributes are of a different data type than the associated variable (containing the packed data) then in files adhering to this standard the associated variable may only be of type byte, short, or long. The attributes scale_factor and add_offset (which must match in data type) must be of type float or double. The data type of the attributes should match the intended type of the unpacked data. (It is not advised to unpack a long into a float as there is a potential precision loss.)
scale_factor 和 add_offset可以對保存的數據進行壓縮。

將對應開關打開後,這兩個屬性就會生效。(開關默認是打開的,python中對開開關的語法是:***.set_auto_maskandscale(True

千萬注意:寫入的值跟讀取的值完全一致。不用自己計算。

實驗中發現調整不同的scale_fator和add_offset,數據文件的大小會不同,數據由於壓縮會損失精度。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章