Skip to content

Commit cc38922

Browse files
committed
docstrings, coverage, pylint
1 parent b1c25df commit cc38922

14 files changed

+114
-38
lines changed

.coveragerc

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ omit =
88
# omit these files
99
pyrate/pyratelog.py
1010
pyrate/scripts/main.py
11-
pyrate/aps.py
11+
pyrate/pyaps.py
1212
pyrate/compat.py
13-
*__init__*
1413

1514
[report]
1615
# Regexes for lines to exclude from consideration

.pylintrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ expected-line-ending-format=
226226
[BASIC]
227227

228228
# Good variable names which should always be accepted, separated by a comma
229-
good-names=i,j,k,ex,Run,_,x,w,f,n,v,t,r,d,c,cd,g,r,q,V,m,A,b,log,y,id,ds,gt,md
229+
good-names=ts,i,j,k,ex,Run,_,x,w,f,n,v,t,r,d,c,cd,g,r,q,V,m,A,b,log,y,id,ds,gt,md
230230

231231
# Bad variable names which should always be refused, separated by a comma
232232
bad-names=foo,bar,baz,toto,tutu,tata

pyrate/aps/__init__.py

+31-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
# This Python module is part of the PyRate software package.
2+
#
3+
# Copyright 2017 Geoscience Australia
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
"""
17+
This is the aps/spatio-temporal filter main module.
18+
"""
19+
120
import logging
221
import os
322
from copy import deepcopy
@@ -36,10 +55,10 @@ def wrap_spatio_temporal_filter(ifg_paths, params, tiles, preread_ifgs):
3655
def spatio_temporal_filter(tsincr, ifg, params, preread_ifgs):
3756
"""
3857
Applies spatio-temportal (aps) filter and save the interferograms.
39-
58+
4059
A first step is to compute the time series using the non-smooth SVD method.
4160
This is followed by temporal and spatial filters respectively.
42-
61+
4362
Parameters
4463
----------
4564
tsincr: ndarray
@@ -60,13 +79,13 @@ def spatio_temporal_filter(tsincr, ifg, params, preread_ifgs):
6079
tsincr -= ts_aps
6180

6281
mpiops.run_once(ts_to_ifgs, tsincr, preread_ifgs)
63-
82+
6483

6584
def calc_svd_time_series(ifg_paths, params, preread_ifgs, tiles):
6685
"""
6786
Time series inversion with no smoothing (svd method)
6887
This is the matlab tsinvnosm.m equivalent.
69-
88+
7089
Parameters
7190
----------
7291
ifg_paths: list
@@ -77,12 +96,12 @@ def calc_svd_time_series(ifg_paths, params, preread_ifgs, tiles):
7796
prepread ifgs dict
7897
tiles: list
7998
list of shared.Tile class instances
80-
99+
81100
Returns
82101
-------
83102
tsincr_g: ndarray
84103
non smooth (svd method) time series of shape (ifg.shape, nvels)
85-
104+
86105
"""
87106
log.info('Calculating time series without smoothing for '
88107
'spatio-temporal filter')
@@ -95,11 +114,11 @@ def calc_svd_time_series(ifg_paths, params, preread_ifgs, tiles):
95114

96115
nvels = None
97116
for t in process_tiles:
98-
log.info('Calculating time series for tile {}'.format(t.index))
117+
log.info('Calculating time series for tile {} during aps '
118+
'correction'.format(t.index))
99119
ifg_parts = [shared.IfgPart(p, t, preread_ifgs) for p in ifg_paths]
100120
mst_tile = np.load(os.path.join(output_dir,
101121
'mst_mat_{}.npy'.format(t.index)))
102-
# don't save this time_series calc, this is done as part of aps filter
103122
tsincr = time_series(ifg_parts, new_params, vcmt=None, mst=mst_tile)[0]
104123
np.save(file=os.path.join(output_dir, 'tsincr_aps_{}.npy'.format(
105124
t.index)), arr=tsincr)
@@ -132,16 +151,16 @@ def ts_to_ifgs(ts, preread_ifgs):
132151
time series nd array (ifg.shape, nvels)
133152
preread_ifgs: dict
134153
dict with ifg basic informations
135-
154+
136155
Saves ifgs on disc after conversion.
137156
"""
138157
log.info('Converting time series to ifgs')
139158
ifgs = list(OrderedDict(sorted(preread_ifgs.items())).values())
140-
epochlist, n = get_epochs(ifgs)
159+
_, n = get_epochs(ifgs)
141160
index_master, index_slave = n[:len(ifgs)], n[len(ifgs):]
142-
for i in range(len(ifgs)):
161+
for i, ifg in enumerate(ifgs):
143162
phase = np.sum(ts[:, :, index_master[i]: index_slave[i]], axis=2)
144-
_save_aps_corrected_phase(ifgs[i].path, phase)
163+
_save_aps_corrected_phase(ifg.path, phase)
145164

146165

147166
def _save_aps_corrected_phase(ifg_path, phase):

pyrate/aps/spatial.py

+25-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
# This Python module is part of the PyRate software package.
2+
#
3+
# Copyright 2017 Geoscience Australia
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
"""
17+
Spatial low pass filter.
18+
"""
19+
# pylint: disable=invalid-name, too-many-locals, too-many-arguments
120
import logging
221
import numpy as np
322
from scipy.fftpack import fft2, ifft2, fftshift, ifftshift
@@ -12,17 +31,17 @@ def spatial_low_pass_filter(ts_hp, ifg, params):
1231
Parameters
1332
----------
1433
ts_hp: ndarray
15-
time series from previous temporal low pass filter output of
34+
time series from previous temporal low pass filter output of
1635
shape (ifg.shape, n_epochs)
1736
ifg: shared.Ifg instance
1837
params: dict
1938
params dict
20-
39+
2140
Returns
2241
-------
2342
ts_hp: ndarray
24-
spatio-temporal filtered time series output of
25-
shape (ifg.shape, n_epochs)
43+
spatio-temporal filtered time series output of
44+
shape (ifg.shape, n_epochs)
2645
"""
2746
log.info('Applying spatial low pass filter')
2847
ts_hp[np.isnan(ts_hp)] = 0 # need it here for cvd and fft
@@ -43,7 +62,7 @@ def slpfilter(phase, ifg, r_dist, params):
4362
ifg: shared.Ifg class instance
4463
params: dict
4564
paramters dict
46-
65+
4766
Returns
4867
-------
4968
out: ndarray
@@ -53,9 +72,8 @@ def slpfilter(phase, ifg, r_dist, params):
5372
return phase
5473
cutoff = params[cf.SLPF_CUTOFF]
5574

56-
5775
if cutoff == 0:
58-
maxvar, alpha = cvd_from_phase(phase, ifg, r_dist, calc_alpha=True)
76+
_, alpha = cvd_from_phase(phase, ifg, r_dist, calc_alpha=True)
5977
cutoff = 1.0/alpha
6078
rows, cols = ifg.shape
6179
return _slp_filter(phase, cutoff, rows, cols,

pyrate/aps/temporal.py

+39-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
# This Python module is part of the PyRate software package.
2+
#
3+
# Copyright 2017 Geoscience Australia
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
"""
17+
Temporal low pass filter.
18+
"""
19+
# pylint: disable=invalid-name, too-many-locals, too-many-arguments
120
import logging
221
import numpy as np
322
from numpy import isnan
@@ -8,9 +27,24 @@
827

928
# TODO: use tiles here and distribute amongst processes
1029
def tlpfilter(tsincr, epochlist, params):
11-
log.info('Applying temporal low pass filter')
30+
"""
31+
Temporal low pass filter
32+
33+
Parameters
34+
----------
35+
tsincr : ndarray
36+
time series array of size (ifg.shape, nvels)
37+
epochlist : list
38+
list of shared.EpochList class instances
39+
params : dict
40+
parameters dict
1241
13-
"""temporal low pass filter"""
42+
Returns
43+
-------
44+
tsfilt_incr : ndarray
45+
temporal filtered time series of shape (ifg.shape, nvels)
46+
"""
47+
log.info('Applying temporal low pass filter')
1448
nanmat = ~isnan(tsincr)
1549
tsfilt_incr = np.empty_like(tsincr, dtype=np.float32) * np.nan
1650
intv = np.diff(epochlist.spans) # time interval for the neighboring epoch
@@ -22,7 +56,7 @@ def tlpfilter(tsincr, epochlist, params):
2256
if method == 1: # gaussian filter
2357
func = gauss
2458
elif method == 2: # triangular filter
25-
func = triangle
59+
func = _triangle
2660
else:
2761
func = mean_filter
2862

@@ -35,7 +69,8 @@ def tlpfilter(tsincr, epochlist, params):
3569
gauss = lambda m, yr, cutoff: np.exp(-(yr / cutoff) ** 2 / 2)
3670

3771

38-
def triangle(m, yr, cutoff):
72+
def _triangle(m, yr, cutoff):
73+
# pylint: disable=unused-argument
3974
wgt = cutoff - abs(yr)
4075
wgt[wgt < 0] = 0
4176
return wgt

pyrate/compat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
This Python module tests compatibilities
1818
"""
1919
# coding: utf-8
20-
# pylint: disable= invalid-name, unused-import
20+
# pylint: disable= invalid-name, unused-import, import-error
2121

2222
from __future__ import absolute_import
2323
import sys

pyrate/covariance.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from pyrate import ifgconstants as ifc
3636
from pyrate import config as cf
3737

38+
# pylint: disable=too-many-arguments
3839
# distance division factor of 1000 converts to km and is needed to match
3940
# Matlab code output
4041
DISTFACT = 1000
@@ -213,6 +214,10 @@ def cvd_from_phase(phase, ifg, r_dist, calc_alpha, save_acg=False,
213214

214215

215216
class RDist:
217+
"""
218+
RDist class used for caching r_dist during maxvar/alpha computation
219+
"""
220+
# pylint: disable=invalid-name
216221
def __init__(self, ifg):
217222
self.r_dist = None
218223
self.ifg = ifg
@@ -229,8 +234,8 @@ def __call__(self):
229234
# calculations in the numpy land
230235
self.r_dist = np.divide(np.sqrt(((xx - self.ifg.x_centre) *
231236
self.ifg.x_size) ** 2 +
232-
((yy - self.ifg.y_centre) *
233-
self.ifg.y_size) ** 2),
237+
((yy - self.ifg.y_centre) *
238+
self.ifg.y_size) ** 2),
234239
DISTFACT) # km
235240
self.r_dist = reshape(self.r_dist, size, order='F')
236241
self.r_dist = self.r_dist[:int(ceil(size / 2.0)) + self.nrows]

pyrate/orbital.py

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
from pyrate.shared import nanmedian, Ifg
3232
from pyrate import config as cf
3333
from pyrate import ifgconstants as ifc
34-
from pyrate import mpiops
3534

3635
log = logging.getLogger(__name__)
3736

pyrate/scripts/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import os
2121
from os.path import abspath
2222
import logging
23-
import click
2423
import json
24+
import click
2525
from pyrate import pyratelog as pylog
2626
from pyrate import config as cf
2727
from pyrate.scripts import run_prepifg, run_pyrate, postprocessing

pyrate/scripts/postprocessing.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import numpy as np
2525
from osgeo import gdal
2626

27-
import pyrate.shared
2827
from pyrate import config as cf
2928
from pyrate import ifgconstants as ifc
3029
from pyrate import shared
@@ -59,7 +58,7 @@ def postprocess_linrate(rows, cols, params):
5958
# load previously saved prepread_ifgs dict
6059
preread_ifgs_file = join(params[cf.TMPDIR], 'preread_ifgs.pk')
6160
ifgs = cp.load(open(preread_ifgs_file, 'rb'))
62-
tiles = pyrate.shared.get_tiles(dest_tifs[0], rows, cols)
61+
tiles = shared.get_tiles(dest_tifs[0], rows, cols)
6362

6463
# linrate aggregation
6564
if mpiops.size >= 3:
@@ -117,7 +116,7 @@ def postprocess_timeseries(rows, cols, params):
117116
epochlist = ifgs['epochlist']
118117
ifgs = [v for v in ifgs.values() if isinstance(v, PrereadIfg)]
119118

120-
tiles = pyrate.shared.get_tiles(dest_tifs[0], rows, cols)
119+
tiles = shared.get_tiles(dest_tifs[0], rows, cols)
121120

122121
# load the first tsincr file to determine the number of time series tifs
123122
tsincr_file = os.path.join(output_dir, 'tsincr_0.npy')
@@ -166,6 +165,7 @@ def postprocess_timeseries(rows, cols, params):
166165

167166

168167
def assemble_tiles(i, n, tile, tsincr_g, output_dir, outtype):
168+
# pylint: disable=too-many-arguments
169169
""" A reusable time series assembling function"""
170170
tsincr_file = os.path.join(output_dir,
171171
'{}_{}.npy'.format(outtype, n))

pyrate/scripts/run_prepifg.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ def main(params=None):
5454
# and the original gamma generated list is ordered) this may not affect
5555
# the important pyrate stuff anyway, but might affect gen_thumbs.py.
5656
# Going to assume base_ifg_paths is ordered correcly
57+
# pylint: disable=too-many-branches
5758

5859
usage = 'Usage: pyrate prepifg <config_file>'
59-
if mpiops.size > 1: # Over-ride input options if this is an MPI job
60+
if mpiops.size > 1: # Over-ride input options if this is an MPI job
6061
params[cf.LUIGI] = False
6162
params[cf.PARALLEL] = False
6263

pyrate/scripts/run_pyrate.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
import logging
2222
import os
23-
import pickle as cp
2423
from os.path import join
24+
import pickle as cp
2525
from collections import OrderedDict
2626
import numpy as np
2727

pyrate/shared.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1093,4 +1093,4 @@ def get_tiles(ifg_path, rows, cols):
10931093
ifg.open(readonly=True)
10941094
tiles = create_tiles(ifg.shape, nrows=rows, ncols=cols)
10951095
ifg.close()
1096-
return tiles
1096+
return tiles

tests/test_mpi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def orbfit_degrees(request):
207207

208208

209209
@pytest.mark.skipif(not MPITEST, reason='skipping mpi tests in travis except '
210-
'python 3.5 and GDAL=2.0.0')
210+
'in TRAVIS and GDAL=2.0.0')
211211
def test_timeseries_linrate_mpi(mpisync, tempdir, modify_config,
212212
ref_est_method, row_splits, col_splits,
213213
get_crop, orbfit_lks, orbfit_method,

0 commit comments

Comments
 (0)