Skip to content

Commit

Permalink
include visualisation
Browse files Browse the repository at this point in the history
  • Loading branch information
nilshempelmann committed Dec 1, 2018
1 parent 6aafc2f commit 7b330bd
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions eggshell/visual/visualisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,18 @@
import logging
# from matplotlib import use
# use('Agg') # use this if no xserver is available
import numpy as np

from matplotlib import pyplot as plt
from matplotlib.patches import Polygon
import matplotlib.patches as mpatches
from matplotlib.collections import PatchCollection

from cartopy import config as cartopy_config
import cartopy.feature as cfeature
from cartopy.util import add_cyclic_point
import re

# from matplotlib.colors import Normalize
# from cartopy import config as cartopy_config
# from cartopy.util import add_cyclic_point
Expand All @@ -29,6 +39,44 @@ def fig2plot(fig, file_extension='png', output_dir='.', bbox_inches='tight', dpi

return graphic

def plot_products(products, extend=[10, 20, 5, 15]):
"""
plot the products extends of the search result
:param products: output of sentinel api search
:return graphic: map of extents
"""


try:
fig = plt.figure(dpi=90, facecolor='w', edgecolor='k')
projection = ccrs.PlateCarree()
ax = plt.axes(projection=projection)
ax.set_extent(extend)
ax.stock_img()
ax.coastlines()
ax.add_feature(cfeature.BORDERS)

pat = re.compile(r'''(-*\d+\.\d+ -*\d+\.\d+);*''')

for key in products.keys():
polygon = str(products[key]['footprint'])

# s = 'POLYGON ((15.71888453311329 9.045763865974665,15.7018748825589 8.97110837227606,15.66795226563288 8.822558900399137,15.639498612331632 8.69721920092792,15.63428409805786 8.674303514900869,15.600477269179995 8.525798537094156,15.566734239298787 8.377334323160321,15.53315342410745 8.228822837291709,15.499521168391912 8.080353481086165,15.493321895031096 8.052970059354971,14.999818486685434 8.053569047879877,14.999818016115439 9.046743365203026,15.71888453311329 9.045763865974665))'
matches = pat.findall(polygon)
if matches:
xy = np.array([map(float, m.split()) for m in matches])
ax.add_patch(mpatches.Polygon(xy, closed=True, transform=ccrs.PlateCarree(), alpha=0.4)) # color='coral'
# ccrs.Geodetic()

ax.gridlines(draw_labels=True,)
img = vs.fig2plot(fig, output_dir='.')
except:
LOGGER.debug('failed to plot EO products')
_, img = mkstemp(dir='.', prefix='dummy_', suffix='.png')

return img


# class MidpointNormalize(Normalize):
Expand Down

0 comments on commit 7b330bd

Please sign in to comment.