Discharge/DischargeDatabase/Examples/22813/includes/diagnostics/ParticleFlux/0514MachNumber_RD.ON/plots.py

#!/usr/bin/python2
# -*- coding: utf-8 -*-

from pygolem_lite import Shot, saveconst
from pygolem_lite.modules import *
from pygolem_lite.utilities import read_config

import numpy as np

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

import matplotlib.pyplot as plt
import os, sys


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


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


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

    for up_ch, down_ch in probe_channels1:
        U_down = data_st[:,down_ch-1] # data columns is indexed from 0
        U_up = data_st[:,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)
        data = get_data([t,M], "" , "M", hlines = [0])
        paralel_multiplot(data, "" ,  'M1-ch{}_ch{}'.format(up_ch, down_ch), [12, 6] , 100, 'vertical', 'png')


        
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']

    for up_ch, down_ch in probe_channels2:
        U_down = data_ja[:,down_ch-1] # data columns is indexed from 0
        U_up = data_ja[:,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)
        data = get_data([t,M], "" , "M", hlines = [0])
        paralel_multiplot(data, "" ,  'M2-ch{}_ch{}'.format(up_ch, down_ch), [12, 6] , 100, 'vertical', 'png')

        
probe_channels2 = [
    (1, 2),
    (3, 4),
    ]
    
def graphs(file_type):
    shot = Shot()
    ShotNo=shot['shotno']
    param = {'ylim':[-0.5,0.5], 'reduction': True, 'ylabel':'U [V]'} 

    outDown = [get_data(['Papouch_St', 1], "" , **param),
               get_data(['Papouch_St', 3], "" , **param),
               get_data(['Papouch_St', 5], "" , **param),
               get_data(['Papouch_St', 7], "" , **param),
               get_data(['Papouch_Ja', 2], "" , **param),
               get_data(['Papouch_St', 9], "" , **param),
               get_data(['Papouch_St', 11], "" , **param),
               get_data(['Papouch_Ja', 1], "" , **param) ]
    
    paralel_multiplot(outDown, '\#'+str(int(ShotNo))+' Down'  , 'graphDown', (6,len(outDown)*2), 100, 'vertical', file_type)

    outUp = [get_data(['Papouch_St', 0], "M1" , **param),
             get_data(['Papouch_St', 2], "M2" , **param),
             get_data(['Papouch_St', 4], "M3" , **param),
             get_data(['Papouch_St', 6], "M4" , **param),
             get_data(['Papouch_Ja', 3], "M5" , **param),
             get_data(['Papouch_St', 8], "M6" , **param),
             get_data(['Papouch_St', 10], "M7" , **param),
             get_data(['Papouch_Ja', 0], "M8" , **param) ]
    


    multiplot(outUp, '\#'+str(int(ShotNo))+' Up'  , 'graphUp', (6,len(outUp)*2), 100, 'vertical', file_type)
	
if __name__ == '__main__':
   #    if sys.argv[1] ==  "plots":
    make_plots1(probe_channels1, automatic_select_up=True)
    make_plots2(probe_channels2, automatic_select_up=True)
    graphs('png')

    saveconst('status', 0)