Skip to content

Commit

Permalink
MAINT: Make several strings case insensitive, see odlgroup#1454 (odlg…
Browse files Browse the repository at this point in the history
…roup#1463)

* MAINT: Make several strings case insensitive, see odlgroup#1454

* MAINT: pep8 fixes

* MAINT: General PEP8 fixes w.r.t escaped characters

* MAINT: Update copyright year

* MAINT: Standardization of PEP8
  • Loading branch information
adler-j authored and kohr-h committed Feb 13, 2019
1 parent 5e53af9 commit c90f3f9
Show file tree
Hide file tree
Showing 60 changed files with 681 additions and 651 deletions.
1 change: 1 addition & 0 deletions .pep8speaks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pycodestyle:
- E402
- E741
- W503
- W504

no_blank_comment: False
only_mention_files_with_errors: True
Expand Down
3 changes: 1 addition & 2 deletions examples/solvers/bregman_tv_tomography.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@
"""

import odl
import numpy as np

# Reconstruction space
reco_space = odl.uniform_discr(min_pt=[-20, -20], max_pt=[20, 20],
shape=[128, 128], dtype='float32')

# Make a parallel beam geometry with flat detector, and create ray transform
geometry = odl.tomo.parallel_beam_geometry(reco_space, num_angles=100)
geometry = odl.tomo.parallel_beam_geometry(reco_space, num_angles=100)
ray_trafo = odl.tomo.RayTransform(reco_space, geometry)

# Create phantom, forward project to create sinograms, and add 10% noise
Expand Down
2 changes: 1 addition & 1 deletion examples/solvers/douglas_rachford_pd_heron.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Solves the generalized Heron problem using the Douglas-Rachford solver.
r"""Solves the generalized Heron problem using the Douglas-Rachford solver.
The generalized Heron problem is defined as
Expand Down
2 changes: 1 addition & 1 deletion odl/contrib/fom/supervised.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def mean_value_difference(data, ground_truth, mask=None, normalized=False,
def standard_deviation_difference(data, ground_truth, mask=None,
normalized=False,
force_lower_is_better=True):
r"""Return absolute difference in std between ``data`` and ``ground_truth``.
r"""Return absolute diff in std between ``data`` and ``ground_truth``.
Parameters
----------
Expand Down
32 changes: 18 additions & 14 deletions odl/contrib/fom/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2018 The ODL contributors
# Copyright 2014-2019 The ODL contributors
#
# This file is part of ODL.
#
Expand Down Expand Up @@ -51,6 +51,10 @@ def filter_image_sep2d(image, fh, fv, impl='numpy', padding=None):
"""
# TODO: generalize for nD
impl, impl_in = str(impl).lower(), impl
if impl not in ('numpy', 'pyfftw'):
raise ValueError('`impl` {!r} not understood'
''.format(impl_in))

image = np.asarray(image)
if image.ndim != 2:
raise ValueError('`image` must be 2-dimensional, got image with '
Expand Down Expand Up @@ -185,7 +189,7 @@ def prepare_for_fft(filt, n_new):


def haarpsi_similarity_map(img1, img2, axis, c, a):
"""Local similarity map for directional features along an axis.
r"""Local similarity map for directional features along an axis.
Parameters
----------
Expand Down Expand Up @@ -214,11 +218,11 @@ def haarpsi_similarity_map(img1, img2, axis, c, a):
.. math::
\mathrm{HS}_{f_1, f_2}^{(k)}(x) =
l_a \\left(
\\frac{1}{2} \sum_{j=1}^2
S\\left(\\left|g_j^{(k)} \\ast f_1 \\right|(x),
\\left|g_j^{(k)} \\ast f_2 \\right|(x), c\\right)
\\right),
l_a \left(
\frac{1}{2} \sum_{j=1}^2
S\left(\left|g_j^{(k)} \ast f_1 \right|(x),
\left|g_j^{(k)} \ast f_2 \right|(x), c\right)
\right),
see `[Rei+2016] <https://arxiv.org/abs/1607.06140>`_ equation (10).
Here, the superscript :math:`(k)` refers to the axis (0 or 1)
Expand All @@ -227,7 +231,7 @@ def haarpsi_similarity_map(img1, img2, axis, c, a):
is the pointwise similarity score
.. math::
S(x, y, c) = \\frac{2xy + c^2}{x^2 + y^2 + c^2},
S(x, y, c) = \frac{2xy + c^2}{x^2 + y^2 + c^2},
Hence, :math:`c` is the :math:`y`-value at which the score
drops to :math:`1 / 2` for :math:`x = 0`. In other words, the smaller
Expand All @@ -247,7 +251,7 @@ def haarpsi_similarity_map(img1, img2, axis, c, a):
...
The logistic function :math:`l_a` transforms values in
:math:`[0, \\infty)` to :math:`[1/2, 1)`, where the parameter
:math:`[0, \infty)` to :math:`[1/2, 1)`, where the parameter
:math:`a` determines how fast the curve attains values close
to 1. Larger :math:`a` means that smaller :math:`x` will yield
a value :math:`l_a(x)` close to 1 (and thus result in a higher
Expand Down Expand Up @@ -324,7 +328,7 @@ def S(x, y):


def haarpsi_weight_map(img1, img2, axis):
"""Weighting map for directional features along an axis.
r"""Weighting map for directional features along an axis.
Parameters
----------
Expand All @@ -346,10 +350,10 @@ def haarpsi_weight_map(img1, img2, axis):
.. math::
\mathrm{W}_{f_1, f_2}^{(k)}(x) =
\max \\left\{
\\left|g_3^{(k)} \\ast f_1 \\right|(x),
\\left|g_3^{(k)} \\ast f_2 \\right|(x)
\\right\},
\max \left\{
\left|g_3^{(k)} \ast f_1 \right|(x),
\left|g_3^{(k)} \ast f_2 \right|(x)
\right\},
see `[Rei+2016] <https://arxiv.org/abs/1607.06140>`_ equations (11)
and (13).
Expand Down
4 changes: 3 additions & 1 deletion odl/contrib/mrc/mrc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2017 The ODL contributors
# Copyright 2014-2019 The ODL contributors
#
# This file is part of ODL.
#
Expand Down Expand Up @@ -122,6 +122,7 @@ def print_mrc2014_spec():
"""
print(MRC_2014_SPEC_TABLE)


print_mrc2014_spec.__doc__ += MRC_2014_SPEC_TABLE


Expand Down Expand Up @@ -193,6 +194,7 @@ def print_fei_ext_header_spec():
"""
print(MRC_FEI_EXT_HEADER_SECTION)


print_fei_ext_header_spec.__doc__ += MRC_FEI_EXT_HEADER_SECTION


Expand Down
1 change: 1 addition & 0 deletions odl/contrib/mrc/test/uncompr_bin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
def test_uncompr_bin_io_without_header(shape, floating_dtype, order):
"""Test I/O bypassing the header processing."""
dtype = np.dtype(floating_dtype)
order = str(order).upper()
with tempfile.NamedTemporaryFile() as named_file:
file = named_file.file

Expand Down
14 changes: 7 additions & 7 deletions odl/contrib/solvers/functional/nonlocalmeans_functionals.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2017 The ODL contributors
# Copyright 2014-2019 The ODL contributors
#
# This file is part of ODL.
#
Expand All @@ -19,7 +19,7 @@

class NLMRegularizer(Functional):

"""The nonlocal means "functional".
r"""The nonlocal means "functional".
This is not a true functional in the strict sense, but regardless it
implements a `proximal` method and is hence usable with proximal solvers.
Expand All @@ -40,9 +40,9 @@ class NLMRegularizer(Functional):
.. math::
NL[u](x) =
\\frac{1}{C(x)}
\\int_\\Omega
e^{-\\frac{(G_a * |u(x + \cdot) - u(y + \cdot)|^2)(0)}{h^2}}
\frac{1}{C(x)}
\int_\Omega
e^{-\frac{(G_a * |u(x + \cdot) - u(y + \cdot)|^2)(0)}{h^2}}
u(y) dy
where :math:`\Omega` is the domain, :math:`G_a` is a gaussian kernel,
Expand All @@ -51,8 +51,8 @@ class NLMRegularizer(Functional):
.. math::
C(x) =
\\int_\\Omega
e^{-\\frac{(G_a * |u(x + \cdot) - u(y + \cdot)|^2)(0)}{h^2}}
\int_\Omega
e^{-\frac{(G_a * |u(x + \cdot) - u(y + \cdot)|^2)(0)}{h^2}}
dy
See [Buades+2005] for more information.
Expand Down
8 changes: 4 additions & 4 deletions odl/contrib/solvers/spdhg/examples/PET_1k.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2018 The ODL contributors
# Copyright 2014-2019 The ODL contributors
#
# This file is part of ODL.
#
Expand Down Expand Up @@ -331,7 +331,7 @@ def fun_select(k):
iter_save_v, niter_v, image_v, out_v, nsub_v = {}, {}, {}, {}, {}
for a in algs:
(iter_save_v[a], niter_v[a], image_v[a], out_v[a], nsub_v[a]) = np.load(
'{}/{}_output.npy'.format(folder_npy, a))
'{}/{}_output.npy'.format(folder_npy, a))

epochs_save = {a: np.array(iter_save_v[a]) / np.float(nsub_v[a]) for a in algs}

Expand Down Expand Up @@ -444,8 +444,8 @@ def fun_select(k):
msize = 9 # marker size

algs = ['pdhg', 'spdhg10', 'spdhg50', 'pesquet10', 'pesquet50']
label = ['PDHG', 'SPDHG (10 subsets)', 'SPDHG (50)', 'Pesquet\&Repetti (10)',
'Pesquet\&Repetti (50)']
label = ['PDHG', 'SPDHG (10 subsets)', 'SPDHG (50)', 'Pesquet\\&Repetti (10)',
'Pesquet\\&Repetti (50)']
fig = []

# ### draw figures
Expand Down
6 changes: 3 additions & 3 deletions odl/contrib/solvers/spdhg/examples/PET_linear_rate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2018 The ODL contributors
# Copyright 2014-2019 The ODL contributors
#
# This file is part of ODL.
#
Expand Down Expand Up @@ -438,8 +438,8 @@ def fun_select(k):
msize = 9 # marker size

algs = ['pdhg', 'spdhg_uni10', 'spdhg_uni50', 'pesquet_uni10', 'pesquet_uni50']
label = ['PDHG', 'SPDHG (10 subsets)', 'SPDHG (50)', 'Pesquet\&Repetti (10)',
'Pesquet\&Repetti (50)']
label = ['PDHG', 'SPDHG (10 subsets)', 'SPDHG (50)', 'Pesquet\\&Repetti (10)',
'Pesquet\\&Repetti (50)']
fig = []

# draw figures
Expand Down
4 changes: 2 additions & 2 deletions odl/contrib/solvers/spdhg/examples/ROF_1k2_primal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2018 The ODL contributors
# Copyright 2014-2019 The ODL contributors
#
# This file is part of ODL.
#
Expand Down Expand Up @@ -384,7 +384,7 @@ def fun_select(k):
msize = 9 # marker size

algs = ['pdhg', 'pa_pdhg', 'spdhg_uni2', 'pa_spdhg_uni2', 'pesquet_uni2']
label = ['PDHG', 'PA-PDHG', 'SPDHG', 'PA-SPDHG', 'Pesquet\&Repetti']
label = ['PDHG', 'PA-PDHG', 'SPDHG', 'PA-SPDHG', 'Pesquet\\&Repetti']
fig = []

# draw first figure
Expand Down
32 changes: 17 additions & 15 deletions odl/contrib/solvers/spdhg/misc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2018 The ODL contributors
# Copyright 2014-2019 The ODL contributors
#
# This file is part of ODL.
#
Expand Down Expand Up @@ -441,20 +441,21 @@ def __repr__(self):


class KullbackLeiblerSmooth(odl.solvers.Functional):
"""The smooth Kullback-Leibler divergence functional.

r"""The smooth Kullback-Leibler divergence functional.
Notes
-----
If the functional is defined on an :math:`\mathbb{R}^n`-like space, the
smooth Kullback-Leibler functional :math:`\\phi` is defined as
smooth Kullback-Leibler functional :math:`\phi` is defined as
.. math::
\\phi(x) = \\sum_{i=1}^n \\begin{cases}
x + r - y + y * \\log(y / (x + r))
& \\text{if $x \geq 0$} \\
\phi(x) = \sum_{i=1}^n \begin{cases}
x + r - y + y * \log(y / (x + r))
& \text{if $x \geq 0$} \
(y / (2 * r^2)) * x^2 + (1 - y / r) * x + r - b +
b * \\log(b / r) & \\text{else}
\\end{cases}
b * \log(b / r) & \text{else}
\end{cases}
where all variables on the right hand side of the equation have a subscript
i which is omitted for readability.
Expand Down Expand Up @@ -561,24 +562,25 @@ def __repr__(self):


class KullbackLeiblerSmoothConvexConj(odl.solvers.Functional):
"""The convex conjugate of the smooth Kullback-Leibler divergence functional.

r"""The convex conj of the smooth Kullback-Leibler divergence functional.
Notes
-----
If the functional is defined on an :math:`\mathbb{R}^n`-like space, the
convex conjugate of the smooth Kullback-Leibler functional :math:`\\phi^*`
convex conjugate of the smooth Kullback-Leibler functional :math:`\phi^*`
is defined as
.. math::
\\phi^*(x) = \\sum_{i=1}^n \\begin{cases}
\phi^*(x) = \sum_{i=1}^n \begin{cases}
r^2 / (2 * y) * x^2 + (r - r^2 / y) * x + r^2 / (2 * y) +
3 / 2 * y - 2 * r - y * log(y / r)
& \\text{if $x < 1 - y / r$} \\
& \text{if $x < 1 - y / r$} \
- r * x - y * log(1 - x)
& \\text{if $1 - y / r <= x < 1} \\
& \text{if $1 - y / r <= x < 1} \
+ \infty
& \\text{else}
\\end{cases}
& \text{else}
\end{cases}
where all variables on the right hand side of the equation have a subscript
:math:`i` which is omitted for readability.
Expand Down
Loading

0 comments on commit c90f3f9

Please sign in to comment.