Skip to content

Commit

Permalink
pylint checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Garthwaite authored and Matt Garthwaite committed Mar 24, 2017
1 parent ebb42ff commit c0fcd83
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions pyrate/orbital.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def remove_orbital_error(ifgs, params, preread_ifgs=None):


def _check_orbital_ifgs(preread_ifgs): # pragma: no cover
"""
"""
Check if the correction has already been performed in a previous run
"""
log.info('Checking Orbital error status')
Expand All @@ -449,7 +449,7 @@ def _check_orbital_ifgs(preread_ifgs): # pragma: no cover
flags = [ifc.PYRATE_ORBITAL_ERROR in preread_ifgs[i].metadata
for i in ifg_paths]
if all(flags):
log.info('Skipped orbital corrections, ifgs already corrected')
log.info('Skipped orbital corrections, ifgs already corrected')
return True
elif (sum(flags) < len(flags)) and (sum(flags) > 0):
log.debug('Detected mix of corrected and uncorrected '
Expand Down
16 changes: 8 additions & 8 deletions pyrate/ref_phs_est.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def estimate_ref_phase(ifgs, params, refpx, refpy):
:returns:
:ref_phs: reference phase correction
:ifgs: reference phase data removed list of ifgs
"""
_check_ref_phs_ifgs(ifgs)
"""
check_ref_phs_ifgs(ifgs)

# set reference phase as the average of the whole image (recommended)
if params[cf.REF_EST_METHOD] == 1:
Expand Down Expand Up @@ -138,22 +138,22 @@ def est_ref_phs_method1(phase_data, comp):
return nanmedian(ifgv)


def _check_ref_phs_ifgs(ifgs, preread_ifgs=None):
def check_ref_phs_ifgs(ifgs, preread_ifgs=None):
"""
Function to check that the ref phase status of all ifgs are the same
"""
log.info('Checking status of reference phase estimation')
if len(ifgs) < 2:
raise ReferencePhaseError('Need to provide at least 2 ifgs')

if preread_ifgs: # check unless for mpi tests
flags = [ifc.PYRATE_REF_PHASE in preread_ifgs[i].metadata
for i in ifgs]
for i in ifgs]
else:
flags = [True if i.dataset.GetMetadataItem(ifc.PYRATE_REF_PHASE)
else False for i in ifgs]
flags = [True if i.dataset.GetMetadataItem(ifc.PYRATE_REF_PHASE)
else False for i in ifgs]

if (sum(flags) == len(flags)):
if sum(flags) == len(flags):
log.info('Skipped reference phase estimation, ' \
'ifgs already corrected')
return True
Expand Down
8 changes: 4 additions & 4 deletions pyrate/scripts/run_pyrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def ref_phase_estimation(ifg_paths, params, refpx, refpy, preread_ifgs=None):
# perform some checks on existing ifgs
if preread_ifgs and mpiops.rank == MASTER_PROCESS:
ifg_paths = sorted(preread_ifgs.keys())
if rpe._check_ref_phs_ifgs(ifg_paths, preread_ifgs):
if rpe.check_ref_phs_ifgs(ifg_paths, preread_ifgs):
return # return if True condition returned

if params[cf.REF_EST_METHOD] == 1:
Expand Down Expand Up @@ -581,15 +581,15 @@ def maxvar_alpha_calc(ifg_paths, params, preread_ifgs):
'to this process, out of a total {} ifgs'.format(
n+1, len(prcs_ifgs), len(ifg_paths)))
# TODO: cvd calculation is still pretty slow - revisit
process_maxvar.append(vcm_module.cvd(i, params, calc_alpha=True,
write_vals=True, save_acg=True)[0])
process_maxvar.append(vcm_module.cvd(i, params, calc_alpha=True,
write_vals=True, save_acg=True)[0])
if mpiops.rank == MASTER_PROCESS:
maxvar = np.empty(len(ifg_paths), dtype=np.float64)
maxvar[process_indices] = process_maxvar
for i in range(1, mpiops.size): # pragma: no cover
rank_indices = mpiops.array_split(range(len(ifg_paths)), i)
this_process_maxvar = np.empty(len(rank_indices),
dtype=np.float64)
dtype=np.float64)
mpiops.comm.Recv(this_process_maxvar, source=i, tag=i)
maxvar[rank_indices] = this_process_maxvar
else: # pragma: no cover
Expand Down
26 changes: 13 additions & 13 deletions pyrate/vcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _unique_points(points):

def cvd(ifg_path, params, calc_alpha=False, write_vals=False, save_acg=False):
"""
Calculate the 1D covariance function of an entire interferogram as the
Calculate the 1D covariance function of an entire interferogram as the
radial average of its 2D autocorrelation.
:param ifg_path: An interferogram.
Expand Down Expand Up @@ -149,17 +149,18 @@ def cvd(ifg_path, params, calc_alpha=False, write_vals=False, save_acg=False):
maxdist = ifg.x_centre * ifg.x_size / distfact
else:
maxdist = ifg.y_centre * ifg.y_size/ distfact

# Here we use data at all radial distances.
# Otherwise filter out data where the distance is greater than maxdist
# r_dist = array([e for e in rorig if e <= maxdist]) #
# acg = array([e for e in rorig if e <= maxdist])
indices_to_keep = r_dist < maxdist
r_dist = r_dist[indices_to_keep]
acg = acg[indices_to_keep]

# save acg vs dist observations to disk
if save_acg: _save_cvd_data(acg, r_dist, ifg_path, params[cf.TMPDIR])
if save_acg:
_save_cvd_data(acg, r_dist, ifg_path, params[cf.TMPDIR])
# NOTE maximum variance usually at the zero lag: max(acg[:len(r_dist)])
maxvar = np.max(acg)

Expand All @@ -181,17 +182,16 @@ def cvd(ifg_path, params, calc_alpha=False, write_vals=False, save_acg=False):
alpha = fmin(pendiffexp, x0=alphaguess, args=(cvdav,), disp=0,
xtol=1e-6, ftol=1e-6)
#print("1st guess alpha", alphaguess, 'converged alpha:', alpha)

alpha = alpha[0]
else:
alpha = None

log.info('Best fit Maxvar = {}, Alpha = {}'.format(maxvar, alpha))
if write_vals: _add_metadata(ifg, maxvar, alpha)
if write_vals:
_add_metadata(ifg, maxvar, alpha)

if isinstance(ifg_path, str):
ifg.close()

return maxvar, alpha


Expand All @@ -207,25 +207,25 @@ def _save_cvd_data(acg, r_dist, ifg_path, outdir):
""" function to save numpy array of autocorrelation data to disk"""
data = np.column_stack((acg, r_dist))
data_file = join(outdir, 'cvd_data_{b}.npy'.format(
b=basename(ifg_path).split('.')[0]))
b=basename(ifg_path).split('.')[0]))
np.save(file=data_file, arr=data)


def get_vcmt(ifgs, maxvar):
"""
Assembles a temporal variance/covariance matrix using the method
described by Biggs et al., Geophys. J. Int, 2007. Matrix elements are
evaluated according to sig_i * sig_j * C_ij where i and j are two
Assembles a temporal variance/covariance matrix using the method
described by Biggs et al., Geophys. J. Int, 2007. Matrix elements are
evaluated according to sig_i * sig_j * C_ij where i and j are two
interferograms and C is a matrix of coefficients:
C = 1 if the master and slave epochs of i and j are equal
C = 0.5 if have i and j share either a common master or slave epoch
C = -0.5 if the master of i or j equals the slave of the other
C = 0 otherwise
:param ifgs: A stack of interferograms.
ifg: :py:class:`pyrate.shared.Ifg`.
:param maxvar: ndarray
numpy array of maximum variance values for each interferogram.
numpy array of maximum variance values for each interferogram.
"""
# pylint: disable=too-many-locals
# c=0.5 for common master or slave; c=-0.5 if master
Expand Down

0 comments on commit c0fcd83

Please sign in to comment.