@@ -153,15 +153,15 @@ def check_nl_local_file_exists(required_files=np.ones(len(BM_FILENAMES),),
153153
154154 if sum (files_exist ) == sum (required_files ):
155155 LOGGER .debug ('Found all required satellite data (' +
156- str (int (sum (required_files ))) + ' files) in folder ' +
157- check_path )
156+ str (int (sum (required_files ))) + ' files) in folder ' +
157+ check_path )
158158 elif sum (files_exist ) == 0 :
159159 LOGGER .info ('No satellite files found locally in %s' , check_path )
160160 else :
161161 LOGGER .debug ('Not all satellite files available. Found ' +
162- str (int (sum (files_exist ))) + ' out of ' +
163- str (int (sum (required_files ))) + ' required files in ' +
164- check_path )
162+ str (int (sum (files_exist ))) + ' out of ' +
163+ str (int (sum (required_files ))) + ' required files in ' +
164+ check_path )
165165
166166 return (files_exist , check_path )
167167
@@ -195,7 +195,7 @@ def download_nl_files(req_files=np.ones(len(BM_FILENAMES),), \
195195 'Climada data directory instead.' )
196196 if np .all (req_files == files_exist ):
197197 LOGGER .debug ('All required files already exist. ' +
198- 'No downloads neccessary.' )
198+ 'No downloads neccessary.' )
199199 return None
200200 try :
201201 curr_wd = getcwd ()
@@ -223,7 +223,7 @@ def load_nightlight_nasa(bounds, req_files, year):
223223 """ Get nightlight from NASA repository that contain input boundary.
224224
225225 Parameters:
226- bounds (tuple): nmin_lon , min_lat, max_lon, max_lat
226+ bounds (tuple): min_lon , min_lat, max_lon, max_lat
227227 req_files (np.array): array with flags for NASA files needed
228228 year (int): nightlight year
229229
@@ -281,26 +281,31 @@ def cut_nl_nasa(aux_nl, idx_info, nightlight, in_lat, in_lon, in_lat_nb,
281281 to: 0, 1, 2 or 3 column of nasa's images.
282282 """
283283 idx , prev_idx , row_added = idx_info
284+
284285 aux_nl = sparse .csc .csc_matrix (aux_nl )
285286 # flip X axis
286287 aux_nl .indices = - aux_nl .indices + aux_nl .shape [0 ] - 1
287288
288289 aux_bnd = []
290+ # in min lon
289291 if int (idx / 2 ) % 4 == in_lon_nb [0 ]:
290292 aux_bnd .append (int (in_lon [0 ] - (int (idx / 2 )% 4 )* 21600 ))
291293 else :
292294 aux_bnd .append (0 )
293295
296+ # in min lat
294297 if idx % 2 == in_lat_nb [0 ]:
295298 aux_bnd .append (in_lat [0 ] - ((idx + 1 )% 2 )* 21600 )
296299 else :
297300 aux_bnd .append (0 )
298301
302+ # in max lon
299303 if int (idx / 2 ) % 4 == in_lon_nb [1 ]:
300304 aux_bnd .append (int (in_lon [1 ] - (int (idx / 2 )% 4 )* 21600 ) + 1 )
301305 else :
302306 aux_bnd .append (21600 )
303307
308+ # in max lat
304309 if idx % 2 == in_lat_nb [1 ]:
305310 aux_bnd .append (in_lat [1 ] - ((idx + 1 )% 2 )* 21600 + 1 )
306311 else :
@@ -313,15 +318,17 @@ def cut_nl_nasa(aux_nl, idx_info, nightlight, in_lat, in_lon, in_lat_nb,
313318 # append horizontally in first rows e.g 0->2 or 1->2
314319 nightlight .resize ((nightlight .shape [0 ],
315320 nightlight .shape [1 ] + aux_bnd [2 ]- aux_bnd [0 ]))
316- nightlight [: aux_bnd [3 ]- aux_bnd [1 ], - aux_bnd [2 ]+ aux_bnd [0 ]:] = \
321+ nightlight [- aux_bnd [3 ]+ aux_bnd [1 ]: , - aux_bnd [2 ]+ aux_bnd [0 ]:] = \
317322 aux_nl [aux_bnd [1 ]:aux_bnd [3 ], aux_bnd [0 ]:aux_bnd [2 ]]
318323 else :
319- # append vertically in lasts rows and columns e.g 0->1 or 2->3
324+ # append vertically in firsts rows and columns e.g 0->1 or 2->3
320325 if not row_added :
321- nightlight .resize ((nightlight .shape [0 ] + aux_bnd [3 ] - aux_bnd [1 ],
322- nightlight .shape [1 ]))
326+ old_shape = nightlight .shape
327+ nightlight .resize ((old_shape [0 ] + aux_bnd [3 ] - aux_bnd [1 ],
328+ old_shape [1 ]))
329+ nightlight [- old_shape [0 ]:, :] = nightlight [:old_shape [0 ], :]
323330 idx_info [2 ] = True
324- nightlight [- aux_bnd [3 ]+ aux_bnd [1 ]: , - aux_bnd [2 ]+ aux_bnd [0 ]:] = \
331+ nightlight [: aux_bnd [3 ]- aux_bnd [1 ], - aux_bnd [2 ]+ aux_bnd [0 ]:] = \
325332 aux_nl [aux_bnd [1 ]:aux_bnd [3 ], aux_bnd [0 ]:aux_bnd [2 ]]
326333
327334def unzip_tif_to_py (file_gz ):
0 commit comments