@@ -44,7 +44,7 @@ def __init__(self, bounds, res_deg):
4444 res_deg : float
4545 Resolution in degrees
4646 """
47- lat = np .arange (bounds [1 ] + 0.5 * res_deg , bounds [3 ], res_deg )
47+ lat = np .arange (bounds [3 ] - 0.5 * res_deg , bounds [1 ], - res_deg )
4848 lon = np .arange (bounds [0 ] + 0.5 * res_deg , bounds [2 ], res_deg )
4949 self .shape = (lat .size , lon .size )
5050 self .transform = rasterio .Affine (res_deg , 0 , bounds [0 ], 0 , - res_deg , bounds [3 ])
@@ -69,9 +69,9 @@ def __enter__(self):
6969 'nodata' : - 32767.0 ,
7070 }
7171
72- # In Windows, unlike Unix, the temporary file cannot be opened before it is closed
72+ # In Windows, unlike Unix, the temporary file cannot be opened before it is closed.
7373 # Therefore it is closed right after creation and only the path/name is kept.
74- tmpfile = tempfile .NamedTemporaryFile ()
74+ tmpfile = tempfile .NamedTemporaryFile (delete = False )
7575 self .topo_path = tmpfile .name
7676 tmpfile .close ()
7777 with rasterio .open (self .topo_path , 'w' , ** dst_meta ) as dst :
@@ -107,14 +107,14 @@ def test_fraction_on_land(self):
107107
108108 # check valid range and order of magnitude
109109 self .assertTrue (np .all ((fraction >= 0 ) & (fraction <= 1 )))
110- np .testing .assert_array_equal (fraction [dist_coast > 4000 ], 0 )
111- np .testing .assert_array_equal (fraction [dist_coast < - 2000 ], 1 )
110+ np .testing .assert_array_equal (fraction [dist_coast > 1000 ], 0 )
111+ np .testing .assert_array_equal (fraction [dist_coast < - 1000 ], 1 )
112112
113113 # check individual known pixel values
114- self .assertEqual (fraction [28 , 13 ], 0.0 )
115- self .assertEqual (fraction [26 , 11 ], 0.0625 )
116- self .assertEqual (fraction [26 , 12 ], 0.7 )
117- self .assertEqual (fraction [23 , 14 ], 1.0 )
114+ self .assertAlmostEqual (fraction [24 , 10 ], 0.0 )
115+ self .assertAlmostEqual (fraction [22 , 11 ], 0.21 )
116+ self .assertAlmostEqual (fraction [22 , 12 ], 0.93 )
117+ self .assertAlmostEqual (fraction [21 , 14 ], 1.0 )
118118
119119
120120 def test_surge_from_track (self ):
@@ -172,13 +172,14 @@ def test_surge_from_track(self):
172172 fraction = surge_haz .fraction .toarray ().reshape (shape )
173173
174174 # check valid range and order of magnitude
175- self .assertTrue (np .all (inten >= 0 ))
176- self .assertTrue (np .all (inten <= 10 ))
177- self .assertTrue (np .all ((fraction >= 0 ) & (fraction <= 1 )))
175+ np .testing .assert_array_equal (inten >= 0 , True )
176+ np .testing .assert_array_equal (inten <= 10 , True )
177+ np .testing .assert_array_equal ((fraction >= 0 ) & (fraction <= 1 ), True )
178+ np .testing .assert_array_equal (inten [fraction == 0 ], 0 )
178179
179180 # check individual known pixel values
180- self .assertAlmostEqual (inten [14 , 26 ], max (- 0.125 + slr , 0 ), places = 2 )
181- self .assertAlmostEqual (inten [14 , 34 ] - slr , 0.592 , places = 2 )
181+ self .assertAlmostEqual (inten [9 , 31 ], max (- 0.391 + slr , 0 ), places = 2 )
182+ self .assertAlmostEqual (inten [14 , 34 ] - slr , 3.637 , places = 2 )
182183
183184
184185# Execute Tests
0 commit comments