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

import matplotlib
matplotlib.rcParams['backend'] = 'Agg'
matplotlib.rc('font',  size='10')
matplotlib.rc('text', usetex=True)  # FIXME !! nicer but slower !!!



from copy import deepcopy

from numpy import *
from pygolem_lite.config import *
from pygolem_lite.modules import *
#from matplotlib.pyplot import *
import time
import os, sys

def graphs(file_type):

    if not os.path.exists('Time_All'):
	print "missing data Komora"
	return
	
    name = "Vacuum Basic Info"
    # graph all
    out_tmp = get_data('Chamber_Evol', 'ch', "" , xlim = [0,None], xlabel = "Time [h]",  tvec_rescale = 1/3600. )

    #print out_tmp
    #print len(out_tmp)
    
    
    out = []
    
    #out_tmp[0]['label'] = 'Chamber temperature'
    #out_tmp[0]['ylabel'] = 'T [deg C]'

    #out += [out_tmp[0]]

    
    out_tmp[0]['kwargs']['label'] = 'PfeifferMerkaVakuaPotrubi'
    out_tmp[0]['ylabel'] = 'p [mPa]'
    out_tmp[0]['yscale'] = 'log'
    out_tmp[0]['data'] /= 1e3 # 5e2
    out_tmp[0]['ylim'] = [0,100]

    out_tmp[4]['kwargs']['label'] = 'Chamber Gas Pressure'
    out_tmp[4]['ylabel'] = 'p [mPa]'
    out_tmp[4]['yscale'] = 'log'
    out_tmp[4]['ylim'] = [0,100]
    
    out.append(deepcopy([out_tmp[0], out_tmp[4]]))
   
    
    out_tmp[0]['kwargs']['label'] = 'PfeifferMerkaVakuaPotrubi'
    out_tmp[0]['ylabel'] = 'p [mPa]'
    out_tmp[0]['ylim'] = [0,10]
    out_tmp[0]['yscale'] = ''

    out_tmp[4]['kwargs']['label'] =  'Chamber Gas Pressure'
    out_tmp[4]['ylabel'] = 'p [mPa]'
    out_tmp[4]['ylim'] = [0,10]
    out_tmp[4]['yscale'] = ''

    out_tmp[1]['kwargs']['label'] = 'Gas filling ON/OFF'
    out_tmp[1]['ylabel'] = 'p [mPa]'
    out_tmp[1]['ylim'] = [0,10]
    out_tmp[1]['yscale'] = ''
    
    out.append(deepcopy([out_tmp[0], out_tmp[4],out_tmp[1]]))



    out_tmp[3]['kwargs']['label'] = '???'
    out_tmp[3]['ylabel'] = '??? [??]'
  
    out += [out_tmp[3]]
    
    out_tmp[5]['kwargs']['label'] = 'Chamber baking'
    out_tmp[5]['ylabel'] = 'ON/OFF'
    
        
    out_tmp[6]['kwargs']['label'] = 'Cross baking'
    out_tmp[6]['ylabel'] = 'ON/OFF'

    out_tmp[7]['kwargs']['label'] = 'Glow discharge'
    out_tmp[7]['ylabel'] = 'ON/OFF'
    
    out += [[out_tmp[5],out_tmp[6], out_tmp[7]]]
    
    try:
      out_tmp[8]['kwargs']['label'] = 'Chamber temperature'
      out_tmp[8]['ylabel'] = 'T [deg C]'
      out += [out_tmp[8]]
    except:
      pass
    #print out_tmp[8]

    multiplot(out, name , 'graph1', (9,12),  100,  'vertical', file_type)


def main():
    #setup()
    graphs('png')
    #graphs('svg')
    saveconst('status', 0)



if __name__ == "__main__":
    main()