Skip to content

Commit

Permalink
Optimize aligning
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Pechnikov committed Aug 24, 2024
1 parent 38a9373 commit ae323ce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
15 changes: 9 additions & 6 deletions pygmtsar/pygmtsar/PRM_gmtsar.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ def resamp(self, repeatPRM, repeatSLC_tofile, interp, debug=False):
if not isinstance(repeatPRM, PRM):
raise Exception('Argument should be PRM class instance')

SLC_tmpname = os.path.split(repeatSLC_tofile)[-1] + '.tmp'

pipe1 = os.pipe()
os.write(pipe1[1], bytearray(repeatPRM.to_str(), 'utf8'))
os.close(pipe1[1])
Expand All @@ -254,23 +256,24 @@ def resamp(self, repeatPRM, repeatSLC_tofile, interp, debug=False):
# stderr=subprocess.PIPE, pass_fds=[pipe1[0], pipe2[1]],
# cwd=cwd, encoding='utf8', shell=True)
argv = ['resamp', f'/dev/stdin', f'/dev/fd/{pipe1[0]}',
f'/dev/fd/{pipe2[1]}', '/dev/stdout', str(interp)]
f'/dev/fd/{pipe2[1]}', SLC_tmpname, str(interp)]
if debug:
print ('DEBUG: argv', argv)
cwd = os.path.dirname(self.filename) if self.filename is not None else '.'
if debug:
print ('DEBUG: cwd', cwd)
p = subprocess.Popen(argv, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, pass_fds=[pipe1[0], pipe2[1]],
cwd=cwd)
stdout_data, stderr_data = p.communicate(input=bytearray(self.to_str(), 'utf8'))

# print errors and notifications
if len(stderr_data) > 0 and debug:
print ('DEBUG: resamp', stderr_data.decode('utf8'))

# save big SLC binary file
with open(repeatSLC_tofile, 'wb') as f:
f.write(stdout_data)

# rename the file to the persistent name
if os.path.exists(repeatSLC_tofile + '.tmp'):
os.rename(repeatSLC_tofile + '.tmp', repeatSLC_tofile)
# PRM file should be small text
data = os.read(pipe2[0],int(10e6))
return PRM.from_str(data.decode('utf8'))
Expand Down
7 changes: 4 additions & 3 deletions pygmtsar/pygmtsar/Stack_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,6 @@ def compute_align(self, geometry='auto', dates=None, n_jobs=-1, degrees=12.0/360
List of dates to process. If None, process all scenes. Default is None.
n_jobs : int, optional
Number of parallel processing jobs. n_jobs=-1 means all processor cores are used. Default is -1.
joblib_aligning_backend: str or None, optional
Returns
-------
Expand All @@ -845,6 +844,9 @@ def compute_align(self, geometry='auto', dates=None, n_jobs=-1, degrees=12.0/360
# supress warnings about unary_union future behaviour to replace None by empty collection
warnings.filterwarnings('ignore')

if joblib_aligning_backend is not None:
print('Note: the joblib_aligning_backend argument has been removed from the compute_align() function.')

if dates is None:
dates = self.df.index.unique()
dates_rep = [date for date in dates if date != self.reference]
Expand All @@ -854,7 +856,6 @@ def compute_align(self, geometry='auto', dates=None, n_jobs=-1, degrees=12.0/360
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:
joblib_backend = None

Expand All @@ -866,7 +867,7 @@ def compute_align(self, geometry='auto', dates=None, n_jobs=-1, degrees=12.0/360
# prepare secondary images
with self.tqdm_joblib(tqdm(desc='Aligning Repeat', total=len(dates_rep)*len(subswaths))) as progress_bar:
# threading backend is the only one working inside Docker container to run multiple binaries in parallel
joblib.Parallel(n_jobs=n_jobs, backend=joblib_aligning_backend)(joblib.delayed(self._align_rep_subswath)(subswath, date, degrees=degrees, debug=debug) \
joblib.Parallel(n_jobs=n_jobs, backend=joblib_backend)(joblib.delayed(self._align_rep_subswath)(subswath, date, degrees=degrees, debug=debug) \
for date in dates_rep for subswath in subswaths)

if len(subswaths) > 1:
Expand Down

0 comments on commit ae323ce

Please sign in to comment.