Beispiel #1
0
    def test_stats_for_satellite_image_fails_with_wrong_arguments(self):
        instance = self.factory(MockHttpClientStats)
        with self.assertRaises(ValueError):
            metaimg = MetaTile('http://a.com', PresetEnum.FALSE_COLOR,
                               SatelliteEnum.SENTINEL_2.name, 1378459200, 98.2,
                               0.3, 11.7, 7.89, 'a1b2c3d4', 'http://b.com')
            instance.stats_for_satellite_image(metaimg)

        with self.assertRaises(ValueError):
            metaimg = MetaTile('http://a.com', PresetEnum.EVI,
                               SatelliteEnum.SENTINEL_2.name, 1378459200, 98.2,
                               0.3, 11.7, 7.89, 'a1b2c3d4', None)
            instance.stats_for_satellite_image(metaimg)
Beispiel #2
0
 def test_stats_for_satellite_image(self):
     instance = self.factory(MockHttpClientStats)
     # stats retrieval currently only works for NDVI and EVI presets
     try:
         metaimg = MetaTile('http://a.com', PresetEnum.EVI,
                            SatelliteEnum.SENTINEL_2.name, 1378459200, 98.2,
                            0.3, 11.7, 7.89, 'a1b2c3d4', 'http://b.com')
         result = instance.stats_for_satellite_image(metaimg)
         self.assertIsInstance(result, dict)
     except:
         self.fail()
     try:
         metaimg = MetaTile('http://a.com', PresetEnum.NDVI,
                            SatelliteEnum.SENTINEL_2.name, 1378459200, 98.2,
                            0.3, 11.7, 7.89, 'a1b2c3d4', 'http://b.com')
         instance.stats_for_satellite_image(metaimg)
         self.assertIsInstance(result, dict)
     except:
         self.fail()
Beispiel #3
0
 def test_download_satellite_image_with_tile_png(self):
     instance = self.factory(MockHttpClientReturningImage)
     metaimg = MetaTile('http://a.com', PresetEnum.FALSE_COLOR,
                        SatelliteEnum.SENTINEL_2.name, 1378459200, 98.2,
                        0.3, 11.7, 7.89, 'a1b2c3d4')
     result = instance.download_satellite_image(metaimg, x=1, y=2, zoom=4)
     self.assertTrue(isinstance(result, SatelliteImage))
     self.assertTrue(isinstance(result.metadata, MetaTile))
     self.assertTrue(isinstance(result.data, Tile))
     self.assertEqual(result.data.image.image_type, ImageTypeEnum.PNG)
     self.assertEqual(result.palette, PaletteEnum.GREEN)
Beispiel #4
0
 def test_download_satellite_image_with_tile_png_fails_without_tile_coords(
         self):
     instance = self.factory(MockHttpClientReturningImage)
     metaimg = MetaTile('http://a.com', PresetEnum.FALSE_COLOR,
                        SatelliteEnum.SENTINEL_2.name, 1378459200, 98.2,
                        0.3, 11.7, 7.89, 'a1b2c3d4')
     with self.assertRaises(AssertionError):
         instance.download_satellite_image(metaimg)
     with self.assertRaises(AssertionError):
         instance.download_satellite_image(metaimg, x=1)
     with self.assertRaises(AssertionError):
         instance.download_satellite_image(metaimg, x=1, y=2)
Beispiel #5
0
    def __init__(self, polygon_id, list_of_dict, query_timestamp):
        """
        Parses raw data dict into a list of `pyowm.agroapi10.imagery.MetaImage` subtypes instances and stores that
        list internally for further filtering

        :param polygon_id: the ID of the polygon that has been searched for images
        :type polygon_id: str
        :param list_of_dict: the input data dictionary
        :type list_of_dict: list
        :param query_timestamp: UNIX timestamp of the query
        :type query_timestamp: int
        :returns: a `pyowm.agroapi10.imagery.SatelliteImagerySearchResultSet` instance or an exception is parsing fails

        """
        assert isinstance(polygon_id, str)
        self.polygon_id = polygon_id

        assert isinstance(list_of_dict, list)

        assert isinstance(query_timestamp, int)
        self.query_timestamp = query_timestamp

        # parse raw data
        result = list()
        for the_dict in list_of_dict:
            # common metadata
            acquisition_time = the_dict.get('dt', None)
            satellite_name = the_dict.get('type', None)
            valid_data_percentage = the_dict.get('dc', None)
            cloud_coverage_percentage = the_dict.get('cl', None)
            sun = the_dict.get('sun', dict())
            sun_azimuth = sun.get('azimuth', None)
            sun_elevation = sun.get('elevation', None)

            # Stats for the images
            stats_dict = the_dict.get('stats', dict())
            stats_url_for_ndvi = stats_dict.get('ndvi', None)
            stats_url_for_evi = stats_dict.get('evi', None)

            # PNG images for the polygon
            png_dict = the_dict.get('image', dict())
            true_color_png_url = png_dict.get('truecolor', None)
            false_color_png_url = png_dict.get('falsecolor', None)
            ndvi_png_url = png_dict.get('ndvi', None)
            evi_png_url = png_dict.get('evi', None)
            if true_color_png_url is not None:
                result.append(
                    MetaPNGImage(true_color_png_url,
                                 PresetEnum.TRUE_COLOR,
                                 satellite_name,
                                 acquisition_time,
                                 valid_data_percentage,
                                 cloud_coverage_percentage,
                                 sun_azimuth,
                                 sun_elevation,
                                 polygon_id=polygon_id))
            if false_color_png_url is not None:
                result.append(
                    MetaPNGImage(false_color_png_url,
                                 PresetEnum.FALSE_COLOR,
                                 satellite_name,
                                 acquisition_time,
                                 valid_data_percentage,
                                 cloud_coverage_percentage,
                                 sun_azimuth,
                                 sun_elevation,
                                 polygon_id=polygon_id))
            if ndvi_png_url is not None:
                result.append(
                    MetaPNGImage(ndvi_png_url,
                                 PresetEnum.NDVI,
                                 satellite_name,
                                 acquisition_time,
                                 valid_data_percentage,
                                 cloud_coverage_percentage,
                                 sun_azimuth,
                                 sun_elevation,
                                 polygon_id=polygon_id,
                                 stats_url=stats_url_for_ndvi))
            if evi_png_url is not None:
                result.append(
                    MetaPNGImage(evi_png_url,
                                 PresetEnum.EVI,
                                 satellite_name,
                                 acquisition_time,
                                 valid_data_percentage,
                                 cloud_coverage_percentage,
                                 sun_azimuth,
                                 sun_elevation,
                                 polygon_id=polygon_id,
                                 stats_url=stats_url_for_evi))

            # Tiles for the polygon
            tiles_dict = the_dict.get('tile', dict())
            true_color_tile_url = tiles_dict.get('truecolor', None)
            false_color_tile_url = tiles_dict.get('falsecolor', None)
            ndvi_tile_url = tiles_dict.get('ndvi', None)
            evi_tile_url = tiles_dict.get('evi', None)
            if true_color_tile_url is not None:
                result.append(
                    MetaTile(true_color_tile_url,
                             PresetEnum.TRUE_COLOR,
                             satellite_name,
                             acquisition_time,
                             valid_data_percentage,
                             cloud_coverage_percentage,
                             sun_azimuth,
                             sun_elevation,
                             polygon_id=polygon_id))
            if false_color_tile_url is not None:
                result.append(
                    MetaTile(false_color_tile_url,
                             PresetEnum.FALSE_COLOR,
                             satellite_name,
                             acquisition_time,
                             valid_data_percentage,
                             cloud_coverage_percentage,
                             sun_azimuth,
                             sun_elevation,
                             polygon_id=polygon_id))
            if ndvi_tile_url is not None:
                result.append(
                    MetaTile(ndvi_tile_url,
                             PresetEnum.NDVI,
                             satellite_name,
                             acquisition_time,
                             valid_data_percentage,
                             cloud_coverage_percentage,
                             sun_azimuth,
                             sun_elevation,
                             polygon_id=polygon_id,
                             stats_url=stats_url_for_ndvi))
            if evi_tile_url is not None:
                result.append(
                    MetaTile(evi_tile_url,
                             PresetEnum.EVI,
                             satellite_name,
                             acquisition_time,
                             valid_data_percentage,
                             cloud_coverage_percentage,
                             sun_azimuth,
                             sun_elevation,
                             polygon_id=polygon_id,
                             stats_url=stats_url_for_evi))

            # geoTiff images for the polygon
            geotiff_dict = the_dict.get('data', dict())
            true_color_geotiff_url = geotiff_dict.get('truecolor', None)
            false_color_geotiff_url = geotiff_dict.get('falsecolor', None)
            ndvi_geotiff_url = geotiff_dict.get('ndvi', None)
            evi_geotiff_url = geotiff_dict.get('evi', None)
            if true_color_geotiff_url is not None:
                result.append(
                    MetaGeoTiffImage(true_color_geotiff_url,
                                     PresetEnum.TRUE_COLOR,
                                     satellite_name,
                                     acquisition_time,
                                     valid_data_percentage,
                                     cloud_coverage_percentage,
                                     sun_azimuth,
                                     sun_elevation,
                                     polygon_id=polygon_id))
            if false_color_geotiff_url is not None:
                result.append(
                    MetaGeoTiffImage(false_color_geotiff_url,
                                     PresetEnum.FALSE_COLOR,
                                     satellite_name,
                                     acquisition_time,
                                     valid_data_percentage,
                                     cloud_coverage_percentage,
                                     sun_azimuth,
                                     sun_elevation,
                                     polygon_id=polygon_id))
            if ndvi_geotiff_url is not None:
                result.append(
                    MetaGeoTiffImage(ndvi_geotiff_url,
                                     PresetEnum.NDVI,
                                     satellite_name,
                                     acquisition_time,
                                     valid_data_percentage,
                                     cloud_coverage_percentage,
                                     sun_azimuth,
                                     sun_elevation,
                                     polygon_id=polygon_id,
                                     stats_url=stats_url_for_ndvi))
            if evi_geotiff_url is not None:
                result.append(
                    MetaGeoTiffImage(evi_geotiff_url,
                                     PresetEnum.EVI,
                                     satellite_name,
                                     acquisition_time,
                                     valid_data_percentage,
                                     cloud_coverage_percentage,
                                     sun_azimuth,
                                     sun_elevation,
                                     polygon_id=polygon_id,
                                     stats_url=stats_url_for_evi))
        self.metaimages = result