From 2cb80577619b9270e9515660f1bed624fcf72416 Mon Sep 17 00:00:00 2001 From: Matt Garthwaite Date: Thu, 23 Mar 2017 17:03:24 +1100 Subject: [PATCH] check for previous reference phase calculation (removal) and skip if previously performed --- pyrate/ifgconstants.py | 2 +- pyrate/ref_phs_est.py | 4 ++-- pyrate/scripts/run_pyrate.py | 31 +++++++++++++++++++++++-------- tests/test_ref_phs_est.py | 2 +- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/pyrate/ifgconstants.py b/pyrate/ifgconstants.py index 1da7e5231..c4c640db2 100644 --- a/pyrate/ifgconstants.py +++ b/pyrate/ifgconstants.py @@ -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' diff --git a/pyrate/ref_phs_est.py b/pyrate/ref_phs_est.py index b4f97e893..6972911d0 100644 --- a/pyrate/ref_phs_est.py +++ b/pyrate/ref_phs_est.py @@ -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 @@ -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 diff --git a/pyrate/scripts/run_pyrate.py b/pyrate/scripts/run_pyrate.py index c88547a9d..afc99507b 100644 --- a/pyrate/scripts/run_pyrate.py +++ b/pyrate/scripts/run_pyrate.py @@ -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 @@ -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) @@ -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 @@ -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 @@ -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 @@ -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) diff --git a/tests/test_ref_phs_est.py b/tests/test_ref_phs_est.py index 4f948fd65..bbec30488 100644 --- a/tests/test_ref_phs_est.py +++ b/tests/test_ref_phs_est.py @@ -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):