def load_training_rasters(response_raster, explanatory_rasters, selected=None):
with rasterio.open(response_raster) as src:<EOL><INDENT>response_data = src.read().flatten()<EOL><DEDENT>if selected is None:<EOL><INDENT>train_y = response_data<EOL><DEDENT>else:<EOL><INDENT>train_y = response_data[selected]<EOL><DEDENT>selected_data = []<EOL>for rast in explanatory_rasters:<EOL><INDENT>with rasterio.open(rast) as src:<EOL><INDENT>explanatory_data = src.read().flatten()<EOL><DEDENT>assert explanatory_data.size == response_data.size<EOL>if selected is None:<EOL><INDENT>selected_data.append(explanatory_data)<EOL><DEDENT>else:<EOL><INDENT>selected_data.append(explanatory_data[selected])<EOL><DEDENT><DEDENT>train_xs = np.asarray(selected_data).T<EOL>return train_xs, train_y<EOL>
Parameters
----------
response_raster : Path to GDAL raster containing responses
explanatory_rasters : List of Paths to GDAL rasters containing explanatory variables

Returns
-------
train_xs : Array of explanatory variables
train_ys : 1xN array of known responses