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,\ ...@@ -60,7 +60,7 @@ from power import PowerSpace,\
## optional submodule `rg` ## optional submodule `rg`
try: try:
from rg import RgSpace,\ 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 LmSpace,\ 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 GlSpace 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 HpSpace 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 = RgSpace((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,7 @@ about.infos.off() ...@@ -48,7 +48,7 @@ about.infos.off()
##----------------------------------------------------------------------------- ##-----------------------------------------------------------------------------
# (global) Faraday map # (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"))) "demo_faraday_map.npy")))
##----------------------------------------------------------------------------- ##-----------------------------------------------------------------------------
...@@ -98,8 +98,8 @@ def run(projection=False, power=False): ...@@ -98,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 = GlSpace(384, nlon=768) # auxiliary gl_space y_space = GLSpace(384, nlon=768) # auxiliary gl_space
z_space = RgSpace([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 = RgSpace(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 = HpSpace(32) x_space = HPSpace(32)
#x_space = GlSpace(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,7 @@ from nifty.operators.nifty_minimization import steepest_descent_new ...@@ -55,7 +55,7 @@ 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 = RgSpace([256, 256]) # define x_space = RGSpace([256, 256]) # define
# signal space # signal space
k_space = x_space.get_codomain() # get conjugate space k_space = x_space.get_codomain() # get conjugate space
......
...@@ -39,7 +39,7 @@ if __name__ == "__main__": ...@@ -39,7 +39,7 @@ 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 = RgSpace([128,]) # x_space = RGSpace([128,]) #
# define signal space # define signal space
k_space = x_space.get_codomain() # get conjugate space k_space = x_space.get_codomain() # get conjugate space
......
...@@ -38,8 +38,8 @@ except(ImportError): ...@@ -38,8 +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 lm_space import LmSpace ## import lm & hp from lm_space import LMSpace ## import lm & hp
from hp_space import HpSpace from hp_space import HPSpace
## TODO: change about ## TODO: change about
else: else:
try: try:
...@@ -49,13 +49,13 @@ else: ...@@ -49,13 +49,13 @@ 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 gl_space import GlSpace ## import lm & gl from gl_space import GLSpace ## import lm & gl
from lm_space import LmSpace from lm_space import LMSpace
else: else:
from gl_space import GlSpace ##import all from gl_space import GLSpace ##import all
from lm_space import LmSpace from lm_space import LMSpace
from hp_space import HpSpace 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
...@@ -7,6 +7,8 @@ from matplotlib.ticker import LogFormatter as lf ...@@ -7,6 +7,8 @@ from matplotlib.ticker import LogFormatter as lf
from d2o import STRATEGIES as DISTRIBUTION_STRATEGIES from d2o import STRATEGIES as DISTRIBUTION_STRATEGIES
from nifty.lm import LMSpace
from nifty.space import Space from nifty.space import Space
from nifty.config import about,\ from nifty.config import about,\
nifty_configuration as gc,\ nifty_configuration as gc,\
...@@ -18,7 +20,8 @@ gl = gdi.get('libsharp_wrapper_gl') ...@@ -18,7 +20,8 @@ gl = gdi.get('libsharp_wrapper_gl')
GL_DISTRIBUTION_STRATEGIES = DISTRIBUTION_STRATEGIES['global'] GL_DISTRIBUTION_STRATEGIES = DISTRIBUTION_STRATEGIES['global']
class GlSpace(Space):
class GLSpace(Space):
""" """
.. __ .. __
.. / / .. / /
...@@ -129,9 +132,9 @@ class GlSpace(Space): ...@@ -129,9 +132,9 @@ class GlSpace(Space):
self.paradict['nlon'] = x[1] self.paradict['nlon'] = x[1]
def copy(self): def copy(self):
return GlSpace(nlat=self.paradict['nlat'], return GLSpace(nlat=self.paradict['nlat'],
nlon=self.paradict['nlon'], nlon=self.paradict['nlon'],
dtype=self.dtype) dtype=self.dtype)
@property @property
def shape(self): def shape(self):
...@@ -205,7 +208,7 @@ class GlSpace(Space): ...@@ -205,7 +208,7 @@ class GlSpace(Space):
if not isinstance(codomain, Space): if not isinstance(codomain, Space):
raise TypeError(about._errors.cstring("ERROR: invalid input.")) raise TypeError(about._errors.cstring("ERROR: invalid input."))
if isinstance(codomain, LmSpace): if isinstance(codomain, LMSpace):
nlat = self.paradict['nlat'] nlat = self.paradict['nlat']
nlon = self.paradict['nlon'] nlon = self.paradict['nlon']
lmax = codomain.paradict['lmax'] lmax = codomain.paradict['lmax']
...@@ -233,9 +236,9 @@ class GlSpace(Space): ...@@ -233,9 +236,9 @@ class GlSpace(Space):
mmax = nlat-1 mmax = nlat-1
# lmax,mmax = nlat-1,nlat-1 # lmax,mmax = nlat-1,nlat-1
if self.dtype == np.dtype('float32'): 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: 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): def get_random_values(self, **kwargs):
""" """
...@@ -308,7 +311,7 @@ class GlSpace(Space): ...@@ -308,7 +311,7 @@ class GlSpace(Space):
sample = self.calc_weight(sample, power=0.5) sample = self.calc_weight(sample, power=0.5)
else: else:
sample = super(GlSpace, self).get_random_values(**arg) sample = super(GLSpace, self).get_random_values(**arg)
# elif(arg['random'] == "uni"): # elif(arg['random'] == "uni"):
...@@ -404,7 +407,7 @@ class GlSpace(Space): ...@@ -404,7 +407,7 @@ class GlSpace(Space):
raise ValueError(about._errors.cstring( raise ValueError(about._errors.cstring(
"ERROR: unsupported codomain.")) "ERROR: unsupported codomain."))
if isinstance(codomain, LmSpace): if isinstance(codomain, LMSpace):
# weight if discrete # weight if discrete
if self.discrete: if self.discrete:
......
...@@ -38,6 +38,8 @@ import pylab as pl ...@@ -38,6 +38,8 @@ import pylab as pl
from d2o import STRATEGIES as DISTRIBUTION_STRATEGIES from d2o import STRATEGIES as DISTRIBUTION_STRATEGIES
from nifty.lm import LMSpace
from nifty.space import Space from nifty.space import Space
from nifty.field import Field from nifty.field import Field
...@@ -51,7 +53,8 @@ hp = gdi.get('healpy') ...@@ -51,7 +53,8 @@ hp = gdi.get('healpy')
HP_DISTRIBUTION_STRATEGIES = DISTRIBUTION_STRATEGIES['global'] HP_DISTRIBUTION_STRATEGIES = DISTRIBUTION_STRATEGIES['global']
class HpSpace(Space):
class HPSpace(Space):
""" """
.. __ .. __
.. / / .. / /
...@@ -148,7 +151,7 @@ class HpSpace(Space): ...@@ -148,7 +151,7 @@ class HpSpace(Space):
self.paradict['nside'] = x[0] self.paradict['nside'] = x[0]
def copy(self): def copy(self):
return HpSpace(nside=self.paradict['nside']) return HPSpace(nside=self.paradict['nside'])
@property @property
def shape(self): def shape(self):
...@@ -221,7 +224,7 @@ class HpSpace(Space): ...@@ -221,7 +224,7 @@ class HpSpace(Space):
if not isinstance(codomain, Space): if not isinstance(codomain, Space):
raise TypeError(about._errors.cstring("ERROR: invalid input.")) raise TypeError(about._errors.cstring("ERROR: invalid input."))
if isinstance(codomain, LmSpace): if isinstance(codomain, LMSpace):
nside = self.paradict['nside'] nside = self.paradict['nside']
lmax = codomain.paradict['lmax'] lmax = codomain.paradict['lmax']
mmax = codomain.paradict['mmax'] mmax = codomain.paradict['mmax']
...@@ -244,7 +247,7 @@ class HpSpace(Space): ...@@ -244,7 +247,7 @@ class HpSpace(Space):
""" """
lmax = 3*self.paradict['nside'] - 1 lmax = 3*self.paradict['nside'] - 1
mmax = lmax 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): def get_random_values(self, **kwargs):
""" """
...@@ -312,7 +315,7 @@ class HpSpace(Space): ...@@ -312,7 +315,7 @@ class HpSpace(Space):
sample = self.calc_weight(sample, power=0.5) sample = self.calc_weight(sample, power=0.5)
else: else:
sample = super(HpSpace, self).get_random_values(**arg) sample = super(HPSpace, self).get_random_values(**arg)
# elif arg['random'] == "uni": # elif arg['random'] == "uni":
...@@ -369,7 +372,7 @@ class HpSpace(Space): ...@@ -369,7 +372,7 @@ class HpSpace(Space):
np_x = x.get_full_data() np_x = x.get_full_data()
if isinstance(codomain, LmSpace): if isinstance(codomain, LMSpace):
# weight if discrete # weight if discrete
if self.discrete: if self.discrete:
x = self.calc_weight(x, power=-0.5) x = self.calc_weight(x, power=-0.5)
......
...@@ -10,8 +10,8 @@ from matplotlib.ticker import LogFormatter as lf ...@@ -10,8 +10,8 @@ from matplotlib.ticker import LogFormatter as lf
from d2o import STRATEGIES as DISTRIBUTION_STRATEGIES from d2o import STRATEGIES as DISTRIBUTION_STRATEGIES
from nifty.space import Space from nifty.space import Space
from hp_space import HpSpace from hp_space import HPSpace
from gl_space import GlSpace from gl_space import GLSpace
from nifty.config import about,\ from nifty.config import about,\
nifty_configuration as gc,\ nifty_configuration as gc,\
dependency_injector as gdi dependency_injector as gdi
...@@ -25,7 +25,7 @@ hp = gdi.get('healpy') ...@@ -25,7 +25,7 @@ hp = gdi.get('healpy')
LM_DISTRIBUTION_STRATEGIES = DISTRIBUTION_STRATEGIES['global'] LM_DISTRIBUTION_STRATEGIES = DISTRIBUTION_STRATEGIES['global']
class LmSpace(Space): class LMSpace(Space):
""" """
.. __ .. __
.. / / .. / /
...@@ -168,9 +168,9 @@ class LmSpace(Space): ...@@ -168,9 +168,9 @@ class LmSpace(Space):
return tuple(sorted(temp)) return tuple(sorted(temp))
def copy(self): def copy(self):
return LmSpace(lmax=self.paradict['lmax'], return LMSpace(lmax=self.paradict['lmax'],
mmax=self.paradict['mmax'], mmax=self.paradict['mmax'],
dtype=self.dtype) dtype=self.dtype)
@property @property
def shape(self): def shape(self):
...@@ -294,7 +294,7 @@ class LmSpace(Space): ...@@ -294,7 +294,7 @@ class LmSpace(Space):
raise TypeError(about._errors.cstring( raise TypeError(about._errors.cstring(
"ERROR: The given codomain must be a nifty lm_space.")) "ERROR: The given codomain must be a nifty lm_space."))
elif isinstance(codomain, GlSpace): elif isinstance(codomain, GLSpace):
# lmax==mmax # lmax==mmax
# nlat==lmax+1 # nlat==lmax+1
# nlon==2*lmax+1 # nlon==2*lmax+1
...@@ -303,7 +303,7 @@ class LmSpace(Space): ...@@ -303,7 +303,7 @@ class LmSpace(Space):
(codomain.paradict['nlon'] == 2*self.paradict['lmax']+1)): (codomain.paradict['nlon'] == 2*self.paradict['lmax']+1)):
return True return True
elif isinstance(codomain, HpSpace): elif isinstance(codomain, HPSpace):
# lmax==mmax # lmax==mmax
# 3*nside-1==lmax # 3*nside-1==lmax
if ((self.paradict['lmax'] == self.paradict['mmax']) and if ((self.paradict['lmax'] == self.paradict['mmax']) and
...@@ -353,11 +353,11 @@ class LmSpace(Space): ...@@ -353,11 +353,11 @@ class LmSpace(Space):
raise NotImplementedError raise NotImplementedError
nlat = self.paradict['lmax'] + 1 nlat = self.paradict['lmax'] + 1
nlon = self.paradict['lmax'] * 2 + 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']): elif coname == 'hp' or (coname is None and not gc['lm2gl']):
nside = (self.paradict['lmax']+1) // 3 nside = (self.paradict['lmax']+1) // 3
return HpSpace(nside=nside) return HPSpace(nside=nside)
else: else:
raise ValueError(about._errors.cstring( raise ValueError(about._errors.cstring(
...@@ -434,7 +434,7 @@ class LmSpace(Space): ...@@ -434,7 +434,7 @@ class LmSpace(Space):
sample = gl.synalm(arg['spec'], lmax=lmax, mmax=mmax) sample = gl.synalm(arg['spec'], lmax=lmax, mmax=mmax)
else: else:
sample = super(LmSpace, self).get_random_values(**arg) sample = super(LMSpace, self).get_random_values(**arg)
# elif arg['random'] == "uni": # elif arg['random'] == "uni":
# x = random.uni(dtype=self.dtype, # x = random.uni(dtype=self.dtype,
...@@ -528,7 +528,7 @@ class LmSpace(Space): ...@@ -528,7 +528,7 @@ class LmSpace(Space):
np_x = x.get_full_data() np_x = x.get_full_data()
if isinstance(codomain, GlSpace): if isinstance(codomain, GLSpace):
nlat = codomain.paradict['nlat'] nlat = codomain.paradict['nlat']
nlon = codomain.paradict['nlon'] nlon = codomain.paradict['nlon']
lmax = self.paradict['lmax'] lmax = self.paradict['lmax']
...@@ -543,7 +543,7 @@ class LmSpace(Space): ...@@ -543,7 +543,7 @@ class LmSpace(Space):
lmax=lmax, mmax=mmax, cl=False) lmax=lmax, mmax=mmax, cl=False)
Tx = codomain.cast(np_Tx) Tx = codomain.cast(np_Tx)
elif isinstance(codomain, HpSpace): elif isinstance(codomain, HPSpace):
nside = codomain.paradict['nside'] nside = codomain.paradict['nside']
lmax = self.paradict['lmax'] lmax = self.paradict['lmax']
mmax = self.paradict['mmax'] mmax = self.paradict['mmax']
......
...@@ -27,7 +27,7 @@ from nifty.field import Field ...@@ -27,7 +27,7 @@ from nifty.field import Field
from nifty.nifty_simple_math import sqrt, exp, log 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 This function is designed to convert a theoretical/statistical power
spectrum of a log-normal field to the theoretical power spectrum of spectrum of a log-normal field to the theoretical power spectrum of
......
...@@ -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='fftw', def __init__(self, distribution_strategy, dtype=np.dtype('float'),
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(
......
...@@ -13,13 +13,13 @@ class RGPowerSpace(PowerSpace): ...@@ -13,13 +13,13 @@ class RGPowerSpace(PowerSpace):
binbounds=None): binbounds=None):
self.dtype = np.dtype(dtype) self.dtype = np.dtype(dtype)
self.paradict = rg_power_space_paradict( self.paradict = rg_power_space_paradict(
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 RgSpace,\ 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 RgSpace(Space): class RGSpace(Space):
""" """
.. _____ _______ .. _____ _______
.. / __/ / _ / .. / __/ / _ /
...@@ -241,7 +241,7 @@ class RgSpace(Space): ...@@ -241,7 +241,7 @@ class RgSpace(Space):
return tuple(sorted(temp)) return tuple(sorted(temp))
def copy(self): def copy(self):
return RgSpace(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 RgSpace(Space): ...@@ -353,7 +353,7 @@ class RgSpace(Space):
if codomain is None: if codomain is None:
return False