如果你訪問這個網站: https ://ruc.noaa.gov/raobs/Data_request.cgi?byr=2010&bmo=5&bdy=26&bhr=12&eyr=2010&emo=5&edy=27&ehr=15&shour=All Times<ype=All Levels&wunits=Knots&access =WMO 臺站 識別符號
在框中鍵入“72632”,將“格式”更改為“NetCDF 格式(二進制)”,然后單擊“繼續資料訪問”,一個 NetCDF 檔案將下載到您的計算機。
如果我在單擊此按鈕后使用 Chrome 開發人員工具跟蹤網路活動,我可以看到導致此檔案被下載的“請求 URL”是: https://ruc.noaa.gov/raobs/GetRaobs.cgi? shour=所有 時間<ype=所有 級別&wunits=節數&bdate=2010052612&edate=2010052715&access=WMO Station Identifier&view=NO&StationIDs=72632&osort=Station Series 排序&oformat=NetCDF format (Binary)
如果您將該 URL 復制并粘貼到 Web 瀏覽器中,則會下載該檔案。
我想要做的是使用 Python 獲取一個格式如上的 URL,并檢索相關的 NetCDF 檔案。
我過去很幸運做過類似的事情
url = 'https://ruc.noaa.gov/raobs/GetRaobs.cgi?shour=All Times<ype=All Levels&wunits=Knots&bdate=2010052612&edate=2010052715&access=WMO Station Identifier&view=NO&StationIDs=72632&osort=Station Series Sort&oformat=NetCDF format (Binary)'
da = xr.open_dataset(url)
但這在這種情況下不起作用:
OSError: [Errno -75] NetCDF: Malformed or unexpected Constraint: b'https://ruc.noaa.gov/raobs/GetRaobs.cgi?shour=All Times<ype=All Levels&wunits=Knots&bdate=2010052612&edate=2010052715&access=WMO Station Identifier&view=NO&StationIDs=72632&osort=Station Series Sort&oformat=NetCDF format (Binary)'
我也嘗試過wget該 URL,但這只是下載了一個我認為沒有用的“.cgi”檔案。
謝謝你的幫助!
uj5u.com熱心網友回復:
您可以使用我的包 nctoolkit 下載檔案,然后匯出到 xarray。這會將檔案保存到臨時目錄,但會在會話完成后將其洗掉。
import nctoolkit as nc
import xarray as xr
ds = nc.open_url("https://ruc.noaa.gov/raobs/GetRaobs.cgi?shour=All Times<ype=All Levels&wunits=Knots&bdate=2010052612&edate=2010052715&access=WMO Station Identifier&view=NO&StationIDs=72632&osort=Station Series Sort&oformat=NetCDF format (Binary)")
ds_xr = ds.to_xarray()
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/483237.html
下一篇:'Viewpagesource'和document.querySelector("html").innerHTML之間的區別是什么?
