【问题标题】:NDFD GRIB2 how to fix mirrored data when using xarrayNDFD GRIB2如何在使用xarray时修复镜像数据
【发布时间】:2021-12-09 08:53:47
【问题描述】:

我在新英格兰提取风速 grib 文件的代码:

import pandas as pd
import numpy as np

import requests
import cfgrib
import xarray as xr

resp = requests.get('https://tgftp.nws.noaa.gov/SL.us008001/ST.opnl/DF.gr2/DC.ndfd/AR.neast/VP.001-003/ds.wspd.bin', stream=True)

f = open('..\\001_003wspd.grib2', 'wb')
f.write(resp1.content)
f.close()

xr_set = xr.load_dataset('..\\001_003wspd.grib2', engine='cfgrib')

xr_set.si10[0].plot(cmap=matplotlib.pyplot.cm.coolwarm)

这给出:

如您所见,它是从东到西每隔一条线镜像的。缅因州是最明显的。

【问题讨论】:

    标签: python python-xarray grib cfgrib ndfd


    【解决方案1】:

    我相信这不是代码问题,而是没有正确写入的文件。如果每两行只取一行,则得到正确的地图:

    import numpy as np
    import requests
    import xarray as xr
    from fs.tempfs import TempFS
    
    resp = requests.get('https://tgftp.nws.noaa.gov/SL.us008001/ST.opnl/DF.gr2/DC.ndfd/AR.neast/VP.001-003/ds.wspd.bin', stream=True)
    
    with TempFS() as tempfs:
        path = tempfs.getsyspath("001_003wspd.grib2")
        f = open(path, 'wb')
        f.write(resp.content)
        f.close()
    
        ds = xr.load_dataset(path, engine='cfgrib')
        ds = ds.isel(y=np.arange(len(ds.y))[1::2])
    
    ds.si10.isel(step=15).plot(cmap="coolwarm", x='longitude', y='latitude')
    

    【讨论】:

      猜你喜欢
      • 2018-02-14
      • 2015-08-14
      • 1970-01-01
      • 2020-08-26
      • 2017-12-26
      • 2019-12-13
      • 1970-01-01
      • 2019-07-04
      • 1970-01-01
      相关资源
      最近更新 更多