<commit_before>from tempfile import mkstemp
from osgeo import gdal, osr

import logging
LOGGER = logging.getLogger("PYWPS")


def get_timestamp(tile):
    """
    returns the creation timestamp of a tile image as datetime.

    :param tile: path to geotiff confom to gdal metadata http://www.gdal.org/gdal_datamodel.html

    :return datetime: timestamp
    """

    from datetime import datetime as dt
    try:
        ds = gdal.Open(tile, 0)
        ts = ds.GetMetadataItem("TIFFTAG_DATETIME")

        LOGGER.debug("timestamp: %s " % ts)
        ds = None  # to close the dataset

        timestamp = dt.strptime(ts, '%Y:%m:%d %H:%M:%S')
    except:
        LOGGER.exception('failed to get timestamp for: %s' % tile)
    return timestamp

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
    """

    import numpy as np

    import matplotlib.pyplot as plt
    import matplotlib
    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 cartopy.crs as ccrs
    import re


    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(), color='coral', alpha=0.6))
    # ccrs.Geodetic()

    ax.gridlines(draw_labels=True,)
    from flyingpigeon import visualisation as vs
    img = vs.fig2plot(fig, output_dir='/home/nils/data')

    return img



def plot_ndvi(geotif, file_extension='png'):
    """
    plots a NDVI image

    :param geotif: geotif file containning one band with NDVI values
    :param file_extension: format of the output graphic. default='png'

    :result str: path to graphic file
    """
    import numpy as np
    import struct

    # from osgeo import ogr
    # from osgeo import osr
    # from osgeo import gdal_array
    # from osgeo.gdalconst import *
<commit_msg>change hard coded path<commit_after>from tempfile import mkstemp
from osgeo import gdal, osr

import logging
LOGGER = logging.getLogger("PYWPS")


def get_timestamp(tile):
    """
    returns the creation timestamp of a tile image as datetime.

    :param tile: path to geotiff confom to gdal metadata http://www.gdal.org/gdal_datamodel.html

    :return datetime: timestamp
    """

    from datetime import datetime as dt
    try:
        ds = gdal.Open(tile, 0)
        ts = ds.GetMetadataItem("TIFFTAG_DATETIME")

        LOGGER.debug("timestamp: %s " % ts)
        ds = None  # to close the dataset

        timestamp = dt.strptime(ts, '%Y:%m:%d %H:%M:%S')
    except:
        LOGGER.exception('failed to get timestamp for: %s' % tile)
    return timestamp

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
    """

    import numpy as np

    import matplotlib.pyplot as plt
    import matplotlib
    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 cartopy.crs as ccrs
    import re


    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(), color='coral', alpha=0.6))
    # ccrs.Geodetic()

    ax.gridlines(draw_labels=True,)
    from flyingpigeon import visualisation as vs
    img = vs.fig2plot(fig, output_dir='.')

    return img



def plot_ndvi(geotif, file_extension='png'):
    """
    plots a NDVI image

    :param geotif: geotif file containning one band with NDVI values
    :param file_extension: format of the output graphic. default='png'

    :result str: path to graphic file
    """
    import numpy as np
    import struct

    # from osgeo import ogr
    # from osgeo import osr
    # from osgeo import gdal_array
    # from osgeo.gdalconst import *

{'fraction_non_alphanumeric': 0.10146561443066517, 'fraction_numerical': 0.139474955709454, 'mean_word_length': 3.379407616361072, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7353861', 'n_tokens_mistral': 2689, 'n_tokens_neox': 2127, 'n_words': 521}