newamplitudes.py 959 Bytes
Newer Older
Martin Reinecke's avatar
5->6  
Martin Reinecke committed
1
import nifty6 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

7
fa = ift.CorrelatedFieldMaker.make(10, 0.1, '')
8
fa.add_fluctuations(sspace, 10, 2, 1, 1e-6, 2, 1e-6, -2, 1e-6, 'spatial')
9
op = fa.finalize()
10
A = fa.amplitude
Philipp Arras's avatar
Philipp Arras committed
11
12
13
14
15

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
16
for _ in range(8):
Philipp Arras's avatar
Philipp Arras committed
17
    pos = ift.from_random('normal', op.domain)
Philipp Arras's avatar
Philipp Arras committed
18

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

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

Philipp Arras's avatar
Philipp Arras committed
26
for pp, ll in [(p1, skys1), (p2, skys2)]:
Philipp Arras's avatar
Philipp Arras committed
27
    mi, ma = None, None
Philipp Arras's avatar
Philipp Arras committed
28
    if False:
Philipp Arras's avatar
Philipp Arras committed
29
30
31
32
33
34
35
        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
36
p1.add(lst1)
Philipp Arras's avatar
Philipp Arras committed
37
38
39
p2.add(lst1)
p1.output(name='full.png')
p2.output(name='xi_fixed.png')