|
25 | 25 | import affine |
26 | 26 | import numpy as np |
27 | 27 | import scipy.sparse as sparse |
28 | | -import gzip |
29 | | -import tifffile |
30 | | -import io |
31 | 28 |
|
32 | 29 | from shapely.geometry import Polygon |
33 | 30 | from pathlib import Path |
@@ -166,34 +163,22 @@ def test_load_nightlight_noaa(self): |
166 | 163 | """ Test that data is downloaded if not present in SYSTEM_DIR, |
167 | 164 | or not downloaded if present. Test the three outputs of the |
168 | 165 | 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 |
182 | 168 | night, coord_nl, fn_light = nightlight.load_nightlight_noaa() |
183 | 169 | self.assertIsInstance(night, sparse._csr.csr_matrix) |
184 | 170 | self.assertIn('F182013.v4c_web.stable_lights.avg_vis.tif',str(fn_light)) |
185 | 171 | self.assertTrue(np.array_equal(np.array([[-65, NOAA_RESOLUTION_DEG], |
186 | 172 | [-180, NOAA_RESOLUTION_DEG]]),coord_nl)) |
187 | 173 | 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') |
191 | 176 | 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) |
195 | 180 |
|
196 | | - # test raises from wrong input agruments |
| 181 | + # Test raises from wrong input agruments |
197 | 182 | with self.assertRaises(ValueError) as cm: |
198 | 183 | night, coord_nl, fn_light = nightlight.load_nightlight_noaa( |
199 | 184 | ref_year = 2050, sat_name = 'F150') |
|
0 commit comments