Commit 1318ccc8 authored by theos's avatar theos

Moved nifty source code into nifty subdirectory.

Adapted imports and setup.py to changes.
parent 71d68281
[DEFAULT]
mpi_module = MPI
mpi_init_checks = False
default_distribution_strategy = fftw
default_comm = COMM_WORLD
...@@ -39,11 +39,10 @@ from d2o import distributed_data_object, d2o_librarian ...@@ -39,11 +39,10 @@ from d2o import distributed_data_object, d2o_librarian
from nifty_cmaps import ncmap from nifty_cmaps import ncmap
from field import Field from field import Field
from space import Space
# this line exists for compatibility reasons # this line exists for compatibility reasons
# TODO: Remove this once the transition to field types is done. # TODO: Remove this once the transition to field types is done.
from space import Space as point_space from spaces.space import Space as point_space
from nifty_random import random from nifty_random import random
from nifty_simple_math import * from nifty_simple_math import *
...@@ -56,15 +55,7 @@ from operators import * ...@@ -56,15 +55,7 @@ from operators import *
from spaces import * from spaces import *
from demos import get_demo_dir from demos import get_demo_dir
from pickling import _pickle_method, _unpickle_method
#import pyximport; pyximport.install(pyimport = True) #import pyximport; pyximport.install(pyimport = True)
from transformations import TransformationFactory,\ from transformations import *
GLLMTransformation,\ \ No newline at end of file
HPLMTransformation,\
LMGLTransformation,\
LMHPTransformation,\
RGRGTransformation
...@@ -12,7 +12,7 @@ from nifty.config import about, \ ...@@ -12,7 +12,7 @@ from nifty.config import about, \
from nifty.field_types import FieldType,\ from nifty.field_types import FieldType,\
FieldArray FieldArray
from nifty.space import Space from nifty.spaces.space import Space
import nifty.nifty_utilities as utilities import nifty.nifty_utilities as utilities
from nifty_random import random from nifty_random import random
......
...@@ -23,7 +23,7 @@ from __future__ import division ...@@ -23,7 +23,7 @@ from __future__ import division
import numpy as np import numpy as np
from nifty.config import about from nifty.config import about
from nifty.field import Field from nifty.field import Field
from nifty.space import Space from nifty.spaces.space import Space
from nifty_minimization import conjugate_gradient from nifty_minimization import conjugate_gradient
from nifty_probing import trace_prober,\ from nifty_probing import trace_prober,\
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
from __future__ import division from __future__ import division
from nifty.config import about from nifty.config import about
from nifty.space import Space from nifty.spaces.space import Space
from nifty.field import Field from nifty.field import Field
from nifty.nifty_utilities import direct_vdot from nifty.nifty_utilities import direct_vdot
......
# NIFTY (Numerical Information Field Theory) has been developed at the ## NIFTY (Numerical Information Field Theory) has been developed at the
# Max-Planck-Institute for Astrophysics. ## Max-Planck-Institute for Astrophysics.
# ##
# Copyright (C) 2014 Max-Planck-Society ## Copyright (C) 2015 Max-Planck-Society
# ##
# Author: Maksim Greiner, Marco Selig ## Author: Marco Selig
# Project homepage: <http://www.mpa-garching.mpg.de/ift/nifty/> ## Project homepage: <http://www.mpa-garching.mpg.de/ift/nifty/>
# ##
# This program is free software: you can redistribute it and/or modify ## This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by ## it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or ## the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version. ## (at your option) any later version.
# ##
# This program is distributed in the hope that it will be useful, ## This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of ## but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details. ## See the GNU General Public License for more details.
# ##
# You should have received a copy of the GNU General Public License ## You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. ## along with this program. If not, see <http://www.gnu.org/licenses/>.
import numpy as np import numpy as np
from numpy import pi
from nifty.config import about from nifty.config import about
from nifty.field import Field from nifty.field import Field
from nifty.nifty_simple_math import sqrt, exp, log
def power_backward_conversion_lm(k_space, p, mean=None):
"""
This function is designed to convert a theoretical/statistical power
spectrum of a log-normal field to the theoretical power spectrum of
the underlying Gaussian field.
The function only works for power spectra defined for lm_spaces
Parameters
----------
k_space : nifty.rg_space,
a regular grid space with the attribute `Fourier = True`
p : np.array,
the power spectrum of the log-normal field.
Needs to have the same number of entries as
`k_space.get_power_indices()[0]`
mean : float, *optional*
specifies the mean of the log-normal field. If `mean` is not
specified the function will use the monopole of the power spectrum.
If it is specified the function will NOT use the monopole of the
spectrum. (default: None)
WARNING: a mean that is too low can violate positive definiteness
of the log-normal field. In this case the function produces an
error.
Returns
-------
mean : float,
the recovered mean of the underlying Gaussian distribution.
p1 : np.array,
the power spectrum of the underlying Gaussian field, where the
monopole has been set to zero. Eventual monopole power has been
shifted to the mean.
References
----------
.. [#] M. Greiner and T.A. Ensslin, "Log-transforming the matter power spectrum";
`arXiv:1312.1354 <http://arxiv.org/abs/1312.1354>`_
"""
p = np.copy(p)
if(mean is not None):
p[0] = 4*pi*mean**2
klen = k_space.get_power_indices()[0]
C_0_Omega = Field(k_space,val=0)
C_0_Omega.val[:len(klen)] = p*sqrt(2*klen+1)/sqrt(4*pi)
C_0_Omega = C_0_Omega.transform()
if(np.any(C_0_Omega.val<0.)):
raise ValueError(about._errors.cstring("ERROR: spectrum or mean incompatible with positive definiteness.\n Try increasing the mean."))
return None
lC = log(C_0_Omega)
Z = lC.transform()
spec = Z.val[:len(klen)]
mean = (spec[0]-0.5*sqrt(4*pi)*log((p*(2*klen+1)/(4*pi)).sum()))/sqrt(4*pi)
spec[0] = 0.
spec = spec*sqrt(4*pi)/sqrt(2*klen+1)
spec = np.real(spec)
if(np.any(spec<0.)):
spec = spec*(spec>0.)
about.warnings.cprint("WARNING: negative modes set to zero.")
return mean.real,spec
def power_forward_conversion_lm(k_space,p,mean=0):
"""
This function is designed to convert a theoretical/statistical power
spectrum of a Gaussian field to the theoretical power spectrum of
the exponentiated field.
The function only works for power spectra defined for lm_spaces
Parameters
----------
k_space : nifty.rg_space,
a regular grid space with the attribute `Fourier = True`
p : np.array,
the power spectrum of the Gaussian field.
Needs to have the same number of entries as
`k_space.get_power_indices()[0]`
m : float, *optional*
specifies the mean of the Gaussian field (default: 0).
Returns
-------
p1 : np.array,
the power spectrum of the exponentiated Gaussian field.
References
----------
.. [#] M. Greiner and T.A. Ensslin, "Log-transforming the matter power spectrum";
`arXiv:1312.1354 <http://arxiv.org/abs/1312.1354>`_
"""
m = mean
klen = k_space.get_power_indices()[0]
C_0_Omega = Field(k_space,val=0)
C_0_Omega.val[:len(klen)] = p*sqrt(2*klen+1)/sqrt(4*pi)
C_0_Omega = C_0_Omega.transform()
C_0_0 = (p*(2*klen+1)/(4*pi)).sum()
exC = exp(C_0_Omega+C_0_0+2*m)
Z = exC.transform()
spec = Z.val[:len(klen)]
spec = spec*sqrt(4*pi)/sqrt(2*klen+1)
spec = np.real(spec)
if(np.any(spec<0.)):
spec = spec*(spec>0.)
about.warnings.cprint("WARNING: negative modes set to zero.")
return spec
def power_backward_conversion_rg(k_space, p, mean=None, bare=True): def power_backward_conversion_rg(k_space, p, mean=None, bare=True):
......
...@@ -7,17 +7,13 @@ from hp_space import HPSpace,\ ...@@ -7,17 +7,13 @@ from hp_space import HPSpace,\
HPSpaceParadict HPSpaceParadict
from lm_space import LMSpace,\ from lm_space import LMSpace,\
LMSpaceParadict,\ LMSpaceParadict
power_backward_conversion_lm,\
power_forward_conversion_lm
from power_space import PowerSpace,\ from power_space import PowerSpace,\
PowerSpaceParadict PowerSpaceParadict
from rg_space import RGSpace,\ from rg_space import RGSpace,\
RGSpaceParadict,\ RGSpaceParadict
power_backward_conversion_rg,\
power_forward_conversion_rg
from space import Space,\ from space import Space,\
SpaceParadict SpaceParadict
...@@ -7,9 +7,9 @@ from matplotlib.ticker import LogFormatter as lf ...@@ -7,9 +7,9 @@ from matplotlib.ticker import LogFormatter as lf
from d2o import STRATEGIES as DISTRIBUTION_STRATEGIES from d2o import STRATEGIES as DISTRIBUTION_STRATEGIES
from nifty.lm.lm_space import LMSpace from nifty.spaces.lm_space import LMSpace
from nifty.space import Space from nifty.spaces.space import Space
from nifty.config import about,\ from nifty.config import about,\
nifty_configuration as gc,\ nifty_configuration as gc,\
dependency_injector as gdi dependency_injector as gdi
...@@ -570,6 +570,8 @@ class GLSpace(Space): ...@@ -570,6 +570,8 @@ class GLSpace(Space):
the figure is not saved (default: False). the figure is not saved (default: False).
""" """
from nifty.field import Field
try: try:
x = x.get_full_data() x = x.get_full_data()
except AttributeError: except AttributeError:
...@@ -602,11 +604,11 @@ class GLSpace(Space): ...@@ -602,11 +604,11 @@ class GLSpace(Space):
if(isinstance(other, tuple)): if(isinstance(other, tuple)):
other = list(other) other = list(other)
for ii in xrange(len(other)): for ii in xrange(len(other)):
if(isinstance(other[ii], field)): if(isinstance(other[ii], Field)):
other[ii] = other[ii].power(**kwargs) other[ii] = other[ii].power(**kwargs)
else: else:
other[ii] = self.enforce_power(other[ii]) other[ii] = self.enforce_power(other[ii])
elif(isinstance(other, field)): elif(isinstance(other, Field)):
other = [other.power(**kwargs)] other = [other.power(**kwargs)]
else: else:
other = [self.enforce_power(other)] other = [self.enforce_power(other)]
......
...@@ -38,10 +38,9 @@ import pylab as pl ...@@ -38,10 +38,9 @@ import pylab as pl
from d2o import STRATEGIES as DISTRIBUTION_STRATEGIES from d2o import STRATEGIES as DISTRIBUTION_STRATEGIES
from nifty.lm.lm_space import LMSpace from nifty.spaces.lm_space import LMSpace
from nifty.space import Space from nifty.spaces.space import Space
from nifty.field import Field
from nifty.config import about,\ from nifty.config import about,\
nifty_configuration as gc,\ nifty_configuration as gc,\
...@@ -523,6 +522,8 @@ class HPSpace(Space): ...@@ -523,6 +522,8 @@ class HPSpace(Space):
Number of iterations performed in the HEALPix basis Number of iterations performed in the HEALPix basis
transformation. transformation.
""" """
from nifty.field import Field
try: try:
x = x.get_full_data() x = x.get_full_data()
except AttributeError: except AttributeError:
......
...@@ -3,6 +3,5 @@ ...@@ -3,6 +3,5 @@
from lm_space import LMSpace from lm_space import LMSpace
from lm_space_paradict import LMSpaceParadict from lm_space_paradict import LMSpaceParadict
from nifty_power_conversion_lm import power_backward_conversion_lm,\
power_forward_conversion_lm
...@@ -9,7 +9,7 @@ from matplotlib.ticker import LogFormatter as lf ...@@ -9,7 +9,7 @@ from matplotlib.ticker import LogFormatter as lf
from d2o import STRATEGIES as DISTRIBUTION_STRATEGIES from d2o import STRATEGIES as DISTRIBUTION_STRATEGIES
from nifty.space import Space from nifty.spaces.space import Space
from nifty.config import about,\ from nifty.config import about,\
nifty_configuration as gc,\ nifty_configuration as gc,\
...@@ -285,8 +285,8 @@ class LMSpace(Space): ...@@ -285,8 +285,8 @@ class LMSpace(Space):
if codomain is None: if codomain is None:
return False return False
from hp_space import HPSpace from nifty.spaces.hp_space import HPSpace
from gl_space import GLSpace from nifty.spaces.gl_space import GLSpace
if not isinstance(codomain, Space): if not isinstance(codomain, Space):
raise TypeError(about._errors.cstring( raise TypeError(about._errors.cstring(
"ERROR: The given codomain must be a nifty lm_space.")) "ERROR: The given codomain must be a nifty lm_space."))
...@@ -721,6 +721,8 @@ class LMSpace(Space): ...@@ -721,6 +721,8 @@ class LMSpace(Space):
the figure is not saved (default: False). the figure is not saved (default: False).
""" """
from nifty.field import Field
try: try:
x = x.get_full_data() x = x.get_full_data()
except AttributeError: except AttributeError:
...@@ -753,11 +755,11 @@ class LMSpace(Space): ...@@ -753,11 +755,11 @@ class LMSpace(Space):
if(isinstance(other, tuple)): if(isinstance(other, tuple)):
other = list(other) other = list(other)
for ii in xrange(len(other)): for ii in xrange(len(other)):
if(isinstance(other[ii], field)): if(isinstance(other[ii], Field)):
other[ii] = other[ii].power(**kwargs) other[ii] = other[ii].power(**kwargs)
else: else:
other[ii] = self.enforce_power(other[ii]) other[ii] = self.enforce_power(other[ii])
elif(isinstance(other, field)): elif(isinstance(other, Field)):
other = [other.power(**kwargs)] other = [other.power(**kwargs)]
else: else:
other = [self.enforce_power(other)] other = [self.enforce_power(other)]
......
...@@ -4,7 +4,7 @@ import numpy as np ...@@ -4,7 +4,7 @@ import numpy as np
from d2o import STRATEGIES from d2o import STRATEGIES
from nifty.config import about from nifty.config import about
from nifty.space import Space from nifty.spaces.space import Space
from power_space_paradict import PowerSpaceParadict from power_space_paradict import PowerSpaceParadict
from nifty.nifty_utilities import cast_axis_to_tuple from nifty.nifty_utilities import cast_axis_to_tuple
......
...@@ -21,6 +21,3 @@ ...@@ -21,6 +21,3 @@
from rg_space import RGSpace from rg_space import RGSpace
from rg_space_paradict import RGSpaceParadict from rg_space_paradict import RGSpaceParadict
from nifty_power_conversion_rg import power_backward_conversion_rg,\
power_forward_conversion_rg
...@@ -43,8 +43,7 @@ from matplotlib.ticker import LogFormatter as lf ...@@ -43,8 +43,7 @@ from matplotlib.ticker import LogFormatter as lf
from d2o import distributed_data_object,\ from d2o import distributed_data_object,\
STRATEGIES as DISTRIBUTION_STRATEGIES STRATEGIES as DISTRIBUTION_STRATEGIES
from nifty.space import Space from nifty.spaces.space import Space
from nifty.field import Field
from nifty.config import about,\ from nifty.config import about,\
nifty_configuration as gc,\ nifty_configuration as gc,\
...@@ -397,6 +396,7 @@ class RGSpace(Space): ...@@ -397,6 +396,7 @@ class RGSpace(Space):
(default: 0). (default: 0).
""" """
from nifty.field import Field
if(not pl.isinteractive())and(not bool(kwargs.get("save",False))): if(not pl.isinteractive())and(not bool(kwargs.get("save",False))):
about.warnings.cprint("WARNING: interactive mode off.") about.warnings.cprint("WARNING: interactive mode off.")
...@@ -453,11 +453,11 @@ class RGSpace(Space): ...@@ -453,11 +453,11 @@ class RGSpace(Space):
if(isinstance(other,tuple)): if(isinstance(other,tuple)):
other = list(other) other = list(other)
for ii in xrange(len(other)): for ii in xrange(len(other)):
if(isinstance(other[ii],field)): if(isinstance(other[ii],Field)):
other[ii] = other[ii].power(**kwargs) other[ii] = other[ii].power(**kwargs)
else: else:
other[ii] = self.enforce_power(other[ii],size=np.size(xaxes),kindex=xaxes) other[ii] = self.enforce_power(other[ii],size=np.size(xaxes),kindex=xaxes)
elif(isinstance(other,field)): elif(isinstance(other,Field)):
other = [other.power(**kwargs)] other = [other.power(**kwargs)]
else: else:
other = [self.enforce_power(other,size=np.size(xaxes),kindex=xaxes)]