1 回答
![?](http://img1.sycdn.imooc.com/533e4d5b0001d57502200203-100-100.jpg)
TA贡献1850条经验 获得超11个赞
正如我们所知,我们不能使用通配符运算符来访问 openDAP 服务器的数据。但我们可以利用 CMIP 模型输出文件的常规结构并手动构建文件名:
import calendar
import pandas as pd
import xarray as xr
# base url
base_url = 'http://esgf-data3.ceda.ac.uk/thredds/dodsC/esg_cmip6/CMIP6/HighResMIP/CMCC/CMCC-CM2-VHR4/highres-future/r1i1p1f1/6hrPlevPt/sfcWind/gn/v20190509/sfcWind_6hrPlevPt_CMCC-CM2-VHR4_highres-future_r1i1p1f1_gn_'
# period of interest
pr = pd.period_range(start='2015-01',end='2050-12', freq='M')
file_list=[]
for dt in pr:
# get recent year and month
year = dt.strftime('%Y')
month = dt.strftime('%m')
# get last day of month (no leap years in CMIP)
last_day_of_month = str(calendar.monthrange(dt.year, dt.month)[1])
if last_day_of_month == '29':
last_day_of_month = '28'
# build complete file name
single_file=(base_url+year+month+'010000-'+year+month+last_day_of_month+'1800.nc')
file_list.append(single_file)
ds=xr.open_mfdataset(file_list)
添加回答
举报