Skip to content
GitLab
Menu
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
b10658a3
Commit
b10658a3
authored
May 11, 2017
by
Theo Steininger
Browse files
Docstring refactoring.
parent
0f817b6e
Pipeline
#12252
passed with stage
in 4 minutes and 58 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
nifty/domain_object.py
View file @
b10658a3
...
...
@@ -40,15 +40,20 @@ class DomainObject(Versionable, Loggable, object):
return
result_hash
def
__eq__
(
self
,
x
):
"""Checks if this domain_object represents the same thing as another domain_object.
""" Checks if two domain_objects are equal.
Parameters
----------
x: domain_object
The domain_object it is compared to.
The domain_object `self` is compared to.
Returns
-------
bool : True if they this and x represent the same thing.
bool
True if `self` and x describe the same manifold.
"""
if
isinstance
(
x
,
type
(
self
)):
for
key
in
vars
(
self
).
keys
():
item1
=
vars
(
self
)[
key
]
...
...
@@ -66,108 +71,137 @@ class DomainObject(Versionable, Loggable, object):
@
abc
.
abstractproperty
def
shape
(
self
):
"""Returns the shape of the underlying array-like object.
""" Returns the shape of the underlying array-like object.
Returns
-------
(int, tuple) : A tuple representing the shape of the underlying array-like object
tuple of ints
The shape of the underlying array-like object.
Raises
------
NotImplementedError : If it is called for an abstract class, all non-abstract child-classes should
implement this.
NotImplementedError
If called for this abstract class.
"""
raise
NotImplementedError
(
"There is no generic shape for DomainObject."
)
@
abc
.
abstractproperty
def
dim
(
self
):
"""Returns the number of pixel-dimensions the object has.
""" Returns the number of pixel-dimensions the object has.
Returns
-------
int : An Integer representing the number of pixels the discretized space has.
int
An Integer representing the number of pixels the discretized
manifold has.
Raises
------
NotImplementedError : If it is called for an abstract class, all non-abstract child-classes should
implement this.
NotImplementedError
If called for this abstract class.
"""
raise
NotImplementedError
(
"There is no generic dim for DomainObject."
)
@
abc
.
abstractmethod
def
weight
(
self
,
x
,
power
=
1
,
axes
=
None
,
inplace
=
False
):
""" Weights a field living on this domain with a specified amount of volume-weights.
""" Weights the field on this domain with the space's volume-weights.
Weights hereby refer to integration weights, as they appear in
discretized integrals. Per default, this function mutliplies each bin
of the field x by its volume, which lets it behave like a density
(top form). However, different powers of the volume can be applied
with the power parameter. The axes parameter specifies which of the
field array's indices correspond to this domain.
Weights hereby refer to integration weights, as they appear in discretized integrals.
Per default, this function mutliplies each bin of the field x by its volume, which lets
it behave like a density (top form). However, different powers of the volume can be applied
with the power parameter. The axes parameter specifies which of the field indices represent this
domain.
Parameters
----------
x :
Field
A
field
with this space as domain to be weighted
.
x :
distributed_data_object
The
field
s data array
.
power : int, *optional*
The power to which the volume-weight is raised.
(default: 1).
The power to which the volume-weight is raised (default: 1).
axes : {int, tuple}, *optional*
Specifies the axes of x which represent this domain
.
Specifies the axes of x which represent this domain
(default: None).
If axes==None:
weighting is applied with respect to all axes
inplace : bool, *optional*
If this is True, the weighting is done on the values of x,
if it is False, x is not modified and this method returns a
weighted copy of x
(default: False).
if it is False, x is not modified and this method returns a
weighted copy of x
(default: False).
Returns
-------
Field
A weighted version of x, with volume-weights raised to power.
distributed_data_object
A weighted version of x, with volume-weights raised to the
given power.
Raises
------
NotImplementedError : If it is called for an abstract class, all non-abstract child-classes should
implement this.
NotImplementedError
If called for this abstract class.
"""
raise
NotImplementedError
(
"There is no generic weight-method for DomainObject."
)
def
pre_cast
(
self
,
x
,
axes
=
None
):
"""Casting operations that are done before fields are initialized.
def
pre_cast
(
self
,
x
,
axes
):
""" Casts input for Field.val before Field performs the cast.
Parameters
----------
x : {array-like, castable}
an array-like object or anything that can be cast to arrays. Examples are Floating Point Numbers
(which will get cast to a constant array) and functions (which will get evaluated on the field positions)
axes : {int, tuple}, *optional*
Specifies the axes of x which represent this domain.
(default: None).
If axes==None:
Assumes the axes to be the fields first axes
an array-like object or anything that can be cast to arrays.
axes : tuple of ints
Specifies the axes of x which correspond to this domain.
Returns
-------
{array-like, castable} : Processed input where casting that needs Space-specific knowledge (for example where points are) was performed.
Currently always returns x unless for a power spectrum is given to a PowerSpace, where this spectrum is evaluated at the power indices.
{array-like, castable}
Processed input where casting that needs Space-specific knowledge
(for example location of pixels on the manifold) was performed.
See Also
--------
post_cast
Notes
-----
Usually returns x, except if a power spectrum is given to a
PowerSpace, where this spectrum is evaluated at the power indices.
"""
return
x
def
post_cast
(
self
,
x
,
axes
=
None
):
"""Casting operations that are done after fields are initialized.
def
post_cast
(
self
,
x
,
axes
):
""" Performs casting operations that are done after Field's cast.
Parameters
----------
x : {array-like, castable}
an array-like object or anything that can be cast to arrays.
axes : {int, tuple}, *optional*
Specifies the axes of x which represent this domain.
(default: None).
If axes==None:
Assumes the axes to be the fields first axes
axes : tuple of ints
Specifies the axes of x which correspond to this domain.
See Also
--------
pre_cast : Casting operations that are done before fields are initialized.
pre_cast
Returns
-------
array-like : Processed input where casting that needs Space-specific knowledge (for example where points are) was performed.
Currently always returns x unchanged.
distributed_data_object
Processed input where casting that needs Space-specific knowledge
(for example location of pixels on the manifold) was performed.
"""
return
x
# ---Serialization---
...
...
nifty/spaces/gl_space/gl_space.py
View file @
b10658a3
...
...
@@ -46,6 +46,13 @@ class GLSpace(Space):
nlon : int, *optional*
Number of longitudinal bins (default: ``2*nlat - 1``).
Raises
------
ValueError
If input `nlat` or `nlon` is invalid.
ImportError
If the pyHealpix module is not available
See Also
--------
hp_space : A class for the HEALPix discretization of the sphere [#]_.
...
...
@@ -65,26 +72,6 @@ class GLSpace(Space):
# ---Overwritten properties and methods---
def
__init__
(
self
,
nlat
,
nlon
=
None
):
"""
Sets the attributes for a gl_space class instance.
Parameters
----------
nlat : int
Number of latitudinal bins, or rings.
nlon : int, *optional*
Number of longitudinal bins (default: ``2*nlat - 1``).
Returns
-------
None
Raises
------
ValueError
If input `nlat` or `nlon` is invalid.
"""
if
'pyHealpix'
not
in
gdi
:
raise
ImportError
(
"The module pyHealpix is needed but not available."
)
...
...
@@ -139,43 +126,26 @@ class GLSpace(Space):
return
result_x
def
get_distance_array
(
self
,
distribution_strategy
):
"""This should not be used, it just raises an error when called.
Raises
------
NotImplementedError
Always when called.
"""
raise
NotImplementedError
def
get_fft_smoothing_kernel_function
(
self
,
sigma
):
"""This should not be used, it just raises an error when called.
Raises
------
NotImplementedError
Always when called.
"""
raise
NotImplementedError
# ---Added properties and methods---
@
property
def
nlat
(
self
):
"""Number of latitudinal bins.
Returns
-------
int : Number of latitudinal bins (or rings) that are used in the pixelization
""" Number of latitudinal bins (or rings) that are used for this
pixelization.
"""
return
self
.
_nlat
@
property
def
nlon
(
self
):
"""Number of longditudinal bins.
Returns
-------
int : Number of longditudinal bins that are used in the pixelization
""" Number of longditudinal bins that are used for this pixelization.
"""
return
self
.
_nlon
def
_parse_nlat
(
self
,
nlat
):
...
...
nifty/spaces/hp_space/hp_space.py
View file @
b10658a3
...
...
@@ -39,6 +39,11 @@ class HPSpace(Space):
Resolution parameter for the HEALPix discretization, resulting in
``12*nside**2`` pixels. Must be positive.
Raises
------
ValueError
If given `nside` < 1.
See Also
--------
gl_space : A class for the Gauss-Legendre discretization of the
...
...
@@ -59,26 +64,6 @@ class HPSpace(Space):
# ---Overwritten properties and methods---
def
__init__
(
self
,
nside
):
"""
Sets the attributes for a hp_space class instance.
Parameters
----------
nside : int
Resolution parameter for the HEALPix discretization, resulting
in ``12*nside**2`` pixels. Must be positive.
Returns
-------
None
Raises
------
ValueError
If input `nside` is invalid.
"""
super
(
HPSpace
,
self
).
__init__
()
self
.
_nside
=
self
.
_parse_nside
(
nside
)
...
...
@@ -126,10 +111,8 @@ class HPSpace(Space):
@
property
def
nside
(
self
):
"""Returns the nside of the corresponding HEALPix pixelization.
Returns
-------
int : the nside of the corresponding HEALPix pixelization. The total number of pixels is 12*nside**2
""" Returns the nside of the corresponding HEALPix pixelization.
The total number of pixels is 12*nside**2
"""
return
self
.
_nside
...
...
nifty/spaces/lm_space/lm_space.py
View file @
b10658a3
...
...
@@ -49,12 +49,14 @@ class LMSpace(Space):
gl_space : A class for the Gauss-Legendre discretization of the
sphere [#]_.
Raises
------
ValueError
If given lmax is negative.
Notes
-----
Hermitian symmetry, i.e. :math:`a_{\ell -m} = \overline{a}_{\ell m}` is
always assumed for the spherical harmonics components, i.e. only fields
on the two-sphere with real-valued representations in position space
can be handled.
This implementation implicitly sets the mmax parameter to lmax.
References
----------
...
...
@@ -67,26 +69,6 @@ class LMSpace(Space):
"""
def
__init__
(
self
,
lmax
):
"""
Sets the attributes for an lm_space class instance.
Parameters
----------
lmax : int
Maximum :math:`\ell`-value up to which the spherical harmonics
coefficients are to be used.
Returns
-------
None.
Raises
------
ValueError
If lmax is negative.
"""
super
(
LMSpace
,
self
).
__init__
()
self
.
_lmax
=
self
.
_parse_lmax
(
lmax
)
...
...
@@ -158,24 +140,25 @@ class LMSpace(Space):
@
property
def
lmax
(
self
):
"""Returns the maximal :math:`l`-value of the spherical harmonics being used.
Returns
-------
int : maximal :math:`l` value of any spherical harmonic :math:`Y_{lm}` that is represented in this Space.
""" Returns the maximal :math:`l` value of any spherical harmonics
:math:`Y_{lm}` that is represented in this Space.
"""
return
self
.
_lmax
@
property
def
mmax
(
self
):
"""Returns the maximal :math:`m`-value of the spherical harmonics being used.
""" Returns the maximal :math:`m` value of any spherical harmonic
:math:`Y_{lm}` that is represented in this Space. As :math:`m` goes
from :math:`-l` to :math:`l` for every :math:`l` this just returns the
same as lmax.
See Also
--------
lmax : Returns the maximal :math:`l`-value of the spherical harmonics being used.
Returns
-------
int : maximal :math:`m` value of any spherical harmonic :math:`Y_{lm}` that is represented in this Space.
As :math:`m` goes from :math:`-l` to :math:`l` for every :math:`l` this just returns the same as lmax.
lmax : Returns the maximal :math:`l`-value of the spherical harmonics
being used.
"""
return
self
.
_lmax
def
_parse_lmax
(
self
,
lmax
):
...
...
nifty/spaces/power_space/power_indices.py
View file @
b10658a3
...
...
@@ -16,12 +16,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
sys
import
numpy
as
np
from
d2o
import
distributed_data_object
,
\
STRATEGIES
as
DISTRIBUTION_STRATEGIES
from
d2o.config
import
dependency_injector
as
d2o_di
from
d2o.config
import
configuration
as
d2o_config
class
PowerIndices
(
object
):
def
__init__
(
self
,
domain
,
distribution_strategy
,
...
...
@@ -312,8 +313,7 @@ class PowerIndices(object):
# Store the individual pundices in the local_pundex array
local_pundex
[
temp_uniqued_pindex
]
=
local_temp_pundex
# Extract the MPI module from the global_pindex d2o
MPI_name
=
global_pindex
.
comm
.
__class__
.
__module__
MPI
=
sys
.
modules
[
MPI_name
]
MPI
=
d2o_di
[
d2o_config
[
'mpi_module'
]]
# Use Allreduce to find the first occurences/smallest pundices
global_pindex
.
comm
.
Allreduce
(
local_pundex
,
global_pundex
,
...
...
nifty/spaces/power_space/power_space.py
View file @
b10658a3
...
...
@@ -64,7 +64,7 @@ class PowerSpace(Space):
self
.
_pundex
=
power_index
[
'pundex'
]
self
.
_k_array
=
power_index
[
'k_array'
]
def
pre_cast
(
self
,
x
,
axes
=
None
):
def
pre_cast
(
self
,
x
,
axes
):
if
callable
(
x
):
return
x
(
self
.
kindex
)
else
:
...
...
nifty/spaces/rg_space/rg_space.py
View file @
b10658a3
...
...
@@ -48,16 +48,35 @@ class RGSpace(Space):
NIFTY subclass for spaces of regular Cartesian grids.
Parameters
----------
shape : {int, numpy.ndarray}
Number of grid points or numbers of gridpoints along each axis.
zerocenter : {bool, numpy.ndarray}, *optional*
Whether x==0 (or k==0, respectively) is located in the center of
the grid (or the center of each axis speparately) or not.
(default: False).
distances : {float, numpy.ndarray}, *optional*
Distance between two grid points along each axis
(default: None).
If distances==None:
if harmonic==True, all distances will be set to 1
if harmonic==False, the distance along each axis will be
set to the inverse of the number of points along that axis
harmonic : bool, *optional*
Whether the space represents a grid in position or harmonic space.
(default: False).
Attributes
----------
harmonic : bool
Whether or not the grid represents a
Fourier basis
.
zerocenter :
{bool, numpy.ndarray}
Whether
the Fourier zero-mode
is located in the center of
the grid
(or the center of each axis speparately) or not.
MR FIXME: this also does something if the space is not harmonic!
d
istance
s : {float, numpy.ndarray}
Distance between two grid points along each axis (default: None).
Whether or not the grid represents a
position or harmonic space
.
zerocenter :
tuple of bool
Whether
x==0 (or k==0, respectively)
is located in the center of
the grid
(or the center of each axis speparately) or not.
distances : tuple of floats
D
istance
between two grid points along the correpsonding axis.
"""
# ---Overwritten properties and methods---
...
...
@@ -67,25 +86,7 @@ class RGSpace(Space):
"""
Sets the attributes for an RGSpace class instance.
Parameters
----------
shape : {int, numpy.ndarray}
Number of grid points or numbers of gridpoints along each axis.
zerocenter : {bool, numpy.ndarray}, *optional*
Whether the Fourier zero-mode is located in the center of the
grid (or the center of each axis speparately) or not
MR FIXME: this also does something if the space is not harmonic!
(default: False).
distances : {float, numpy.ndarray}, *optional*
Distance between two grid points along each axis
(default: None).
If distances==None:
if harmonic==True, all distances will be set to 1
if harmonic==False, the distance along each axis will be
set to the inverse of the number of points along that axis
harmonic : bool, *optional*
Whether the space represents a Fourier or a position grid
(default: False).
Returns
-------
...
...
@@ -205,6 +206,21 @@ class RGSpace(Space):
return
result_x
def
get_distance_array
(
self
,
distribution_strategy
):
""" Calculates an n-dimensional array with its entries being the
lengths of the vectors from the zero point of the grid.
Parameters
----------
distribution_strategy : str
The distribution_strategy which shall be used the returned
distributed_data_object.
Returns
-------
distributed_data_object
A d2o containing the distances
"""
shape
=
self
.
shape
# prepare the distributed_data_object
nkdict
=
distributed_data_object
(
...
...
@@ -249,8 +265,8 @@ class RGSpace(Space):
dists
=
np
.
sqrt
(
dists
)
return
dists
def
get_fft_smoothing_kernel_function
(
self
,
sigma
):
def
get_fft_smoothing_kernel_function
(
self
,
sigma
):
if
sigma
is
None
:
sigma
=
np
.
sqrt
(
2
)
*
np
.
max
(
self
.
distances
)
...
...
@@ -260,23 +276,26 @@ class RGSpace(Space):
@
property
def
distances
(
self
):
"""Returns the distance of gridpoints along each axis
Returns
-------
array-like : An array of positive floating point numbers with the
n-th entry giving the distances of grid points along the n-th dimension.
"""Distance between two grid points along each axis. It is a tuple
of positive floating point numbers with the n-th entry giving the
distances of grid points along the n-th dimension.
"""
return
self
.
_distances
@
property
def
zerocenter
(
self
):
"""Returns True if grid points lie symmetrically around zero
Returns
-------
bool : True if the grid points are centered around the 0 grid point. This option
makes most sense for harmonic space (where the zero-mode plays a special role)
but may be used for position space, too.
bool
True if the grid points are centered around the 0 grid point. This
option is most common for harmonic spaces (where both conventions
are used) but may be used for position spaces, too.
"""
return
self
.
_zerocenter
def
_parse_shape
(
self
,
shape
):
...
...
nifty/spaces/space/space.py
View file @
b10658a3
...
...
@@ -16,129 +16,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
.. __ ____ __
.. /__/ / _/ / /_
.. __ ___ __ / /_ / _/ __ __
.. / _ | / / / _/ / / / / / /
.. / / / / / / / / / /_ / /_/ /
.. /__/ /__/ /__/ /__/ \___/ \___ / core
.. /______/
.. The NIFTY project homepage is http://www.mpa-garching.mpg.de/ift/nifty/
NIFTY [#]_, "Numerical Information Field Theory", is a versatile
library designed to enable the development of signal inference algorithms
that operate regardless of the underlying spatial grid and its resolution.
Its object-oriented framework is written in Python, although it accesses
libraries written in Cython, C++, and C for efficiency.
NIFTY offers a toolkit that abstracts discretized representations of
continuous spaces, fields in these spaces, and operators acting on fields
into classes. Thereby, the correct normalization of operations on fields is
taken care of automatically without concerning the user. This allows for an
abstract formulation and programming of inference algorithms, including
those derived within information field theory. Thus, NIFTY permits its user
to rapidly prototype algorithms in 1D and then apply the developed code in
higher-dimensional settings of real world problems. The set of spaces on
which NIFTY operates comprises point sets, n-dimensional regular grids,
spherical spaces, their harmonic counterparts, and product spaces
constructed as combinations of those.
References
----------