Skip to content

Commit

Permalink
Enhance debugging output for aligning and reframing
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyPechnikov committed Mar 7, 2024
1 parent 64a500f commit 46de7aa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
14 changes: 11 additions & 3 deletions pygmtsar/pygmtsar/Stack_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,10 +850,18 @@ 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:
joblib_backend = 'sequential'
joblib_aligning_backend = 'sequential'
else:
if joblib_aligning_backend is None:
joblib_aligning_backend = 'loky'
joblib_backend = 'loky'

# prepare reference scene
#self.stack_ref()
with self.tqdm_joblib(tqdm(desc='Aligning Reference', total=len(subswaths))) as progress_bar:
joblib.Parallel(n_jobs=n_jobs)(joblib.delayed(self._align_ref_subswath)(subswath, debug=debug) for subswath in subswaths)
joblib.Parallel(n_jobs=n_jobs, backend=joblib_backend)(joblib.delayed(self._align_ref_subswath)(subswath, debug=debug) for subswath in subswaths)

# prepare secondary images
with self.tqdm_joblib(tqdm(desc='Aligning Repeat', total=len(dates_rep)*len(subswaths))) as progress_bar:
Expand All @@ -869,7 +877,7 @@ def compute_align(self, geometry='auto', dates=None, n_jobs=-1, degrees=12.0/360
minx, miny, maxx, maxy = np.round(extent_ra.bounds).astype(int)
#print ('minx, miny, maxx, maxy', minx, miny, maxx, maxy)
with self.tqdm_joblib(tqdm(desc=f'Merging Subswaths', total=len(dates))) as progress_bar:
joblib.Parallel(n_jobs=n_jobs)(joblib.delayed(self._merge_subswaths)(date, offsets, minx, miny, maxx, maxy, debug=debug) \
joblib.Parallel(n_jobs=n_jobs, backend=joblib_backend)(joblib.delayed(self._merge_subswaths)(date, offsets, minx, miny, maxx, maxy, debug=debug) \
for date in dates)
else:
# DEM extent in radar coordinates, merged reference PRM required
Expand All @@ -878,7 +886,7 @@ def compute_align(self, geometry='auto', dates=None, n_jobs=-1, degrees=12.0/360
#print ('minx, miny, maxx, maxy', minx, miny, maxx, maxy)
# in case of a single subswath only convert SLC to NetCDF grid
with self.tqdm_joblib(tqdm(desc='Convert Subswath', total=len(dates))) as progress_bar:
joblib.Parallel(n_jobs=n_jobs)(joblib.delayed(self._convert_subswath)(subswaths[0], date, minx, miny, maxx, maxy, debug=debug) \
joblib.Parallel(n_jobs=n_jobs, backend=joblib_backend)(joblib.delayed(self._convert_subswath)(subswaths[0], date, minx, miny, maxx, maxy, debug=debug) \
for date in dates)

# merge subswaths, datapath and metapath converted to lists even for a single subswath, geometry merges bursts
Expand Down
10 changes: 8 additions & 2 deletions pygmtsar/pygmtsar/Stack_reframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _reframe_subswath(self, subswath, date, geometry, debug=False):
#geometry = geometry.buffer(1e-3)
raise ValueError(f"Unsupported Point geometry. Unfortunately, GMTSAR tools cannot crop a scene to a single burst.")
if isinstance(geometry, Polygon):
rect = geometry.minimum_rotated_rectangle.exterior
rect = geometry.exterior
# define diagonal line
diag1 = LineString([rect.coords[0], rect.coords[2]])
diag2 = LineString([rect.coords[1], rect.coords[3]])
Expand All @@ -82,6 +82,8 @@ def _reframe_subswath(self, subswath, date, geometry, debug=False):

self._make_s1a_tops(subswath, date, debug=debug)
prm = PRM.from_file(old_filename+'.PRM')
if debug:
print ('DEBUG: ','geometry', geometry)
tmpazi_a = prm.SAT_llt2rat([geometry.coords[0][0], geometry.coords[0][1], 0], precise=1, debug=debug)[1]
tmpazi_b = prm.SAT_llt2rat([geometry.coords[-1][0], geometry.coords[-1][1], 0], precise=1, debug=debug)[1]
tmpazi = min(tmpazi_a, tmpazi_b)
Expand Down Expand Up @@ -178,8 +180,12 @@ def compute_reframe(self, geometry=None, n_jobs=-1, **kwargs):
geometries = {subswath: self.df[self.df.subswath==subswath].geometry.unary_union for subswath in subswaths}

# process all the scenes
if n_jobs is None or ('debug' in kwargs and kwargs['debug'] == True):
joblib_backend = 'sequential'
else:
joblib_backend = 'loky'
with self.tqdm_joblib(tqdm(desc='Reframing', total=len(dates)*len(subswaths))) as progress_bar:
records = joblib.Parallel(n_jobs=n_jobs)(joblib.delayed(self._reframe_subswath)\
records = joblib.Parallel(n_jobs=n_jobs, backend=joblib_backend)(joblib.delayed(self._reframe_subswath)\
(subswath, date,
geometry.intersection(geometries[subswath]) if geometry is not None else geometries[subswath],
**kwargs) for date in dates for subswath in subswaths)
Expand Down

0 comments on commit 46de7aa

Please sign in to comment.