Skip to content

Commit

Permalink
check for previous reference phase calculation (removal) and skip if …
Browse files Browse the repository at this point in the history
…previously performed
  • Loading branch information
Matt Garthwaite authored and Matt Garthwaite committed Mar 23, 2017
1 parent b1c8922 commit 2cb8057
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pyrate/ifgconstants.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
LINSAMP = 'LINEAR_RATE_SAMPLES'
PYRATE_ORBITAL_ERROR = 'ORBITAL_ERROR'
ORB_REMOVED = 'REMOVED'
REF_PHASE = 'REFERENCE_PHASE'
PYRATE_REF_PHASE = 'REFERENCE_PHASE'
REF_PHASE_REMOVED = 'REMOVED'
NAN_STATUS = 'NAN_STATUS'
NAN_CONVERTED = 'CONVERTED'
Expand Down
4 changes: 2 additions & 2 deletions pyrate/ref_phs_est.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def estimate_ref_phase(ifgs, params, refpx, refpy):
raise ReferencePhaseError('No such option. Use refest=1 or 2')

for i in ifgs:
i.meta_data[ifc.REF_PHASE] = ifc.REF_PHASE_REMOVED
i.meta_data[ifc.PYRATE_REF_PHASE] = ifc.REF_PHASE_REMOVED
i.write_modified_phase()
return ref_phs, ifgs

Expand Down Expand Up @@ -146,7 +146,7 @@ def _validate_ifgs(ifgs):
"""
if len(ifgs) < 2:
raise ReferencePhaseError('Need to provide at least 2 ifgs')
flags = [i.dataset.GetMetadataItem(ifc.REF_PHASE) for i in ifgs]
flags = [i.dataset.GetMetadataItem(ifc.PYRATE_REF_PHASE) for i in ifgs]
if all(flags):
log.info('Ifgs already reference phase corrected')
return
Expand Down
31 changes: 23 additions & 8 deletions pyrate/scripts/run_pyrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,15 +310,15 @@ def orb_fit_calc(ifg_paths, params, preread_ifgs=None):
# Here we do all the multilooking in one process, but in memory
# can use multiple processes if we write data to disc during
# remove_orbital_error step
# A performance comparison should be performed be performed for saving
# multilooked files on disc vs in memory single process multilooking
# A performance comparison should be made for saving multilooked
# files on disc vs in memory single process multilooking
if mpiops.rank == MASTER_PROCESS:
orbital.remove_orbital_error(ifg_paths, params, preread_ifgs)
mpiops.comm.barrier()
#log.info('Finished orbfit calculation in process {}'.format(mpiops.rank))


def ref_phase_estimation(ifg_paths, params, refpx, refpy):
def ref_phase_estimation(ifg_paths, params, refpx, refpy, preread_ifgs=None):
"""
Reference phase estimation
Expand All @@ -333,8 +333,22 @@ def ref_phase_estimation(ifg_paths, params, refpx, refpy):
refpy: float
reference pixel y-coordinate
"""

log.info('Estimating and removing reference phase')
# perform some checks on existing ifgs
if preread_ifgs: # check unless for mpi tests
log.info('Checking status of reference phase estimation')
ifg_paths = sorted(preread_ifgs.keys())
# preread_ifgs[i].metadata contains ifg metadata
flags = [ifc.PYRATE_REF_PHASE in preread_ifgs[i].metadata
for i in ifg_paths]
if all(flags):
log.info('Skipped reference phase estimation, ifgs already corrected')
return True
elif (sum(flags) < len(flags)) and (sum(flags) > 0):
log.debug('Detected mix of corrected and uncorrected '
'reference phases in ifgs')
else:
log.info('Estimating and removing reference phase')

if params[cf.REF_EST_METHOD] == 1:
# calculate phase sum for later use in ref phase method 1
comp = phase_sum(ifg_paths, params)
Expand Down Expand Up @@ -395,7 +409,7 @@ def _inner(ifg_path):
refpx, refpy, thresh)
phase_data -= ref_ph
md = ifg.meta_data
md[ifc.REF_PHASE] = ifc.REF_PHASE_REMOVED
md[ifc.PYRATE_REF_PHASE] = ifc.REF_PHASE_REMOVED
ifg.write_modified_phase(data=phase_data)
ifg.close()
return ref_ph
Expand Down Expand Up @@ -430,7 +444,7 @@ def _inner(ifg_path):
ref_phase = rpe.est_ref_phs_method1(phase_data, comp)
phase_data -= ref_phase
md = ifg.meta_data
md[ifc.REF_PHASE] = ifc.REF_PHASE_REMOVED
md[ifc.PYRATE_REF_PHASE] = ifc.REF_PHASE_REMOVED
ifg.write_modified_phase(data=phase_data)
ifg.close()
return ref_phase
Expand Down Expand Up @@ -464,6 +478,7 @@ def process_ifgs(ifg_paths, params, rows, cols):
mst_calc(ifg_paths, params, tiles, preread_ifgs)

# Estimate reference pixel location
# TODO: Skip this if reference phase already removed?
refpx, refpy = ref_pixel_calc(ifg_paths, params)

# remove APS delay here, and write aps delay removed ifgs to disc
Expand All @@ -480,7 +495,7 @@ def process_ifgs(ifg_paths, params, rows, cols):
orb_fit_calc(ifg_paths, params, preread_ifgs)

# calc and remove reference phase
ref_phase_estimation(ifg_paths, params, refpx, refpy)
ref_phase_estimation(ifg_paths, params, refpx, refpy, preread_ifgs)

# calculate maxvar and alpha values
maxvar = maxvar_alpha_calc(ifg_paths, params, preread_ifgs)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ref_phs_est.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_need_at_least_two_ifgs(self):
def test_metadata(self):
estimate_ref_phase(self.ifgs, self.params, self.refpx, self.refpy)
for s in self.ifgs:
self.assertEqual(s.dataset.GetMetadataItem(ifc.REF_PHASE),
self.assertEqual(s.dataset.GetMetadataItem(ifc.PYRATE_REF_PHASE),
ifc.REF_PHASE_REMOVED)

def test_mixed_metadata_raises(self):
Expand Down

0 comments on commit 2cb8057

Please sign in to comment.