def load_training_vector(response_shapes, explanatory_rasters, response_field, metric='<STR_LIT>'):
from rasterstats import zonal_stats<EOL>all_means = []<EOL>all_zones = None<EOL>for i, raster in enumerate(explanatory_rasters):<EOL><INDENT>logger.debug("<STR_LIT>" % raster)<EOL>stats = zonal_stats(response_shapes, raster, stats=metric, prefix="<STR_LIT>", geojson_out=True)<EOL>zones = [x['<STR_LIT>'][response_field] for x in stats]<EOL>if all_zones:<EOL><INDENT>assert zones == all_zones<EOL><DEDENT>else:<EOL><INDENT>all_zones = zones<EOL><DEDENT>means = [x['<STR_LIT>']['<STR_LIT>' + metric] for x in stats]<EOL>all_means.append(means)<EOL><DEDENT>train_y = np.array(all_zones)<EOL>train_xs = np.array(all_means).T<EOL>return train_xs, train_y<EOL>
Parameters
----------
response_shapes : Source of vector features for raster_stats;
                  can be OGR file path or iterable of geojson-like features
response_field : Field name containing the known response category (must be numeric)
explanatory_rasters : List of Paths to GDAL rasters containing explanatory variables
metric : Statistic to aggregate explanatory data across line and polygon vector features
         Defaults to 'mean' (optional)

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