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,\ ...@@ -60,7 +60,7 @@ from power import PowerSpace,\
## optional submodule `rg` ## optional submodule `rg`
try: try:
from rg import rg_space,\ from rg import RgSpace,\
power_backward_conversion_rg,\ power_backward_conversion_rg,\
power_forward_conversion_rg power_forward_conversion_rg
from nifty_paradict import rg_space_paradict from nifty_paradict import rg_space_paradict
...@@ -69,19 +69,19 @@ except(ImportError): ...@@ -69,19 +69,19 @@ except(ImportError):
## optional submodule `lm` ## optional submodule `lm`
try: try:
from lm import lm_space,\ from lm import LmSpace,\
power_backward_conversion_lm,\ power_backward_conversion_lm,\
power_forward_conversion_lm power_forward_conversion_lm
from nifty_paradict import lm_space_paradict from nifty_paradict import lm_space_paradict
try: try:
from lm import gl_space from lm import GlSpace
from nifty_paradict import gl_space_paradict from nifty_paradict import gl_space_paradict
except(ImportError): except(ImportError):
pass pass
try: try:
from lm import hp_space from lm import HpSpace
from nifty_paradict import hp_space_paradict from nifty_paradict import hp_space_paradict
except(ImportError): except(ImportError):
pass pass
......
...@@ -256,7 +256,7 @@ class problem(object): ...@@ -256,7 +256,7 @@ class problem(object):
##----------------------------------------------------------------------------- ##-----------------------------------------------------------------------------
# #
if(__name__=="__main__"): if(__name__=="__main__"):
x = rg_space((1280), zerocenter=True) x = RgSpace((1280), zerocenter=True)
p = problem(x, log = False) p = problem(x, log = False)
about.warnings.off() about.warnings.off()
## pl.close("all") ## pl.close("all")
......
...@@ -48,7 +48,8 @@ about.infos.off() ...@@ -48,7 +48,8 @@ about.infos.off()
##----------------------------------------------------------------------------- ##-----------------------------------------------------------------------------
# (global) Faraday map # (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): ...@@ -97,8 +98,8 @@ def run(projection=False, power=False):
m4.plot(title=r"angular quadrupole of $m$ on a Gauss-Legendre grid", **nicely) m4.plot(title=r"angular quadrupole of $m$ on a Gauss-Legendre grid", **nicely)
# (d) representation on regular grid # (d) representation on regular grid
y_space = gl_space(384, nlon=768) # auxiliary gl_space y_space = GlSpace(384, nlon=768) # auxiliary gl_space
z_space = rg_space([768, 384], dist=[1/360, 1/180]) z_space = RgSpace([768, 384], dist=[1/360, 1/180])
m5 = m1.transform(y_space) m5 = m1.transform(y_space)
m5.cast_domain(z_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 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__": ...@@ -9,7 +9,7 @@ if __name__ == "__main__":
shape = (256, 256) shape = (256, 256)
x_space = rg_space(shape) x_space = RgSpace(shape)
k_space = x_space.get_codomain() k_space = x_space.get_codomain()
power = lambda k: 42/((1+k*shape[0])**3) power = lambda k: 42/((1+k*shape[0])**3)
......
...@@ -49,8 +49,8 @@ if __name__ == "__main__": ...@@ -49,8 +49,8 @@ if __name__ == "__main__":
#shape = [1024, 1024] #shape = [1024, 1024]
#x_space = rg_space(shape) #x_space = rg_space(shape)
#y_space = point_space(1280*1280) #y_space = point_space(1280*1280)
x_space = hp_space(32) x_space = HpSpace(32)
#x_space = gl_space(800) #x_space = GlSpace(800)
k_space = x_space.get_codomain() # get conjugate space k_space = x_space.get_codomain() # get conjugate space
......
...@@ -55,7 +55,8 @@ from nifty.operators.nifty_minimization import steepest_descent_new ...@@ -55,7 +55,8 @@ from nifty.operators.nifty_minimization import steepest_descent_new
if __name__ == "__main__": if __name__ == "__main__":
# some signal space; e.g., a two-dimensional regular grid # 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 k_space = x_space.get_codomain() # get conjugate space
......
...@@ -39,7 +39,8 @@ if __name__ == "__main__": ...@@ -39,7 +39,8 @@ if __name__ == "__main__":
# some signal space; e.g., a one-dimensional regular grid # 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 k_space = x_space.get_codomain() # get conjugate space
......
...@@ -38,7 +38,8 @@ except(ImportError): ...@@ -38,7 +38,8 @@ except(ImportError):
"INFO: neither libsharp_wrapper_gl nor healpy available.") "INFO: neither libsharp_wrapper_gl nor healpy available.")
pass ## import nothing pass ## import nothing
else: 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 ## TODO: change about
else: else:
try: try:
...@@ -48,9 +49,12 @@ else: ...@@ -48,9 +49,12 @@ else:
about._errors.cprint( about._errors.cprint(
"ERROR: installed healpy version is older than 1.8.1!")) "ERROR: installed healpy version is older than 1.8.1!"))
except(ImportError): 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: 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,\ from nifty.lm.nifty_power_conversion_lm import power_backward_conversion_lm,\
power_forward_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 ...@@ -7,7 +7,7 @@ from nifty.nifty_paradict import power_space_paradict
class PowerSpace(Space): 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): log=False, nbin=None, binbounds=None):
self.dtype = np.dtype(dtype) self.dtype = np.dtype(dtype)
self.paradict = power_space_paradict( self.paradict = power_space_paradict(
......
...@@ -4,7 +4,7 @@ import numpy as np ...@@ -4,7 +4,7 @@ import numpy as np
from nifty.power import PowerSpace from nifty.power import PowerSpace
from nifty.nifty_paradict import rg_power_space_paradict 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): class RGPowerSpace(PowerSpace):
...@@ -16,10 +16,10 @@ class RGPowerSpace(PowerSpace): ...@@ -16,10 +16,10 @@ class RGPowerSpace(PowerSpace):
shape=shape, shape=shape,
dgrid=dgrid, dgrid=dgrid,
zerocentered=zerocentered, zerocentered=zerocentered,
distribution_strategy=distribution_strategy distribution_strategy=distribution_strategy,
log=log, log=log,
nbin=nbin, nbin=nbin,
binbounds=binbounds) binbounds=binbounds)
self.power_indices = RGPowerIndexFactory.get_power_indices( # self.power_indices = RGPowerIndexFactory.get_power_indices(
**self.paradict.parameters) # **self.paradict.parameters)
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
## along with this program. If not, see <http://www.gnu.org/licenses/>. ## along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import division from __future__ import division
from nifty_rg import rg_space,\ from nifty_rg import RgSpace,\
utilities utilities
from nifty_power_conversion_rg import power_backward_conversion_rg,\ from nifty_power_conversion_rg import power_backward_conversion_rg,\
power_forward_conversion_rg power_forward_conversion_rg
......
...@@ -59,7 +59,7 @@ MPI = gdi[gc['mpi_module']] ...@@ -59,7 +59,7 @@ MPI = gdi[gc['mpi_module']]
RG_DISTRIBUTION_STRATEGIES = DISTRIBUTION_STRATEGIES['global'] RG_DISTRIBUTION_STRATEGIES = DISTRIBUTION_STRATEGIES['global']
class rg_space(Space): class RgSpace(Space):
""" """
.. _____ _______ .. _____ _______
.. / __/ / _ / .. / __/ / _ /
...@@ -241,7 +241,7 @@ class rg_space(Space): ...@@ -241,7 +241,7 @@ class rg_space(Space):
return tuple(sorted(temp)) return tuple(sorted(temp))
def copy(self): def copy(self):
return rg_space(shape=self.paradict['shape'], return RgSpace(shape=self.paradict['shape'],
complexity=self.paradict['complexity'], complexity=self.paradict['complexity'],
zerocenter=self.paradict['zerocenter'], zerocenter=self.paradict['zerocenter'],
distances=self.distances, distances=self.distances,
...@@ -353,7 +353,7 @@ class rg_space(Space): ...@@ -353,7 +353,7 @@ class rg_space(Space):
if codomain is None: if codomain is None:
return False return False
if not isinstance(codomain, rg_space): if not isinstance(codomain, RgSpace):
raise TypeError(about._errors.cstring( raise TypeError(about._errors.cstring(
"ERROR: The given codomain must be a nifty rg_space.")) "ERROR: The given codomain must be a nifty rg_space."))
...@@ -461,7 +461,7 @@ class rg_space(Space): ...@@ -461,7 +461,7 @@ class rg_space(Space):
complexity = {0: 1, 1: 0, 2: 2}[self.paradict['complexity']] complexity = {0: 1, 1: 0, 2: 2}[self.paradict['complexity']]
harmonic = bool(not self.harmonic) harmonic = bool(not self.harmonic)
new_space = rg_space(shape, new_space = RgSpace(shape,
zerocenter=cozerocenter, zerocenter=cozerocenter,
complexity=complexity, complexity=complexity,
distances=distances, distances=distances,
...@@ -541,7 +541,7 @@ class rg_space(Space): ...@@ -541,7 +541,7 @@ class rg_space(Space):
# Case 1: uniform distribution over {-1,+1}/{1,i,-1,-i} # Case 1: uniform distribution over {-1,+1}/{1,i,-1,-i}
if arg['random'] == 'pm1' and not hermitianizeQ: 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: elif arg['random'] == 'pm1' and hermitianizeQ:
sample = self.get_random_values(random='uni', vmin=-1, vmax=1) sample = self.get_random_values(random='uni', vmin=-1, vmax=1)
...@@ -579,14 +579,14 @@ class rg_space(Space): ...@@ -579,14 +579,14 @@ class rg_space(Space):
# Case 2: normal distribution with zero-mean and a given standard # Case 2: normal distribution with zero-mean and a given standard
# deviation or variance # deviation or variance
elif arg['random'] == 'gau': elif arg['random'] == 'gau':
sample = super(rg_space, self).get_random_values(**arg) sample = super(RgSpace, self).get_random_values(**arg)
if hermitianizeQ: if hermitianizeQ:
sample = utilities.hermitianize_gaussian(sample) sample = utilities.hermitianize_gaussian(sample)
# Case 3: uniform distribution # Case 3: uniform distribution
elif arg['random'] == "uni" and not hermitianizeQ: 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: elif arg['random'] == "uni" and hermitianizeQ:
# For a hermitian uniform sample, generate a gaussian one # For a hermitian uniform sample, generate a gaussian one
...@@ -1614,6 +1614,6 @@ class rg_space(Space): ...@@ -1614,6 +1614,6 @@ class rg_space(Space):
fig.canvas.draw() fig.canvas.draw()
def __repr__(self): def __repr__(self):
string = super(rg_space, self).__repr__() string = super(RgSpace, self).__repr__()
string += repr(self.fft_machine) + "\n " string += repr(self.fft_machine) + "\n "
return string return string
...@@ -6,7 +6,7 @@ import d2o ...@@ -6,7 +6,7 @@ import d2o
class TestFFTWTransform(unittest.TestCase): class TestFFTWTransform(unittest.TestCase):
def test_comm(self): 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)) a = np.ones((8, 8))
b = d2o.distributed_data_object(a) b = d2o.distributed_data_object(a)
b.comm = [1, 2, 3] # change comm to something not supported b.comm = [1, 2, 3] # change comm to something not supported
...@@ -14,14 +14,14 @@ class TestFFTWTransform(unittest.TestCase): ...@@ -14,14 +14,14 @@ class TestFFTWTransform(unittest.TestCase):
x.fft_machine.transform(b, x, x.get_codomain()) x.fft_machine.transform(b, x, x.get_codomain())
def test_shapemismatch(self): 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)) a = np.ones((8, 8))
b = x.cast(a) b = x.cast(a)
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
x.fft_machine.transform(b, x, x.get_codomain(), axes=(0, 1, 2)) x.fft_machine.transform(b, x, x.get_codomain(), axes=(0, 1, 2))
def test_local_ndarray(self): 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)) a = np.ones((8, 8))
self.assertTrue( self.assertTrue(
np.allclose( np.allclose(
...@@ -31,7 +31,7 @@ class TestFFTWTransform(unittest.TestCase): ...@@ -31,7 +31,7 @@ class TestFFTWTransform(unittest.TestCase):
) )
def test_local_notzero(self): 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)) a = np.ones((8, 8))
b = x.cast(a) b = x.cast(a)
self.assertTrue( self.assertTrue(
...@@ -42,7 +42,7 @@ class TestFFTWTransform(unittest.TestCase): ...@@ -42,7 +42,7 @@ class TestFFTWTransform(unittest.TestCase):
) )
def test_not(self): 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)) a = np.ones((8, 8))
b = d2o.distributed_data_object(a, distribution_strategy='not') b = d2o.distributed_data_object(a, distribution_strategy='not')
self.assertTrue( self.assertTrue(
...@@ -53,7 +53,7 @@ class TestFFTWTransform(unittest.TestCase): ...@@ -53,7 +53,7 @@ class TestFFTWTransform(unittest.TestCase):
) )
def test_mpi_axesnone(self): 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)) a = np.ones((8, 8))
b = x.cast(a) b = x.cast(a)
self.assertTrue( self.assertTrue(
...@@ -64,7 +64,7 @@ class TestFFTWTransform(unittest.TestCase): ...@@ -64,7 +64,7 @@ class TestFFTWTransform(unittest.TestCase):
) )
def test_mpi_axesnone_equal(self): 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)) a = np.ones((8, 8))
b = d2o.distributed_data_object(a, distribution_strategy='equal') b = d2o.distributed_data_object(a, distribution_strategy='equal')
self.assertTrue( self.assertTrue(
...@@ -75,7 +75,7 @@ class TestFFTWTransform(unittest.TestCase): ...@@ -75,7 +75,7 @@ class TestFFTWTransform(unittest.TestCase):
) )
def test_mpi_axesall(self): 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)) a = np.ones((8, 8))
b = x.cast(a) b = x.cast(a)
self.assertTrue( self.assertTrue(
...@@ -86,7 +86,7 @@ class TestFFTWTransform(unittest.TestCase): ...@@ -86,7 +86,7 @@ class TestFFTWTransform(unittest.TestCase):
) )
def test_mpi_axesall_equal(self): 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)) a = np.ones((8, 8))
b = d2o.distributed_data_object(a, distribution_strategy='equal') b = d2o.distributed_data_object(a, distribution_strategy='equal')
self.assertTrue( self.assertTrue(
...@@ -97,7 +97,7 @@ class TestFFTWTransform(unittest.TestCase): ...@@ -97,7 +97,7 @@ class TestFFTWTransform(unittest.TestCase):
) )
def test_mpi_zero(self): 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)) a = np.ones((8, 8)) + 1j*np.zeros((8, 8))
b = x.cast(a) b = x.cast(a)
self.assertTrue( self.assertTrue(
...@@ -108,7 +108,7 @@ class TestFFTWTransform(unittest.TestCase): ...@@ -108,7 +108,7 @@ class TestFFTWTransform(unittest.TestCase):
) )
def test_mpi_zero_equal(self): 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)) a = np.ones((8, 8)) + 1j*np.zeros((8, 8))
b = d2o.distributed_data_object(a, distribution_strategy='equal') b = d2o.distributed_data_object(a, distribution_strategy='equal')
self.assertTrue( self.assertTrue(
...@@ -119,7 +119,7 @@ class TestFFTWTransform(unittest.TestCase): ...@@ -119,7 +119,7 @@ class TestFFTWTransform(unittest.TestCase):
) )
def test_mpi_zero_not(self): 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)) a = np.ones((8, 8)) + 1j*np.zeros((8, 8))
b = d2o.distributed_data_object(a, distribution_strategy='not') b = d2o.distributed_data_object(a, distribution_strategy='not')
self.assertTrue( self.assertTrue(
......
...@@ -11,12 +11,12 @@ import numpy as np ...@@ -11,12 +11,12 @@ import numpy as np
from d2o import distributed_data_object from d2o import distributed_data_object
from nifty import space, \ from nifty import Space, \
point_space, \ point_space
rg_space, \
lm_space, \ from nifty.rg import RgSpace
hp_space, \
gl_space from nifty.lm import *
from nifty.field import Field from nifty.field import Field
...@@ -95,7 +95,7 @@ for param in itertools.product([(1,), (4, 6), (5, 8)], ...@@ -95,7 +95,7 @@ for param in itertools.product([(1,), (4, 6), (5, 8)],
[False], [False],
DATAMODELS['rg_space'], DATAMODELS['rg_space'],
fft_modules): fft_modules):
space_list += [[rg_space(shape=param[0], space_list += [[RgSpace(shape=param[0],
zerocenter=param[1], zerocenter=param[1],
complexity=param[2], complexity=param[2],
distances=param[3], distances=param[3],
...@@ -104,12 +104,12 @@ for param in itertools.product([(1,), (4, 6), (5, 8)], ...@@ -104,12 +104,12 @@ for param in itertools.product([(1,), (4, 6), (5, 8)],
def generate_space_with_size(name, num): def generate_space_with_size(name, num):
space_dict = {'space': space(), space_dict = {'space': Space(),
'point_space': point_space(num), 'point_space': point_space(num),
'rg_space': rg_space((num, num)), 'rg_space': RgSpace((num, num)),
'lm_space': lm_space(mmax=num+1, lmax=num+1), 'lm_space': LmSpace(mmax=num+1, lmax=num+1),
'hp_space': hp_space(num), 'hp_space': HpSpace(num),
'gl_space': gl_space(nlat=num, nlon=2*num-1), 'gl_space': GlSpace(nlat=num, nlon=2*num-1),
} }
return space_dict[name] return space_dict[name]
...@@ -135,7 +135,7 @@ class Test_field_init(unittest.TestCase): ...@@ -135,7 +135,7 @@ class Test_field_init(unittest.TestCase):
def test_successfull_init_and_attributes(self, shape, zerocenter, def test_successfull_init_and_attributes(self, shape, zerocenter,
complexity, distances, harmonic, complexity, distances, harmonic,
fft_module, datamodel): fft_module, datamodel):
s = rg_space(shape=shape, zerocenter=zerocenter, s = RgSpace(shape=shape, zerocenter=zerocenter,
complexity=complexity, distances=distances, complexity=complexity, distances=distances,
harmonic=harmonic, fft_module=fft_module) harmonic=harmonic, fft_module=fft_module)
f = Field(domain=(s,), dtype=s.dtype, datamodel=datamodel) f = Field(domain=(s,), dtype=s.dtype, datamodel=datamodel)
...@@ -171,10 +171,10 @@ class Test_field_multiple_rg_init(unittest.TestCase): ...@@ -171,10 +171,10 @@ class Test_field_multiple_rg_init(unittest.TestCase):
def test_multiple_space_init(self, shape, zerocenter, def test_multiple_space_init(self, shape, zerocenter,
complexity, distances, harmonic, complexity, distances, harmonic,
fft_module, datamodel): fft_module, datamodel):
s1 = rg_space(shape=shape, zerocenter=zerocenter, s1 = RgSpace(shape=shape, zerocenter=zerocenter,
complexity=complexity, distances=distances, complexity=complexity, distances=distances,
harmonic=harmonic, fft_module=fft_module) harmonic=harmonic, fft_module=fft_module)
s2 = rg_space(shape=shape, zerocenter=zerocenter, s2 = RgSpace(shape=shape, zerocenter=zerocenter,
complexity=complexity, distances=distances,