def stats(self, shp, stats='<STR_LIT>', add_stats=None, raster_out=True, *args, **kwargs):
df = pd.DataFrame(zonal_stats(shp, self.raster, nodata=self.nodata_value,<EOL>all_touched=True, raster_out=raster_out,<EOL>affine=Affine.from_gdal(*self.geot),<EOL>geojson_out=True, stats=stats, add_stats=add_stats))<EOL>df['<STR_LIT>'] = df.properties.apply(lambda x: GeoRaster(x['<STR_LIT>'],<EOL>Affine.to_gdal(x['<STR_LIT>']),<EOL>nodata_value=x['<STR_LIT>'],<EOL>projection=self.projection,<EOL>datatype=self.datatype))<EOL>statcols = list(set([i for i in df.properties[<NUM_LIT:0>].keys()]).difference(set(shp.columns)))<EOL>cols = shp.columns.tolist()+statcols<EOL>cols = [i for i in cols if i != '<STR_LIT>' and i.find('<STR_LIT>') == -<NUM_LIT:1>]<EOL>df2 = pd.DataFrame([df.properties.apply(lambda x: x[i]) for i in cols]).T<EOL>df2.columns = cols<EOL>df2 = df2.merge(df[['<STR_LIT:id>', '<STR_LIT>']], left_index=True, right_index=True)<EOL>df2.set_index('<STR_LIT:id>', inplace=True)<EOL>return df2<EOL>
Compute raster statistics for a given geometry in shape, where shape is either
a GeoPandas DataFrame, shapefile, or some other geometry format used by
python-raster-stats. Runs python-raster-stats in background
(additional help and info can be found there)

Returns dataframe with statistics and clipped raster

Usage:

df = geo.stats(shape, stats=stats, add_stats=add_stats)

where:
raster_out: If True (Default), returns clipped Georasters