Source code :: plots

[Return]
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from pygolem_lite import Shot, saveconst
import numpy as np

import matplotlib
matplotlib.rcParams['backend'] = 'Agg'
matplotlib.rc('font',  size='10')

import matplotlib.pyplot as plt


R = 47.0                                   # [Ohm] resistance for U -> I


def calculate_M(U_up, U_down):
    return 0.5 * np.log(U_up / U_down) # should be I, but U/R / U/R would be the same


def make_img1(t, M, up_ch, down_ch):
    plt.figure(figsize=[12, 6])          #size in inches
    plt.plot(t * 1e3, M)                  # in ms
    plt.xlabel('time [ms]')
    plt.ylabel('M')
    fname = 'M1-ch{}_ch{}.png'.format(up_ch, down_ch)
    plt.savefig(fname)
    plt.close()                           #close this figure

def make_img2(t, M, up_ch, down_ch):
    plt.figure(figsize=[12, 6])          #size in inches
    plt.plot(t * 1e3, M)                  # in ms
    plt.xlabel('time [ms]')
    plt.ylabel('M')
    fname = 'M2-ch{}_ch{}.png'.format(up_ch, down_ch)
    plt.savefig(fname)
    plt.close()                           #close this figure


def make_plots1(probe_channels1, automatic_select_up):
    shot = Shot()
    t, data_st = shot['papouch_st']

    start = shot['plasma_start']
    end = shot['plasma_end']
    start_idx = np.where(start <= t)[0][0]
    end_idx = np.where(t <= end)[0][-1]
    t = t[start_idx:end_idx]

    for up_ch, down_ch in probe_channels1:
        U_down = data_st[start_idx:end_idx,down_ch-1] # data columns is indexed from 0
        U_up = data_st[start_idx:end_idx,up_ch-1]
       # if automatic_select_up and U_down.mean() > U_up.mean():
          #  U_up, U_down = U_down, U_up   #swap
        M = calculate_M(U_up, U_down)
        make_img1(t, M, up_ch, down_ch)

        
probe_channels1 = [
    (1, 2),
    (3, 4),
    (5, 6),
    (7, 8),
    (9,10),
    (11,12),
    ]

def make_plots2(probe_channels2, automatic_select_up):
    shot = Shot()
    t, data_ja = shot['papouch_ja']

    start = shot['plasma_start']
    end = shot['plasma_end']
    start_idx = np.where(start <= t)[0][0]
    end_idx = np.where(t <= end)[0][-1]
    t = t[start_idx:end_idx]

    for up_ch, down_ch in probe_channels2:
        U_down = data_ja[start_idx:end_idx,down_ch-1] # data columns is indexed from 0
        U_up = data_ja[start_idx:end_idx,up_ch-1]
       # if automatic_select_up and U_down.mean() > U_up.mean():
          #  U_up, U_down = U_down, U_up   #swap
        M = calculate_M(U_up, U_down)
        make_img2(t, M, up_ch, down_ch)

        
probe_channels2 = [
    (1, 2),
    ]

if __name__ == '__main__':
    make_plots1(probe_channels1, automatic_select_up=True)
    make_plots2(probe_channels2, automatic_select_up=True)
    saveconst('status', 0)

Navigation