Julia HTTP GET Headers 未按预期工作

Julia HTTP GET Headers not working as intended

我想下载一个范围内的 grib2 文件数据,如本 Python 笔记本中所做的那样: https://nbviewer.org/github/microsoft/AIforEarthDataSets/blob/main/data/noaa-hrrr.ipynb (参见单元格 5)

我尝试了以下代码,但它似乎下载了整个 GRIB 文件而不是范围:

using HTTP
url = "https://noaahrrr.blob.core.windows.net/hrrr/hrrr.20210513/conus/hrrr.t12z.wrfsfcf01.grib2"
range_start = 38448330
range_end   = 39758083
    
grib2_bytes = HTTP.request("GET", url; headers = Dict("Range" => Dict("bytes" => [range_start; range_end]) ) );

# save bytes to file
io = open("variable.grib2", "w");
write(io, grib2_bytes); # I can see the file is too big (148 MB)
close(io)

# rest of the code is just to read the data
# The downloaded file subset is a valid GRIB2 file.
using GRIB
f = GribFile("variable.grib2")
msg = Message(f)

要模仿 python 代码,您应该使用 string interpolation:

range_start = 38448330
range_end   = 39758083

headers = Dict(
    "Range" => "bytes=$(range_start)-$(range_end)"
)