Skip to content

Commit b189f4a

Browse files
committed
resolve conflict.
2 parents 4abe5dc + eeb3889 commit b189f4a

File tree

6 files changed

+10112
-7
lines changed

6 files changed

+10112
-7
lines changed

climada/hazard/storm_europe.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,18 @@ def read_footprints(self, path, description=None,
7272

7373
file_names = get_file_names(path)
7474

75-
if ref_raster is not None and centroids is None:
76-
centroids = self._centroids_from_nc(ref_raster)
77-
elif ref_raster is not None and centroids is not None:
75+
if ref_raster is not None and centroids is not None:
7876
LOGGER.warning('Overriding ref_raster with centroids')
79-
else:
80-
centroids = self._centroids_from_nc(file_name[0])
8177

82-
files_omit = to_list(files_omit)
78+
if centroids is not None:
79+
pass
80+
elif ref_raster is not None:
81+
centroids = self._centroids_from_nc(ref_raster)
82+
elif ref_raster is None:
83+
centroids = self._centroids_from_nc(file_names[0])
84+
85+
if isinstance(files_omit, str):
86+
files_omit = [files_omit]
8387

8488
for fn in file_names:
8589
if any(fo in fn for fo in files_omit):
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
"""
2+
Test StormEurope class
3+
"""
4+
5+
import os
6+
import unittest
7+
import datetime as dt
8+
import numpy as np
9+
from scipy import sparse
10+
11+
from climada import StormEurope, Centroids, GridPoints, SYSTEM_DIR
12+
13+
14+
class TestReader(unittest.TestCase):
15+
""" Test loading functions from the StormEurope class """
16+
17+
fn = [
18+
'fp_lothar_crop-test.nc',
19+
'fp_xynthia_crop-test.nc',
20+
]
21+
ncdfs = [os.path.join(SYSTEM_DIR, f) for f in fn]
22+
23+
ct = Centroids(os.path.join(SYSTEM_DIR, 'fp_centroids-test.csv'))
24+
25+
def test_centroids_from_nc(self):
26+
""" Test if centroids can be constructed correctly """
27+
ct = StormEurope._centroids_from_nc(self.ncdfs[0])
28+
29+
self.assertTrue(isinstance(ct, Centroids))
30+
self.assertTrue(isinstance(ct.coord, GridPoints))
31+
self.assertEqual(ct.size, 10000)
32+
self.assertEqual(ct.coord.shape[0], ct.id.shape[0])
33+
34+
def test_read_footprints(self):
35+
""" Test read_footprints function, using two small test files"""
36+
se = StormEurope()
37+
se.read_footprints(self.ncdfs)
38+
39+
self.assertEqual(se.tag.haz_type, 'WS')
40+
self.assertEqual(se.units, 'm/s')
41+
self.assertEqual(se.event_id.size, 2)
42+
self.assertEqual(se.date.size, 2)
43+
self.assertEqual(dt.datetime.fromordinal(se.date[0]).year, 1999)
44+
self.assertEqual(dt.datetime.fromordinal(se.date[0]).month, 12)
45+
self.assertEqual(dt.datetime.fromordinal(se.date[0]).day, 26)
46+
self.assertEqual(se.event_id[0], 1)
47+
self.assertEqual(se.event_name[0], 'Lothar')
48+
self.assertTrue(isinstance(se.intensity, sparse.csr.csr_matrix))
49+
self.assertTrue(isinstance(se.fraction, sparse.csr.csr_matrix))
50+
self.assertEqual(se.intensity.shape, (2, 10000))
51+
self.assertEqual(se.fraction.shape, (2, 10000))
52+
53+
def test_read_with_ref(self):
54+
""" Test read_footprints while passing in a reference raster. """
55+
se = StormEurope()
56+
se.read_footprints(self.ncdfs, ref_raster=self.ncdfs[1])
57+
58+
self.assertEqual(se.tag.haz_type, 'WS')
59+
self.assertEqual(se.units, 'm/s')
60+
self.assertEqual(se.event_id.size, 2)
61+
self.assertEqual(se.date.size, 2)
62+
self.assertEqual(dt.datetime.fromordinal(se.date[0]).year, 1999)
63+
self.assertEqual(dt.datetime.fromordinal(se.date[0]).month, 12)
64+
self.assertEqual(dt.datetime.fromordinal(se.date[0]).day, 26)
65+
self.assertEqual(se.event_id[0], 1)
66+
self.assertEqual(se.event_name[0], 'Lothar')
67+
self.assertTrue(isinstance(se.intensity, sparse.csr.csr_matrix))
68+
self.assertTrue(isinstance(se.fraction, sparse.csr.csr_matrix))
69+
self.assertEqual(se.intensity.shape, (2, 10000))
70+
self.assertEqual(se.fraction.shape, (2, 10000))
71+
72+
def test_read_with_cent(self):
73+
""" Test read_footprints while passing in a Centroids object """
74+
se = StormEurope()
75+
se.read_footprints(self.ncdfs, centroids=self.ct)
76+
77+
self.assertEqual(se.tag.haz_type, 'WS')
78+
self.assertEqual(se.units, 'm/s')
79+
self.assertEqual(se.event_id.size, 2)
80+
self.assertEqual(se.date.size, 2)
81+
self.assertEqual(dt.datetime.fromordinal(se.date[0]).year, 1999)
82+
self.assertEqual(dt.datetime.fromordinal(se.date[0]).month, 12)
83+
self.assertEqual(dt.datetime.fromordinal(se.date[0]).day, 26)
84+
self.assertEqual(se.event_id[0], 1)
85+
self.assertEqual(se.event_name[0], 'Lothar')
86+
self.assertTrue(isinstance(se.intensity, sparse.csr.csr_matrix))
87+
self.assertTrue(isinstance(se.fraction, sparse.csr.csr_matrix))
88+
self.assertEqual(se.intensity.shape, (2, 10000))
89+
self.assertEqual(se.fraction.shape, (2, 10000))
90+
self.assertEqual(
91+
se.centroids.region_id[
92+
np.isnan(se.centroids.region_id)
93+
].size,
94+
7515
95+
)
96+
97+
98+
# Execute Tests
99+
TESTS = unittest.TestLoader().loadTestsFromTestCase(TestReader)
100+
unittest.TextTestRunner(verbosity=2).run(TESTS)

climada/util/test/test_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def test_globbing(self):
8989

9090
tmp_files = os.listdir(file_name)
9191
tmp_files = [file_name + f for f in tmp_files]
92-
tmp_files = [f for f in tmp_files if not os.path.isdir(f)
92+
tmp_files = [f for f in tmp_files if not os.path.isdir(f)
9393
and not os.path.basename(os.path.normpath(f)).startswith('.')]
9494

9595
self.assertEqual(len(tmp_files), len(out))

0 commit comments

Comments
 (0)