Commit e7fd7bd1 authored by theos's avatar theos

Renamed field to Field; removed space; point_space is now called Space.

parent 25d4a36c
...@@ -38,17 +38,19 @@ from config import about,\ ...@@ -38,17 +38,19 @@ from config import about,\
from d2o import distributed_data_object, d2o_librarian from d2o import distributed_data_object, d2o_librarian
from nifty_cmaps import ncmap from nifty_cmaps import ncmap
from nifty_field import field from field import Field
from nifty_core import space,\ from space import Space
point_space
# this line exists for compatibility reasons
# TODO: Remove this once the transition to field types is done.
from space import Space as point_space
from nifty_random import random from nifty_random import random
from nifty_simple_math import * from nifty_simple_math import *
from nifty_utilities import * from nifty_utilities import *
from nifty_paradict import space_paradict,\ from nifty_paradict import space_paradict,\
point_space_paradict,\ nested_space_paradict
nested_space_paradict
from field_types import FieldType,\ from field_types import FieldType,\
FieldArray FieldArray
......
...@@ -112,7 +112,7 @@ class problem(object): ...@@ -112,7 +112,7 @@ class problem(object):
Parameters Parameters
---------- ----------
newspace : {scalar, list, array, field, function}, *optional* newspace : {scalar, list, array, Field, function}, *optional*
Assumed power spectrum (default: k ** -2). Assumed power spectrum (default: k ** -2).
""" """
...@@ -135,7 +135,7 @@ class problem(object): ...@@ -135,7 +135,7 @@ class problem(object):
Parameters Parameters
---------- ----------
newspace : {scalar, list, array, field, function}, *optional* newspace : {scalar, list, array, Field, function}, *optional*
Initial power spectrum (default: k ** -2). Initial power spectrum (default: k ** -2).
q : {scalar, list, array}, *optional* q : {scalar, list, array}, *optional*
Spectral scale parameter of the assumed inverse-Gamme prior Spectral scale parameter of the assumed inverse-Gamme prior
...@@ -210,7 +210,7 @@ class problem(object): ...@@ -210,7 +210,7 @@ class problem(object):
self.s.plot(title="signal", save="img/signal.png") self.s.plot(title="signal", save="img/signal.png")
try: try:
d_ = field(self.z, val=self.d.val, target=self.k) d_ = Field(self.z, val=self.d.val, target=self.k)
d_.plot(title="data", vmin=self.s.min(), vmax=self.s.max(), d_.plot(title="data", vmin=self.s.min(), vmax=self.s.max(),
save="img/data.png") save="img/data.png")
except: except:
...@@ -240,7 +240,7 @@ class problem(object): ...@@ -240,7 +240,7 @@ class problem(object):
self.s.plot(title="signal") self.s.plot(title="signal")
## plot data ## plot data
try: try:
d_ = field(self.z, val=self.d.val, target=self.k) d_ = Field(self.z, val=self.d.val, target=self.k)
d_.plot(title="data", vmin=self.s.min(), vmax=self.s.max()) d_.plot(title="data", vmin=self.s.min(), vmax=self.s.max())
except: except:
pass pass
......
...@@ -72,7 +72,7 @@ if __name__ == "__main__": ...@@ -72,7 +72,7 @@ if __name__ == "__main__":
# some noise variance; e.g., signal-to-noise ratio of 1 # some noise variance; e.g., signal-to-noise ratio of 1
N = diagonal_operator(d_space, diag=s.var(), bare=True) # define noise covariance N = diagonal_operator(d_space, diag=s.var(), bare=True) # define noise covariance
n = N.get_random_field(domain=d_space) # generate noise n = N.get_random_Field(domain=d_space) # generate noise
d = R(s) + n # compute data d = R(s) + n # compute data
...@@ -84,7 +84,7 @@ if __name__ == "__main__": ...@@ -84,7 +84,7 @@ if __name__ == "__main__":
#m = D(j, tol=1E-8, limii=20, note=True, force=True) #m = D(j, tol=1E-8, limii=20, note=True, force=True)
ident = identity(x_space) ident = identity(x_space)
#xi = field(x_space, random='gau', target=k_space) #xi = Field(x_space, random='gau', target=k_space)
m = D(j, W=S, tol=1E-8, limii=100, note=True) m = D(j, W=S, tol=1E-8, limii=100, note=True)
...@@ -101,11 +101,11 @@ if __name__ == "__main__": ...@@ -101,11 +101,11 @@ if __name__ == "__main__":
mono=False, save = 'power_plot_s.png', nbin=1000, log=True, mono=False, save = 'power_plot_s.png', nbin=1000, log=True,
vmax = 100, vmin=10e-7) vmax = 100, vmin=10e-7)
d_ = field(x_space, val=d.val, target=k_space) d_ = Field(x_space, val=d.val, target=k_space)
d_.plot(title="data", vmin=s.min(), vmax=s.max(), save = 'plot_d.png') d_.plot(title="data", vmin=s.min(), vmax=s.max(), save = 'plot_d.png')
n_ = field(x_space, val=n.val, target=k_space) n_ = Field(x_space, val=n.val, target=k_space)
n_.plot(title="data", vmin=s.min(), vmax=s.max(), save = 'plot_n.png') n_.plot(title="data", vmin=s.min(), vmax=s.max(), save = 'plot_n.png')
......
...@@ -103,15 +103,15 @@ if __name__ == "__main__": ...@@ -103,15 +103,15 @@ if __name__ == "__main__":
return energy(x), gradient(x) return energy(x), gradient(x)
m = field(x_space, codomain=k_space) # reconstruct map m = Field(x_space, codomain=k_space) # reconstruct map
#with PyCallGraph(output=graphviz, config=config): #with PyCallGraph(output=graphviz, config=config):
m, convergence = steepest_descent(eggs=eggs, note=True)(m, tol=1E-3, clevel=3) m, convergence = steepest_descent(eggs=eggs, note=True)(m, tol=1E-3, clevel=3)
m = field(x_space, codomain=k_space) m = Field(x_space, codomain=k_space)
m, convergence = steepest_descent_new(energy, gradient, note=True)(m, tol=1E-3, clevel=3) m, convergence = steepest_descent_new(energy, gradient, note=True)(m, tol=1E-3, clevel=3)
#s.plot(title="signal") # plot signal #s.plot(title="signal") # plot signal
#d_ = field(x_space, val=d.val, target=k_space) #d_ = Field(x_space, val=d.val, target=k_space)
#d_.plot(title="data", vmin=s.min(), vmax=s.max()) # plot data #d_.plot(title="data", vmin=s.min(), vmax=s.max()) # plot data
#m.plot(title="reconstructed map", vmin=s.min(), vmax=s.max()) # plot map #m.plot(title="reconstructed map", vmin=s.min(), vmax=s.max()) # plot map
...@@ -79,7 +79,7 @@ if __name__ == "__main__": ...@@ -79,7 +79,7 @@ if __name__ == "__main__":
vminmax = {"vmin":1.5 * s.val.min(), "vmax":1.5 * s.val.max()} vminmax = {"vmin":1.5 * s.val.min(), "vmax":1.5 * s.val.max()}
s.plot(title="signal", **vminmax) # plot signal s.plot(title="signal", **vminmax) # plot signal
d_ = field(x_space, val=d.val, target=k_space) d_ = Field(x_space, val=d.val, target=k_space)
d_.plot(title="data", **vminmax) # plot data d_.plot(title="data", **vminmax) # plot data
m.plot(title="reconstructed map", error=D.diag(bare=True), **vminmax) # plot map m.plot(title="reconstructed map", error=D.diag(bare=True), **vminmax) # plot map
D.plot(title="information propagator", bare=True) # plot information propagator D.plot(title="information propagator", bare=True) # plot information propagator
......
...@@ -9,10 +9,10 @@ from nifty.config import about, \ ...@@ -9,10 +9,10 @@ from nifty.config import about, \
nifty_configuration as gc, \ nifty_configuration as gc, \
dependency_injector as gdi dependency_injector as gdi
from nifty.field_types import Field_type,\ from nifty.field_types import FieldType,\
Field_array FieldArray
from nifty.nifty_core import space from nifty.space import Space
import nifty.nifty_utilities as utilities import nifty.nifty_utilities as utilities
from nifty_random import random from nifty_random import random
...@@ -20,7 +20,7 @@ from nifty_random import random ...@@ -20,7 +20,7 @@ from nifty_random import random
POINT_DISTRIBUTION_STRATEGIES = DISTRIBUTION_STRATEGIES['global'] POINT_DISTRIBUTION_STRATEGIES = DISTRIBUTION_STRATEGIES['global']
class field(object): class Field(object):
""" """
.. ____ __ __ __ .. ____ __ __ __
.. / _/ /__/ / / / / .. / _/ /__/ / / / /
...@@ -133,7 +133,7 @@ class field(object): ...@@ -133,7 +133,7 @@ class field(object):
""" """
# If the given val was a field, try to cast it accordingly to the given # If the given val was a field, try to cast it accordingly to the given
# domain and codomain, etc... # domain and codomain, etc...
if isinstance(val, field): if isinstance(val, Field):
self._init_from_field(f=val, self._init_from_field(f=val,
domain=domain, domain=domain,
codomain=codomain, codomain=codomain,
...@@ -273,7 +273,7 @@ class field(object): ...@@ -273,7 +273,7 @@ class field(object):
elif not isinstance(domain, tuple): elif not isinstance(domain, tuple):
domain = (domain,) domain = (domain,)
for d in domain: for d in domain:
if not isinstance(d, space): if not isinstance(d, Space):
raise TypeError(about._errors.cstring( raise TypeError(about._errors.cstring(
"ERROR: Given domain contains something that is not a " "ERROR: Given domain contains something that is not a "
"nifty.space.")) "nifty.space."))
...@@ -286,7 +286,7 @@ class field(object): ...@@ -286,7 +286,7 @@ class field(object):
raise ValueError(about._errors.cstring( raise ValueError(about._errors.cstring(
"ERROR: domain and codomain do not have the same length.")) "ERROR: domain and codomain do not have the same length."))
for (cd, d) in zip(codomain, domain): for (cd, d) in zip(codomain, domain):
if not isinstance(cd, space): if not isinstance(cd, Space):
raise TypeError(about._errors.cstring( raise TypeError(about._errors.cstring(
"ERROR: Given codomain contains something that is not a" "ERROR: Given codomain contains something that is not a"
"nifty.space.")) "nifty.space."))
...@@ -302,9 +302,9 @@ class field(object): ...@@ -302,9 +302,9 @@ class field(object):
elif not isinstance(field_type, tuple): elif not isinstance(field_type, tuple):
field_type = (field_type,) field_type = (field_type,)
for ft in field_type: for ft in field_type:
if not isinstance(ft, Field_type): if not isinstance(ft, FieldType):
raise TypeError(about._errors.cstring( raise TypeError(about._errors.cstring(
"ERROR: Given object is not a nifty.Field_type.")) "ERROR: Given object is not a nifty.FieldType."))
return field_type return field_type
def _build_codomain(self, domain): def _build_codomain(self, domain):
...@@ -417,7 +417,7 @@ class field(object): ...@@ -417,7 +417,7 @@ class field(object):
kwargs == {}): kwargs == {}):
new_field = self._fast_copy_empty() new_field = self._fast_copy_empty()
else: else:
new_field = field(domain=domain, codomain=codomain, dtype=dtype, new_field = Field(domain=domain, codomain=codomain, dtype=dtype,
comm=comm, datamodel=datamodel, comm=comm, datamodel=datamodel,
field_type=field_type, **kwargs) field_type=field_type, **kwargs)
return new_field return new_field
...@@ -543,7 +543,7 @@ class field(object): ...@@ -543,7 +543,7 @@ class field(object):
Whether the method should raise a warning if information is Whether the method should raise a warning if information is
lost during casting (default: False). lost during casting (default: False).
""" """
if isinstance(x, field): if isinstance(x, Field):
x = x.get_val() x = x.get_val()
if dtype is None: if dtype is None:
...@@ -695,7 +695,7 @@ class field(object): ...@@ -695,7 +695,7 @@ class field(object):
return None return None
# Case 2: x is a field # Case 2: x is a field
elif isinstance(x, field): elif isinstance(x, Field):
for ind, sp in enumerate(self.domain): for ind, sp in enumerate(self.domain):
assert sp == x.domain[ind] assert sp == x.domain[ind]
...@@ -1281,8 +1281,8 @@ class field(object): ...@@ -1281,8 +1281,8 @@ class field(object):
def _binary_helper(self, other, op='None', inplace=False): def _binary_helper(self, other, op='None', inplace=False):
# if other is a field, make sure that the domains match # if other is a field, make sure that the domains match
if isinstance(other, field): if isinstance(other, Field):
other = field(domain=self.domain, other = Field(domain=self.domain,
val=other, val=other,
codomain=self.codomain, codomain=self.codomain,
copy=False) copy=False)
...@@ -1326,11 +1326,13 @@ class field(object): ...@@ -1326,11 +1326,13 @@ class field(object):
'mean': lambda y: getattr(y, 'mean')(axis=axis), 'mean': lambda y: getattr(y, 'mean')(axis=axis),
'std': lambda y: getattr(y, 'std')(axis=axis), 'std': lambda y: getattr(y, 'std')(axis=axis),
'var': lambda y: getattr(y, 'var')(axis=axis), 'var': lambda y: getattr(y, 'var')(axis=axis),
'argmin_nonflat': lambda y: getattr(y, 'argmin_nonflat')( 'argmin_nonflat': lambda y: getattr(y,
axis=axis), 'argmin_nonflat')(
axis=axis),
'argmin': lambda y: getattr(y, 'argmin')(axis=axis), 'argmin': lambda y: getattr(y, 'argmin')(axis=axis),
'argmax_nonflat': lambda y: getattr(y, 'argmax_nonflat')( 'argmax_nonflat': lambda y: getattr(y,
axis=axis), 'argmax_nonflat')(
axis=axis),
'argmax': lambda y: getattr(y, 'argmax')(axis=axis), 'argmax': lambda y: getattr(y, 'argmax')(axis=axis),
'conjugate': lambda y: getattr(y, 'conjugate')(), 'conjugate': lambda y: getattr(y, 'conjugate')(),
'sum': lambda y: getattr(y, 'sum')(axis=axis), 'sum': lambda y: getattr(y, 'sum')(axis=axis),
...@@ -1451,6 +1453,6 @@ class field(object): ...@@ -1451,6 +1453,6 @@ class field(object):
return self._binary_helper(other, op='gt') return self._binary_helper(other, op='gt')
class EmptyField(field): class EmptyField(Field):
def __init__(self): def __init__(self):
pass pass
...@@ -41,10 +41,9 @@ from matplotlib.ticker import LogFormatter as lf ...@@ -41,10 +41,9 @@ from matplotlib.ticker import LogFormatter as lf
from d2o import STRATEGIES as DISTRIBUTION_STRATEGIES from d2o import STRATEGIES as DISTRIBUTION_STRATEGIES
from nifty.nifty_core import space,\ from nifty.nifty_core import Space
point_space
from nifty.nifty_field import field from nifty.field import Field
from nifty.config import about,\ from nifty.config import about,\
nifty_configuration as gc,\ nifty_configuration as gc,\
...@@ -63,7 +62,7 @@ GL_DISTRIBUTION_STRATEGIES = DISTRIBUTION_STRATEGIES['global'] ...@@ -63,7 +62,7 @@ GL_DISTRIBUTION_STRATEGIES = DISTRIBUTION_STRATEGIES['global']
HP_DISTRIBUTION_STRATEGIES = DISTRIBUTION_STRATEGIES['global'] HP_DISTRIBUTION_STRATEGIES = DISTRIBUTION_STRATEGIES['global']
class lm_space(point_space): class lm_space(Space):
""" """
.. __ .. __
.. / / .. / /
...@@ -277,7 +276,7 @@ class lm_space(point_space): ...@@ -277,7 +276,7 @@ class lm_space(point_space):
mol[self.paradict['lmax'] + 1:] = 2 # redundant: (l,m) and (l,-m) mol[self.paradict['lmax'] + 1:] = 2 # redundant: (l,m) and (l,-m)
return mol return mol
def _complement_cast(self, x, axis=None, **kwargs): def complement_cast(self, x, axis=None, **kwargs):
if axis is None: if axis is None:
lmax = self.paradict['lmax'] lmax = self.paradict['lmax']
complexity_mask = x[:lmax+1].iscomplex() complexity_mask = x[:lmax+1].iscomplex()
...@@ -912,7 +911,7 @@ class lm_space(point_space): ...@@ -912,7 +911,7 @@ class lm_space(point_space):
return l, m return l, m
class gl_space(point_space): class gl_space(Space):
""" """
.. __ .. __
.. / / .. / /
...@@ -1256,12 +1255,13 @@ class gl_space(point_space): ...@@ -1256,12 +1255,13 @@ class gl_space(point_space):
p=np.float32(power), p=np.float32(power),
nlat=nlat, nlon=nlon, nlat=nlat, nlon=nlon,
overwrite=False) overwrite=False)
return self.cast(np_result) # return self.cast(np_result)
return np_result
def get_weight(self, power=1): def get_weight(self, power=1):
# TODO: Check if this function is compatible to the rest of nifty # TODO: Check if this function is compatible to the rest of nifty
# TODO: Can this be done more efficiently? # TODO: Can this be done more efficiently?
dummy = self.dtype(1) dummy = self.dtype.type(1)
weighted_dummy = self.calc_weight(dummy, power=power) weighted_dummy = self.calc_weight(dummy, power=power)
return weighted_dummy / dummy return weighted_dummy / dummy
...@@ -1571,7 +1571,7 @@ class gl_space(point_space): ...@@ -1571,7 +1571,7 @@ class gl_space(point_space):
fig.canvas.draw() fig.canvas.draw()
class hp_space(point_space): class hp_space(Space):
""" """
.. __ .. __
.. / / .. / /
...@@ -2082,11 +2082,11 @@ class hp_space(point_space): ...@@ -2082,11 +2082,11 @@ class hp_space(point_space):
if(isinstance(other, tuple)): if(isinstance(other, tuple)):
other = list(other) other = list(other)
for ii in xrange(len(other)): for ii in xrange(len(other)):
if(isinstance(other[ii], field)): if(isinstance(other[ii], Field)):
other[ii] = other[ii].power(**kwargs) other[ii] = other[ii].power(**kwargs)
else: else:
other[ii] = self.enforce_power(other[ii]) other[ii] = self.enforce_power(other[ii])
elif(isinstance(other, field)): elif(isinstance(other, Field)):
other = [other.power(**kwargs)] other = [other.power(**kwargs)]
else: else:
other = [self.enforce_power(other)] other = [self.enforce_power(other)]
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
import numpy as np import numpy as np
from numpy import pi from numpy import pi
from nifty.config import about from nifty.config import about
from nifty.nifty_field import field from nifty.field import Field
from nifty.nifty_simple_math import sqrt, exp, log from nifty.nifty_simple_math import sqrt, exp, log
...@@ -71,7 +71,7 @@ def power_backward_conversion_lm(k_space,p,mean=None): ...@@ -71,7 +71,7 @@ def power_backward_conversion_lm(k_space,p,mean=None):
p[0] = 4*pi*mean**2 p[0] = 4*pi*mean**2
klen = k_space.get_power_indices()[0] klen = k_space.get_power_indices()[0]
C_0_Omega = field(k_space,val=0) C_0_Omega = Field(k_space,val=0)
C_0_Omega.val[:len(klen)] = p*sqrt(2*klen+1)/sqrt(4*pi) C_0_Omega.val[:len(klen)] = p*sqrt(2*klen+1)/sqrt(4*pi)
C_0_Omega = C_0_Omega.transform() C_0_Omega = C_0_Omega.transform()
...@@ -130,7 +130,7 @@ def power_forward_conversion_lm(k_space,p,mean=0): ...@@ -130,7 +130,7 @@ def power_forward_conversion_lm(k_space,p,mean=0):
""" """
m = mean m = mean
klen = k_space.get_power_indices()[0] klen = k_space.get_power_indices()[0]
C_0_Omega = field(k_space,val=0) C_0_Omega = Field(k_space,val=0)
C_0_Omega.val[:len(klen)] = p*sqrt(2*klen+1)/sqrt(4*pi) C_0_Omega.val[:len(klen)] = p*sqrt(2*klen+1)/sqrt(4*pi)
C_0_Omega = C_0_Omega.transform() C_0_Omega = C_0_Omega.transform()
......
...@@ -48,22 +48,6 @@ class space_paradict(object): ...@@ -48,22 +48,6 @@ class space_paradict(object):
return result_hash return result_hash
class point_space_paradict(space_paradict):
def __setitem__(self, key, arg):
if key is not 'num':
raise ValueError(about._errors.cstring(
"ERROR: Unsupported point_space parameter"))
if not np.isscalar(arg):
raise ValueError(about._errors.cstring(
"ERROR: 'num' parameter must be scalar. Got: " + str(arg)))
if abs(arg) != arg:
raise ValueError(about._errors.cstring(
"ERROR: 'num' parameter must be positive. Got: " + str(arg)))
temp = np.int(arg)
self.parameters.__setitem__(key, temp)
class rg_space_paradict(space_paradict): class rg_space_paradict(space_paradict):
def __init__(self, shape, complexity, zerocenter): def __init__(self, shape, complexity, zerocenter):
...@@ -218,165 +202,3 @@ class hp_space_paradict(space_paradict): ...@@ -218,165 +202,3 @@ class hp_space_paradict(space_paradict):
raise ValueError(about._errors.cstring( raise ValueError(about._errors.cstring(
"ERROR: invalid parameter ( nside <> 2**n ).")) "ERROR: invalid parameter ( nside <> 2**n )."))
self.parameters.__setitem__(key, temp) self.parameters.__setitem__(key, temp)
###################
#
#
# class _space(object):
# def __init__(self):
# self.paradict = space_paradict(default=123)
# #self.para = [1,2,3]
#
# @property
# def para(self):
# return self.paradict['default']
# #return self.distributed_val
#
# @para.setter
# def para(self, x):
# self.paradict['default'] = x
#
###################
###################
#
#
#
# class _point_space(object):
# def __init__(self):
# self.paradict = point_space_paradict()
# self.para = [10]
#
# @property
# def para(self):
# temp = np.array([self.paradict['num']], dtype=int)
# return temp
# #return self.distributed_val
#
# @para.setter
# def para(self, x):
# self.paradict['num'] = x
#
###################
###################
#
#
# class _rg_space(object):
# def __init__(self):
# self.paradict = rg_space_paradict(num=[10,100,200])
#
# @property
# def para(self):
# temp = np.array(self.paradict['num'] + \
# [self.paradict['hermitian']] + \
# self.paradict['zerocenter'], dtype=int)
# return temp
#
#
# @para.setter
# def para(self, x):
# self.paradict['num'] = x[:(np.size(x)-1)//2]
# self.paradict['zerocenter'] = x[(np.size(x)+1)//2:]
# self.paradict['complexity'] = x[(np.size(x)-1)//2]
#
###################
###################
#
# class _nested_space(object):
# def __init__(self):
# self.paradict = nested_space_paradict(ndim=10)
# for i in range(10):