Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_init(self):
bbox = BBox((8.655, 111.7, 8.688, 111.6), crs=CRS.WGS84)
data_request = WcsRequest(data_folder=self.OUTPUT_FOLDER, bbox=bbox, layer='BANDS-S2-L1C')
data_request.create_request(reset_wfs_iterator=True) # This method is used by s2cloudless, don't rename it
self.assertEqual(self.OUTPUT_FOLDER, data_request.data_folder,
msg="Expected {}, got {}".format(self.OUTPUT_FOLDER, data_request.data_folder))
self.assertTrue(isinstance(data_request.get_filename_list(), list), "Expected a list")
self.assertTrue(isinstance(data_request.get_url_list(), list), "Expected a list")
self.assertTrue(data_request.is_valid_request(), "Request should be valid")
def setUpClass(cls):
super().setUpClass()
polygon = shapely.geometry.Polygon([(465888.8773268595, 5079639.43613863),
(465885.3413983975, 5079641.52461826),
(465882.9542217017, 5079647.16604353),
(465888.8780175466, 5079668.70367663),
(465888.877326859, 5079639.436138632)])
cls.wkt_string = 'MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), ' \
'(30 20, 20 15, 20 25, 30 20)))'
cls.geometry1 = Geometry(polygon, CRS(32633))
cls.geometry2 = Geometry(cls.wkt_string, CRS.WGS84)
cls.bbox = BBox(bbox=[14.00, 45.00, 14.03, 45.03], crs=CRS.WGS84)
cls.bbox_collection = BBoxCollection([cls.bbox, BBox('46,13,47,20', CRS.WGS84)])
cls.geometry_list = [cls.geometry1, cls.geometry2, cls.bbox, cls.bbox_collection]
def setUpClass(cls):
super().setUpClass()
with open(os.path.join(cls.INPUT_FOLDER, "test_fis_results.txt"), 'r') as file:
results = [ast.literal_eval(line.strip()) for line in file]
bbox = BBox([14.00, 45.00, 14.03, 45.03], crs=CRS.WGS84)
geometry1 = Geometry(Polygon([(465888.877326859, 5079639.436138632),
(465885.3413983975, 5079641.524618266),
(465882.9542217017, 5079647.166043535),
(465888.8780175466, 5079668.703676634),
(465888.877326859, 5079639.436138632)]),
CRS(32633))
geometry2 = Geometry('POLYGON((-5.13 48, -5.23 48.09, -5.13 48.17, -5.03 48.08, -5.13 48))', CRS.WGS84)
cls.test_cases = [
cls.FisTestCase('geometry',
FisRequest(layer='TRUE-COLOR-S2-L1C',
geometry_list=[geometry1],
time=('2017-1-1', '2017-2-1'),
resolution="50m",
histogram_type=HistogramType.STREAMING,
bins=5),
raw_result=results[0],
result_length=1),
cls.FisTestCase('bbox',
FisRequest(layer='BANDS-S2-L1C',
geometry_list=[bbox],
time='2017-1-1',
resolution="50m",
def setUpClass(cls):
super().setUpClass()
with open(os.path.join(cls.INPUT_FOLDER, "test_fis_results.txt"), 'r') as file:
results = [ast.literal_eval(line.strip()) for line in file]
bbox = BBox([14.00, 45.00, 14.03, 45.03], crs=CRS.WGS84)
geometry1 = Geometry(Polygon([(465888.877326859, 5079639.436138632),
(465885.3413983975, 5079641.524618266),
(465882.9542217017, 5079647.166043535),
(465888.8780175466, 5079668.703676634),
(465888.877326859, 5079639.436138632)]),
CRS(32633))
geometry2 = Geometry('POLYGON((-5.13 48, -5.23 48.09, -5.13 48.17, -5.03 48.08, -5.13 48))', CRS.WGS84)
cls.test_cases = [
cls.FisTestCase('geometry',
FisRequest(layer='TRUE-COLOR-S2-L1C',
geometry_list=[geometry1],
time=('2017-1-1', '2017-2-1'),
resolution="50m",
histogram_type=HistogramType.STREAMING,
bins=5),
def setUpClass(cls):
super().setUpClass()
polygon = shapely.geometry.Polygon([(465888.8773268595, 5079639.43613863),
(465885.3413983975, 5079641.52461826),
(465882.9542217017, 5079647.16604353),
(465888.8780175466, 5079668.70367663),
(465888.877326859, 5079639.436138632)])
cls.wkt_string = 'MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), ' \
'(30 20, 20 15, 20 25, 30 20)))'
cls.geometry1 = Geometry(polygon, CRS(32633))
cls.geometry2 = Geometry(cls.wkt_string, CRS.WGS84)
cls.bbox = BBox(bbox=[14.00, 45.00, 14.03, 45.03], crs=CRS.WGS84)
cls.bbox_collection = BBoxCollection([cls.bbox, BBox('46,13,47,20', CRS.WGS84)])
cls.geometry_list = [cls.geometry1, cls.geometry2, cls.bbox, cls.bbox_collection]
def setUpClass(cls):
super().setUpClass()
geojson = read_data(os.path.join(cls.INPUT_FOLDER, 'cies_islands.json'))
cls.area = shapely.geometry.shape(geojson)
bbox_grid = [BBox((x / 10, y / 100, (x + 1) / 10, (y + 1) / 100), CRS.WGS84)
for x, y in itertools.product(range(-90, -87), range(4200, 4250))]
cls.test_cases = [
cls.SplitterTestCase('BBoxSplitter',
BBoxSplitter([cls.area], CRS.WGS84, 5, reduce_bbox_sizes=True), bbox_len=19),
cls.SplitterTestCase('OsmSplitter',
OsmSplitter([cls.area], CRS.WGS84, 15, reduce_bbox_sizes=True), bbox_len=24),
cls.SplitterTestCase('TileSplitter',
TileSplitter([cls.area], CRS.WGS84, ('2017-10-01', '2018-03-01'), tile_split_shape=40,
data_source=DataSource.SENTINEL2_L1C, reduce_bbox_sizes=True),
bbox_len=13),
cls.SplitterTestCase('CustomGridSplitter',
CustomGridSplitter([cls.area], CRS.WGS84, bbox_grid, bbox_split_shape=(3, 4),
reduce_bbox_sizes=False),
bbox_len=41)
]
def test_ogc_string(self):
crs_values = (
(CRS.POP_WEB, 'EPSG:3857'),
(CRS.WGS84, 'EPSG:4326'),
(CRS.UTM_33N, 'EPSG:32633'),
(CRS.UTM_33S, 'EPSG:32733')
)
for crs, epsg in crs_values:
with self.subTest(msg=epsg):
ogc_str = CRS.ogc_string(crs)
self.assertEqual(epsg, ogc_str, msg="Expected {}, got {}".format(epsg, ogc_str))
def test_bbox_transform(self):
bbox = BBox(((111.644, 8.655), (111.7, 8.688)), CRS.WGS84)
new_bbox = geo_utils.transform_bbox(bbox, CRS.POP_WEB)
expected_bbox = BBox((12428153.23, 967155.41, 12434387.12, 970871.43), CRS.POP_WEB)
for coord, expected_coord in zip(new_bbox, expected_bbox):
self.assertAlmostEqual(coord, expected_coord, delta=1E-2,
msg='Expected coord {}, got {}'.format(expected_coord, coord))
self.assertEqual(new_bbox.get_crs(), expected_bbox.get_crs(),
'Expected CRS {}, got {}'.format(expected_bbox.get_crs(), new_bbox.get_crs()))
def setUpClass(cls):
super().setUpClass()
bbox = BBox(bbox=[(2947363, 4629723), (3007595, 4669471)], crs=CRS.POP_WEB)
bbox = bbox.transform(CRS.WGS84)
query_filter1 = 'f12458==32632'
query_filter2 = 'f12458==32635'
cls.test_cases = [
TestCaseContainer('All features', GeopediaFeatureIterator(1749), min_features=100, min_size=1609),
TestCaseContainer('BBox filter', GeopediaFeatureIterator('1749', bbox=bbox), min_features=21),
TestCaseContainer('Query Filter', GeopediaFeatureIterator('ttl1749', query_filter=query_filter1),
min_features=76),
TestCaseContainer('Both filters - No data',
GeopediaFeatureIterator(1749, bbox=bbox, query_filter=query_filter1), min_features=0),
TestCaseContainer('Both filters - Some data',
GeopediaFeatureIterator(1749, bbox=bbox, query_filter=query_filter2), min_features=21)
]
def plot_vector_timeless(self, feature_name):
""" Plot FeatureType.VECTOR_TIMELESS data
:param feature_name: name of the eopatch featrue
:type feature_name: str
:return: visalization
:rtype: geoviews
"""
crs = self.eopatch.bbox.crs
if crs is CRS.WGS84:
crs = CRS.POP_WEB
data_gpd = self.eopatch[FeatureType.VECTOR_TIMELESS][feature_name].to_crs(
{'init': 'epsg:{}'.format(crs.value)})
else:
data_gpd = self.eopatch[FeatureType.VECTOR_TIMELESS][feature_name]
return gv.Polygons(data_gpd, crs=ccrs.epsg(int(crs.value)), vdims=self.vdims)