Commit 3860e6da authored by Theo Steininger's avatar Theo Steininger
Browse files

Merge branch 'spacy_docuy' into 'master'

Spacy docuy

See merge request !98
parents c70631e0 f3472938
Pipeline #12354 failed with stages
in 4 minutes and 54 seconds
......@@ -24,6 +24,21 @@ from keepers import Loggable,\
class DomainObject(Versionable, Loggable, 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.
Attributes
----------
dim : int
Number of pixel-dimensions of the underlying data object.
shape : tuple
Shape of the array that stores the degrees of freedom for any field
on this domain.
"""
__metaclass__ = NiftyMeta
def __init__(self):
......
......@@ -42,9 +42,26 @@ class GLSpace(Space):
Parameters
----------
nlat : int
Number of latitudinal bins, or rings.
Number of latitudinal bins (or rings) that are used for this
pixelization.
nlon : int, *optional*
Number of longitudinal bins (default: ``2*nlat - 1``).
Number of longditudinal bins that are used for this pixelization.
Attributes
----------
dim : np.int
Total number of dimensionality, i.e. the number of pixels.
harmonic : bool
Specifies whether the space is a signal or harmonic space.
nlat : int
Number of latitudinal bins (or rings) that are used for this
pixelization.
nlon : int
Number of longditudinal bins that are used for this pixelization.
total_volume : np.float
The total volume of the space.
shape : tuple of np.ints
The shape of the space's data array.
Raises
------
......
......@@ -35,9 +35,23 @@ class HPSpace(Space):
Parameters
----------
nside :
Resolution parameter for the HEALPix discretization, resulting in
``12*nside**2`` pixels. Must be positive.
nside : int
The corresponding HEALPix pixelization. The total number of pixels
is 12*nside**2.
Attributes
----------
dim : np.int
Total number of dimensionality, i.e. the number of pixels.
harmonic : bool
Specifies whether the space is a signal or harmonic space.
nside : int
The corresponding HEALPix pixelization. The total number of pixels
is 12*nside**2.
total_volume : np.float
The total volume of the space.
shape : tuple of np.ints
The shape of the space's data array.
Raises
------
......
......@@ -40,8 +40,25 @@ class LMSpace(Space):
Parameters
----------
lmax : int
Maximum :math:`\ell`-value up to which the spherical harmonics
coefficients are to be used.
The maximal :math:`l` value of any spherical harmonics
:math:`Y_{lm}` that is represented in this Space.
Attributes
----------
lmax : int
The maximal :math:`l` value of any spherical harmonics
:math:`Y_{lm}` that is represented in this Space.
mmax : int
The maximal :math:`m` value of any spherical harmonic
:math:`Y_{lm}` that is represented in this Space.
dim : np.int
Total number of dimensionality, i.e. the number of pixels.
harmonic : bool
Specifies whether the space is a signal or harmonic space.
total_volume : np.float
The total volume of the space.
shape : tuple of np.ints
The shape of the space's data array.
See Also
--------
......
......@@ -25,32 +25,32 @@ from d2o.config import configuration as d2o_config
class PowerIndices(object):
"""Computes helpful quantities to deal with power spectra.
Given the shape and the density of a underlying rectangular grid this
class provides the user
with the pindex, kindex, rho and pundex. The indices are binned
according to the supplied parameter scheme. If wanted, computed
results are stored for future reuse.
Parameters
----------
domain : NIFTy harmonic space
The space for which the power indices get computed
distribution_strategy : str
The distribution_strategy that will be used for the k_array and pindex
distributed_data_object.
logarithmic : bool *optional*
Flag specifying if the binning of the default indices is
performed on logarithmic scale.
nbin : integer *optional*
Number of used bins for the binning of the default indices.
binbounds : {list, array}
Array-like inner boundaries of the used bins of the default
indices.
"""
def __init__(self, domain, distribution_strategy,
logarithmic=False, nbin=None, binbounds=None):
"""
Returns an instance of the PowerIndices class. Given the shape and
the density of a underlying rectangular grid it provides the user
with the pindex, kindex, rho and pundex. The indices are binned
according to the supplied parameter scheme. If wanted, computed
results are stored for future reuse.
Parameters
----------
shape : tuple, list, ndarray
Array-like object which specifies the shape of the underlying
rectangular grid
dgrid : tuple, list, ndarray
Array-like object which specifies the step-width of the
underlying grid
logarithmic : bool *optional*
Flag specifying if the binning of the default indices is
performed on logarithmic scale.
nbin : integer *optional*
Number of used bins for the binning of the default indices.
binbounds : {list, array}
Array-like inner boundaries of the used bins of the default
indices.
"""
self.domain = domain
self.distribution_strategy = distribution_strategy
......
......@@ -54,14 +54,24 @@ class PowerSpace(Space):
Attributes
----------
pindex : distributed_data_object
TODO add description
This holds the information which pixel of the harmonic partner gets
mapped to which power bin
kindex : numpy.ndarray
TODO add description
Sorted array of all k-modes.
pundex : numpy.ndarray
TODO add description
Flat index of the first occurence of a k-vector with length==kindex[n]
in the k_array.
rho : numpy.ndarray
The amount of k-modes that get mapped to one power bin is given by
rho.
dim : np.int
Total number of dimensionality, i.e. the number of pixels.
harmonic : bool
Specifies whether the space is a signal or harmonic space.
total_volume : np.float
The total volume of the space.
shape : tuple of np.ints
The shape of the space's data array.
Notes
......@@ -95,10 +105,7 @@ class PowerSpace(Space):
nbin=nbin,
binbounds=binbounds)
config = power_index['config']
self._logarithmic = config['logarithmic']
self._nbin = config['nbin']
self._binbounds = config['binbounds']
self._config = power_index['config']
self._pindex = power_index['pindex']
self._kindex = power_index['kindex']
......@@ -157,9 +164,9 @@ class PowerSpace(Space):
distribution_strategy = self.pindex.distribution_strategy
return self.__class__(harmonic_partner=self.harmonic_partner,
distribution_strategy=distribution_strategy,
logarithmic=self.logarithmic,
nbin=self.nbin,
binbounds=self.binbounds)
logarithmic=self.config["logarithmic"],
nbin=self.config["nbin"],
binbounds=self.config["binbounds"])
def weight(self, x, power=1, axes=None, inplace=False):
reshaper = [1, ] * len(x.shape)
......@@ -197,26 +204,15 @@ class PowerSpace(Space):
return self._harmonic_partner
@property
def logarithmic(self):
""" Returns True if logarithmic binning is used.
def config(self):
""" Returns the configuration which was used for `logarithmic`, `nbin`
and `binbounds` during initialization.
"""
return self._logarithmic
@property
def nbin(self):
""" Returns the number of power bins if specfied during initialization.
"""
return self._nbin
@property
def binbounds(self):
""" Inner boundaries of the used bins if specfied during initialization.
"""
return self._binbounds
return self._config
@property
def pindex(self):
""" A distributed_data_objects having the shape of the harmonic partner
""" A distributed_data_object having the shape of the harmonic partner
space containing the indices of the power bin a pixel belongs to.
"""
return self._pindex
......@@ -252,9 +248,9 @@ class PowerSpace(Space):
def _to_hdf5(self, hdf5_group):
hdf5_group['kindex'] = self.kindex
hdf5_group['rho'] = self.rho
hdf5_group['pundex'] = self.pundex
hdf5_group['logarithmic'] = self.logarithmic
hdf5_group['rho'] = self.config["rho"]
hdf5_group['pundex'] = self.config["pundex"]
hdf5_group['logarithmic'] = self.config["logarithmic"]
# Store nbin as string, since it can be None
hdf5_group.attrs['nbin'] = str(self.nbin)
hdf5_group.attrs['binbounds'] = str(self.binbounds)
......@@ -276,9 +272,11 @@ class PowerSpace(Space):
# set all values
new_ps._harmonic_partner = repository.get('harmonic_partner',
hdf5_group)
new_ps._logarithmic = hdf5_group['logarithmic'][()]
exec('new_ps._nbin = ' + hdf5_group.attrs['nbin'])
exec('new_ps._binbounds = ' + hdf5_group.attrs['binbounds'])
new_ps.config = {}
new_ps.config['logarithmic'] = hdf5_group['logarithmic'][()]
exec("new_ps.config['nbin'] = " + hdf5_group.attrs['nbin'])
exec("new_ps.config['binbounds'] = " + hdf5_group.attrs['binbounds'])
new_ps._pindex = repository.get('pindex', hdf5_group)
new_ps._kindex = hdf5_group['kindex'][:]
......
......@@ -76,7 +76,15 @@ class RGSpace(Space):
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
Distance between two grid points along the correpsonding axis.
Distance between two grid points along the correponding axis.
dim : np.int
Total number of dimensionality, i.e. the number of pixels.
harmonic : bool
Specifies whether the space is a signal or harmonic space.
total_volume : np.float
The total volume of the space.
shape : tuple of np.ints
The shape of the space's data array.
"""
......@@ -286,7 +294,7 @@ class RGSpace(Space):
@property
def zerocenter(self):
"""Returns True if grid points lie symmetrically around zero
"""Returns True if grid points lie symmetrically around zero.
Returns
-------
......
......@@ -22,42 +22,43 @@ from nifty.domain_object import DomainObject
class Space(DomainObject):
def __init__(self):
""" The abstract base class for all NIFTy spaces.
An instance of a space contains information about the manifolds
geometry and enhances the functionality of DomainObject by methods that
are needed for powerspectrum analysis and smoothing.
Parameters
----------
None
Attributes
----------
dim : np.int
Total number of dimensionality, i.e. the number of pixels.
harmonic : bool
Specifies whether the space is a signal or harmonic space.
total_volume : np.float
The total volume of the space.
shape : tuple of np.ints
The shape of the space's data array.
Raises
------
TypeError
Raised if instantiated directly.
Notes
-----
`Space` is an abstract base class. In order to allow for instantiation
the methods `get_distance_array`, `total_volume` and `copy` must be
implemented as well as the abstract methods inherited from
`DomainObject`.
"""
""" The abstract base class for all NIFTy spaces.
An instance of a space contains information about the manifolds
geometry and enhances the functionality of DomainObject by methods that
are needed for powerspectrum analysis and smoothing.
Parameters
----------
None
Attributes
----------
dim : np.int
Total number of dimensionality, i.e. the number of pixels.
harmonic : bool
Specifies whether the space is a signal or harmonic space.
total_volume : np.float
The total volume of the space.
shape : tuple of np.ints
The shape of the space's data array.
Raises
------
TypeError
Raised if instantiated directly.
Notes
-----
`Space` is an abstract base class. In order to allow for instantiation
the methods `get_distance_array`, `total_volume` and `copy` must be
implemented as well as the abstract methods inherited from
`DomainObject`.
"""
def __init__(self):
super(Space, self).__init__()
@abc.abstractproperty
......
......@@ -39,9 +39,7 @@ CONSTRUCTOR_CONFIGS = [
'dim': 5,
'total_volume': 8.0,
'harmonic_partner': RGSpace((8,), harmonic=True),
'logarithmic': False,
'nbin': None,
'binbounds': None,
'config': {'logarithmic': False, 'nbin': None, 'binbounds': None},
'pindex': distributed_data_object([0, 1, 2, 3, 4, 3, 2, 1]),
'kindex': np.array([0., 1., 2., 3., 4.]),
'rho': np.array([1, 2, 2, 2, 1]),
......@@ -54,9 +52,7 @@ CONSTRUCTOR_CONFIGS = [
'dim': 2,
'total_volume': 8.0,
'harmonic_partner': RGSpace((8,), harmonic=True),
'logarithmic': True,
'nbin': None,
'binbounds': None,
'config': {'logarithmic': True, 'nbin': None, 'binbounds': None},
'pindex': distributed_data_object([0, 1, 1, 1, 1, 1, 1, 1]),
'kindex': np.array([0., 2.28571429]),
'rho': np.array([1, 7]),
......@@ -95,9 +91,7 @@ def get_weight_configs():
class PowerSpaceInterfaceTest(unittest.TestCase):
@expand([
['harmonic_partner', Space],
['logarithmic', bool],
['nbin', (int, NoneType)],
['binbounds', (list, NoneType)],
['config', dict],
['pindex', distributed_data_object],
['kindex', np.ndarray],
['rho', np.ndarray],
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment