我一直在尝试使用Will Holgren的示例get_nomads.py模块,他足够好来转发我的方法。在代码中,有一个调用来获取THREDDS数据,如下所示:
from pydap.client import open_url
dataset = open_url('https://nomads.ncdc.noaa.gov/thredds/dodsC/gfs-004/201612/20161201/gfs_4_20161201_0000_003.grb2')
这不起作用,因为(显然)旧的THREDDS服务器已停用。
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2018.2.4\helpers\pydev\_pydevd_bundle\pydevd_exec2.py", line 3, in Exec
exec(exp, global_vars, local_vars)
File "<input>", line 1, in <module>
File "C:\Users\pmoran\jira\slf\venv\lib\site-packages\pydap\client.py", line 64, in open_url
dataset = DAPHandler(url, application, session, output_grid).dataset
File "C:\Users\pmoran\jira\slf\venv\lib\site-packages\pydap\handlers\dap.py", line 51, in __init__
raise_for_status(r)
File "C:\Users\pmoran\jira\slf\venv\lib\site-packages\pydap\net.py", line 30, in raise_for_status
comment=response.body
webob.exc.HTTPError: 404 Not Found
因此,环顾四周,我找不到支持这种数据访问方法的THREDDS服务器。
顺便说一句:我能够按以下方式获取数据:
url = 'http://dtvirt5.deltares.nl:8080/thredds/dodsC/opendap/rijkswaterstaat/jarkus/profiles/transect.nc'
dataset = open_url(url)
<DatasetType with children 'id', 'areacode', 'areaname', 'alongshore', 'cross_shore', 'time', 'time_bounds', 'epsg', 'x', 'y', 'lat', 'lon', 'angle', 'mean_high_water', 'mean_low_water', 'max_cross_shore_measurement', 'min_cross_shore_measurement', 'nsources', 'max_altitude_measurement', 'min_altitude_measurement', 'rsp_x', 'rsp_y', 'rsp_lat', 'rsp_lon', 'time_topo', 'time_bathy', 'origin', 'altitude'>
variable = dataset['id']
print(variable[0:10])
[2000100 2000101 2000102 2000103 2000104 2000105 2000106 2000120 2000140
2000160]
我还看到我可以手动从https://www.ncei.noaa.gov/thredds/dodsC/gfs-g4-anl-files/201808/20180828/gfsanl_4_20180828_1800_006.grb2.html下载数据
但是我似乎找不到使用pydap下载数据的参数格式。我想我所需要的只是一个指向真实THREDDS服务器的指针,该服务器在相同的URI位置具有适当的DDS和DAS文件。
有人知道如何使用pydap客户端获取GFS4 GRB文件吗?
谢谢
答案 0 :(得分:1)
还没有使用pydap进行过测试,也没有使用netCDF4进行过测试,而netCDF4确实可以对THREDDS进行测试。这应该使用pydap工作。
dataset = open_url('http://www.ncei.noaa.gov/thredds/dodsC/gfs-g4-anl-files/201612/20161201/gfsanl_4_20161201_0000_003.grb2')
该文件的THREDDS OPeNDAP表单为here:
YYYYMM /组织的主要目录位于:
https://www.ncei.noaa.gov/thredds/catalog/gfs-g4-anl-files/catalog.html
所有带有TDS访问链接的NCEI GFS数据集都可以在此处找到:
https://www.ncdc.noaa.gov/data-access/model-data/model-datasets/global-forcast-system-gfs
答案 1 :(得分:0)
当我尝试为您提供pydap的Eric链接时,出现此错误。
dataset = open_url('http://www.ncei.noaa.gov/thredds/dodsC/gfs-g4-anl-files/201612/20161201/gfsanl_4_20161201_0000_003.grb2')
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2018.2.4\helpers\pydev\_pydevd_bundle\pydevd_exec2.py", line 3, in Exec
exec(exp, global_vars, local_vars)
File "<input>", line 1, in <module>
File "C:\Users\pmoran\jira\slf\venv\lib\site-packages\pydap\client.py", line 64, in open_url
dataset = DAPHandler(url, application, session, output_grid).dataset
File "C:\Users\pmoran\jira\slf\venv\lib\site-packages\pydap\handlers\dap.py", line 64, in __init__
self.dataset = build_dataset(dds)
File "C:\Users\pmoran\jira\slf\venv\lib\site-packages\pydap\parsers\dds.py", line 161, in build_dataset
return DDSParser(dds).parse()
File "C:\Users\pmoran\jira\slf\venv\lib\site-packages\pydap\parsers\dds.py", line 49, in parse
self.consume('dataset')
File "C:\Users\pmoran\jira\slf\venv\lib\site-packages\pydap\parsers\dds.py", line 41, in consume
token = super(DDSParser, self).consume(regexp)
File "C:\Users\pmoran\jira\slf\venv\lib\site-packages\pydap\parsers\__init__.py", line 182, in consume
raise Exception("Unable to parse token: %s" % self.buffer[:10])
Exception: Unable to parse token: <!DOCTYPE
但是,根据您的建议,我可以使用NETCDF4获取数据。 这就是我所做的。
>>> import netCDF4
>>> nc = netCDF4.Dataset('http://www.ncei.noaa.gov/thredds/dodsC/gfs-g4-anl-files/201612/20161201/gfsanl_4_20161201_0000_003.grb2')
>>> nc.variables.keys()
odict_keys(['LatLon_Projection', 'lat', 'lon', 'reftime', 'time', 'time_bounds',
...
'v-component_of_wind_altitude_above_msl', 'v-component_of_wind_height_above_ground', 'v-component_of_wind_tropopause', 'v-component_of_wind_sigma'])
这似乎可行。不确定pydap怎么了。