diff --git a/src/griml/test/test.py b/src/griml/test/test.py index ccb13cf..33b507e 100644 --- a/src/griml/test/test.py +++ b/src/griml/test/test.py @@ -1,3 +1,6 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + import unittest, tempfile, rasterio, os from rasterio.transform import from_origin import geopandas as gpd @@ -12,15 +15,15 @@ class TestGrIML(unittest.TestCase): '''Unittest for the GrIML post-processing workflow''' def setUp(self): - # Set up temporary directories + '''Set up temporary directories''' self.temp_dir = tempfile.TemporaryDirectory() def tearDown(self): - # Clean up temporary files + '''Clean up temporary files''' self.temp_dir.cleanup() def create_sample_raster(self, filepath): - # Generate a small synthetic raster file with three bands + '''Generate a small synthetic raster file with three bands''' transform = from_origin(0, 10, 0.1, 0.1) # Top-left origin, 0.1 cell size with rasterio.open( filepath, 'w', @@ -33,7 +36,7 @@ def create_sample_raster(self, filepath): dst.write(data) def create_sample_pointfile(self, filepath, num_features=5): - # Generate a synthetic GeoDataFrame with simple point geometries + '''Generate a synthetic GeoDataFrame with simple point geometries''' data = { 'geometry': [Point(x, y) for x, y in zip(range(num_features), range(num_features))], 'id': [int(i) for i in range(num_features)], @@ -44,10 +47,9 @@ def create_sample_pointfile(self, filepath, num_features=5): gdf.reset_index(drop=True, inplace=True) gdf.set_index("row_id", inplace=True) gdf.to_file(filepath) - # return gdf def create_sample_polyfile(self, filepath, num_features=5, side_length=1.0): - # Generate a synthetic GeoDataFrame with square polygon geometries + '''Generate a synthetic GeoDataFrame with square polygon geometries''' half_side = side_length / 2 data = { 'geometry': [ @@ -73,7 +75,6 @@ def create_sample_polyfile(self, filepath, num_features=5, side_length=1.0): gdf.reset_index(drop=True, inplace=True) gdf.set_index("row_id", inplace=True) gdf.to_file(filepath) - # return gdf def test_convert(self): '''Test vector to raster conversion''' diff --git a/test/process_with_test_data.py b/test/process_with_test_data.py new file mode 100644 index 0000000..1c4709d --- /dev/null +++ b/test/process_with_test_data.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +from griml.convert.convert import convert +from griml.filter.filter_vectors import filter_vectors +from griml.merge.merge_vectors import merge_vectors +from griml.metadata.add_metadata import add_metadata + +def test_convert(): + '''Test vector to raster conversion''' + proj = 'EPSG:3413' + band_info = [{'b_number':1, 'method':'VIS', 'source':'S2'}, + {'b_number':2, 'method':'SAR', 'source':'S1'}, + {'b_number':3, 'method':'DEM', 'source':'ARCTICDEM'}] + start='20170701' + end='20170831' + infile = 'test_north_greenland.tif' + convert([infile], proj, band_info, start, end) + +def test_filter(self): + '''Test vector filtering''' + infile1 = 'test_filter.shp' + infile2 = 'test_icemask.shp' + filter_vectors([infile1], infile2) + +def test_merge(self): + '''Test vector merging''' + infile1 = 'test_merge_1.shp' + infile2 = 'test_merge_2.shp' + merge_vectors([infile1,infile2]) + +def test_metadata(self): + '''Test metadata population''' + infile1 = 'test_merge_2.shp' + infile2 = 'test_placenames.shp' + infile3 = 'greenland_basins_polarstereo.shp' + add_metadata(infile1, infile2, infile3) + +if __name__ == "__main__": + test_convert() + test_filter() + test_merge() + test_metadata() diff --git a/test/test (copy).py b/test/test (copy).py deleted file mode 100644 index 24346c3..0000000 --- a/test/test (copy).py +++ /dev/null @@ -1,43 +0,0 @@ -from griml.convert.convert import convert -from griml.filter.filter_vectors import filter_vectors -from griml.merge.merge_vectors import merge_vectors -from griml.metadata.add_metadata import add_metadata -import unittest, pkg_resources, os -import geopandas as gpd -import griml - -class TestGrIML(unittest.TestCase): - '''Unittest for the GrIML post-processing workflow''' - - def test_convert(self): - '''Test vector to raster conversion''' - proj = 'EPSG:3413' - band_info = [{'b_number':1, 'method':'VIS', 'source':'S2'}, - {'b_number':2, 'method':'SAR', 'source':'S1'}, - {'b_number':3, 'method':'DEM', 'source':'ARCTICDEM'}] - start='20170701' - end='20170831' - infile = os.path.join(os.path.dirname(griml.__file__),'test/test_north_greenland.tif') - convert([infile], proj, band_info, start, end) - - def test_filter(self): - '''Test vector filtering''' - infile1 = os.path.join(os.path.dirname(griml.__file__),'test/test_filter.shp') - infile2 = os.path.join(os.path.dirname(griml.__file__),'test/test_icemask.shp') - filter_vectors([infile1], infile2) - - def test_merge(self): - '''Test vector merging''' - infile1 = os.path.join(os.path.dirname(griml.__file__),'test/test_merge_1.shp') - infile2 = os.path.join(os.path.dirname(griml.__file__),'test/test_merge_2.shp') - merge_vectors([infile1,infile2]) - - def test_metadata(self): - '''Test metadata population''' - infile1 = os.path.join(os.path.dirname(griml.__file__),'test/test_merge_2.shp') - infile2 = os.path.join(os.path.dirname(griml.__file__),'test/test_placenames.shp') - infile3 = os.path.join(os.path.dirname(griml.__file__),'test/greenland_basins_polarstereo.shp') - add_metadata(infile1, infile2, infile3) - -if __name__ == "__main__": - unittest.main() diff --git a/test/test.py b/test/test.py deleted file mode 100644 index 24346c3..0000000 --- a/test/test.py +++ /dev/null @@ -1,43 +0,0 @@ -from griml.convert.convert import convert -from griml.filter.filter_vectors import filter_vectors -from griml.merge.merge_vectors import merge_vectors -from griml.metadata.add_metadata import add_metadata -import unittest, pkg_resources, os -import geopandas as gpd -import griml - -class TestGrIML(unittest.TestCase): - '''Unittest for the GrIML post-processing workflow''' - - def test_convert(self): - '''Test vector to raster conversion''' - proj = 'EPSG:3413' - band_info = [{'b_number':1, 'method':'VIS', 'source':'S2'}, - {'b_number':2, 'method':'SAR', 'source':'S1'}, - {'b_number':3, 'method':'DEM', 'source':'ARCTICDEM'}] - start='20170701' - end='20170831' - infile = os.path.join(os.path.dirname(griml.__file__),'test/test_north_greenland.tif') - convert([infile], proj, band_info, start, end) - - def test_filter(self): - '''Test vector filtering''' - infile1 = os.path.join(os.path.dirname(griml.__file__),'test/test_filter.shp') - infile2 = os.path.join(os.path.dirname(griml.__file__),'test/test_icemask.shp') - filter_vectors([infile1], infile2) - - def test_merge(self): - '''Test vector merging''' - infile1 = os.path.join(os.path.dirname(griml.__file__),'test/test_merge_1.shp') - infile2 = os.path.join(os.path.dirname(griml.__file__),'test/test_merge_2.shp') - merge_vectors([infile1,infile2]) - - def test_metadata(self): - '''Test metadata population''' - infile1 = os.path.join(os.path.dirname(griml.__file__),'test/test_merge_2.shp') - infile2 = os.path.join(os.path.dirname(griml.__file__),'test/test_placenames.shp') - infile3 = os.path.join(os.path.dirname(griml.__file__),'test/greenland_basins_polarstereo.shp') - add_metadata(infile1, infile2, infile3) - -if __name__ == "__main__": - unittest.main()