Skip to content

Commit

Permalink
tests modified
Browse files Browse the repository at this point in the history
  • Loading branch information
PennyHow committed Nov 5, 2024
1 parent 07671cd commit 88796a7
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 93 deletions.
15 changes: 8 additions & 7 deletions src/griml/test/test.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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',
Expand All @@ -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)],
Expand All @@ -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': [
Expand All @@ -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'''
Expand Down
43 changes: 43 additions & 0 deletions test/process_with_test_data.py
Original file line number Diff line number Diff line change
@@ -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()
43 changes: 0 additions & 43 deletions test/test (copy).py

This file was deleted.

43 changes: 0 additions & 43 deletions test/test.py

This file was deleted.

0 comments on commit 88796a7

Please sign in to comment.