修改read_micaps_1解码3位数海平面气压bug#55
Open
LuckyBoy314 wants to merge 1 commit into
Open
Conversation
原来解码3位数海平面气压的代码不对, 假设:MSLP = 132 第一行执行: 132 <= 600 132 / 10 + 1000 = 1013.2 然后第二行重新判断: data['MSLP'] > 600 现在 1013.2 > 600 成立,所以它又会被第二行处理一次: 1013.2 / 10 + 900 = 1001.32 结果本来应该是 1013.2 hPa,却变成了 1001.32 hPa。 所以这段代码会把原本小于等于 600 的气压值二次转换
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
原来解码3位数海平面气压的代码不对
假设:MSLP = 132
第一行执行:
132 <= 600
132 / 10 + 1000 = 1013.2
然后第二行重新判断:
data['MSLP'] > 600
现在 1013.2 > 600 成立,所以它又会被第二行处理一次:
1013.2 / 10 + 900 = 1001.32
结果本来应该是 1013.2 hPa,却变成了 1001.32 hPa。
所以这段代码会把原本小于等于 600 的气压值二次转换
正确写法是先基于原始数据生成两个布尔掩码
low_mask = data["MSLP"] <= 600
high_mask = data["MSLP"] > 600
data.loc[low_mask, "MSLP"] = data.loc[low_mask, "MSLP"] / 10.0 + 1000.0
data.loc[high_mask, "MSLP"] = data.loc[high_mask, "MSLP"] / 10.0 + 900.0
这样第二行判断用的是修改前的分类结果,不会受到第一行赋值影响。
还要考虑缺测值和 NaN
如果前面已经执行了:
data["MSLP"] = data["MSLP"].mask(data["MSLP"] == 9999.0)
那么 MSLP 中可能有 NaN。一般来说:
NaN <= 600
NaN > 600
都会返回 False,不会被转换。
正确的版本
valid_mask = data["MSLP"].notna()
low_mask = valid_mask & (data["MSLP"] <= 600)
high_mask = valid_mask & (data["MSLP"] > 600)
data.loc[low_mask, "MSLP"] = data.loc[low_mask, "MSLP"] / 10.0 + 1000.0
data.loc[high_mask, "MSLP"] = data.loc[high_mask, "MSLP"] / 10.0 + 900.0