我有一个我用xarray读过的netCDF文件。该数组包含时间,latidude,经度和只有一个数据变量(即索引值)
# read the netCDF files
with xr.open_mfdataset('wet_tropics.nc') as wet:
print(wet)
Out[]:
<xarray.Dataset>
Dimensions: (time: 1437, x: 24, y: 20)
Coordinates:
* y (y) float64 -1.878e+06 -1.878e+06 -1.878e+06 -1.878e+06 ...
* x (x) float64 1.468e+06 1.468e+06 1.468e+06 1.468e+06 ...
* time (time) object '2013-03-29T00:22:28.500000000' ...
Data variables:
index_values (time, y, x) float64 dask.array<shape=(1437, 20, 24), chunksize=(1437, 20, 24)>
到目前为止,这么好。 现在我需要将广义加法模型应用于数组中的每个网格单元。我想使用的模型来自Facebook Prophet(https://facebook.github.io/prophet/),之前我已成功将它应用于pandas数据库。例如:
cns_ap['y'] = cns_ap['av_index'] # Prophet requires specific names 'y' and 'ds' for column names
cns_ap['ds'] = cns_ap['Date']
cns_ap['cap'] = 1
m1 = Prophet(weekly_seasonality=False, # disables weekly_seasonality
daily_seasonality=False, # disables daily_seasonality
growth='logistic', # logistic because indices have a maximum
yearly_seasonality=4, # fourier transform. int between 1-10
changepoint_prior_scale=0.5).fit(cns_ap)
future1 = m1.make_future_dataframe(periods=60, # 5 year prediction
freq='M', # monthly predictions
include_history=True) # fits model to all historical data
future1['cap'] = 1 # sets cap at maximum index value
forecast1 = m1.predict(future1)
# m1.plot_components(forecast1, plot_cap=False);
# m1.plot(forecast1, plot_cap=False, ylabel='CNS index', xlabel='Year');
问题是我现在必须的 1)遍历netCDF文件的每个单元格, 2)通过时间获取该单元格的所有值, 3)应用GAM(使用fbprophet),然后导出并绘制结果。
问题:您对如何遍历栅格有任何想法,始终获取每个像素的index_values以便我可以运行GAM吗? 我认为嵌套的for循环是可行的,虽然我不知道如何制作一个遍历每个单元格的循环。
感谢任何帮助