Commit 46021a81 authored by Martin Reinecke's avatar Martin Reinecke

renaming

parent 52e58aeb
Pipeline #64986 passed with stages
in 8 minutes and 31 seconds
...@@ -24,11 +24,11 @@ for ii in range(10, 26): ...@@ -24,11 +24,11 @@ for ii in range(10, 26):
img = np.random.randn(nu*nv) img = np.random.randn(nu*nv)
img = img.reshape((nu, nv)) img = img.reshape((nu, nv))
img = ift.from_global_data(uvspace, img) img = ift.makeField(uvspace, img)
t0 = time() t0 = time()
GM = ift.GridderMaker(uvspace, eps=1e-7, uv=uv) GM = ift.GridderMaker(uvspace, eps=1e-7, uv=uv)
vis = ift.from_global_data(visspace, vis) vis = ift.makeField(visspace, vis)
op = GM.getFull().adjoint op = GM.getFull().adjoint
t1 = time() t1 = time()
op(img).val op(img).val
......
...@@ -57,7 +57,7 @@ if __name__ == '__main__': ...@@ -57,7 +57,7 @@ if __name__ == '__main__':
for _ in range(n_samps): for _ in range(n_samps):
fld = pspec(ift.from_random('normal', pspec.domain)) fld = pspec(ift.from_random('normal', pspec.domain))
klengths = fld.domain[0].k_lengths klengths = fld.domain[0].k_lengths
ycoord = fld.to_global_data_rw() ycoord = fld.val.copy()
ycoord[0] = ycoord[1] ycoord[0] = ycoord[1]
ax.plot(klengths, ycoord, alpha=1) ax.plot(klengths, ycoord, alpha=1)
...@@ -80,7 +80,7 @@ if __name__ == '__main__': ...@@ -80,7 +80,7 @@ if __name__ == '__main__':
foo = [] foo = []
for ax in axs: for ax in axs:
pos = ift.from_random('normal', correlated_field.domain) pos = ift.from_random('normal', correlated_field.domain)
fld = correlated_field(pos).to_global_data() fld = correlated_field(pos).val
foo.append((ax, fld)) foo.append((ax, fld))
mi, ma = np.inf, -np.inf mi, ma = np.inf, -np.inf
for _, fld in foo: for _, fld in foo:
...@@ -106,7 +106,7 @@ if __name__ == '__main__': ...@@ -106,7 +106,7 @@ if __name__ == '__main__':
flds = [] flds = []
for _ in range(n_samps): for _ in range(n_samps):
pos = ift.from_random('normal', correlated_field.domain) pos = ift.from_random('normal', correlated_field.domain)
ax.plot(correlated_field(pos).to_global_data()) ax.plot(correlated_field(pos).val)
plt.savefig('correlated_fields.png') plt.savefig('correlated_fields.png')
plt.close() plt.close()
...@@ -40,7 +40,7 @@ class SingleDomain(ift.LinearOperator): ...@@ -40,7 +40,7 @@ class SingleDomain(ift.LinearOperator):
def apply(self, x, mode): def apply(self, x, mode):
self._check_input(x, mode) self._check_input(x, mode)
return ift.from_global_data(self._tgt(mode), x.val) return ift.makeField(self._tgt(mode), x.val)
def random_los(n_los): def random_los(n_los):
......
...@@ -38,11 +38,11 @@ signal_vals = np.zeros(npix, dtype=np.float64) ...@@ -38,11 +38,11 @@ signal_vals = np.zeros(npix, dtype=np.float64)
for i in range(0, npix, npix//12 + 27): for i in range(0, npix, npix//12 + 27):
signal_vals[i] = 500. signal_vals[i] = 500.
signal = ift.from_global_data(domain, signal_vals) signal = ift.makeField(domain, signal_vals)
delta_vals = np.zeros(npix, dtype=np.float64) delta_vals = np.zeros(npix, dtype=np.float64)
delta_vals[0] = 1.0 delta_vals[0] = 1.0
delta = ift.from_global_data(domain, delta_vals) delta = ift.makeField(domain, delta_vals)
# Define kernel function # Define kernel function
...@@ -58,12 +58,12 @@ domain = ift.RGSpace((100, 100)) ...@@ -58,12 +58,12 @@ domain = ift.RGSpace((100, 100))
signal_vals = np.zeros(domain.shape, dtype=np.float64) signal_vals = np.zeros(domain.shape, dtype=np.float64)
signal_vals[35, 70] = 5000. signal_vals[35, 70] = 5000.
signal_vals[45, 8] = 5000. signal_vals[45, 8] = 5000.
signal = ift.from_global_data(domain, signal_vals) signal = ift.makeField(domain, signal_vals)
# Define delta signal, generate kernel image # Define delta signal, generate kernel image
delta_vals = np.zeros(domain.shape, dtype=np.float64) delta_vals = np.zeros(domain.shape, dtype=np.float64)
delta_vals[0, 0] = 1.0 delta_vals[0, 0] = 1.0
delta = ift.from_global_data(domain, delta_vals) delta = ift.makeField(domain, delta_vals)
# Define kernel function # Define kernel function
......
...@@ -78,7 +78,7 @@ class PolynomialResponse(ift.LinearOperator): ...@@ -78,7 +78,7 @@ class PolynomialResponse(ift.LinearOperator):
else: else:
# FIXME Can this be optimized? # FIXME Can this be optimized?
out = self._mat.conj().T.dot(val) out = self._mat.conj().T.dot(val)
return ift.from_global_data(self._tgt(mode), out) return ift.makeField(self._tgt(mode), out)
# Generate some mock data # Generate some mock data
...@@ -99,8 +99,8 @@ R = PolynomialResponse(p_space, x) ...@@ -99,8 +99,8 @@ R = PolynomialResponse(p_space, x)
ift.extra.consistency_check(R) ift.extra.consistency_check(R)
d_space = R.target d_space = R.target
d = ift.from_global_data(d_space, y) d = ift.makeField(d_space, y)
N = ift.DiagonalOperator(ift.from_global_data(d_space, var)) N = ift.DiagonalOperator(ift.makeField(d_space, var))
IC = ift.DeltaEnergyController(tol_rel_deltaE=1e-12, iteration_limit=200) IC = ift.DeltaEnergyController(tol_rel_deltaE=1e-12, iteration_limit=200)
likelihood = ift.GaussianEnergy(d, N)(R) likelihood = ift.GaussianEnergy(d, N)(R)
......
...@@ -33,7 +33,7 @@ from ..operators.linear_operator import LinearOperator ...@@ -33,7 +33,7 @@ from ..operators.linear_operator import LinearOperator
from ..operators.operator import Operator from ..operators.operator import Operator
from ..operators.simple_linear_operators import ducktape from ..operators.simple_linear_operators import ducktape
from ..probing import StatCalculator from ..probing import StatCalculator
from ..sugar import from_global_data, full, makeDomain from ..sugar import makeField, full, makeDomain
def _reshaper(x, N): def _reshaper(x, N):
...@@ -68,8 +68,8 @@ def _normal(mean, sig, key, N=0): ...@@ -68,8 +68,8 @@ def _normal(mean, sig, key, N=0):
else: else:
domain = UnstructuredDomain(N) domain = UnstructuredDomain(N)
mean, sig = (_reshaper(param, N) for param in (mean, sig)) mean, sig = (_reshaper(param, N) for param in (mean, sig))
return Adder(from_global_data(domain, mean)) @ (DiagonalOperator( return Adder(makeField(domain, mean)) @ (DiagonalOperator(
from_global_data(domain, sig)) @ ducktape(domain, None, key)) makeField(domain, sig)) @ ducktape(domain, None, key))
def _log_k_lengths(pspace): def _log_k_lengths(pspace):
...@@ -144,7 +144,7 @@ class _SlopeRemover(EndomorphicOperator): ...@@ -144,7 +144,7 @@ class _SlopeRemover(EndomorphicOperator):
res = x.copy() res = x.copy()
res[self._last] -= (x*self._sc[self._extender]).sum( res[self._last] -= (x*self._sc[self._extender]).sum(
axis=self._space, keepdims=True) axis=self._space, keepdims=True)
return from_global_data(self._tgt(mode), res) return makeField(self._tgt(mode), res)
class _TwoLogIntegrations(LinearOperator): class _TwoLogIntegrations(LinearOperator):
...@@ -186,7 +186,7 @@ class _TwoLogIntegrations(LinearOperator): ...@@ -186,7 +186,7 @@ class _TwoLogIntegrations(LinearOperator):
x[from_third] *= (self._log_vol/2.)[extender_sl] x[from_third] *= (self._log_vol/2.)[extender_sl]
x[no_border] += x[from_third] x[no_border] += x[from_third]
res[second] += np.cumsum(x[from_third][reverse], axis=axis)[reverse] res[second] += np.cumsum(x[from_third][reverse], axis=axis)[reverse]
return from_global_data(self._tgt(mode), res) return makeField(self._tgt(mode), res)
class _Normalization(Operator): class _Normalization(Operator):
...@@ -202,7 +202,7 @@ class _Normalization(Operator): ...@@ -202,7 +202,7 @@ class _Normalization(Operator):
mode_multiplicity = pd.adjoint(full(pd.target, 1.)).val.copy() mode_multiplicity = pd.adjoint(full(pd.target, 1.)).val.copy()
zero_mode = (slice(None),)*self._domain.axes[space][0] + (0,) zero_mode = (slice(None),)*self._domain.axes[space][0] + (0,)
mode_multiplicity[zero_mode] = 0 mode_multiplicity[zero_mode] = 0
self._mode_multiplicity = from_global_data(self._domain, self._mode_multiplicity = makeField(self._domain,
mode_multiplicity) mode_multiplicity)
self._specsum = _SpecialSum(self._domain, space) self._specsum = _SpecialSum(self._domain, space)
...@@ -243,7 +243,7 @@ class _Distributor(LinearOperator): ...@@ -243,7 +243,7 @@ class _Distributor(LinearOperator):
else: else:
res = np.empty(self._tgt(mode).shape) res = np.empty(self._tgt(mode).shape)
res[self._dofdex] = x res[self._dofdex] = x
return from_global_data(self._tgt(mode), res) return makeField(self._tgt(mode), res)
class _Amplitude(Operator): class _Amplitude(Operator):
...@@ -284,24 +284,24 @@ class _Amplitude(Operator): ...@@ -284,24 +284,24 @@ class _Amplitude(Operator):
# Prepare constant fields # Prepare constant fields
foo = np.zeros(shp) foo = np.zeros(shp)
foo[0] = foo[1] = np.sqrt(_log_vol(target[space])) foo[0] = foo[1] = np.sqrt(_log_vol(target[space]))
vflex = DiagonalOperator(from_global_data(dom[space], foo), dom, space) vflex = DiagonalOperator(makeField(dom[space], foo), dom, space)
foo = np.zeros(shp, dtype=np.float64) foo = np.zeros(shp, dtype=np.float64)
foo[0] += 1 foo[0] += 1
vasp = DiagonalOperator(from_global_data(dom[space], foo), dom, space) vasp = DiagonalOperator(makeField(dom[space], foo), dom, space)
foo = np.ones(shp) foo = np.ones(shp)
foo[0] = _log_vol(target[space])**2/12. foo[0] = _log_vol(target[space])**2/12.
shift = DiagonalOperator(from_global_data(dom[space], foo), dom, space) shift = DiagonalOperator(makeField(dom[space], foo), dom, space)
vslope = DiagonalOperator( vslope = DiagonalOperator(
from_global_data(target[space], makeField(target[space],
_relative_log_k_lengths(target[space])), _relative_log_k_lengths(target[space])),
target, space) target, space)
foo, bar = [np.zeros(target[space].shape) for _ in range(2)] foo, bar = [np.zeros(target[space].shape) for _ in range(2)]
bar[1:] = foo[0] = totvol bar[1:] = foo[0] = totvol
vol0, vol1 = [DiagonalOperator(from_global_data(target[space], aa), vol0, vol1 = [DiagonalOperator(makeField(target[space], aa),
target, space) for aa in (foo, bar)] target, space) for aa in (foo, bar)]
# Prepare fields for Adder # Prepare fields for Adder
......
...@@ -21,7 +21,7 @@ from ..domain_tuple import DomainTuple ...@@ -21,7 +21,7 @@ from ..domain_tuple import DomainTuple
from ..domains.rg_space import RGSpace from ..domains.rg_space import RGSpace
from ..domains.unstructured_domain import UnstructuredDomain from ..domains.unstructured_domain import UnstructuredDomain
from ..operators.linear_operator import LinearOperator from ..operators.linear_operator import LinearOperator
from ..sugar import from_global_data, makeDomain from ..sugar import makeField, makeDomain
class GridderMaker(object): class GridderMaker(object):
...@@ -85,7 +85,7 @@ class _RestOperator(LinearOperator): ...@@ -85,7 +85,7 @@ class _RestOperator(LinearOperator):
res = self._gconf.grid2dirty(res) res = self._gconf.grid2dirty(res)
else: else:
res = self._gconf.dirty2grid(res) res = self._gconf.dirty2grid(res)
return from_global_data(self._tgt(mode), res) return makeField(self._tgt(mode), res)
class RadioGridder(LinearOperator): class RadioGridder(LinearOperator):
...@@ -108,4 +108,4 @@ class RadioGridder(LinearOperator): ...@@ -108,4 +108,4 @@ class RadioGridder(LinearOperator):
res = nifty_gridder.grid2vis(self._bl, self._gconf, self._idx, res = nifty_gridder.grid2vis(self._bl, self._gconf, self._idx,
x.val) x.val)
res = self._bl.vis2ms(res, self._idx).reshape((-1,)) res = self._bl.vis2ms(res, self._idx).reshape((-1,))
return from_global_data(self._tgt(mode), res) return makeField(self._tgt(mode), res)
...@@ -23,7 +23,7 @@ from .multi_domain import MultiDomain ...@@ -23,7 +23,7 @@ from .multi_domain import MultiDomain
from .multi_field import MultiField from .multi_field import MultiField
from .operators.linear_operator import LinearOperator from .operators.linear_operator import LinearOperator
from .operators.sandwich_operator import SandwichOperator from .operators.sandwich_operator import SandwichOperator
from .sugar import from_global_data, makeDomain from .sugar import makeField, makeDomain
class _DomRemover(LinearOperator): class _DomRemover(LinearOperator):
...@@ -68,7 +68,7 @@ class _DomRemover(LinearOperator): ...@@ -68,7 +68,7 @@ class _DomRemover(LinearOperator):
res[i0:i1] = x[kk].ravel() res[i0:i1] = x[kk].ravel()
else: else:
res[kk] = x[i0:i1].reshape(dd.shape) res[kk] = x[i0:i1].reshape(dd.shape)
return from_global_data(self._tgt(mode), res) return makeField(self._tgt(mode), res)
@staticmethod @staticmethod
def _check_float_dtype(fld): def _check_float_dtype(fld):
...@@ -137,7 +137,7 @@ def operator_spectrum(A, k, hermitian, which='LM', tol=0): ...@@ -137,7 +137,7 @@ def operator_spectrum(A, k, hermitian, which='LM', tol=0):
Ar = SandwichOperator.make(_DomRemover(A.domain).adjoint, A) Ar = SandwichOperator.make(_DomRemover(A.domain).adjoint, A)
M = ssl.LinearOperator( M = ssl.LinearOperator(
shape=2*(size,), shape=2*(size,),
matvec=lambda x: Ar(from_global_data(Ar.domain, x)).val) matvec=lambda x: Ar(makeField(Ar.domain, x)).val)
f = ssl.eigsh if hermitian else ssl.eigs f = ssl.eigsh if hermitian else ssl.eigs
eigs = f(M, k=k, tol=tol, return_eigenvectors=False, which=which) eigs = f(M, k=k, tol=tol, return_eigenvectors=False, which=which)
return np.flip(np.sort(eigs), axis=0) return np.flip(np.sort(eigs), axis=0)
...@@ -335,8 +335,8 @@ def _plot2D(f, ax, **kwargs): ...@@ -335,8 +335,8 @@ def _plot2D(f, ax, **kwargs):
if (not isinstance(dom[1], RGSpace)) or len(dom[1].shape) != 1: if (not isinstance(dom[1], RGSpace)) or len(dom[1].shape) != 1:
raise TypeError("need 1D RGSpace as second domain") raise TypeError("need 1D RGSpace as second domain")
if dom[1].shape[0] == 1: if dom[1].shape[0] == 1:
from .sugar import from_global_data from .sugar import makeField
f = from_global_data(f.domain[0], f.val[..., 0]) f = makeField(f.domain[0], f.val[..., 0])
else: else:
rgb = _rgb_data(f.val) rgb = _rgb_data(f.val)
have_rgb = True have_rgb = True
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
from .multi_field import MultiField from .multi_field import MultiField
from .operators.endomorphic_operator import EndomorphicOperator from .operators.endomorphic_operator import EndomorphicOperator
from .operators.operator import Operator from .operators.operator import Operator
from .sugar import from_global_data, from_random from .sugar import makeField, from_random
class StatCalculator(object): class StatCalculator(object):
...@@ -146,5 +146,5 @@ def approximation2endo(op, nsamples): ...@@ -146,5 +146,5 @@ def approximation2endo(op, nsamples):
for kk in dct: for kk in dct:
foo = dct[kk].to_global_data_rw() foo = dct[kk].to_global_data_rw()
foo[foo == 0] = 1 foo[foo == 0] = 1
dct[kk] = from_global_data(dct[kk].domain, foo) dct[kk] = makeField(dct[kk].domain, foo)
return MultiField.from_dict(dct) return MultiField.from_dict(dct)
...@@ -35,7 +35,7 @@ from .plot import Plot ...@@ -35,7 +35,7 @@ from .plot import Plot
__all__ = ['PS_field', 'power_analyze', 'create_power_operator', __all__ = ['PS_field', 'power_analyze', 'create_power_operator',
'create_harmonic_smoothing_operator', 'from_random', 'create_harmonic_smoothing_operator', 'from_random',
'full', 'from_global_data', 'full', 'makeField',
'makeDomain', 'sqrt', 'exp', 'log', 'tanh', 'sigmoid', 'makeDomain', 'sqrt', 'exp', 'log', 'tanh', 'sigmoid',
'sin', 'cos', 'tan', 'sinh', 'cosh', 'log10', 'sin', 'cos', 'tan', 'sinh', 'cosh', 'log10',
'absolute', 'one_over', 'clip', 'sinc', "log1p", "expm1", 'absolute', 'one_over', 'clip', 'sinc', "log1p", "expm1",
...@@ -280,7 +280,7 @@ def from_random(random_type, domain, dtype=np.float64, **kwargs): ...@@ -280,7 +280,7 @@ def from_random(random_type, domain, dtype=np.float64, **kwargs):
return Field.from_random(random_type, domain, dtype, **kwargs) return Field.from_random(random_type, domain, dtype, **kwargs)
def from_global_data(domain, arr): def makeField(domain, arr):
"""Convenience function creating Fields/MultiFields from Numpy arrays or """Convenience function creating Fields/MultiFields from Numpy arrays or
dicts of Numpy arrays. dicts of Numpy arrays.
......
...@@ -175,14 +175,14 @@ def test_dataconv(): ...@@ -175,14 +175,14 @@ def test_dataconv():
s1 = ift.RGSpace((10,)) s1 = ift.RGSpace((10,))
ld = np.arange(s1.shape[0]) ld = np.arange(s1.shape[0])
gd = np.arange(s1.shape[0]) gd = np.arange(s1.shape[0])
assert_equal(gd, ift.from_global_data(s1, gd).val) assert_equal(gd, ift.makeField(s1, gd).val)
def test_cast_domain(): def test_cast_domain():
s1 = ift.RGSpace((10,)) s1 = ift.RGSpace((10,))
s2 = ift.RGSpace((10,), distances=20.) s2 = ift.RGSpace((10,), distances=20.)
d = np.arange(s1.shape[0]) d = np.arange(s1.shape[0])
d2 = ift.from_global_data(s1, d).cast_domain(s2).val d2 = ift.makeField(s1, d).cast_domain(s2).val
assert_equal(d, d2) assert_equal(d, d2)
...@@ -207,7 +207,7 @@ def test_trivialities(): ...@@ -207,7 +207,7 @@ def test_trivialities():
assert_equal(f1.sum(), f1.sum(0)) assert_equal(f1.sum(), f1.sum(0))
assert_equal(f1.conjugate().val, assert_equal(f1.conjugate().val,
ift.Field.full(s1, 27. - 3j).val) ift.Field.full(s1, 27. - 3j).val)
f1 = ift.from_global_data(s1, np.arange(10)) f1 = ift.makeField(s1, np.arange(10))
# assert_equal(f1.min(), 0) # assert_equal(f1.min(), 0)
# assert_equal(f1.max(), 9) # assert_equal(f1.max(), 9)
assert_equal(f1.prod(), 0) assert_equal(f1.prod(), 0)
......
...@@ -37,14 +37,14 @@ def test_func(): ...@@ -37,14 +37,14 @@ def test_func():
def test_multifield_field_consistency(): def test_multifield_field_consistency():
f1 = ift.full(dom, 27) f1 = ift.full(dom, 27)
f2 = ift.from_global_data(dom['d1'], f1['d1'].val) f2 = ift.makeField(dom['d1'], f1['d1'].val)
assert_equal(f1.sum(), f2.sum()) assert_equal(f1.sum(), f2.sum())
assert_equal(f1.size, f2.size) assert_equal(f1.size, f2.size)
def test_dataconv(): def test_dataconv():
f1 = ift.full(dom, 27) f1 = ift.full(dom, 27)
f2 = ift.from_global_data(dom, f1.to_global_data()) f2 = ift.makeField(dom, f1.to_global_data())
for key, val in f1.items(): for key, val in f1.items():
assert_equal(val.val, f2[key].val) assert_equal(val.val, f2[key].val)
if "d1" not in f2: if "d1" not in f2:
......
...@@ -44,7 +44,7 @@ def test_gridding(nu, nv, N, eps): ...@@ -44,7 +44,7 @@ def test_gridding(nu, nv, N, eps):
uv[:, 0] = uv[:, 0]/dstx uv[:, 0] = uv[:, 0]/dstx
uv[:, 1] = uv[:, 1]/dsty uv[:, 1] = uv[:, 1]/dsty
GM = ift.GridderMaker(dom, uv=uv, eps=eps) GM = ift.GridderMaker(dom, uv=uv, eps=eps)
vis2 = ift.from_global_data(ift.UnstructuredDomain(vis.shape), vis) vis2 = ift.makeField(ift.UnstructuredDomain(vis.shape), vis)
Op = GM.getFull() Op = GM.getFull()
pynu = Op(vis2).val pynu = Op(vis2).val
...@@ -75,7 +75,7 @@ def test_cartesian(): ...@@ -75,7 +75,7 @@ def test_cartesian():
fld = ift.from_random('normal', dom) fld = ift.from_random('normal', dom)
arr = fld.val arr = fld.val
fld2 = ift.from_global_data(dom, np.roll(arr, (nx//2, ny//2), axis=(0, 1))) fld2 = ift.makeField(dom, np.roll(arr, (nx//2, ny//2), axis=(0, 1)))
res = op(fld2).val.reshape(nx, ny) res = op(fld2).val.reshape(nx, ny)
fft = ift.FFTOperator(dom.get_default_codomain(), target=dom).adjoint fft = ift.FFTOperator(dom.get_default_codomain(), target=dom).adjoint
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment