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
6ad2e1ec
Commit
6ad2e1ec
authored
Feb 02, 2018
by
Martin Reinecke
Browse files
renamings
parent
63eb16f4
Pipeline
#24332
passed with stage
in 5 minutes and 53 seconds
Changes
22
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
demos/wiener_filter_via_curvature.py
View file @
6ad2e1ec
...
...
@@ -58,7 +58,7 @@ if __name__ == "__main__":
data_domain
=
R
.
target
[
0
]
noiseless_data
=
R
(
mock_signal
)
noise_amplitude
=
noiseless_data
.
std
()
/
signal_to_noise
noise_amplitude
=
noiseless_data
.
val
.
std
()
/
signal_to_noise
N
=
ift
.
DiagonalOperator
(
ift
.
Field
.
full
(
data_domain
,
noise_amplitude
**
2
))
noise
=
ift
.
Field
.
from_random
(
...
...
nifty4/__init__.py
View file @
6ad2e1ec
...
...
@@ -2,10 +2,9 @@ from .version import __version__
from
.
import
dobj
from
.domain_object
import
DomainObject
from
.spaces.field_array
import
FieldArray
from
.spaces.space
import
Space
from
.spaces.domain
import
Domain
from
.spaces.unstructured_domain
import
UnstructuredDomain
from
.spaces.structured_domain
import
StructuredDomain
from
.spaces.rg_space
import
RGSpace
from
.spaces.lm_space
import
LMSpace
from
.spaces.hp_space
import
HPSpace
...
...
@@ -55,7 +54,7 @@ from .sugar import *
from
.plotting.plot
import
plot
from
.
import
library
__all__
=
[
"Domain
Object"
,
"FieldArray"
,
"Space
"
,
"RGSpace"
,
"LMSpace"
,
__all__
=
[
"Domain
"
,
"UnstructuredDomain"
,
"StructuredDomain
"
,
"RGSpace"
,
"LMSpace"
,
"HPSpace"
,
"GLSpace"
,
"DOFSpace"
,
"PowerSpace"
,
"DomainTuple"
,
"LinearOperator"
,
"EndomorphicOperator"
,
"ScalingOperator"
,
"DiagonalOperator"
,
"FFTOperator"
,
"FFTSmoothingOperator"
,
...
...
nifty4/domain_tuple.py
View file @
6ad2e1ec
...
...
@@ -17,7 +17,7 @@
# and financially supported by the Studienstiftung des deutschen Volkes.
from
functools
import
reduce
from
.
domain_object
import
Domain
Object
from
.
spaces.domain
import
Domain
class
DomainTuple
(
object
):
...
...
@@ -28,12 +28,10 @@ class DomainTuple(object):
self
.
_axtuple
=
self
.
_get_axes_tuple
()
shape_tuple
=
tuple
(
sp
.
shape
for
sp
in
self
.
_dom
)
self
.
_shape
=
reduce
(
lambda
x
,
y
:
x
+
y
,
shape_tuple
,
())
self
.
_dim
=
reduce
(
lambda
x
,
y
:
x
*
y
,
self
.
_shape
,
1
)
self
.
_accdims
=
(
1
,)
self
.
_size
=
reduce
(
lambda
x
,
y
:
x
*
y
,
self
.
_shape
,
1
)
prod
=
1
for
dom
in
self
.
_dom
:
prod
*=
dom
.
dim
self
.
_accdims
+=
(
prod
,)
prod
*=
dom
.
size
def
_get_axes_tuple
(
self
):
i
=
0
...
...
@@ -60,16 +58,16 @@ class DomainTuple(object):
def
_parse_domain
(
domain
):
if
domain
is
None
:
return
()
if
isinstance
(
domain
,
Domain
Object
):
if
isinstance
(
domain
,
Domain
):
return
(
domain
,)
if
not
isinstance
(
domain
,
tuple
):
domain
=
tuple
(
domain
)
for
d
in
domain
:
if
not
isinstance
(
d
,
Domain
Object
):
if
not
isinstance
(
d
,
Domain
):
raise
TypeError
(
"Given object contains something that is not an "
"instance of Domain
Object
class."
)
"instance of Domain class."
)
return
domain
def
__getitem__
(
self
,
i
):
...
...
@@ -80,8 +78,8 @@ class DomainTuple(object):
return
self
.
_shape
@
property
def
dim
(
self
):
return
self
.
_
dim
def
size
(
self
):
return
self
.
_
size
@
property
def
axes
(
self
):
...
...
nifty4/field.py
View file @
6ad2e1ec
...
...
@@ -35,7 +35,7 @@ class Field(object):
Parameters
----------
domain : None, DomainTuple, tuple
of
Domain
Objects, or single DomainObject
domain : None, DomainTuple, tuple
(
Domain
), or Domain
val : None, Field, data_object, or scalar
The values the array should contain after init. A scalar input will
...
...
@@ -156,7 +156,7 @@ class Field(object):
'pm1', 'normal', 'uniform' are the supported arguments for this
method.
domain : Domain
Object
domain : Domain
Tuple
The domain of the output random field
dtype : type
...
...
@@ -201,7 +201,7 @@ class Field(object):
return
self
.
_domain
.
shape
@
property
def
dim
(
self
):
def
size
(
self
):
""" Returns the total number of pixel-dimensions the field has.
Effectively, all values from shape are multiplied.
...
...
@@ -211,7 +211,7 @@ class Field(object):
out : int
The dimension of the Field.
"""
return
self
.
_domain
.
dim
return
self
.
_domain
.
size
@
property
def
real
(
self
):
...
...
nifty4/operators/response_operator.py
View file @
6ad2e1ec
...
...
@@ -17,7 +17,7 @@
# and financially supported by the Studienstiftung des deutschen Volkes.
from
..field
import
Field
from
..spaces.
field_array
import
FieldArray
from
..spaces.
unstructured_domain
import
UnstructuredDomain
from
..domain_tuple
import
DomainTuple
from
.linear_operator
import
LinearOperator
from
.fft_smoothing_operator
import
FFTSmoothingOperator
...
...
@@ -30,7 +30,7 @@ class GeometryRemover(LinearOperator):
def
__init__
(
self
,
domain
):
super
(
GeometryRemover
,
self
).
__init__
()
self
.
_domain
=
DomainTuple
.
make
(
domain
)
target_list
=
[
FieldArray
(
dom
.
shape
)
for
dom
in
self
.
_domain
]
target_list
=
[
UnstructuredDomain
(
dom
.
shape
)
for
dom
in
self
.
_domain
]
self
.
_target
=
DomainTuple
.
make
(
target_list
)
@
property
...
...
nifty4/spaces/dof_space.py
View file @
6ad2e1ec
...
...
@@ -17,10 +17,10 @@
# and financially supported by the Studienstiftung des deutschen Volkes.
import
numpy
as
np
from
.s
pace
import
Space
from
.s
tructured_domain
import
StructuredDomain
class
DOFSpace
(
S
pace
):
class
DOFSpace
(
S
tructuredDomain
):
def
__init__
(
self
,
dof_weights
):
super
(
DOFSpace
,
self
).
__init__
()
self
.
_dvol
=
tuple
(
dof_weights
)
...
...
@@ -35,7 +35,7 @@ class DOFSpace(Space):
return
(
len
(
self
.
_dvol
),)
@
property
def
dim
(
self
):
def
size
(
self
):
return
len
(
self
.
_dvol
)
def
scalar_dvol
(
self
):
...
...
nifty4/
domain_object
.py
→
nifty4/
spaces/domain
.py
View file @
6ad2e1ec
...
...
@@ -16,19 +16,15 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from
__future__
import
division
import
abc
from
.utilities
import
NiftyMeta
from
.
.utilities
import
NiftyMeta
from
future.utils
import
with_metaclass
import
numpy
as
np
class
Domain
Object
(
with_metaclass
(
class
Domain
(
with_metaclass
(
NiftyMeta
,
type
(
'NewBase'
,
(
object
,),
{}))):
"""The abstract class that can be used as a domain for a field.
This holds all the information and functionality a field needs to know
about its domain and how the data of the field are stored.
"""The abstract class repesenting a (structured or unstructured) domain.
"""
def
__init__
(
self
):
...
...
@@ -45,16 +41,16 @@ class DomainObject(with_metaclass(
return
result_hash
def
__eq__
(
self
,
x
):
"""Checks if two domain
_object
s are equal.
"""Checks if two domains are equal.
Parameters
----------
x:
d
omain
_object
The domain
_object
`self` is compared to.
x:
D
omain
The domain `self` is compared to.
Returns
-------
bool: True iff `self` and x describe the same
manifold
.
bool: True iff `self` and x describe the same
domain
.
"""
if
self
is
x
:
# shortcut for simple case
return
True
...
...
@@ -70,47 +66,22 @@ class DomainObject(with_metaclass(
@
abc
.
abstractproperty
def
shape
(
self
):
"""The domain-object's shape contribution to the underlying array.
"""The shape of the array-like object required to store information
living on the domain.
Returns
-------
tuple of ints: shape of the
underlying
array-like object
tuple of ints: shape of the
required
array-like object
"""
raise
NotImplementedError
@
abc
.
abstractproperty
def
dim
(
self
):
""" Returns the number of pixel-dimensions the object has.
Returns
-------
int: number of pixels
"""
raise
NotImplementedError
@
abc
.
abstractmethod
def
scalar_dvol
(
self
):
"""Returns the volume factors of this domain as a floating
point scalar, if the volume factors are all identical, otherwise
returns None.
def
size
(
self
):
"""Number of data elements associated with this domain.
Equivalent to the products over all entries in the domain's shape.
Returns
-------
float or None: Volume factor
int: number of data elements
"""
raise
NotImplementedError
def
dvol
(
self
):
"""Returns the volume factors of this domain, either as a floating
point scalar (if the volume factors are all identical) or as a
floating point array with a shape of `self.shape`.
Returns
-------
float or numpy.ndarray(dtype=float): Volume factors
"""
return
self
.
scalar_dvol
()
def
total_volume
(
self
):
tmp
=
self
.
dvol
()
return
self
.
dim
*
tmp
if
np
.
isscalar
(
tmp
)
else
np
.
sum
(
tmp
)
nifty4/spaces/gl_space.py
View file @
6ad2e1ec
...
...
@@ -18,10 +18,10 @@
from
__future__
import
division
import
numpy
as
np
from
.s
pace
import
Space
from
.s
tructured_domain
import
StructuredDomain
class
GLSpace
(
S
pace
):
class
GLSpace
(
S
tructuredDomain
):
"""NIFTy subclass for Gauss-Legendre pixelizations [#]_ of the two-sphere.
Parameters
...
...
@@ -79,7 +79,7 @@ class GLSpace(Space):
return
(
np
.
int
((
self
.
nlat
*
self
.
nlon
)),)
@
property
def
dim
(
self
):
def
size
(
self
):
return
np
.
int
((
self
.
nlat
*
self
.
nlon
))
def
scalar_dvol
(
self
):
...
...
nifty4/spaces/hp_space.py
View file @
6ad2e1ec
...
...
@@ -18,10 +18,10 @@
from
__future__
import
division
import
numpy
as
np
from
.s
pace
import
Space
from
.s
tructured_domain
import
StructuredDomain
class
HPSpace
(
S
pace
):
class
HPSpace
(
S
tructuredDomain
):
"""NIFTy subclass for HEALPix discretizations of the two-sphere [#]_.
Parameters
...
...
@@ -65,10 +65,10 @@ class HPSpace(Space):
@
property
def
shape
(
self
):
return
(
self
.
dim
,)
return
(
self
.
size
,)
@
property
def
dim
(
self
):
def
size
(
self
):
return
np
.
int
(
12
*
self
.
nside
*
self
.
nside
)
def
scalar_dvol
(
self
):
...
...
nifty4/spaces/lm_space.py
View file @
6ad2e1ec
...
...
@@ -18,12 +18,12 @@
from
__future__
import
division
import
numpy
as
np
from
.s
pace
import
Space
from
.s
tructured_domain
import
StructuredDomain
from
..field
import
Field
,
exp
from
..
import
dobj
class
LMSpace
(
S
pace
):
class
LMSpace
(
S
tructuredDomain
):
"""NIFTy subclass for spherical harmonics components, for representations
of fields on the two-sphere.
...
...
@@ -75,10 +75,10 @@ class LMSpace(Space):
@
property
def
shape
(
self
):
return
(
self
.
dim
,
)
return
(
self
.
size
,
)
@
property
def
dim
(
self
):
def
size
(
self
):
l
=
self
.
_lmax
m
=
self
.
_mmax
# the LMSpace consists of the full triangle (including -m's!),
...
...
@@ -91,7 +91,7 @@ class LMSpace(Space):
def
get_k_length_array
(
self
):
lmax
=
self
.
_lmax
mmax
=
self
.
_mmax
ldist
=
np
.
empty
((
self
.
dim
,),
dtype
=
np
.
float64
)
ldist
=
np
.
empty
((
self
.
size
,),
dtype
=
np
.
float64
)
ldist
[
0
:
lmax
+
1
]
=
np
.
arange
(
lmax
+
1
,
dtype
=
np
.
float64
)
tmp
=
np
.
empty
((
2
*
lmax
+
2
),
dtype
=
np
.
float64
)
tmp
[
0
::
2
]
=
np
.
arange
(
lmax
+
1
)
...
...
nifty4/spaces/power_space.py
View file @
6ad2e1ec
...
...
@@ -17,11 +17,11 @@
# and financially supported by the Studienstiftung des deutschen Volkes.
import
numpy
as
np
from
.s
pace
import
Space
from
.s
tructured_domain
import
StructuredDomain
from
..
import
dobj
class
PowerSpace
(
S
pace
):
class
PowerSpace
(
S
tructuredDomain
):
"""NIFTy class for spaces of power spectra.
A power space is the result of a projection of a harmonic space where
...
...
@@ -90,7 +90,7 @@ class PowerSpace(Space):
@
staticmethod
def
useful_binbounds
(
space
,
logarithmic
,
nbin
=
None
):
if
not
(
isinstance
(
space
,
S
pace
)
and
space
.
harmonic
):
if
not
(
isinstance
(
space
,
S
tructuredDomain
)
and
space
.
harmonic
):
raise
ValueError
(
"first argument must be a harmonic space."
)
if
logarithmic
is
None
and
nbin
is
None
:
return
None
...
...
@@ -122,7 +122,7 @@ class PowerSpace(Space):
super
(
PowerSpace
,
self
).
__init__
()
self
.
_needed_for_hash
+=
[
'_harmonic_partner'
,
'_binbounds'
]
if
not
(
isinstance
(
harmonic_partner
,
S
pace
)
and
if
not
(
isinstance
(
harmonic_partner
,
S
tructuredDomain
)
and
harmonic_partner
.
harmonic
):
raise
ValueError
(
"harmonic_partner must be a harmonic space."
)
if
harmonic_partner
.
scalar_dvol
()
is
None
:
...
...
@@ -180,7 +180,7 @@ class PowerSpace(Space):
return
self
.
k_lengths
.
shape
@
property
def
dim
(
self
):
def
size
(
self
):
return
self
.
shape
[
0
]
def
scalar_dvol
(
self
):
...
...
nifty4/spaces/rg_space.py
View file @
6ad2e1ec
...
...
@@ -20,13 +20,13 @@ from __future__ import division
from
builtins
import
range
from
functools
import
reduce
import
numpy
as
np
from
.s
pace
import
Space
from
.s
tructured_domain
import
StructuredDomain
from
..field
import
Field
,
exp
from
..
import
dobj
class
RGSpace
(
S
pace
):
"""NIFTy subclass for
spaces of
regular Cartesian grids.
class
RGSpace
(
S
tructuredDomain
):
"""NIFTy subclass for regular Cartesian grids.
Parameters
----------
...
...
@@ -66,7 +66,7 @@ class RGSpace(Space):
self
.
_distances
=
tuple
(
temp
)
self
.
_dvol
=
float
(
reduce
(
lambda
x
,
y
:
x
*
y
,
self
.
_distances
))
self
.
_
dim
=
int
(
reduce
(
lambda
x
,
y
:
x
*
y
,
self
.
_shape
))
self
.
_
size
=
int
(
reduce
(
lambda
x
,
y
:
x
*
y
,
self
.
_shape
))
def
__repr__
(
self
):
return
(
"RGSpace(shape=%r, distances=%r, harmonic=%r)"
...
...
@@ -81,8 +81,8 @@ class RGSpace(Space):
return
self
.
_shape
@
property
def
dim
(
self
):
return
self
.
_
dim
def
size
(
self
):
return
self
.
_
size
def
scalar_dvol
(
self
):
return
self
.
_dvol
...
...
nifty4/spaces/s
pace
.py
→
nifty4/spaces/s
tructured_domain
.py
View file @
6ad2e1ec
...
...
@@ -17,28 +17,56 @@
# and financially supported by the Studienstiftung des deutschen Volkes.
import
abc
from
..domain_object
import
DomainObject
from
.domain
import
Domain
import
numpy
as
np
class
S
pace
(
Domain
Object
):
"""The abstract base class for all
NIFTy space
s.
class
S
tructuredDomain
(
Domain
):
"""The abstract base class for all
structured NIFTy domain
s.
An instance of a space contains information about the manifold's
geometry and enhances the functionality of Domain
Object
by methods that
geometry and enhances the functionality of Domain by methods that
are needed for power spectrum analysis and smoothing.
"""
def
__init__
(
self
):
super
(
Space
,
self
).
__init__
()
super
(
StructuredDomain
,
self
).
__init__
()
@
abc
.
abstractmethod
def
scalar_dvol
(
self
):
"""Returns the volume factors of this domain as a floating
point scalar, if the volume factors are all identical, otherwise
returns None.
Returns
-------
float or None: Volume factor
"""
raise
NotImplementedError
def
dvol
(
self
):
"""Returns the volume factors of this domain, either as a floating
point scalar (if the volume factors are all identical) or as a
floating point array with a shape of `self.shape`.
Returns
-------
float or numpy.ndarray(dtype=float): Volume factors
"""
return
self
.
scalar_dvol
()
def
total_volume
(
self
):
tmp
=
self
.
dvol
()
return
self
.
size
*
tmp
if
np
.
isscalar
(
tmp
)
else
np
.
sum
(
tmp
)
@
abc
.
abstractproperty
def
harmonic
(
self
):
""" Returns True iff this
space
is a harmonic
space
."""
""" Returns True iff this
domain
is a harmonic
domain
."""
raise
NotImplementedError
def
get_k_length_array
(
self
):
"""The length of the k vector for every pixel.
This method is only implemented for harmonic
space
s.
This method is only implemented for harmonic
domain
s.
Returns
-------
...
...
@@ -49,27 +77,26 @@ class Space(DomainObject):
def
get_unique_k_lengths
(
self
):
""" Returns an array of floats containing the unique k vector lengths
for this
space
.
This method is only implemented for harmonic
space
s.
for this
domain
.
This method is only implemented for harmonic
domain
s.
"""
raise
NotImplementedError
def
get_fft_smoothing_kernel_function
(
self
,
sigma
):
"""This method returns a smoothing kernel function.
This method, which is only implemented for harmonic spaces, helps
smoothing fields that live in a position space that has this space as
its harmonic space. The returned function multiplies field values of a
field with a zero centered Gaussian which corresponds to a convolution
with a Gaussian kernel and sigma standard deviation in position space.
This method, which is only implemented for harmonic domains, helps
smoothing fields that live on a domain that has this domain as
its harmonic partner. The returned function multiplies field values of
a field with a zero centered Gaussian which corresponds to a
convolution with a Gaussian kernel and sigma standard deviation in
position space.
Parameters
----------
sigma : float
A real number representing a physical scale on which the smoothing
takes place. The smoothing is defined with respect to the real
physical field and points that are closer together than one sigma
are blurred together. Mathematically sigma is the standard
takes place. Mathematically sigma is the standard
deviation of a convolution with a normalized, zero-centered
Gaussian that takes place in position space.
...
...
nifty4/spaces/
field_array
.py
→
nifty4/spaces/
unstructured_domain
.py
View file @
6ad2e1ec
...
...
@@ -16,13 +16,13 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from
.
.domain
_object
import
Domain
Object
from
.domain
import
Domain
from
functools
import
reduce
class
FieldArray
(
Domain
Object
):
class
UnstructuredDomain
(
Domain
):
def
__init__
(
self
,
shape
):
super
(
FieldArray
,
self
).
__init__
()
super
(
UnstructuredDomain
,
self
).
__init__
()
self
.
_needed_for_hash
+=
[
"_shape"
]
try
:
self
.
_shape
=
tuple
([
int
(
i
)
for
i
in
shape
])
...
...
@@ -30,15 +30,12 @@ class FieldArray(DomainObject):
self
.
_shape
=
(
int
(
shape
),
)
def
__repr__
(
self
):
return
"
FieldArray
(shape=%r)"
%
(
self
.
shape
,
)
return
"
UnstructuredDomain
(shape=%r)"
%
(
self
.
shape
,
)
@
property
def
shape
(
self
):
return
self
.
_shape
@
property
def
dim
(
self
):
def
size
(
self
):
return
reduce
(
lambda
x
,
y
:
x
*
y
,
self
.
shape
)
def
scalar_dvol
(
self
):
return
1.
nifty4/sugar.py
View file @
6ad2e1ec
...
...
@@ -17,7 +17,7 @@
# and financially supported by the Studienstiftung des deutschen Volkes.
import
numpy
as
np
from
.spaces.s
pace
import
Space
from
.spaces.s
tructured_domain
import
StructuredDomain
from
.spaces.power_space
import
PowerSpace
from
.field
import
Field
,
sqrt
from
.operators.diagonal_operator
import
DiagonalOperator
...
...
@@ -246,7 +246,7 @@ def create_composed_ht_operator(domain, codomain=None):
codomain
=
[
None
]
*
len
(
domain
)
res
=
None
for
i
,
space
in
enumerate
(
domain
):
if
isinstance
(
space
,
S
pace
)
and
space
.
harmonic
:
if
isinstance
(
space
,
S
tructuredDomain
)
and
space
.
harmonic
:
tdom
=
domain
if
res
is
None
else
res
.
target
op
=
HarmonicTransformOperator
(
tdom
,
codomain
[
i
],
i
)
res
=
op
if
res
is
None
else
op
*
res
...
...
test/test_field.py
View file @
6ad2e1ec
...
...
@@ -33,7 +33,7 @@ class Test_Interface(unittest.TestCase):
[[
'domain'
,
ift
.
DomainTuple
],
[
'val'
,
ift
.
dobj
.
data_object
],
[
'shape'
,
tuple
],
[
'
dim
'
,
(
np
.
int
,
np
.
int64
)]]))
[
'
size
'
,
(
np
.
int
,
np
.
int64
)]]))
def
test_return_types
(
self
,
domain
,
attribute_desired_type
):
attribute
=
attribute_desired_type
[
0
]
desired_type
=
attribute_desired_type
[
1
]
...
...
test/test_spaces/test_gl_space.py
View file @
6ad2e1ec
...
...
@@ -31,7 +31,7 @@ CONSTRUCTOR_CONFIGS = [
'nlon'
:
3
,
'harmonic'
:
False
,
'shape'
:
(
6
,),
'
dim
'
:
6
,
'
size
'
:
6
,
}],
[
0
,
None
,
{
'error'
:
ValueError
...
...
test/test_spaces/test_hp_space.py
View file @
6ad2e1ec
...
...
@@ -30,19 +30,19 @@ CONSTRUCTOR_CONFIGS = [
'nside'
:
2
,
'harmonic'
:
False
,
'shape'
:
(
48
,),
'
dim
'
:
48
,
'
size
'
:
48
,
}],
[
5
,
{
'nside'
:
5
,
'harmonic'
:
False
,
'shape'
:
(
300
,),
'
dim
'
:
300
,
'
size
'
:
300
,
}],
[
1
,
{
'nside'
:
1
,
'harmonic'
:
False
,
'shape'
:
(
12
,),
'
dim
'
:
12
,
'
size
'
:
12
,
}],
[
0
,
{
'error'
:
ValueError
...
...
test/test_spaces/test_interface.py
<