Skip to content

Commit

Permalink
Add test for "catchstats"
Browse files Browse the repository at this point in the history
  • Loading branch information
casadoj committed Apr 5, 2024
1 parent 8706c64 commit e7f4908
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/test_catchstats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import unittest
from pathlib import Path
import pandas as pd
import pandas.testing as pdt
import sys
sys.path.append('../src/lisfloodutilities/catchstats')
from catchstats import _read_inputmaps, _read_masks, _read_pixarea, catchment_statistics

class TestCatchStats(unittest.TestCase):

path = Path('data/catchstats')

def test_catchstats(self):

# compute test values
maps = _read_inputmaps(path / 'maps')
masks = _read_masks(path / 'masks')
weight = _read_pixarea(path / 'pixarea_iberian_01min.nc')
test = catchment_statistics(maps, masks, ['mean', 'std', 'min', 'max', 'count'], weight=weight, output=None).to_pandas()

# load expected values
expected = pd.read_csv(path / 'expected.csv', index_col='id')
expected.index =expected.index.astype(test.index.dtype)

# check
try:
pdt.assert_frame_equal(test, expected)
except AssertionError as e:
print(e)

0 comments on commit e7f4908

Please sign in to comment.