newamplitudes.py 1 KB
Newer Older
Philipp Arras's avatar
Philipp Arras committed
1
import nifty5 as ift
Philipp Arras's avatar
Philipp Arras committed
2
3
import numpy as np
np.random.seed(42)
Philipp Arras's avatar
Philipp Arras committed
4

Philipp Arras's avatar
Philipp Arras committed
5
sspace = ift.RGSpace((128,))
Philipp Arras's avatar
Philipp Arras committed
6
hspace = sspace.get_default_codomain()
Philipp Arras's avatar
Philipp Arras committed
7
target0 = ift.PowerSpace(hspace)
Philipp Arras's avatar
Philipp Arras committed
8

Philipp Arras's avatar
Work    
Philipp Arras committed
9
fa = ift.FinalAmplitude()
Philipp Arras's avatar
Philipp Arras committed
10
11
12
13
14
15
16
17
fa.add_fluctuations(target0, 10, 2, 1, 1e-6, 2, 1e-6, -2, 1e-6, 'spatial')
op = fa.finalize(10, 0.1, '')
A = fa.amplitudes[0]

cstpos = ift.from_random('normal', op.domain)
p1, p2 = [ift.Plot() for _ in range(2)]
lst1 = []
skys1, skys2 = [], []
Philipp Arras's avatar
Philipp Arras committed
18
for _ in range(8):
Philipp Arras's avatar
Philipp Arras committed
19
    pos = ift.from_random('normal', op.domain)
Philipp Arras's avatar
Philipp Arras committed
20

Philipp Arras's avatar
Philipp Arras committed
21
    foo = ift.MultiField.union([cstpos, pos.extract(A.domain)])
Philipp Arras's avatar
Philipp Arras committed
22
    skys2.append(op(foo))
Philipp Arras's avatar
Philipp Arras committed
23

Philipp Arras's avatar
Philipp Arras committed
24
    sky = op(pos)
Philipp Arras's avatar
Philipp Arras committed
25
    skys1.append(sky)
Philipp Arras's avatar
Philipp Arras committed
26
    lst1.append(A.force(pos))
Philipp Arras's avatar
Philipp Arras committed
27

Philipp Arras's avatar
Philipp Arras committed
28
for pp, ll in [(p1, skys1), (p2, skys2)]:
Philipp Arras's avatar
Philipp Arras committed
29
    mi, ma = None, None
Philipp Arras's avatar
Philipp Arras committed
30
    if False:
Philipp Arras's avatar
Philipp Arras committed
31
32
33
34
35
36
37
        mi, ma = np.inf, -np.inf
        for ss in ll:
            mi = min([mi, np.amin(ss.val)])
            ma = max([ma, np.amax(ss.val)])
    for ss in ll:
        pp.add(ss, zmin=mi, zmax=ma)

Philipp Arras's avatar
Philipp Arras committed
38
p1.add(lst1)
Philipp Arras's avatar
Philipp Arras committed
39
40
41
p2.add(lst1)
p1.output(name='full.png')
p2.output(name='xi_fixed.png')