Skip to content

Commit ac492fe

Browse files
reverse previous commit
1 parent 15e3904 commit ac492fe

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed

climada/test/test_nightlight.py

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
import affine
2626
import numpy as np
2727
import scipy.sparse as sparse
28-
import gzip
29-
import tifffile
30-
import io
3128

3229
from shapely.geometry import Polygon
3330
from pathlib import Path
@@ -166,34 +163,22 @@ def test_load_nightlight_noaa(self):
166163
""" Test that data is downloaded if not present in SYSTEM_DIR,
167164
or not downloaded if present. Test the three outputs of the
168165
function."""
169-
170-
# path of fake .tif.gz file
171-
path_fake_file = SYSTEM_DIR.joinpath('F182013.v4c_web.stable_lights.avg_vis.tif.gz')
172-
# create an empty image
173-
image = np.zeros((100, 100), dtype=np.uint8)
174-
# save the image as .tif
175-
with io.BytesIO() as mem:
176-
tifffile.imwrite(mem, image)
177-
# compressed image to a gzip file
178-
with gzip.GzipFile(path_fake_file, 'wb') as f:
179-
f.write(mem.getvalue())
180-
181-
# using already existing file and without providing arguments
166+
167+
# Using an already existing file and without providing arguments
182168
night, coord_nl, fn_light = nightlight.load_nightlight_noaa()
183169
self.assertIsInstance(night, sparse._csr.csr_matrix)
184170
self.assertIn('F182013.v4c_web.stable_lights.avg_vis.tif',str(fn_light))
185171
self.assertTrue(np.array_equal(np.array([[-65, NOAA_RESOLUTION_DEG],
186172
[-180, NOAA_RESOLUTION_DEG]]),coord_nl))
187173
os.remove(SYSTEM_DIR.joinpath('F182013.v4c_web.stable_lights.avg_vis.p'))
188-
189-
# with arguments
190-
night, coord_nl, fn_light = nightlight.load_nightlight_noaa(ref_year = 2013, sat_name = 'F18')
174+
# With arguments
175+
night, coord_nl, fn_light = nightlight.load_nightlight_noaa(ref_year = 2010, sat_name = 'F18')
191176
self.assertIsInstance(night, sparse._csr.csr_matrix)
192-
self.assertIn('F182013.v4c_web.stable_lights.avg_vis.tif', str(fn_light))
193-
os.remove(SYSTEM_DIR.joinpath('F182013.v4c_web.stable_lights.avg_vis.p'))
194-
os.remove(path_fake_file)
177+
self.assertIn('F182010.v4d_web.stable_lights.avg_vis', str(fn_light))
178+
file = str(SYSTEM_DIR.joinpath('F182010.v4d_web.stable_lights.avg_vis.p'))
179+
os.remove(file)
195180

196-
# test raises from wrong input agruments
181+
# Test raises from wrong input agruments
197182
with self.assertRaises(ValueError) as cm:
198183
night, coord_nl, fn_light = nightlight.load_nightlight_noaa(
199184
ref_year = 2050, sat_name = 'F150')

0 commit comments

Comments
 (0)