Commit d349bf74 authored by csongor's avatar csongor
Browse files

Move Space classes in separate files

parent 0677d4f0
......@@ -60,7 +60,7 @@ from power import PowerSpace,\
## optional submodule `rg`
try:
from rg import rg_space,\
from rg import RgSpace,\
power_backward_conversion_rg,\
power_forward_conversion_rg
from nifty_paradict import rg_space_paradict
......@@ -69,19 +69,19 @@ except(ImportError):
## optional submodule `lm`
try:
from lm import lm_space,\
from lm import LmSpace,\
power_backward_conversion_lm,\
power_forward_conversion_lm
from nifty_paradict import lm_space_paradict
try:
from lm import gl_space
from lm import GlSpace
from nifty_paradict import gl_space_paradict
except(ImportError):
pass
try:
from lm import hp_space
from lm import HpSpace
from nifty_paradict import hp_space_paradict
except(ImportError):
pass
......
......@@ -256,7 +256,7 @@ class problem(object):
##-----------------------------------------------------------------------------
#
if(__name__=="__main__"):
x = rg_space((1280), zerocenter=True)
x = RgSpace((1280), zerocenter=True)
p = problem(x, log = False)
about.warnings.off()
## pl.close("all")
......
......@@ -48,7 +48,8 @@ about.infos.off()
##-----------------------------------------------------------------------------
# (global) Faraday map
m = field(hp_space(128), val=np.load(os.path.join(get_demo_dir(),"demo_faraday_map.npy")))
m = field(HpSpace(128), val=np.load(os.path.join(get_demo_dir(),
"demo_faraday_map.npy")))
##-----------------------------------------------------------------------------
......@@ -97,8 +98,8 @@ def run(projection=False, power=False):
m4.plot(title=r"angular quadrupole of $m$ on a Gauss-Legendre grid", **nicely)
# (d) representation on regular grid
y_space = gl_space(384, nlon=768) # auxiliary gl_space
z_space = rg_space([768, 384], dist=[1/360, 1/180])
y_space = GlSpace(384, nlon=768) # auxiliary gl_space
z_space = RgSpace([768, 384], dist=[1/360, 1/180])
m5 = m1.transform(y_space)
m5.cast_domain(z_space)
m5.set_val(np.roll(m5.val[::-1, ::-1], y_space.paradict['nlon']//2, axis=1)) # rearrange value array
......
......@@ -9,7 +9,7 @@ if __name__ == "__main__":
shape = (256, 256)
x_space = rg_space(shape)
x_space = RgSpace(shape)
k_space = x_space.get_codomain()
power = lambda k: 42/((1+k*shape[0])**3)
......
......@@ -49,8 +49,8 @@ if __name__ == "__main__":
#shape = [1024, 1024]
#x_space = rg_space(shape)
#y_space = point_space(1280*1280)
x_space = hp_space(32)
#x_space = gl_space(800)
x_space = HpSpace(32)
#x_space = GlSpace(800)
k_space = x_space.get_codomain() # get conjugate space
......
......@@ -55,7 +55,8 @@ from nifty.operators.nifty_minimization import steepest_descent_new
if __name__ == "__main__":
# some signal space; e.g., a two-dimensional regular grid
x_space = rg_space([256, 256]) # define signal space
x_space = RgSpace([256, 256]) # define
# signal space
k_space = x_space.get_codomain() # get conjugate space
......
......@@ -39,7 +39,8 @@ if __name__ == "__main__":
# some signal space; e.g., a one-dimensional regular grid
x_space = rg_space([128,]) # define signal space
x_space = RgSpace([128,]) #
# define signal space
k_space = x_space.get_codomain() # get conjugate space
......
......@@ -38,7 +38,8 @@ except(ImportError):
"INFO: neither libsharp_wrapper_gl nor healpy available.")
pass ## import nothing
else:
from nifty_lm import lm_space, hp_space ## import lm & hp
from lm_space import LmSpace ## import lm & hp
from hp_space import HpSpace
## TODO: change about
else:
try:
......@@ -48,9 +49,12 @@ else:
about._errors.cprint(
"ERROR: installed healpy version is older than 1.8.1!"))
except(ImportError):
from nifty_lm import lm_space, gl_space ## import lm & gl
from gl_space import GlSpace ## import lm & gl
from lm_space import LmSpace
else:
from nifty_lm import lm_space, gl_space, hp_space ##import all
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
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -7,7 +7,7 @@ from nifty.nifty_paradict import power_space_paradict
class PowerSpace(Space):
def __init__(self, dtype=np.dtype('float'), distribution_strategy,
def __init__(self, dtype=np.dtype('float'), distribution_strategy='fftw',
log=False, nbin=None, binbounds=None):
self.dtype = np.dtype(dtype)
self.paradict = power_space_paradict(
......
......@@ -4,7 +4,7 @@ import numpy as np
from nifty.power import PowerSpace
from nifty.nifty_paradict import rg_power_space_paradict
from nifty.power.power_index_factory import RGPowerIndexFactory
# from nifty.power.power_index_factory import RGPowerIndexFactory
class RGPowerSpace(PowerSpace):
......@@ -16,10 +16,10 @@ class RGPowerSpace(PowerSpace):
shape=shape,
dgrid=dgrid,
zerocentered=zerocentered,
distribution_strategy=distribution_strategy
distribution_strategy=distribution_strategy,
log=log,
nbin=nbin,
binbounds=binbounds)
self.power_indices = RGPowerIndexFactory.get_power_indices(
**self.paradict.parameters)
# self.power_indices = RGPowerIndexFactory.get_power_indices(
# **self.paradict.parameters)
......@@ -20,7 +20,7 @@
## along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import division
from nifty_rg import rg_space,\
from nifty_rg import RgSpace,\
utilities
from nifty_power_conversion_rg import power_backward_conversion_rg,\
power_forward_conversion_rg
......
......@@ -59,7 +59,7 @@ MPI = gdi[gc['mpi_module']]
RG_DISTRIBUTION_STRATEGIES = DISTRIBUTION_STRATEGIES['global']
class rg_space(Space):
class RgSpace(Space):
"""
.. _____ _______
.. / __/ / _ /
......@@ -241,7 +241,7 @@ class rg_space(Space):
return tuple(sorted(temp))
def copy(self):
return rg_space(shape=self.paradict['shape'],
return RgSpace(shape=self.paradict['shape'],
complexity=self.paradict['complexity'],
zerocenter=self.paradict['zerocenter'],
distances=self.distances,
......@@ -353,7 +353,7 @@ class rg_space(Space):
if codomain is None:
return False
if not isinstance(codomain, rg_space):
if not isinstance(codomain, RgSpace):
raise TypeError(about._errors.cstring(
"ERROR: The given codomain must be a nifty rg_space."))
......@@ -461,7 +461,7 @@ class rg_space(Space):
complexity = {0: 1, 1: 0, 2: 2}[self.paradict['complexity']]
harmonic = bool(not self.harmonic)
new_space = rg_space(shape,
new_space = RgSpace(shape,
zerocenter=cozerocenter,
complexity=complexity,
distances=distances,
......@@ -541,7 +541,7 @@ class rg_space(Space):
# Case 1: uniform distribution over {-1,+1}/{1,i,-1,-i}
if arg['random'] == 'pm1' and not hermitianizeQ:
sample = super(rg_space, self).get_random_values(**arg)
sample = super(RgSpace, self).get_random_values(**arg)
elif arg['random'] == 'pm1' and hermitianizeQ:
sample = self.get_random_values(random='uni', vmin=-1, vmax=1)
......@@ -579,14 +579,14 @@ class rg_space(Space):
# Case 2: normal distribution with zero-mean and a given standard
# deviation or variance
elif arg['random'] == 'gau':
sample = super(rg_space, self).get_random_values(**arg)
sample = super(RgSpace, self).get_random_values(**arg)
if hermitianizeQ:
sample = utilities.hermitianize_gaussian(sample)
# Case 3: uniform distribution
elif arg['random'] == "uni" and not hermitianizeQ:
sample = super(rg_space, self).get_random_values(**arg)
sample = super(RgSpace, self).get_random_values(**arg)
elif arg['random'] == "uni" and hermitianizeQ:
# For a hermitian uniform sample, generate a gaussian one
......@@ -1614,6 +1614,6 @@ class rg_space(Space):
fig.canvas.draw()
def __repr__(self):
string = super(rg_space, self).__repr__()
string = super(RgSpace, self).__repr__()
string += repr(self.fft_machine) + "\n "
return string
......@@ -6,7 +6,7 @@ import d2o
class TestFFTWTransform(unittest.TestCase):
def test_comm(self):
x = nt.rg_space((8, 8), fft_module='pyfftw')
x = nt.RgSpace((8, 8), fft_module='pyfftw')
a = np.ones((8, 8))
b = d2o.distributed_data_object(a)
b.comm = [1, 2, 3] # change comm to something not supported
......@@ -14,14 +14,14 @@ class TestFFTWTransform(unittest.TestCase):
x.fft_machine.transform(b, x, x.get_codomain())
def test_shapemismatch(self):
x = nt.rg_space((8, 8), fft_module='pyfftw')
x = nt.RgSpace((8, 8), fft_module='pyfftw')
a = np.ones((8, 8))
b = x.cast(a)
with self.assertRaises(ValueError):
x.fft_machine.transform(b, x, x.get_codomain(), axes=(0, 1, 2))
def test_local_ndarray(self):
x = nt.rg_space((8, 8), fft_module='pyfftw')
x = nt.RgSpace((8, 8), fft_module='pyfftw')
a = np.ones((8, 8))
self.assertTrue(
np.allclose(
......@@ -31,7 +31,7 @@ class TestFFTWTransform(unittest.TestCase):
)
def test_local_notzero(self):
x = nt.rg_space(8, fft_module='pyfftw')
x = nt.RgSpace(8, fft_module='pyfftw')
a = np.ones((8, 8))
b = x.cast(a)
self.assertTrue(
......@@ -42,7 +42,7 @@ class TestFFTWTransform(unittest.TestCase):
)
def test_not(self):
x = nt.rg_space((8, 8), fft_module='pyfftw')
x = nt.RgSpace((8, 8), fft_module='pyfftw')
a = np.ones((8, 8))
b = d2o.distributed_data_object(a, distribution_strategy='not')
self.assertTrue(
......@@ -53,7 +53,7 @@ class TestFFTWTransform(unittest.TestCase):
)
def test_mpi_axesnone(self):
x = nt.rg_space((8, 8), fft_module='pyfftw')
x = nt.RgSpace((8, 8), fft_module='pyfftw')
a = np.ones((8, 8))
b = x.cast(a)
self.assertTrue(
......@@ -64,7 +64,7 @@ class TestFFTWTransform(unittest.TestCase):
)
def test_mpi_axesnone_equal(self):
x = nt.rg_space((8, 8), fft_module='pyfftw')
x = nt.RgSpace((8, 8), fft_module='pyfftw')
a = np.ones((8, 8))
b = d2o.distributed_data_object(a, distribution_strategy='equal')
self.assertTrue(
......@@ -75,7 +75,7 @@ class TestFFTWTransform(unittest.TestCase):
)
def test_mpi_axesall(self):
x = nt.rg_space((8, 8), fft_module='pyfftw')
x = nt.RgSpace((8, 8), fft_module='pyfftw')
a = np.ones((8, 8))
b = x.cast(a)
self.assertTrue(
......@@ -86,7 +86,7 @@ class TestFFTWTransform(unittest.TestCase):
)
def test_mpi_axesall_equal(self):
x = nt.rg_space((8, 8), fft_module='pyfftw')
x = nt.RgSpace((8, 8), fft_module='pyfftw')
a = np.ones((8, 8))
b = d2o.distributed_data_object(a, distribution_strategy='equal')
self.assertTrue(
......@@ -97,7 +97,7 @@ class TestFFTWTransform(unittest.TestCase):
)
def test_mpi_zero(self):
x = nt.rg_space(8, fft_module='pyfftw')
x = nt.RgSpace(8, fft_module='pyfftw')
a = np.ones((8, 8)) + 1j*np.zeros((8, 8))
b = x.cast(a)
self.assertTrue(
......@@ -108,7 +108,7 @@ class TestFFTWTransform(unittest.TestCase):
)
def test_mpi_zero_equal(self):
x = nt.rg_space(8, fft_module='pyfftw')
x = nt.RgSpace(8, fft_module='pyfftw')
a = np.ones((8, 8)) + 1j*np.zeros((8, 8))
b = d2o.distributed_data_object(a, distribution_strategy='equal')
self.assertTrue(
......@@ -119,7 +119,7 @@ class TestFFTWTransform(unittest.TestCase):
)
def test_mpi_zero_not(self):
x = nt.rg_space(8, fft_module='pyfftw')
x = nt.RgSpace(8, fft_module='pyfftw')
a = np.ones((8, 8)) + 1j*np.zeros((8, 8))
b = d2o.distributed_data_object(a, distribution_strategy='not')
self.assertTrue(
......
......@@ -11,12 +11,12 @@ import numpy as np
from d2o import distributed_data_object
from nifty import space, \
point_space, \
rg_space, \
lm_space, \
hp_space, \
gl_space
from nifty import Space, \
point_space
from nifty.rg import RgSpace
from nifty.lm import *
from nifty.field import Field
......@@ -95,7 +95,7 @@ for param in itertools.product([(1,), (4, 6), (5, 8)],
[False],
DATAMODELS['rg_space'],
fft_modules):
space_list += [[rg_space(shape=param[0],
space_list += [[RgSpace(shape=param[0],
zerocenter=param[1],
complexity=param[2],
distances=param[3],
......@@ -104,12 +104,12 @@ for param in itertools.product([(1,), (4, 6), (5, 8)],
def generate_space_with_size(name, num):
space_dict = {'space': space(),
space_dict = {'space': Space(),
'point_space': point_space(num),
'rg_space': rg_space((num, num)),
'lm_space': lm_space(mmax=num+1, lmax=num+1),
'hp_space': hp_space(num),
'gl_space': gl_space(nlat=num, nlon=2*num-1),
'rg_space': RgSpace((num, num)),
'lm_space': LmSpace(mmax=num+1, lmax=num+1),
'hp_space': HpSpace(num),
'gl_space': GlSpace(nlat=num, nlon=2*num-1),
}
return space_dict[name]
......@@ -135,7 +135,7 @@ class Test_field_init(unittest.TestCase):
def test_successfull_init_and_attributes(self, shape, zerocenter,
complexity, distances, harmonic,
fft_module, datamodel):
s = rg_space(shape=shape, zerocenter=zerocenter,
s = RgSpace(shape=shape, zerocenter=zerocenter,
complexity=complexity, distances=distances,
harmonic=harmonic, fft_module=fft_module)
f = Field(domain=(s,), dtype=s.dtype, datamodel=datamodel)
......@@ -171,10 +171,10 @@ class Test_field_multiple_rg_init(unittest.TestCase):
def test_multiple_space_init(self, shape, zerocenter,
complexity, distances, harmonic,
fft_module, datamodel):
s1 = rg_space(shape=shape, zerocenter=zerocenter,
s1 = RgSpace(shape=shape, zerocenter=zerocenter,
complexity=complexity, distances=distances,
harmonic=harmonic, fft_module=fft_module)
s2 = rg_space(shape=shape, zerocenter=zerocenter,
s2 = RgSpace(shape=shape, zerocenter=zerocenter,
complexity=complexity, distances=distances,
harmonic=harmonic, fft_module=fft_module)
f = Field(domain=(s1, s2), dtype=s1.dtype, datamodel=datamodel)
......
......@@ -9,8 +9,8 @@ import unittest
import itertools
import numpy as np
from nifty import space,\
rg_space,\
from nifty import Space,\
RgSpace,\
Field,\
distributed_data_object
......@@ -34,19 +34,19 @@ from nifty.lm.nifty_lm import LM_DISTRIBUTION_STRATEGIES,\
available = []
try:
from nifty import lm_space
from nifty import LmSpace
except ImportError:
pass
else:
available += ['lm_space']
try:
from nifty import gl_space
from nifty import GlSpace
except ImportError:
pass
else:
available += ['gl_space']
try:
from nifty import hp_space
from nifty import HpSpace
except ImportError:
pass
else:
......@@ -135,7 +135,7 @@ all_operators = ['operator', 'diagonal_operator', 'power_operator',
###############################################################################
def generate_operator(name):
x = rg_space((8, 8))
x = RgSpace((8, 8))
k = x.get_codomain()
operator_dict = {'operator': operator(domain=x),
'diagonal_operator': diagonal_operator(domain=x),
......
......@@ -20,7 +20,7 @@ from nifty.nifty_core import POINT_DISTRIBUTION_STRATEGIES,\
from nifty.rg.nifty_rg import RG_DISTRIBUTION_STRATEGIES,\
gc as RG_GC,\
rg_space
RgSpace
from nifty.lm.nifty_lm import LM_DISTRIBUTION_STRATEGIES,\
GL_DISTRIBUTION_STRATEGIES,\
HP_DISTRIBUTION_STRATEGIES
......@@ -32,19 +32,19 @@ from nifty.operators.nifty_operators import power_operator
available = []
try:
from nifty import lm_space
from nifty import LmSpace
except ImportError:
pass
else:
available += ['lm_space']
try:
from nifty import gl_space
from nifty import GlSpace
except ImportError:
pass
else:
available += ['gl_space']
try:
from nifty import hp_space
from nifty import HpSpace
except ImportError:
pass
else:
......@@ -169,14 +169,14 @@ fft_test_data = np.array(
def generate_space(name):
space_dict = {'space': space(),
'point_space': point_space(10),
'rg_space': rg_space((8, 8)),
'rg_space': RgSpace((8, 8)),
}
if 'lm_space' in available:
space_dict['lm_space'] = lm_space(mmax=11, lmax=11)
space_dict['lm_space'] = LmSpace(mmax=11, lmax=11)
if 'hp_space' in available:
space_dict['hp_space'] = hp_space(8)
space_dict['hp_space'] = HpSpace(8)
if 'gl_space' in available:
space_dict['gl_space'] = gl_space(nlat=10, nlon=19)
space_dict['gl_space'] = GlSpace(nlat=10, nlon=19)
return space_dict[name]
......@@ -184,14 +184,14 @@ def generate_space(name):
def generate_space_with_size(name, num):
space_dict = {'space': space(),
'point_space': point_space(num),
'rg_space': rg_space((num, num)),
'rg_space': RgSpace((num, num)),
}
if 'lm_space' in available:
space_dict['lm_space'] = lm_space(mmax=num, lmax=num)
space_dict['lm_space'] = LmSpace(mmax=num, lmax=num)
if 'hp_space' in available:
space_dict['hp_space'] = hp_space(num)
space_dict['hp_space'] = HpSpace(num)
if 'gl_space' in available:
space_dict['gl_space'] = gl_space(nlat=num, nlon=num)
space_dict['gl_space'] = GlSpace(nlat=num, nlon=num)
return space_dict[name]
......@@ -660,7 +660,7 @@ class Test_RG_Space(unittest.TestCase):
testcase_func_name=custom_name_func)
def test_successfull_init(self, shape, complexity, zerocenter, distances,
harmonic, fft_module):
x = rg_space(shape,
x = RgSpace(shape,
complexity=complexity,
zerocenter=zerocenter,
distances=distances,
......@@ -681,7 +681,7 @@ class Test_RG_Space(unittest.TestCase):
shape = (10, 10)
zerocenter = True
complexity = 2
x = rg_space(shape, zerocenter=zerocenter, complexity=complexity)
x = RgSpace(shape, zerocenter=zerocenter, complexity=complexity)
assert_equal(x.para, np.array([10, 10, 2, 1, 1]))
new_para = np.array([6, 6, 1, 0, 1])
......@@ -691,11 +691,11 @@ class Test_RG_Space(unittest.TestCase):
###############################################################################
def test_init_fail(self):
assert_raises(ValueError, lambda: rg_space((-3, 10)))
assert_raises(ValueError, lambda: rg_space((10, 10), complexity=3))
assert_raises(ValueError, lambda: rg_space((10, 10),
assert_raises(ValueError, lambda: RgSpace((-3, 10)))
assert_raises(ValueError, lambda: RgSpace((10, 10), complexity=3))
assert_raises(ValueError, lambda: RgSpace((10, 10),
distances=[1, 1, 1]))
assert_raises(ValueError, lambda: rg_space((10, 10),
assert_raises(ValueError, lambda: RgSpace((10, 10),
zerocenter=[1, 1, 1]))
###############################################################################
......@@ -714,7 +714,7 @@ class Test_RG_Space(unittest.TestCase):
@parameterized.expand([], testcase_func_name=custom_name_func)
def test_enforce_power(self):
shape = (6, 6)
x = rg_space(shape)
x = RgSpace(shape)
assert_equal(x.enforce_power(2),
np.array([2., 2., 2., 2., 2., 2., 2., 2., 2., 2.]))
......@@ -734,7 +734,7 @@ class Test_RG_Space(unittest.TestCase):
testcase_func_name=custom_name_func)
def test_get_check_codomain(self, complexity, distances, harmonic):
shape = (6, 6)
x = rg_space(shape, complexity=complexity, distances=distances,
x = RgSpace(shape, complexity=complexity, distances=distances,
harmonic=harmonic)
y = x.get_codomain()
assert(x.check_codomain(y))
......@@ -748,7 +748,7 @@ class Test_RG_Space(unittest.TestCase):
# #DATAMODELS['rg_space']),
# testcase_func_name=custom_name_func)
# def test_get_random_values(self, harmonic, datamodel):
# x = rg_space((4, 4), complexity=1, harmonic=harmonic,
# x = RgSpace((4, 4), complexity=1, harmonic=harmonic,
# datamodel=datamodel)
#
# # pm1
......@@ -778,7 +778,7 @@ class Test_RG_Space(unittest.TestCase):
def test_calc_dot(self):
shape = (8, 8)
a = np.arange(np.prod(shape)).reshape(shape)
x = rg_space(shape)
x = RgSpace(shape)
assert_equal(x.calc_dot(a, a), 85344)
assert_equal(x.calc_dot(a, 1), 2016)
assert_equal(x.calc_dot(1, a), 2016)
......@@ -792,7 +792,7 @@ class Test_RG_Space(unittest.TestCase):
data = fft_test_data.copy()
shape = data.shape
x = rg_space(shape, complexity=complexity)
x = RgSpace(shape, complexity=complexity)
data = fft_test_data.copy()
data = x.cast(data)
check_equality(x, data, x.calc_transform(x.calc_transform(data)))
......@@ -806,7 +806,7 @@ class Test_RG_Space(unittest.TestCase):
data = fft_test_data.copy()
shape = data.shape
x = rg_space(shape, complexity=2, zerocenter=False,
x = RgSpace(shape, complexity=2, zerocenter=False,
fft_module=fft_module)
casted_data = x.cast(data)
assert(check_almost_equality(x, x.calc_transform(casted_data),
......@@ -829,7 +829,7 @@ class Test_RG_Space(unittest.TestCase):