爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 10704|回复: 9

[其他] 求助,short格式值相同,转成flt值反而不同,这是啥原因

[复制链接]
回帖奖励 150 金钱 回复本帖可获得 10 金钱奖励! 每人限 1 次

新浪微博达人勋

发表于 2021-11-3 17:13:27 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
本帖最后由 t_imba 于 2021-11-3 17:14 编辑

将多年的数据合并起来成为一个新文件,原始数据是short格式的,合并之后用short2flt转浮点数,结果除了第一年的数据和原始数据浮点数值相同,其他年份的数据都不一样,验证SHORT格式的值却是相同的,请问这是什么原因?同事用pythonXARRAY包读好像数据也是正确的。是不是除了SHORT2FLT还有什么short格式转浮点的函数,大佬救命

1971年

1971年
2.png
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2021-11-3 18:02:28 | 显示全部楼层

回帖奖励 +10 金钱

本帖最后由 一大碗年糕 于 2021-11-3 18:04 编辑

看到这么多金币激发了我学习的兴趣(不是
short2flt在NCL中描述如下:
Description
This function converts short data to float using the "scale" and "offset" attributes (if present), and preserves metadata.
Other attributes similar to "scale" and "offset" will be recognized:
offset:
"add_offset", "OFFSET", "Offset", "_offset", "Intercept", "intercept"
scale:
"SCALE", "Scale", "_scale", "scale_factor", "Scale_factor", "Slope" , "slope"
Note: this function is slightly different than the built-in set of conversion functions (like floattointeger and shorttobyte), because it requires loading the "contributed.ncl" script and it preserves metadata. It has a slightly different naming style than the built-in functions, just to set it apart from these other functions.

即short2float受scale和offset这两个attributes影响
显然当短型short型解压到float型时需要用的y = x * scale_factor + add_offset
所以问题目测是在合并原始数据时改变了变量的scale和add_offset这两个属性
比如ncl压缩转换函数pack_values中就有设置
the scale_factor (opt@scale_factor) and add_offset (opt@add_offset) values to be used by the function.
解决办法:分别看下两个变量属性,把合并之后的变量的scale和offset属性改成原变量的再用short2float即可。
当然考虑或许这个If the names given do not match any attributes, the scale factor will be assigned a value of 1.0 and the offset will be assigned a value of 0.0. 这种情况也不是没有可能
参考关于scale和offset属性在netcdf中的描述:
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.
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.
When scale_factor and add_offset are used for packing, the associated variable (containing the packed data) is typically of type byte or short, whereas the unpacked values are intended to be of type float or double. The attributes scale_factor and add_offset should both be of the type intended for the unpacked data, e.g. float or double.
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2021-11-3 22:35:31 | 显示全部楼层
听大佬一席话,胜过我琢磨好久,确实是scale_factor和add_offset值不同,原来都没注意到过这一点。以后校对数据得检验了。
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2021-11-3 22:37:46 | 显示全部楼层
一大碗年糕 发表于 2021-11-3 18:02
看到这么多金币激发了我学习的兴趣(不是
short2flt在NCL中描述如下:
Description


听大佬一席话,胜过我琢磨好久,确实是scale_factor和add_offset值不同,原来都没注意到过这一点。以后校对数据得检验了。
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2021-11-3 22:54:02 | 显示全部楼层
一大碗年糕 发表于 2021-11-3 18:02
看到这么多金币激发了我学习的兴趣(不是
short2flt在NCL中描述如下:
Description

我先都转成浮点的再合并了。好像没法分段赋值scale_factor 和 add_offset
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2021-11-4 10:41:53 | 显示全部楼层
t_imba 发表于 2021-11-3 22:37
听大佬一席话,胜过我琢磨好久,确实是scale_factor和add_offset值不同,原来都没注意到过这一点。以后 ...

不是大佬我也,水帖群众哈哈
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2021-11-7 10:19:01 | 显示全部楼层

回帖奖励 +10 金钱

本帖最后由 SAREbenjamin 于 2021-11-9 10:17 编辑

舍友也遇到过这个问题 大概是这样的...
他用的是ERA5数据 后期需要补充层次
他先合并数据到同一个数组 再short2flt 这样出来的结果是错的 会存在一个明显的“断层”

密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2022-3-20 22:14:22 | 显示全部楼层

回帖奖励 +10 金钱

哇,上面的回复真的赞!
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2022-3-26 15:01:30 | 显示全部楼层

回帖奖励 +10 金钱

我也遇到过,我的做法是先在命令行用cdo把文件的数据类型从short转为float,然后再用ncl统一读数据
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

 成长值: 0
发表于 2022-3-28 09:57:33 | 显示全部楼层

回帖奖励 +10 金钱

顶一顶
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表