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
from nifty_cmaps import ncmap
from field import Field
from space import Space
# this line exists for compatibility reasons
# 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_simple_math import *
......@@ -56,15 +55,7 @@ from operators import *
from spaces import *
from demos import get_demo_dir
from pickling import _pickle_method, _unpickle_method
#import pyximport; pyximport.install(pyimport = True)
from transformations import TransformationFactory,\
GLLMTransformation,\
HPLMTransformation,\
LMGLTransformation,\
LMHPTransformation,\
RGRGTransformation
from transformations import *
\ No newline at end of file
......@@ -12,7 +12,7 @@ from nifty.config import about, \
from nifty.field_types import FieldType,\
FieldArray
from nifty.space import Space
from nifty.spaces.space import Space
import nifty.nifty_utilities as utilities
from nifty_random import random
......
......@@ -23,7 +23,7 @@ from __future__ import division
import numpy as np
from nifty.config import about
from nifty.field import Field
from nifty.space import Space
from nifty.spaces.space import Space
from nifty_minimization import conjugate_gradient
from nifty_probing import trace_prober,\
......
......@@ -22,7 +22,7 @@
from __future__ import division
from nifty.config import about
from nifty.space import Space
from nifty.spaces.space import Space
from nifty.field import Field
from nifty.nifty_utilities import direct_vdot
......
# NIFTY (Numerical Information Field Theory) has been developed at the
# Max-Planck-Institute for Astrophysics.
#
# Copyright (C) 2014 Max-Planck-Society
#
# Author: Maksim Greiner, Marco Selig
# Project homepage: <http://www.mpa-garching.mpg.de/ift/nifty/>
#
# 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
## NIFTY (Numerical Information Field Theory) has been developed at the
## Max-Planck-Institute for Astrophysics.
##
## Copyright (C) 2015 Max-Planck-Society
##
## Author: Marco Selig
## Project homepage: <http://www.mpa-garching.mpg.de/ift/nifty/>
##
## 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
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
## See the GNU General Public License for more details.
##
## 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 numpy as np
from numpy import pi
from nifty.config import about
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):
......@@ -181,4 +308,4 @@ def power_forward_conversion_rg(k_space, p, mean=0, bare=True):
if bare:
new_spec /= weight
return new_spec.real
return new_spec.real
\ No newline at end of file
......@@ -7,17 +7,13 @@ from hp_space import HPSpace,\
HPSpaceParadict
from lm_space import LMSpace,\
LMSpaceParadict,\
power_backward_conversion_lm,\
power_forward_conversion_lm
LMSpaceParadict
from power_space import PowerSpace,\
PowerSpaceParadict
from rg_space import RGSpace,\
RGSpaceParadict,\
power_backward_conversion_rg,\
power_forward_conversion_rg
RGSpaceParadict
from space import Space,\
SpaceParadict
......@@ -7,9 +7,9 @@ from matplotlib.ticker import LogFormatter as lf
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,\
nifty_configuration as gc,\
dependency_injector as gdi
......@@ -570,6 +570,8 @@ class GLSpace(Space):
the figure is not saved (default: False).
"""
from nifty.field import Field
try:
x = x.get_full_data()
except AttributeError:
......@@ -602,11 +604,11 @@ class GLSpace(Space):
if(isinstance(other, tuple)):
other = list(other)
for ii in xrange(len(other)):
if(isinstance(other[ii], field)):
if(isinstance(other[ii], Field)):
other[ii] = other[ii].power(**kwargs)
else:
other[ii] = self.enforce_power(other[ii])
elif(isinstance(other, field)):
elif(isinstance(other, Field)):
other = [other.power(**kwargs)]
else:
other = [self.enforce_power(other)]
......
......@@ -38,10 +38,9 @@ import pylab as pl
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.field import Field
from nifty.spaces.space import Space
from nifty.config import about,\
nifty_configuration as gc,\
......@@ -523,6 +522,8 @@ class HPSpace(Space):
Number of iterations performed in the HEALPix basis
transformation.
"""
from nifty.field import Field
try:
x = x.get_full_data()
except AttributeError:
......
......@@ -3,6 +3,5 @@
from lm_space import LMSpace
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
from d2o import STRATEGIES as DISTRIBUTION_STRATEGIES
from nifty.space import Space
from nifty.spaces.space import Space
from nifty.config import about,\
nifty_configuration as gc,\
......@@ -285,8 +285,8 @@ class LMSpace(Space):
if codomain is None:
return False
from hp_space import HPSpace
from gl_space import GLSpace
from nifty.spaces.hp_space import HPSpace
from nifty.spaces.gl_space import GLSpace
if not isinstance(codomain, Space):
raise TypeError(about._errors.cstring(
"ERROR: The given codomain must be a nifty lm_space."))
......@@ -721,6 +721,8 @@ class LMSpace(Space):
the figure is not saved (default: False).
"""
from nifty.field import Field
try:
x = x.get_full_data()
except AttributeError:
......@@ -753,11 +755,11 @@ class LMSpace(Space):
if(isinstance(other, tuple)):
other = list(other)
for ii in xrange(len(other)):
if(isinstance(other[ii], field)):
if(isinstance(other[ii], Field)):
other[ii] = other[ii].power(**kwargs)
else:
other[ii] = self.enforce_power(other[ii])
elif(isinstance(other, field)):
elif(isinstance(other, Field)):
other = [other.power(**kwargs)]
else:
other = [self.enforce_power(other)]
......
......@@ -4,7 +4,7 @@ import numpy as np
from d2o import STRATEGIES
from nifty.config import about
from nifty.space import Space
from nifty.spaces.space import Space
from power_space_paradict import PowerSpaceParadict
from nifty.nifty_utilities import cast_axis_to_tuple
......
......@@ -21,6 +21,3 @@
from rg_space import RGSpace
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
from d2o import distributed_data_object,\
STRATEGIES as DISTRIBUTION_STRATEGIES
from nifty.space import Space
from nifty.field import Field
from nifty.spaces.space import Space
from nifty.config import about,\
nifty_configuration as gc,\
......@@ -397,6 +396,7 @@ class RGSpace(Space):
(default: 0).
"""
from nifty.field import Field
if(not pl.isinteractive())and(not bool(kwargs.get("save",False))):
about.warnings.cprint("WARNING: interactive mode off.")
......@@ -453,11 +453,11 @@ class RGSpace(Space):
if(isinstance(other,tuple)):
other = list(other)
for ii in xrange(len(other)):
if(isinstance(other[ii],field)):
if(isinstance(other[ii],Field)):
other[ii] = other[ii].power(**kwargs)
else:
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)]
else:
other = [self.enforce_power(other,size=np.size(xaxes),kindex=xaxes)]
......@@ -623,6 +623,8 @@ class RGSpace(Space):
Whether a scalar is extented to a constant array or not
(default: True).
"""
from nifty.field import Field
about.warnings.cflush(
"WARNING: _enforce_values is deprecated function. Please use self.cast")
if(isinstance(x, Field)):
......
from nifty.rg import RGSpace
from nifty.lm import GLSpace, HPSpace, LMSpace
from nifty.spaces import RGSpace, GLSpace, HPSpace, LMSpace
from rgrgtransformation import RGRGTransformation
from gllmtransformation import GLLMTransformation
......
[DEFAULT]
use_libsharp = True
use_healpy = True
verbosity = 1
fft_module = pyfftw
default_comm = COMM_WORLD
mpi_module = MPI
lm2gl = True
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 2 21:29:30 2015
@author: steininger
"""
import numpy as np
from nifty.config import about
class space_paradict(object):
def __init__(self, **kwargs):
if not hasattr(self, 'parameters'):
self.parameters = {}
for key in kwargs:
self[key] = kwargs[key]
def __iter__(self):
return self.parameters.__iter__()
def __eq__(self, other):
return (isinstance(other, self.__class__) and
self.__dict__ == other.__dict__)
def __ne__(self, other):
return not self.__eq__(other)
def __repr__(self):
return self.parameters.__repr__()
def __setitem__(self, key, arg):
raise NotImplementedError
def __getitem__(self, key):
return self.parameters.__getitem__(key)
def __hash__(self):
result_hash = 0
for (key, item) in self.parameters.items():
try:
temp_hash = hash(item)
except TypeError:
temp_hash = hash(tuple(item))
result_hash ^= temp_hash ^ int(hash(key)/131)
return result_hash
class rg_space_paradict(space_paradict):
def __init__(self, shape, zerocenter, distances, harmonic):
if not hasattr(self, 'parameters'):
self.parameters = {}
self.parameters.__setitem__('shape', shape)
self.parameters.__setitem__('harmonic', harmonic)
space_paradict.__init__(
self, zerocenter=zerocenter, distances=distances)
def __setitem__(self, key, arg):
if key not in ['shape', 'zerocenter', 'distances']:
raise ValueError(about._errors.cstring(
"ERROR: Unsupported RGSpace parameter:" + key))
if key == 'shape':
temp = np.empty(len(self['shape']), dtype=np.int)
temp[:] = arg
temp = tuple(temp)
elif key == 'zerocenter':
temp = np.empty(len(self['shape']), dtype=bool)
temp[:] = arg
temp = tuple(temp)
elif key == 'distances':
if arg is None:
if self['harmonic']:
temp = np.ones_like(self['shape'], dtype=np.float)
else:
temp = 1 / np.array(self['shape'], dtype=np.float)
else:
temp = np.empty(len(self['shape']), dtype=np.float)
temp[:] = arg
temp = tuple(temp)
elif key == 'harmonic':
temp = bool(arg)
self.parameters.__setitem__(key, temp)
class lm_space_paradict(space_paradict):
def __init__(self, lmax, mmax):
space_paradict.__init__(self, lmax=lmax)
if mmax is None:
mmax = -1
self['mmax'] = mmax