Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ift
NIFTy
Commits
a8302a53
Commit
a8302a53
authored
Sep 04, 2017
by
Martin Reinecke
Browse files
more PEP8
parent
7306562b
Changes
11
Hide whitespace changes
Inline
Side-by-side
nifty2go/nifty_utilities.py
View file @
a8302a53
...
...
@@ -23,6 +23,7 @@ from itertools import product
import
itertools
from
functools
import
reduce
def
get_slice_list
(
shape
,
axes
):
"""
Helper function which generates slice list(s) to traverse over all
...
...
@@ -111,6 +112,8 @@ def parse_domain(domain):
"Given object contains something that is not an "
"instance of DomainObject-class."
)
return
domain
def
slicing_generator
(
shape
,
axes
):
"""
Helper function which generates slice list(s) to traverse over all
...
...
@@ -154,6 +157,7 @@ def slicing_generator(shape, axes):
yield
[
slice
(
None
,
None
)]
return
def
bincount_axis
(
obj
,
minlength
=
None
,
weights
=
None
,
axis
=
None
):
if
minlength
is
not
None
:
length
=
max
(
np
.
amax
(
obj
)
+
1
,
minlength
)
...
...
nifty2go/operators/diagonal_operator/diagonal_operator.py
View file @
a8302a53
...
...
@@ -98,7 +98,8 @@ class DiagonalOperator(EndomorphicOperator):
operation
=
lambda
z
:
z
.
adjoint
().
__mul__
)
def
_inverse_times
(
self
,
x
,
spaces
):
return
self
.
_times_helper
(
x
,
spaces
,
operation
=
lambda
z
:
z
.
__rtruediv__
)
return
self
.
_times_helper
(
x
,
spaces
,
operation
=
lambda
z
:
z
.
__rtruediv__
)
def
_adjoint_inverse_times
(
self
,
x
,
spaces
):
return
self
.
_times_helper
(
x
,
spaces
,
...
...
@@ -221,4 +222,4 @@ class DiagonalOperator(EndomorphicOperator):
# here the actual multiplication takes place
local_result
=
operation
(
reshaped_local_diagonal
)(
x
.
val
)
return
Field
(
x
.
domain
,
val
=
local_result
)
return
Field
(
x
.
domain
,
val
=
local_result
)
nifty2go/operators/fft_operator/fft_operator.py
View file @
a8302a53
...
...
@@ -16,8 +16,6 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
import
numpy
as
np
from
...
import
nifty_utilities
as
utilities
from
...spaces
import
RGSpace
,
\
GLSpace
,
\
...
...
nifty2go/operators/fft_operator/transformations/rgrgtransformation.py
View file @
a8302a53
...
...
@@ -20,7 +20,7 @@ from __future__ import division
import
numpy
as
np
from
.transformation
import
Transformation
from
.rg_transforms
import
SerialFFT
from
....
import
RGSpace
class
RGRGTransformation
(
Transformation
):
...
...
@@ -36,7 +36,6 @@ class RGRGTransformation(Transformation):
def
unitary
(
self
):
return
True
def
transform
(
self
,
val
,
axes
=
None
):
"""
RG -> RG transform method.
...
...
nifty2go/operators/fft_operator/transformations/slicing_transformation.py
View file @
a8302a53
...
...
@@ -29,7 +29,7 @@ class SlicingTransformation(Transformation):
return_shape
=
np
.
array
(
val
.
shape
)
return_shape
[
list
(
axes
)]
=
self
.
codomain
.
shape
return_shape
=
tuple
(
return_shape
)
return_val
=
np
.
empty
(
return_shape
,
dtype
=
val
.
dtype
)
return_val
=
np
.
empty
(
return_shape
,
dtype
=
val
.
dtype
)
for
slice_list
in
utilities
.
get_slice_list
(
val
.
shape
,
axes
):
return_val
[
slice_list
]
=
self
.
_transformation_of_slice
(
...
...
nifty2go/operators/fft_operator/transformations/transformation.py
View file @
a8302a53
...
...
@@ -21,7 +21,8 @@ import abc
from
future.utils
import
with_metaclass
class
Transformation
(
with_metaclass
(
abc
.
ABCMeta
,
type
(
'NewBase'
,
(
object
,),
{}))):
class
Transformation
(
with_metaclass
(
abc
.
ABCMeta
,
type
(
'NewBase'
,
(
object
,),
{}))):
def
__init__
(
self
,
domain
,
codomain
):
self
.
domain
=
domain
...
...
nifty2go/operators/smoothing_operator/direct_smoothing_operator.py
View file @
a8302a53
...
...
@@ -186,9 +186,8 @@ class DirectSmoothingOperator(EndomorphicOperator):
distance_array
=
x
.
domain
[
spaces
[
0
]].
get_distance_array
()
#MR FIXME: this causes calls of log(0.) which should probably be avoided
if
self
.
log_distances
:
np
.
log
(
np
.
maximum
(
distance_array
,
1e-15
),
out
=
distance_array
)
np
.
log
(
np
.
maximum
(
distance_array
,
1e-15
),
out
=
distance_array
)
augmented_data
=
x
.
val
augmented_distance_array
=
distance_array
...
...
nifty2go/operators/smoothing_operator/fft_smoothing_operator.py
View file @
a8302a53
...
...
@@ -62,7 +62,6 @@ class FFTSmoothingOperator(EndomorphicOperator):
coaxes
=
transformed_x
.
domain_axes
[
spaces
[
0
]]
kernel
=
codomain
.
get_distance_array
()
kernel
=
codomain
.
get_fft_smoothing_kernel_function
(
self
.
sigma
)(
kernel
)
# now, apply the kernel to transformed_x
...
...
@@ -77,15 +76,9 @@ class FFTSmoothingOperator(EndomorphicOperator):
local_transformed_x
*=
local_kernel
transformed_x
.
val
=
local_transformed_x
smoothed_x
=
transformator
.
adjoint_times
(
transformed_x
,
spaces
=
spaces
)
result
=
x
.
copy_empty
()
result
=
smoothed_x
transformed_x
.
val
=
local_transformed_x
return
result
return
transformator
.
adjoint_times
(
transformed_x
,
spaces
=
spaces
)
def
_get_transformator
(
self
,
dtype
):
if
dtype
not
in
self
.
_transformator_cache
:
...
...
nifty2go/spaces/gl_space/gl_space.py
View file @
a8302a53
...
...
@@ -24,6 +24,7 @@ import numpy as np
from
..space
import
Space
import
pyHealpix
class
GLSpace
(
Space
):
"""
.. __
...
...
@@ -177,7 +178,7 @@ class GLSpace(Space):
def
get_default_codomain
(
self
):
from
..
import
LMSpace
return
LMSpace
(
lmax
=
self
.
nlat
-
1
,
mmax
=
(
self
.
nlon
-
1
)
//
2
)
return
LMSpace
(
lmax
=
self
.
nlat
-
1
,
mmax
=
(
self
.
nlon
-
1
)
//
2
)
def
check_codomain
(
self
,
codomain
):
from
..
import
LMSpace
...
...
nifty2go/spaces/power_space/power_space.py
View file @
a8302a53
...
...
@@ -16,7 +16,6 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
import
ast
import
numpy
as
np
from
...spaces.space
import
Space
...
...
@@ -137,7 +136,7 @@ class PowerSpace(Space):
temp_rho
=
np
.
bincount
(
temp_pindex
.
flatten
())
assert
not
np
.
any
(
temp_rho
==
0
),
"empty bins detected"
temp_kindex
=
np
.
bincount
(
temp_pindex
.
flatten
(),
weights
=
distance_array
.
flatten
())
/
temp_rho
weights
=
distance_array
.
flatten
())
/
temp_rho
self
.
_powerIndexCache
[
key
]
=
(
binbounds
,
temp_pindex
,
temp_kindex
,
...
...
@@ -148,7 +147,6 @@ class PowerSpace(Space):
@
staticmethod
def
_compute_pindex
(
harmonic_partner
,
distance_array
,
binbounds
):
pindex
=
np
.
empty
(
distance_array
.
shape
,
dtype
=
np
.
int
)
if
binbounds
is
None
:
binbounds
=
harmonic_partner
.
get_natural_binbounds
()
return
np
.
searchsorted
(
binbounds
,
distance_array
)
...
...
nifty2go/spaces/rg_space/rg_space.py
View file @
a8302a53
...
...
@@ -230,7 +230,6 @@ class RGSpace(Space):
raise
AttributeError
(
"The grid-distances of domain and codomain "
"do not match."
)
# ---Added properties and methods---
@
property
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment