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,\
from d2o import distributed_data_object, d2o_librarian
from nifty_cmaps import ncmap
from nifty_field import field
from nifty_core import space,\
point_space
from field import Field
from space import 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_simple_math import *
from nifty_utilities import *
from nifty_paradict import space_paradict,\
point_space_paradict,\
nested_space_paradict
nested_space_paradict
from field_types import FieldType,\
FieldArray
......
......@@ -112,7 +112,7 @@ class problem(object):
Parameters
----------
newspace : {scalar, list, array, field, function}, *optional*
newspace : {scalar, list, array, Field, function}, *optional*
Assumed power spectrum (default: k ** -2).
"""
......@@ -135,7 +135,7 @@ class problem(object):
Parameters
----------
newspace : {scalar, list, array, field, function}, *optional*
newspace : {scalar, list, array, Field, function}, *optional*
Initial power spectrum (default: k ** -2).
q : {scalar, list, array}, *optional*
Spectral scale parameter of the assumed inverse-Gamme prior
......@@ -210,7 +210,7 @@ class problem(object):
self.s.plot(title="signal", save="img/signal.png")
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(),
save="img/data.png")
except:
......@@ -240,7 +240,7 @@ class problem(object):
self.s.plot(title="signal")
## plot data
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())
except:
pass
......
......@@ -72,7 +72,7 @@ if __name__ == "__main__":
# 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 = 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
......@@ -84,7 +84,7 @@ if __name__ == "__main__":
#m = D(j, tol=1E-8, limii=20, note=True, force=True)
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)
......@@ -101,11 +101,11 @@ if __name__ == "__main__":
mono=False, save = 'power_plot_s.png', nbin=1000, log=True,
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')
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')
......
......@@ -103,15 +103,15 @@ if __name__ == "__main__":
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):
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)
#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
#m.plot(title="reconstructed map", vmin=s.min(), vmax=s.max()) # plot map
......@@ -79,7 +79,7 @@ if __name__ == "__main__":
vminmax = {"vmin":1.5 * s.val.min(), "vmax":1.5 * s.val.max()}
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
m.plot(title="reconstructed map", error=D.diag(bare=True), **vminmax) # plot map
D.plot(title="information propagator", bare=True) # plot information propagator
......
......@@ -9,10 +9,10 @@ from nifty.config import about, \
nifty_configuration as gc, \
dependency_injector as gdi
from nifty.field_types import Field_type,\
Field_array
from nifty.field_types import FieldType,\
FieldArray
from nifty.nifty_core import space
from nifty.space import Space
import nifty.nifty_utilities as utilities
from nifty_random import random
......@@ -20,7 +20,7 @@ from nifty_random import random
POINT_DISTRIBUTION_STRATEGIES = DISTRIBUTION_STRATEGIES['global']
class field(object):
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
# domain and codomain, etc...
if isinstance(val, field):
if isinstance(val, Field):
self._init_from_field(f=val,
domain=domain,
codomain=codomain,
......@@ -273,7 +273,7 @@ class field(object):
elif not isinstance(domain, tuple):
domain = (domain,)
for d in domain:
if not isinstance(d, space):
if not isinstance(d, Space):
raise TypeError(about._errors.cstring(
"ERROR: Given domain contains something that is not a "
"nifty.space."))
......@@ -286,7 +286,7 @@ class field(object):
raise ValueError(about._errors.cstring(
"ERROR: domain and codomain do not have the same length."))
for (cd, d) in zip(codomain, domain):
if not isinstance(cd, space):
if not isinstance(cd, Space):
raise TypeError(about._errors.cstring(
"ERROR: Given codomain contains something that is not a"
"nifty.space."))
......@@ -302,9 +302,9 @@ class field(object):
elif not isinstance(field_type, tuple):
field_type = (field_type,)
for ft in field_type:
if not isinstance(ft, Field_type):
if not isinstance(ft, FieldType):
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
def _build_codomain(self, domain):
......@@ -417,7 +417,7 @@ class field(object):
kwargs == {}):
new_field = self._fast_copy_empty()
else:
new_field = field(domain=domain, codomain=codomain, dtype=dtype,
new_field = Field(domain=domain, codomain=codomain, dtype=dtype,
comm=comm, datamodel=datamodel,
field_type=field_type, **kwargs)
return new_field
......@@ -543,7 +543,7 @@ class field(object):
Whether the method should raise a warning if information is
lost during casting (default: False).
"""
if isinstance(x, field):
if isinstance(x, Field):
x = x.get_val()
if dtype is None:
......@@ -695,7 +695,7 @@ class field(object):
return None
# Case 2: x is a field
elif isinstance(x, field):
elif isinstance(x, Field):
for ind, sp in enumerate(self.domain):
assert sp == x.domain[ind]
......@@ -1281,8 +1281,8 @@ class field(object):
def _binary_helper(self, other, op='None', inplace=False):
# if other is a field, make sure that the domains match
if isinstance(other, field):
other = field(domain=self.domain,
if isinstance(other, Field):
other = Field(domain=self.domain,
val=other,
codomain=self.codomain,
copy=False)
......@@ -1326,11 +1326,13 @@ class field(object):
'mean': lambda y: getattr(y, 'mean')(axis=axis),
'std': lambda y: getattr(y, 'std')(axis=axis),
'var': lambda y: getattr(y, 'var')(axis=axis),
'argmin_nonflat': lambda y: getattr(y, 'argmin_nonflat')(
axis=axis),
'argmin_nonflat': lambda y: getattr(y,
'argmin_nonflat')(
axis=axis),
'argmin': lambda y: getattr(y, 'argmin')(axis=axis),
'argmax_nonflat': lambda y: getattr(y, 'argmax_nonflat')(
axis=axis),
'argmax_nonflat': lambda y: getattr(y,
'argmax_nonflat')(
axis=axis),
'argmax': lambda y: getattr(y, 'argmax')(axis=axis),
'conjugate': lambda y: getattr(y, 'conjugate')(),
'sum': lambda y: getattr(y, 'sum')(axis=axis),
......@@ -1451,6 +1453,6 @@ class field(object):
return self._binary_helper(other, op='gt')
class EmptyField(field):
class EmptyField(Field):
def __init__(self):
pass
......@@ -41,10 +41,9 @@ from matplotlib.ticker import LogFormatter as lf
from d2o import STRATEGIES as DISTRIBUTION_STRATEGIES
from nifty.nifty_core import space,\
point_space
from nifty.nifty_core import Space
from nifty.nifty_field import field
from nifty.field import Field
from nifty.config import about,\
nifty_configuration as gc,\
......@@ -63,7 +62,7 @@ GL_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):
mol[self.paradict['lmax'] + 1:] = 2 # redundant: (l,m) and (l,-m)
return mol
def _complement_cast(self, x, axis=None, **kwargs):
def complement_cast(self, x, axis=None, **kwargs):
if axis is None:
lmax = self.paradict['lmax']
complexity_mask = x[:lmax+1].iscomplex()
......@@ -912,7 +911,7 @@ class lm_space(point_space):
return l, m
class gl_space(point_space):
class gl_space(Space):
"""
.. __
.. / /
......@@ -1256,12 +1255,13 @@ class gl_space(point_space):
p=np.float32(power),
nlat=nlat, nlon=nlon,
overwrite=False)
return self.cast(np_result)
# return self.cast(np_result)
return np_result
def get_weight(self, power=1):
# TODO: Check if this function is compatible to the rest of nifty
# TODO: Can this be done more efficiently?
dummy = self.dtype(1)
dummy = self.dtype.type(1)
weighted_dummy = self.calc_weight(dummy, power=power)
return weighted_dummy / dummy
......@@ -1571,7 +1571,7 @@ class gl_space(point_space):
fig.canvas.draw()
class hp_space(point_space):
class hp_space(Space):
"""
.. __
.. / /
......@@ -2082,11 +2082,11 @@ class hp_space(point_space):
if(isinstance(other, tuple)):
other = list(other)
for ii in xrange(len(other)):
if(isinstance(other[ii], field)):
if(isinstance(other[ii], Field)):
other[ii] = other[ii].power(**kwargs)
else:
other[ii] = self.enforce_power(other[ii])
elif(isinstance(other, field)):
elif(isinstance(other, Field)):
other = [other.power(**kwargs)]
else:
other = [self.enforce_power(other)]
......
......@@ -23,7 +23,7 @@
import numpy as np
from numpy import pi
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
......@@ -71,7 +71,7 @@ def power_backward_conversion_lm(k_space,p,mean=None):
p[0] = 4*pi*mean**2
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 = C_0_Omega.transform()
......@@ -130,7 +130,7 @@ def power_forward_conversion_lm(k_space,p,mean=0):
"""
m = mean
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 = C_0_Omega.transform()
......
......@@ -48,22 +48,6 @@ class space_paradict(object):
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):
def __init__(self, shape, complexity, zerocenter):
......@@ -218,165 +202,3 @@ class hp_space_paradict(space_paradict):
raise ValueError(about._errors.cstring(
"ERROR: invalid parameter ( nside <> 2**n )."))
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):
# self.paradict[i] = [1+i, 2+i, 3+i]
#
# @property
# def para(self):
# temp = []
# for i in range(self.paradict.ndim):
# temp = np.append(temp, self.paradict[i])
# return temp
#
# @para.setter
# def para(self, x):
# dict_iter = 0
# x_iter = 0
# while dict_iter < self.paradict.ndim:
# temp = x[x_iter:x_iter+len(self.paradict[dict_iter])]
# self.paradict[dict_iter] = temp
# x_iter = x_iter+len(self.paradict[dict_iter])
# dict_iter += 1
#
###################
###################
#
# class _lm_space(object):
# def __init__(self):
# self.paradict = lm_space_paradict(lmax = 10)
#
# @property
# def para(self):
# temp = np.array([self.paradict['lmax'],
# self.paradict['mmax']], dtype=int)
# return temp
#
#
# @para.setter
# def para(self, x):
# self.paradict['lmax'] = x[0]
# self.paradict['mmax'] = x[1]
#
#
###################
###################
#
# class _gl_space(object):
# def __init__(self):
# self.paradict = gl_space_paradict(nlat = 10)
#
# @property
# def para(self):
# temp = np.array([self.paradict['nlat'],
# self.paradict['nlon']], dtype=int)
# return temp
#
#
# @para.setter
# def para(self, x):
# self.paradict['nlat'] = x[0]
# self.paradict['nlon'] = x[1]
#
#
###################
###################
#
#
# class _hp_space(object):
# def __init__(self):
# self.paradict = hp_space_paradict(nside=16)
#
# @property
# def para(self):
# temp = np.array([self.paradict['nside']], dtype=int)
# return temp
#
#
# @para.setter
# def para(self, x):
# self.paradict['nside'] = x[0]
#
#
#
###################
###################
#
#
#
# if __name__ == '__main__':
# myspace = _space()
# print myspace.para
# print myspace.paradict.parameters.items()
# myspace.para = [4,5,6]
# print myspace.para
# print myspace.paradict.parameters.items()
#
# myspace.paradict.parameters['default'] = [1,4,7]
# print myspace.para
# print myspace.paradict.parameters.items()
......@@ -22,7 +22,7 @@
##-----------------------------------------------------------------------------
import numpy as np
#from nifty.nifty_core import field
#from nifty.field import Field
from nifty.config import about
......
......@@ -5,6 +5,7 @@ from itertools import product
from nifty.config import about
def get_slice_list(shape, axes):
"""
Helper function which generates slice list(s) to traverse over all
......
......@@ -40,7 +40,7 @@ from __future__ import division
#from nifty_core import *
import numpy as np
from nifty.config import notification, about
from nifty.nifty_field import field
from nifty.field import Field
from nifty.nifty_simple_math import vdot
......@@ -555,7 +555,7 @@ class steepest_descent(object):
has converged or not.
"""
if(not isinstance(x0,field)):
if(not isinstance(x0,Field)):
raise TypeError(about._errors.cstring("ERROR: invalid input."))
self.x = x0
......@@ -844,7 +844,7 @@ class quasi_newton_minimizer(object):
has converged or not.
"""
if not isinstance(x0, field):
if not isinstance(x0, Field):
raise TypeError(about._errors.cstring("ERROR: invalid input."))
self.x = x0
......
......@@ -22,9 +22,9 @@
from __future__ import division
import numpy as np
from nifty.config import about
from nifty.nifty_field import field
from nifty.nifty_core import space, \
point_space
from nifty.field import Field
from nifty.space import Space
from nifty_minimization import conjugate_gradient
from nifty_probing import trace_prober,\
inverse_trace_prober,\
......@@ -227,7 +227,7 @@ class operator(object):
def _briefing(self, x, domain, codomain, inverse):
# make sure, that the result_field of the briefing lives in the
# given domain and codomain
result_field = field(domain=domain, val=x, codomain=codomain,
result_field = Field(domain=domain, val=x, codomain=codomain,
copy=False)
# weight if necessary
......@@ -238,7 +238,7 @@ class operator(object):
def _debriefing(self, x, y, target, cotarget, inverse):
# The debriefing takes care that the result field lives in the same
# fourier-type domain as the input field
assert(isinstance(y, field))
assert(isinstance(y, Field))
# weight if necessary
if (not self.imp) and (not target.discrete) and inverse:
......@@ -1402,7 +1402,7 @@ class diagonal_operator(operator):
diag_val = self.domain.calc_weight(self.val, power=-1)
else:
diag_val = self.val
diag = field(self.domain, codomain=self.codomain, val=diag_val)
diag = Field(self.domain, codomain=self.codomain, val=diag_val)
else:
diag = super(diagonal_operator, self).diag(bare=bare,
domain=domain,
......@@ -1490,7 +1490,7 @@ class diagonal_operator(operator):
power=-1)
else:
inverse_diag_val = inverse_val
inverse_diag = field(self.domain, codomain=self.codomain,
inverse_diag = Field(self.domain, codomain=self.codomain,
val=inverse_diag_val)
else:
......@@ -1578,7 +1578,7 @@ class diagonal_operator(operator):
Random field.
"""
temp_field = field(domain=self.domain,
temp_field = Field(domain=self.domain,
codomain=self.codomain,
random='gau',
std=nifty_simple_math.sqrt(
......@@ -1592,7 +1592,7 @@ class diagonal_operator(operator):
else:
codomain = domain.get_codomain()
return field(domain=domain, val=temp_field, codomain=codomain)
return Field(domain=domain, val=temp_field, codomain=codomain)
# if domain.harmonic != self.domain.harmonic:
# temp_field = temp_field.transform(new_domain=domain)
......@@ -1802,7 +1802,7 @@ class power_operator(diagonal_operator):
"""
# Set the domain
if not isinstance(domain, space):
if not isinstance(domain, Space):
raise TypeError(about._errors.cstring(
"ERROR: The given domain is not a nifty space."))
self.domain = domain
......@@ -2173,7 +2173,7 @@ class projection_operator(operator):