Skip to content

Commit

Permalink
Clean code for sequential joblib processing for debug mode. Add user …
Browse files Browse the repository at this point in the history
…notice for this mode.
  • Loading branch information
AlexeyPechnikov committed Mar 8, 2024
1 parent ad5320f commit 15491b6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
5 changes: 2 additions & 3 deletions pygmtsar/pygmtsar/Stack_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,12 +851,11 @@ def compute_align(self, geometry='auto', dates=None, n_jobs=-1, degrees=12.0/360
subswaths = self.get_subswaths()

if n_jobs is None or debug == True:
print ('Note: sequential joblib processing is applied when "n_jobs" is None or "debug" is True.')
joblib_backend = 'sequential'
joblib_aligning_backend = 'sequential'
else:
if joblib_aligning_backend is None:
joblib_aligning_backend = 'loky'
joblib_backend = 'loky'
joblib_backend = None

# prepare reference scene
#self.stack_ref()
Expand Down
3 changes: 2 additions & 1 deletion pygmtsar/pygmtsar/Stack_reframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,10 @@ def compute_reframe(self, geometry=None, n_jobs=-1, **kwargs):

# process all the scenes
if n_jobs is None or ('debug' in kwargs and kwargs['debug'] == True):
print ('Note: sequential joblib processing is applied when "n_jobs" is None or "debug" is True.')
joblib_backend = 'sequential'
else:
joblib_backend = 'loky'
joblib_backend = None
with self.tqdm_joblib(tqdm(desc='Reframing', total=len(dates)*len(subswaths))) as progress_bar:
records = joblib.Parallel(n_jobs=n_jobs, backend=joblib_backend)(joblib.delayed(self._reframe_subswath)\
(subswath, date,
Expand Down
22 changes: 8 additions & 14 deletions pygmtsar/pygmtsar/Tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,14 @@ def _download(self, base_url, path_id, tile_id, archive, filetype,
bottom, top = int(bottom), int(top)
#print ('left, right', left, right, 'bottom, top', bottom, top)

if joblib_backend is None or n_jobs is None:
# do not use joblib parallel processing
tile_xarrays = []
with self.tqdm_joblib(tqdm(desc=f'Tiles Downloading', total=(right-left+1)*(top-bottom+1))) as pbar:
for x in range(left, right + 1):
for y in range(bottom, top + 1):
tile = self._download_tile(base_url, path_id, tile_id, archive, filetype, product, x, y, debug)
tile_xarrays.append(tile)
pbar.update(1)
else:
with self.tqdm_joblib(tqdm(desc=f'Tiles Parallel Downloading', total=(right-left+1)*(top-bottom+1))) as progress_bar:
tile_xarrays = joblib.Parallel(n_jobs=n_jobs, backend=joblib_backend)(joblib.delayed(self._download_tile)\
(base_url, path_id, tile_id, archive, filetype, product, x, y, debug)\
for x in range(left, right + 1) for y in range(bottom, top + 1))
if n_jobs is None or debug == True:
print ('Note: sequential joblib processing is applied when "n_jobs" is None or "debug" is True.')
joblib_backend = 'sequential'

with self.tqdm_joblib(tqdm(desc=f'Tiles Parallel Downloading', total=(right-left+1)*(top-bottom+1))) as progress_bar:
tile_xarrays = joblib.Parallel(n_jobs=n_jobs, backend=joblib_backend)(joblib.delayed(self._download_tile)\
(base_url, path_id, tile_id, archive, filetype, product, x, y, debug)\
for x in range(left, right + 1) for y in range(bottom, top + 1))

tile_xarrays = [tile for tile in tile_xarrays if tile is not None]
if len(tile_xarrays) == 0:
Expand Down

0 comments on commit 15491b6

Please sign in to comment.