<jupyter_start><jupyter_text>Figure 2b (no color)<jupyter_code>from matplotlib import pyplot
%matplotlib inline
#import pyproj
import numpy
import geopandas
from django.db import connection
from database.models import Site
from landscape.models import LandCover
from django.contrib.gis.db.models.functions import Intersection, Envelope
from django.contrib.gis.db.models import Collect
from shapely.geometry import shape
from descartes import PolygonPatch
from matplotlib.collections import PatchCollection
site = Site.objects.get(name="Hofgarten")
def get_geodataframe(queryset, modification=None, crs={'init':'epsg:4326'}):
    query = queryset.query.sql_with_params()
    if modification:
        query = (modification, query[1])
    return geopandas.read_postgis(query[0], connection, 
                                   geom_col='geometry', 
                                   params=query[1], 
                                   index_col='id',
                                   crs=crs)
def get_landcover(point, radius=100):
    buffer = point.buffer(radius)
    result = LandCover.objects.filter(geometry__intersects=buffer.envelope)\
                          .annotate(intersection=Intersection('geometry', buffer.envelope))#.aggregate(total=Collect('intersection'))
    return result
def get_patch_collection(shapes, edgecolor='black', facecolor='none', hatch=None):
    patches = []
    for shape in shapes:
        try:
            patches.append(PolygonPatch(shape))
        except AssertionError:
            for sub_shape in shape:
                patches.append(PolygonPatch(sub_shape))
    return PatchCollection(patches, edgecolor=edgecolor, facecolor=facecolor, hatch=hatch)
modification = 'SELECT "landscape_landcover"."id", "landscape_landcover"."cover_type", ST_Intersection("landscape_landcover"."geometry", %s) AS "geometry" FROM "landscape_landcover" WHERE ST_Intersects("landscape_landcover"."geometry", %s)'
point_landcover = get_geodataframe(get_landcover(site.geometry, radius = 600),
                                   modification=modification)
radii = geopandas.GeoDataFrame([#{'name': 'recording location', 'geometry': shape(eval(site.geometry.geojson))},
                                {'name': '50m', 'geometry': shape(eval(site.geometry.buffer(50).geojson))},
                                {'name': '100m', 'geometry': shape(eval(site.geometry.buffer(100).geojson))},
                                {'name': '200m', 'geometry': shape(eval(site.geometry.buffer(200).geojson))},
                                {'name': '500m', 'geometry': shape(eval(site.geometry.buffer(500).geojson))},], 
                               index=numpy.arange(4), crs={'init':'epsg:4326'}, geometry='geometry')
buildings = get_patch_collection(shapes=point_landcover[point_landcover.cover_type == 1].geometry.as_matrix(), 
                                 facecolor='0.3', edgecolor='0.7', hatch='///')
surfaces = get_patch_collection(shapes=point_landcover[point_landcover.cover_type == 2].geometry.as_matrix(), 
                                facecolor='0.3')
field = get_patch_collection(shapes=point_landcover[point_landcover.cover_type == 12].geometry.as_matrix(), 
                             facecolor='0.8', hatch='...')
trees = get_patch_collection(shapes=point_landcover[point_landcover.cover_type == 9].geometry.as_matrix(), 
                             facecolor='white')
water = get_patch_collection(shapes=point_landcover[point_landcover.cover_type == 6].geometry.as_matrix(), 
                             hatch='xx')
figure3, ax = pyplot.subplots()
figure3.set_dpi(192)
figure3.set_figwidth(7)
figure3.set_figheight(7)
ax.set_aspect('equal')
#p1 = point_landcover.plot(ax=ax, vmax=15, column='cover_type', edgecolor='black')
ax.add_collection(buildings)
ax.add_collection(surfaces)
ax.add_collection(field)
ax.add_collection(trees)
ax.add_collection(water)
p2 = radii.plot(ax=ax, facecolor='none', edgecolor='black', linewidth=3, linestyle='-')
#a_hillshade = ax.imshow('data', extent='extent', interpolation='none', data=hillshade, cmap='gray', alpha=0.5)
p3 = ax.scatter(site.geometry.coords[0], site.geometry.coords[1], marker='+', color='black', s=500, linewidths=3)
bbox = numpy.array(site.geometry.buffer(600).envelope.coords[0])
ax.set_xlim([bbox[:, 0].min(), bbox[:, 0].max()])
ax.set_ylim([bbox[:, 1].min(), bbox[:, 1].max()])
ax.set_frame_on(False)
ax.tick_params(axis='both', 
               bottom=False, right=False, top=False, left=False,
               labelbottom=False, labelleft=False)
t2 = ax.set_title('contributing land cover', loc='left')
x = site.geometry.coords[0]
y = site.geometry.coords[1]
#a1 = ax.annotate('200m', (x+150, y+150), xytext=(x+200, y+200), ha='center', va='center', size=12, arrowprops=ap)
#a2 = ax.annotate('500m', (x+450, y+450), xytext=(x+400, y+400), ha='center', va='center', size=12, arrowprops=ap)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14585028478437753, 'fraction_numerical': 0.025427176566314078, 'mean_word_length': 3.673954372623574, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '180446', 'license': 'MIT', 'n_tokens_mistral': 1625, 'n_tokens_neox': 1523, 'n_words': 253, 'path': 'archive/Figure 2b (no color).ipynb', 'repo_name': 'jacobdein/alpine-soundscapes', 'size': '4916'}