#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 18 14:03:44 2017

@author: xliq
"""

'''
The MetroPy Phasor-2D File:
    Generates the 2D heatmaps of the Phasor Metrology data.
'''
#### Initialization
from sys import argv
FITS_file = argv[1]
rmsLength = int(argv[2])
resolution = int(argv[3])
img = argv[4]

#### Importing
# import necessary things from the init file
from MetroPy_Init import plotstyle, phasor
from MetroPy_Helper import heatmap2d, plotnumber, plotlabel

# import necessary packages
import os
import matplotlib.pyplot as plt
# plotstyle for Metrology data
plt.style.use(plotstyle)
# numpy ofcourse
import numpy as np
    
# format
plt.rcParams['font.size'] = 10
plt.rcParams['image.cmap'] = 'Blues'
plt.rc('xtick', labelsize=5)
plt.rc('ytick', labelsize=5)

# phasor[0][:, n], phasor[0][:, n+1] = AT[x] D[5-x] FT, n = 0, 1, ..., 30
# x = 4, 3, 2, 1 for n in [0, 6], [8, 14], [16, 22], [24, 30]
# phasor[0][:, n], phasor[0][:, n+1] = AT[x] D[5-x] SC, n = 32, 33, ..., 62
# x = 4, 3, 2, 1 for n in [32, 38], [40, 46], [48, 54], [56, 62]     
size = [18, 28]
counter = 0
# activate progressbar    
#bar = pb.ProgressBar()
for n in np.arange(0, 64, 2):
 
    fig = plt.gcf()
    plt.subplot(8, 4, plotnumber('phasor', n, counter))
    plt.axvline(0, 0, 1, color='grey', lw=0.5)
    plt.axhline(0, 0, 1, color='grey', lw=0.5)
    plt.xlabel('Voltage [V]')
    plt.ylabel('Voltage [V]')
    plt.title('AT%s' %plotlabel('phasor', n))
    heatmap2d(fig, phasor[0], n, max(abs(phasor[0][:,n])), 
              max(abs(phasor[0][:,n+1])), resolution, size)
    
    counter += 1

print('Phasor 2D Plots: Done!')

plt.savefig('%s.Phasor2D.%s' %(FITS_file, img), bbox_inches='tight')
