Commit 32ab3895 authored by Philipp Frank's avatar Philipp Frank
Browse files

add docs and gradient tests

parent ccc06713
......@@ -28,18 +28,52 @@ from ..sugar import makeOp
from ..field import Field
from import UnstructuredDomain
from .light_cone_operator import LightConeOperator,field_from_function
def make_dynamic_operator(FFT,harmonic_padding,
def make_dynamic_operator(FFT,harmonic_padding,sm_s0,sm_x0,
keys=['f', 'c'],
sm_x0=[0.18, 0.18],
Constructs an operator for a dynamic field prior
FFT : FFTOperator
harmonic_padding : None, list of float
Amount of central padding in harmonic space in pixels. If None the field is not padded at all.
sm_s0 : float
Cutoff for dynamic smoothness prior
sm_x0 : float, List of float
Scaling of dynamic smoothness along each axis
keys : List of String
keys of input fields of operator.
causal : boolean
Whether or not the reconstructed dynamics should be causal in time
cone : boolean
Whether or not the reconstructed dynamics should be within a light cone
minimum_phase: boolean
Whether or not the reconstructed dynamics should be minimum phase
sigc : float, List of float
variance of light cone parameters.
If cone is False this is ignored
quant : float
Quantization of the light cone in pixels.
If cone is False this is ignored
ops = {}
if harmonic_padding is None:
CentralPadd = ScalingOperator(1.,
......@@ -51,24 +85,26 @@ def make_dynamic_operator(FFT,harmonic_padding,
ops['CentralPadd'] = CentralPadd
sdom =[0].get_default_codomain()
FFTB = FFTOperator(sdom)(Realizer(sdom))
m = FieldAdapter(sdom, keys[0])
dists =[0].distances
if isinstance(sm_x0,float):
sm_x0 = list((sm_x0,)*len(dists))
def func(x):
res = 1.
for i in range(len(sm_x0)):
for i in range(len(dists)):
res = res + (x[i]/sm_x0[i]/dists[i])**2
return sm_s0/res
Sm = field_from_function(, func)
Sm = makeOp(Sm)
m = Sm(m)
m = FFTB(m)
m = CentralPadd.adjoint(m)
ops[keys[0]+'_k'] = m
m = -m.log()
if not minimum_phase:
m = m.exp()
......@@ -85,10 +121,10 @@ def make_dynamic_operator(FFT,harmonic_padding,
m = kernel(m)
elif minimum_phase:
raise(ValueError,"minimum phase and not causal not possible!")
if cone:
if len( < 2:
raise(ValueError,"Light cone requires dimensionality >= 2")
if cone and len( > 1:
if isinstance(sigc,float):
sigc = list((sigc,)*(len(
cdom = UnstructuredDomain(len(sigc))
c = FieldAdapter(cdom, keys[1])
Sigc = makeOp(Field(, np.array(sigc)))
......@@ -131,6 +131,18 @@ class Model_Tests(unittest.TestCase):
ift.extra.check_value_gradient_consistency(model, pos, tol=1e-2,
[ift.FFTOperator(ift.RGSpace(64, distances=.789)),
ift.FFTOperator(ift.RGSpace([32, 32], distances=.789)),
ift.FFTOperator(ift.RGSpace([32, 32, 32], distances=.789))],
[4, 78, 23]))
def testDynamicModel(self, FFT, seed):
model,_ = ift.make_dynamic_operator(FFT,None,1.,1.)
S = ift.ScalingOperator(1., model.domain)
pos = S.draw_sample()
# FIXME I dont know why smaller tol fails for 3D example
ift.extra.check_value_gradient_consistency(model, pos, tol=1e-6, ntries=20)
# @expand(product(
# ['Variable', 'Constant'],
# [ift.GLSpace(15),
Supports Markdown
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