def second_layer_input_matrix(X, models):
'''Build a second layer model input matrix by taking the
metadata from X given to the first layer models and forming
a new matrix from the 1-D predictions of the first layer models
'''
preds = predict_many(dict(X=X), to_raster=False,
ensemble=models)
example = preds[0].flat
input_matrix = np.empty((example.shape[0], len(preds)))
for j, pred in enumerate(preds):
input_matrix[:, j] = pred.flat.values[:, 0]
attrs = X.attrs.copy()
attrs['old_dims'] = [X[SOIL_MOISTURE].dims] * len(preds)
attrs['canvas'] = X[SOIL_MOISTURE].canvas
tags = [tag for tag, _ in models]
arr = xr.DataArray(input_matrix,
coords=[('space', example.space),
('band', tags)],
dims=('space', 'band'),
attrs=attrs)
return xr.Dataset(dict(flat=arr), attrs=attrs)
评论列表
文章目录