Commit 71d68281 authored by theos's avatar theos

Fixed import structure.

parent 3193a3ac
......@@ -54,39 +54,8 @@ from field_types import FieldType,\
from operators import *
from power import PowerSpace,\
PowerIndexFactory
## optional submodule `rg`
try:
from rg import RGSpace,\
power_backward_conversion_rg,\
power_forward_conversion_rg
from nifty_paradict import rg_space_paradict
except(ImportError):
pass
## optional submodule `lm`
try:
from lm import LMSpace,\
power_backward_conversion_lm,\
power_forward_conversion_lm
from nifty_paradict import lm_space_paradict
try:
from lm import GLSpace
from nifty_paradict import gl_space_paradict
except(ImportError):
pass
try:
from lm import HPSpace
from nifty_paradict import hp_space_paradict
except(ImportError):
pass
except(ImportError):
pass
from spaces import *
from demos import get_demo_dir
from pickling import _pickle_method, _unpickle_method
......
# -*- coding: utf-8 -*-
import os
from distutils.version import LooseVersion as lv
import numpy as np
import keepers
......@@ -29,11 +31,24 @@ variable_lm2gl = keepers.Variable(
if z else True) and isinstance(z, bool),
genus='boolean')
def _healpy_validator(use_healpy):
if not isinstance(use_healpy, bool):
return False
if not use_healpy:
return False
if 'healpy' not in dependency_injector:
return False
healpy = dependency_injector['healpy']
if lv(healpy.__version__) < lv('1.8.1'):
return False
return True
variable_use_healpy = keepers.Variable(
'use_healpy',
[True, False],
lambda z: (('healpy' in dependency_injector)
if z else True) and isinstance(z, bool),
_healpy_validator,
genus='boolean')
variable_use_libsharp = keepers.Variable(
......
## 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/>.
from __future__ import division
from nifty.config import about
from distutils.version import LooseVersion as lv
try:
import libsharp_wrapper_gl as gl
except(ImportError):
try:
import healpy as hp
if lv(hp.__version__) < lv('1.8.1'):
raise ImportError(
about._errors.cprint(
"ERROR: installed healpy version is older than 1.8.1!"))
except(ImportError):
about.infos.cprint(
"INFO: neither libsharp_wrapper_gl nor healpy available.")
pass ## import nothing
else:
from lm_space import LMSpace ## import lm & hp
from hp_space import HPSpace
## TODO: change about
else:
try:
import healpy as hp
if lv(hp.__version__) < lv('1.8.1'):
raise ImportError(
about._errors.cprint(
"ERROR: installed healpy version is older than 1.8.1!"))
except(ImportError):
from gl_space import GLSpace ## import lm & gl
from lm_space import LMSpace
else:
from gl_space import GLSpace ##import all
from lm_space import LMSpace
from hp_space import HPSpace
from nifty.lm.nifty_power_conversion_lm import power_backward_conversion_lm,\
power_forward_conversion_lm
......@@ -19,7 +19,7 @@
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
from setuptools import setup
from setuptools import setup, find_packages
import os
exec(open('version.py').read())
......@@ -32,9 +32,7 @@ setup(name="ift_nifty",
maintainer_email="theos@mpa-garching.mpg.de",
description="Numerical Information Field Theory",
url="http://www.mpa-garching.mpg.de/ift/nifty/",
packages=["nifty", "nifty.demos", "nifty.rg", "nifty.lm",
"nifty.operators", "nifty.dummys", "nifty.field_types",
"nifty.config", "nifty.power", "nifty.transformations"],
packages=find_packages(),
package_dir={"nifty": ""},
zip_safe=False,
dependency_links=[
......
# -*- coding: utf-8 -*-
from gl_space import GLSpace,\
GLSpaceParadict
from hp_space import HPSpace,\
HPSpaceParadict
from lm_space import LMSpace,\
LMSpaceParadict,\
power_backward_conversion_lm,\
power_forward_conversion_lm
from power_space import PowerSpace,\
PowerSpaceParadict
from rg_space import RGSpace,\
RGSpaceParadict,\
power_backward_conversion_rg,\
power_forward_conversion_rg
from space import Space,\
SpaceParadict
# -*- coding: utf-8 -*-
from gl_space import GLSpace
from gl_space_paradict import GLSpaceParadict
\ No newline at end of file
......@@ -13,7 +13,7 @@ from nifty.space import Space
from nifty.config import about,\
nifty_configuration as gc,\
dependency_injector as gdi
from nifty.nifty_paradict import gl_space_paradict
from gl_space_paradict import GLSpaceParadict
from nifty.nifty_random import random
gl = gdi.get('libsharp_wrapper_gl')
......@@ -105,7 +105,7 @@ class GLSpace(Space):
"ERROR: libsharp_wrapper_gl not loaded."))
self._cache_dict = {'check_codomain': {}}
self.paradict = gl_space_paradict(nlat=nlat, nlon=nlon)
self.paradict = GLSpaceParadict(nlat=nlat, nlon=nlon)
# check data type
dtype = np.dtype(dtype)
......
# -*- coding: utf-8 -*-
from nifty.config import about
from nifty.spaces.space import SpaceParadict
class GLSpaceParadict(SpaceParadict):
def __init__(self, nlat, nlon):
SpaceParadict.__init__(self, nlat=nlat)
if nlon is None:
nlon = -1
self['nlon'] = nlon
def __setitem__(self, key, arg):
if key not in ['nlat', 'nlon']:
raise ValueError(about._errors.cstring(
"ERROR: Unsupported GLSpace parameter: " + key))
if key == 'nlat':
temp = int(arg)
if(temp < 1):
raise ValueError(about._errors.cstring(
"ERROR: nlat: nonpositive number."))
if (temp % 2 != 0):
raise ValueError(about._errors.cstring(
"ERROR: invalid parameter (nlat <> 2n)."))
try:
if temp < self['mmax']:
about.warnings.cprint(
"WARNING: mmax parameter set to lmax.")
self['mmax'] = temp
if (temp != self['mmax']):
about.warnings.cprint(
"WARNING: unrecommended parameter set (mmax <> lmax).")
except:
pass
elif key == 'nlon':
temp = int(arg)
if (temp < 1):
about.warnings.cprint(
"WARNING: nlon parameter set to default.")
temp = 2 * self['nlat'] - 1
if(temp != 2 * self['nlat'] - 1):
about.warnings.cprint(
"WARNING: unrecommended parameter set (nlon <> 2*nlat-1).")
self.parameters.__setitem__(key, temp)
# -*- coding: utf-8 -*-
from hp_space import HPSpace
from hp_space_paradict import HPSpaceParadict
......@@ -46,7 +46,7 @@ from nifty.field import Field
from nifty.config import about,\
nifty_configuration as gc,\
dependency_injector as gdi
from nifty.nifty_paradict import hp_space_paradict
from hp_space_paradict import HPSpaceParadict
from nifty.nifty_random import random
hp = gdi.get('healpy')
......@@ -133,7 +133,7 @@ class HPSpace(Space):
self._cache_dict = {'check_codomain': {}}
# check parameters
self.paradict = hp_space_paradict(nside=nside)
self.paradict = HPSpaceParadict(nside=nside)
self.dtype = np.dtype('float64')
......
# -*- coding: utf-8 -*-
from nifty.config import about
from nifty.spaces.space import SpaceParadict
class HPSpaceParadict(SpaceParadict):
def __init__(self, nside):
SpaceParadict.__init__(self, nside=nside)
def __setitem__(self, key, arg):
if key not in ['nside']:
raise ValueError(about._errors.cstring(
"ERROR: Unsupported hp_space parameter"))
temp = int(arg)
# if(not hp.isnsideok(nside)):
if ((temp & (temp - 1)) != 0) or (temp < 2):
raise ValueError(about._errors.cstring(
"ERROR: invalid parameter ( nside <> 2**n )."))
self.parameters.__setitem__(key, temp)
# -*- coding: utf-8 -*-
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
......@@ -10,12 +10,12 @@ from matplotlib.ticker import LogFormatter as lf
from d2o import STRATEGIES as DISTRIBUTION_STRATEGIES
from nifty.space import Space
#from hp_space import HPSpace
#from gl_space import GLSpace
from nifty.config import about,\
nifty_configuration as gc,\
dependency_injector as gdi
from nifty.nifty_paradict import lm_space_paradict
from lm_space_paradict import LMSpaceParadict
from nifty.nifty_power_indices import lm_power_indices
from nifty.nifty_random import random
......@@ -120,7 +120,7 @@ class LMSpace(Space):
self._cache_dict = {'check_codomain': {}}
self.paradict = lm_space_paradict(lmax=lmax, mmax=mmax)
self.paradict = LMSpaceParadict(lmax=lmax, mmax=mmax)
# check data type
dtype = np.dtype(dtype)
......
# -*- coding: utf-8 -*-
import numpy as np
from nifty.config import about
from nifty.spaces.space import SpaceParadict
class LMSpaceParadict(SpaceParadict):
def __init__(self, lmax, mmax):
SpaceParadict.__init__(self, lmax=lmax)
if mmax is None:
mmax = -1
self['mmax'] = mmax
def __setitem__(self, key, arg):
if key not in ['lmax', 'mmax']:
raise ValueError(about._errors.cstring(
"ERROR: Unsupported LMSpace parameter: " + key))
if key == 'lmax':
temp = np.int(arg)
if temp < 1:
raise ValueError(about._errors.cstring(
"ERROR: lmax: nonpositive number."))
# exception lmax == 2 (nside == 1)
if (temp % 2 == 0) and (temp > 2):
about.warnings.cprint(
"WARNING: unrecommended parameter (lmax <> 2*n+1).")
try:
if temp < self['mmax']:
about.warnings.cprint(
"WARNING: mmax parameter set to lmax.")
self['mmax'] = temp
if (temp != self['mmax']):
about.warnings.cprint(
"WARNING: unrecommended parameter set (mmax <> lmax).")
except:
pass
elif key == 'mmax':
temp = int(arg)
if (temp < 1) or(temp > self['lmax']):
about.warnings.cprint(
"WARNING: mmax parameter set to default.")
temp = self['lmax']
if(temp != self['lmax']):
about.warnings.cprint(
"WARNING: unrecommended parameter set (mmax <> lmax).")
self.parameters.__setitem__(key, temp)
# -*- coding: utf-8 -*-
from power_space import PowerSpace
from power_space_paradict import PowerSpaceParadict
from power_index_factory import PowerIndexFactory
\ No newline at end of file
......@@ -5,7 +5,7 @@ from d2o import STRATEGIES
from nifty.config import about
from nifty.space import Space
from nifty.nifty_paradict import power_space_paradict
from power_space_paradict import PowerSpaceParadict
from nifty.nifty_utilities import cast_axis_to_tuple
......@@ -15,11 +15,11 @@ class PowerSpace(Space):
# the **kwargs is in the __init__ in order to enable a
# PowerSpace(**power_index) initialization
self.dtype = np.dtype(dtype)
self.paradict = power_space_paradict(pindex=pindex,
kindex=kindex,
rho=rho,
config=config,
harmonic_domain=harmonic_domain)
self.paradict = PowerSpaceParadict(pindex=pindex,
kindex=kindex,
rho=rho,
config=config,
harmonic_domain=harmonic_domain)
self._harmonic = True
@property
......
# -*- coding: utf-8 -*-
from nifty.config import about
from nifty.spaces.space import SpaceParadict
class PowerSpaceParadict(SpaceParadict):
def __init__(self, pindex, kindex, rho, config, harmonic_domain):
SpaceParadict.__init__(self,
pindex=pindex,
kindex=kindex,
rho=rho,
config=config,
harmonic_domain=harmonic_domain)
def __setitem__(self, key, arg):
if key not in ['pindex', 'kindex', 'rho', 'config', 'harmonic_domain']:
raise ValueError(about._errors.cstring(
"ERROR: Unsupported PowerSpace parameter: " + key))
if key == 'harmonic_domain':
if not arg.harmonic:
raise ValueError(about._errors.cstring(
"ERROR: harmonic_domain must be harmonic."))
temp = arg
else:
temp = arg
self.parameters.__setitem__(key, temp)
def __hash__(self):
return (hash(frozenset(self.parameters['config'].items())) ^
(hash(self.parameters['harmonic_domain'])/131))
......@@ -19,8 +19,8 @@
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import division
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
......@@ -49,7 +49,7 @@ from nifty.field import Field
from nifty.config import about,\
nifty_configuration as gc,\
dependency_injector as gdi
from nifty.nifty_paradict import rg_space_paradict
from rg_space_paradict import RGSpaceParadict
import nifty.nifty_utilities as utilities
MPI = gdi[gc['mpi_module']]
......@@ -150,10 +150,10 @@ class RGSpace(Space):
None
"""
self.paradict = rg_space_paradict(shape=shape,
zerocenter=zerocenter,
distances=distances,
harmonic=harmonic)
self.paradict = RGSpaceParadict(shape=shape,
zerocenter=zerocenter,
distances=distances,
harmonic=harmonic)
self.dtype = np.dtype(dtype)
@property
......
# -*- coding: utf-8 -*-
import numpy as np
from nifty.config import about
from nifty.spaces.space import SpaceParadict
class RGSpaceParadict(SpaceParadict):
def __init__(self, shape, zerocenter, distances, harmonic):
if not hasattr(self, 'parameters'):
self.parameters = {}
self.parameters.__setitem__('shape', shape)
self.parameters.__setitem__('harmonic', harmonic)
SpaceParadict.__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)
# -*- coding: utf-8 -*-
from space import Space
from space_paradict import SpaceParadict
\ No newline at end of file
......@@ -145,7 +145,7 @@ import numpy as np
import pylab as pl
from nifty.config import about
from nifty_paradict import space_paradict
from space_paradict import SpaceParadict
class Space(object):
......@@ -198,7 +198,7 @@ class Space(object):
-------
None.
"""
self.paradict = space_paradict(**kwargs)
self.paradict = SpaceParadict(**kwargs)
# parse dtype
dtype = np.dtype(dtype)
......
# -*- coding: utf-8 -*-
class SpaceParadict(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
......@@ -4,4 +4,4 @@
# 1) we don't load dependencies by storing it in __init__.py
# 2) we can import it in setup.py for the same reason
# 3) we can import it into your module module
__version__ = '2.0.0a1'
\ No newline at end of file
__version__ = '3.0.0a1'
\ No newline at end of file
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