Commit 5e42cb29 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

rearranging

parent a5edfc6c
Pipeline #20571 passed with stage
in 4 minutes and 52 seconds
......@@ -8,8 +8,6 @@ from .domain_tuple import DomainTuple
from .domain_object import DomainObject
from .random import Random
from .basic_arithmetics import *
from .nifty_utilities import *
......@@ -32,6 +30,6 @@ from . import plotting
from . import library
from .data_objects import numpy_do as dobj
from . import dobj
from .memoization import memo
......@@ -3,8 +3,13 @@
import numpy as np
from numpy import ndarray as data_object
from numpy import full, empty, sqrt, ones, zeros, vdot, abs, bincount, exp, log
from ..nifty_utilities import cast_iseq_to_tuple, get_slice_list
from functools import reduce
from .random import Random
def from_object(object, dtype=None, copy=True):
return np.array(object, dtype=dtype, copy=copy)
def from_random(random_type, shape, dtype=np.float64, **kwargs):
generator_function = getattr(Random, random_type)
return generator_function(dtype=dtype, shape=shape, **kwargs)
......@@ -20,7 +20,6 @@ from __future__ import division, print_function
from builtins import range
import numpy as np
from . import nifty_utilities as utilities
from .random import Random
from .domain_tuple import DomainTuple
from functools import reduce
from . import dobj
......@@ -184,9 +183,9 @@ class Field(object):
"""
domain = DomainTuple.make(domain)
generator_function = getattr(Random, random_type)
return Field(domain=domain, val=generator_function(dtype=dtype,
shape=domain.shape, **kwargs))
return Field(domain=domain,
val=dobj.from_random(random_type, dtype=dtype,
shape=domain.shape, **kwargs))
# ---Properties---
......
......@@ -141,7 +141,7 @@ class PowerSpace(Space):
harmonic_partner=self.harmonic_partner,
k_length_array=k_length_array,
binbounds=binbounds)
temp_rho = dobj.bincount(temp_pindex.ravel())
temp_rho = np.bincount(temp_pindex.ravel())
assert not np.any(temp_rho == 0), "empty bins detected"
temp_k_lengths = np.bincount(temp_pindex.ravel(),
weights=k_length_array.ravel()) \
......
......@@ -17,14 +17,15 @@
# and financially supported by the Studienstiftung des deutschen Volkes.
import numpy as np
from . import Space,\
PowerSpace,\
Field,\
ComposedOperator,\
DiagonalOperator,\
FFTOperator,\
sqrt
PowerSpace,\
Field,\
ComposedOperator,\
DiagonalOperator,\
PowerProjectionOperator,\
FFTOperator,\
sqrt,\
DomainTuple
from . import nifty_utilities as utilities
__all__ = ['power_analyze',
......@@ -223,16 +224,16 @@ def create_power_field(domain, power_spectrum, dtype=None):
power_domain = PowerSpace(domain)
fp = Field(power_domain, val=power_spectrum(power_domain.k_lengths),
dtype=dtype)
f = power_synthesize_special(fp)
P = PowerProjectionOperator(domain, power_domain)
f = P.adjoint_times(fp)
if not issubclass(fp.dtype.type, np.complexfloating):
f = f.real
f **= 2
return f
def create_power_operator(domain, power_spectrum, dtype=None):
def create_power_operator(domain, power_spectrum, space=None, dtype=None):
""" Creates a diagonal operator with the given power spectrum.
Constructs a diagonal operator that lives over the specified domain.
......@@ -241,9 +242,10 @@ def create_power_operator(domain, power_spectrum, dtype=None):
----------
domain : DomainObject
Domain over which the power operator shall live.
power_spectrum : callable
A method that implements the square root of a power spectrum as a
function of k.
power_spectrum : callable of Field
An object that implements the power spectrum as a function of k.
space : int
the domain index on which the power operator will work
dtype : type *optional*
dtype that the field holding the power spectrum shall use
(default : None).
......@@ -254,8 +256,18 @@ def create_power_operator(domain, power_spectrum, dtype=None):
DiagonalOperator : An operator that implements the given power spectrum.
"""
domain = DomainTuple.make(domain)
if space is None:
if len(domain)!=1:
raise ValueError("space keyword must be set")
else:
space = 0
space = int(space)
return DiagonalOperator(
create_power_field(domain, power_spectrum, dtype).weight(1))
create_power_field(domain[space],
power_spectrum, dtype).weight(1),
domain=domain,
spaces=space)
def generate_posterior_sample(mean, covariance):
......
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