Commit 61e4b7a3 authored by theos's avatar theos
Browse files

Changed wording of LmSpace, GlSpace and HpSpace to PEP8 convention.

parent 38cd41a8
......@@ -60,7 +60,7 @@ from power import PowerSpace,\
## optional submodule `rg`
try:
from rg import RgSpace,\
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 LmSpace,\
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 lm import GLSpace
from nifty_paradict import gl_space_paradict
except(ImportError):
pass
try:
from lm import HpSpace
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 = RgSpace((1280), zerocenter=True)
x = RGSpace((1280), zerocenter=True)
p = problem(x, log = False)
about.warnings.off()
## pl.close("all")
......
......@@ -48,7 +48,7 @@ about.infos.off()
##-----------------------------------------------------------------------------
# (global) Faraday map
m = field(HpSpace(128), val=np.load(os.path.join(get_demo_dir(),
m = field(HPSpace(128), val=np.load(os.path.join(get_demo_dir(),
"demo_faraday_map.npy")))
##-----------------------------------------------------------------------------
......@@ -98,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 = GlSpace(384, nlon=768) # auxiliary gl_space
z_space = RgSpace([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 = RgSpace(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 = HpSpace(32)
#x_space = GlSpace(800)
x_space = HPSpace(32)
#x_space = GLSpace(800)
k_space = x_space.get_codomain() # get conjugate space
......
......@@ -55,7 +55,7 @@ from nifty.operators.nifty_minimization import steepest_descent_new
if __name__ == "__main__":
# some signal space; e.g., a two-dimensional regular grid
x_space = RgSpace([256, 256]) # define
x_space = RGSpace([256, 256]) # define
# signal space
k_space = x_space.get_codomain() # get conjugate space
......
......@@ -39,7 +39,7 @@ if __name__ == "__main__":
# some signal space; e.g., a one-dimensional regular grid
x_space = RgSpace([128,]) #
x_space = RGSpace([128,]) #
# define signal space
k_space = x_space.get_codomain() # get conjugate space
......
......@@ -38,8 +38,8 @@ except(ImportError):
"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
from lm_space import LMSpace ## import lm & hp
from hp_space import HPSpace
## TODO: change about
else:
try:
......@@ -49,13 +49,13 @@ else:
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
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 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
power_forward_conversion_lm
......@@ -7,6 +7,8 @@ from matplotlib.ticker import LogFormatter as lf
from d2o import STRATEGIES as DISTRIBUTION_STRATEGIES
from nifty.lm import LMSpace
from nifty.space import Space
from nifty.config import about,\
nifty_configuration as gc,\
......@@ -18,7 +20,8 @@ gl = gdi.get('libsharp_wrapper_gl')
GL_DISTRIBUTION_STRATEGIES = DISTRIBUTION_STRATEGIES['global']
class GlSpace(Space):
class GLSpace(Space):
"""
.. __
.. / /
......@@ -129,9 +132,9 @@ class GlSpace(Space):
self.paradict['nlon'] = x[1]
def copy(self):
return GlSpace(nlat=self.paradict['nlat'],
nlon=self.paradict['nlon'],
dtype=self.dtype)
return GLSpace(nlat=self.paradict['nlat'],
nlon=self.paradict['nlon'],
dtype=self.dtype)
@property
def shape(self):
......@@ -205,7 +208,7 @@ class GlSpace(Space):
if not isinstance(codomain, Space):
raise TypeError(about._errors.cstring("ERROR: invalid input."))
if isinstance(codomain, LmSpace):
if isinstance(codomain, LMSpace):
nlat = self.paradict['nlat']
nlon = self.paradict['nlon']
lmax = codomain.paradict['lmax']
......@@ -233,9 +236,9 @@ class GlSpace(Space):
mmax = nlat-1
# lmax,mmax = nlat-1,nlat-1
if self.dtype == np.dtype('float32'):
return LmSpace(lmax=lmax, mmax=mmax, dtype=np.complex64)
return LMSpace(lmax=lmax, mmax=mmax, dtype=np.complex64)
else:
return LmSpace(lmax=lmax, mmax=mmax, dtype=np.complex128)
return LMSpace(lmax=lmax, mmax=mmax, dtype=np.complex128)
def get_random_values(self, **kwargs):
"""
......@@ -308,7 +311,7 @@ class GlSpace(Space):
sample = self.calc_weight(sample, power=0.5)
else:
sample = super(GlSpace, self).get_random_values(**arg)
sample = super(GLSpace, self).get_random_values(**arg)
# elif(arg['random'] == "uni"):
......@@ -404,7 +407,7 @@ class GlSpace(Space):
raise ValueError(about._errors.cstring(
"ERROR: unsupported codomain."))
if isinstance(codomain, LmSpace):
if isinstance(codomain, LMSpace):
# weight if discrete
if self.discrete:
......
......@@ -38,6 +38,8 @@ import pylab as pl
from d2o import STRATEGIES as DISTRIBUTION_STRATEGIES
from nifty.lm import LMSpace
from nifty.space import Space
from nifty.field import Field
......@@ -51,7 +53,8 @@ hp = gdi.get('healpy')
HP_DISTRIBUTION_STRATEGIES = DISTRIBUTION_STRATEGIES['global']
class HpSpace(Space):
class HPSpace(Space):
"""
.. __
.. / /
......@@ -148,7 +151,7 @@ class HpSpace(Space):
self.paradict['nside'] = x[0]
def copy(self):
return HpSpace(nside=self.paradict['nside'])
return HPSpace(nside=self.paradict['nside'])
@property
def shape(self):
......@@ -221,7 +224,7 @@ class HpSpace(Space):
if not isinstance(codomain, Space):
raise TypeError(about._errors.cstring("ERROR: invalid input."))
if isinstance(codomain, LmSpace):
if isinstance(codomain, LMSpace):
nside = self.paradict['nside']
lmax = codomain.paradict['lmax']
mmax = codomain.paradict['mmax']
......@@ -244,7 +247,7 @@ class HpSpace(Space):
"""
lmax = 3*self.paradict['nside'] - 1
mmax = lmax
return LmSpace(lmax=lmax, mmax=mmax, dtype=np.dtype('complex128'))
return LMSpace(lmax=lmax, mmax=mmax, dtype=np.dtype('complex128'))
def get_random_values(self, **kwargs):
"""
......@@ -312,7 +315,7 @@ class HpSpace(Space):
sample = self.calc_weight(sample, power=0.5)
else:
sample = super(HpSpace, self).get_random_values(**arg)
sample = super(HPSpace, self).get_random_values(**arg)
# elif arg['random'] == "uni":
......@@ -369,7 +372,7 @@ class HpSpace(Space):
np_x = x.get_full_data()
if isinstance(codomain, LmSpace):
if isinstance(codomain, LMSpace):
# weight if discrete
if self.discrete:
x = self.calc_weight(x, power=-0.5)
......
......@@ -10,8 +10,8 @@ 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 hp_space import HPSpace
from gl_space import GLSpace
from nifty.config import about,\
nifty_configuration as gc,\
dependency_injector as gdi
......@@ -25,7 +25,7 @@ hp = gdi.get('healpy')
LM_DISTRIBUTION_STRATEGIES = DISTRIBUTION_STRATEGIES['global']
class LmSpace(Space):
class LMSpace(Space):
"""
.. __
.. / /
......@@ -168,9 +168,9 @@ class LmSpace(Space):
return tuple(sorted(temp))
def copy(self):
return LmSpace(lmax=self.paradict['lmax'],
mmax=self.paradict['mmax'],
dtype=self.dtype)
return LMSpace(lmax=self.paradict['lmax'],
mmax=self.paradict['mmax'],
dtype=self.dtype)
@property
def shape(self):
......@@ -294,7 +294,7 @@ class LmSpace(Space):
raise TypeError(about._errors.cstring(
"ERROR: The given codomain must be a nifty lm_space."))
elif isinstance(codomain, GlSpace):
elif isinstance(codomain, GLSpace):
# lmax==mmax
# nlat==lmax+1
# nlon==2*lmax+1
......@@ -303,7 +303,7 @@ class LmSpace(Space):
(codomain.paradict['nlon'] == 2*self.paradict['lmax']+1)):
return True
elif isinstance(codomain, HpSpace):
elif isinstance(codomain, HPSpace):
# lmax==mmax
# 3*nside-1==lmax
if ((self.paradict['lmax'] == self.paradict['mmax']) and
......@@ -353,11 +353,11 @@ class LmSpace(Space):
raise NotImplementedError
nlat = self.paradict['lmax'] + 1
nlon = self.paradict['lmax'] * 2 + 1
return GlSpace(nlat=nlat, nlon=nlon, dtype=new_dtype)
return GLSpace(nlat=nlat, nlon=nlon, dtype=new_dtype)
elif coname == 'hp' or (coname is None and not gc['lm2gl']):
nside = (self.paradict['lmax']+1) // 3
return HpSpace(nside=nside)
return HPSpace(nside=nside)
else:
raise ValueError(about._errors.cstring(
......@@ -434,7 +434,7 @@ class LmSpace(Space):
sample = gl.synalm(arg['spec'], lmax=lmax, mmax=mmax)
else:
sample = super(LmSpace, self).get_random_values(**arg)
sample = super(LMSpace, self).get_random_values(**arg)
# elif arg['random'] == "uni":
# x = random.uni(dtype=self.dtype,
......@@ -528,7 +528,7 @@ class LmSpace(Space):
np_x = x.get_full_data()
if isinstance(codomain, GlSpace):
if isinstance(codomain, GLSpace):
nlat = codomain.paradict['nlat']
nlon = codomain.paradict['nlon']
lmax = self.paradict['lmax']
......@@ -543,7 +543,7 @@ class LmSpace(Space):
lmax=lmax, mmax=mmax, cl=False)
Tx = codomain.cast(np_Tx)
elif isinstance(codomain, HpSpace):
elif isinstance(codomain, HPSpace):
nside = codomain.paradict['nside']
lmax = self.paradict['lmax']
mmax = self.paradict['mmax']
......
......@@ -27,7 +27,7 @@ from nifty.field import Field
from nifty.nifty_simple_math import sqrt, exp, log
def power_backward_conversion_lm(k_space,p,mean=None):
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
......
......@@ -7,7 +7,7 @@ from nifty.nifty_paradict import power_space_paradict
class PowerSpace(Space):
def __init__(self, dtype=np.dtype('float'), distribution_strategy='fftw',
def __init__(self, distribution_strategy, dtype=np.dtype('float'),
log=False, nbin=None, binbounds=None):
self.dtype = np.dtype(dtype)
self.paradict = power_space_paradict(
......
......@@ -13,13 +13,13 @@ class RGPowerSpace(PowerSpace):
binbounds=None):
self.dtype = np.dtype(dtype)
self.paradict = rg_power_space_paradict(
shape=shape,
dgrid=dgrid,
zerocentered=zerocentered,
distribution_strategy=distribution_strategy,
log=log,
nbin=nbin,
binbounds=binbounds)
shape=shape,
dgrid=dgrid,
zerocentered=zerocentered,
distribution_strategy=distribution_strategy,
log=log,
nbin=nbin,
binbounds=binbounds)
# 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 RgSpace,\
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 RgSpace(Space):
class RGSpace(Space):
"""
.. _____ _______
.. / __/ / _ /
......@@ -241,7 +241,7 @@ class RgSpace(Space):
return tuple(sorted(temp))
def copy(self):
return RgSpace(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 RgSpace(Space):
if codomain is None:
return False
if not isinstance(codomain, RgSpace):
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 RgSpace(Space):
complexity = {0: 1, 1: 0, 2: 2}[self.paradict['complexity']]
harmonic = bool(not self.harmonic)
new_space = RgSpace(shape,
new_space = RGSpace(shape,
zerocenter=cozerocenter,
complexity=complexity,
distances=distances,
......@@ -541,7 +541,7 @@ class RgSpace(Space):
# Case 1: uniform distribution over {-1,+1}/{1,i,-1,-i}
if arg['random'] == 'pm1' and not hermitianizeQ:
sample = super(RgSpace, 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 RgSpace(Space):
# Case 2: normal distribution with zero-mean and a given standard
# deviation or variance
elif arg['random'] == 'gau':
sample = super(RgSpace, 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(RgSpace, 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 RgSpace(Space):
fig.canvas.draw()
def __repr__(self):
string = super(RgSpace, 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.RgSpace((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.RgSpace((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.RgSpace((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.RgSpace(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.RgSpace((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.RgSpace((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.RgSpace((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.RgSpace((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.RgSpace((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.RgSpace(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.RgSpace(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.RgSpace(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(
......
......@@ -14,7 +14,7 @@ from d2o import distributed_data_object
from nifty import Space, \
point_space
from nifty.rg import RgSpace
from nifty.rg import RGSpace
from nifty.lm import *
......@@ -95,7 +95,7 @@ for param in itertools.product([(1,), (4, 6), (5, 8)],
[False],
DATAMODELS['rg_space'],
fft_modules):
space_list += [[RgSpace(shape=param[0],
space_list += [[RGSpace(shape=param[0],
zerocenter=param[1],
complexity=param[2],
distances=param[3],
......@@ -106,10 +106,10 @@ for param in itertools.product([(1,), (4, 6), (5, 8)],
def generate_space_with_size(name, num):
space_dict = {'space': Space(),
'point_space': point_space(num),
'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),
'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 = RgSpace(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 = RgSpace(shape=shape, zerocenter=zerocenter,