"""
	Classes and functions used to visualize data for thermo scientific analyzers
"""

from pandas import Series, DataFrame
import pandas as pd
import datetime as dt
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import dates as d
import os
import math
import glob
import matplotlib
import warnings
import sys

__all__ = ['diurnal_plot','diurnal_plot_single', 'ThermoPlot']

def diurnal_plot(data, dates=[], shaded=False, title="Diurnal Profile of Trace Gases", xlabel="Local Time: East St. Louis, MO"):
    '''
       
	   If plotting the entire DataFrame (data), choose all_data=True, else choose all_data=False
	   and declare the date or dates to plot as a list. `data` should be a pandas core DataFrame 
	   with time index and each trace gas concentration as a column
       
       returns a single plot for NOx, SO2, and O3
	   
	   >>>
	   
    '''
    
    # Check to make sure the data is a valid dataframe
    if not isinstance(data, pd.DataFrame):
         print ("data is not a pandas DataFrame, thus this will not end well for you.")
         exit
    
    # If length of dates is zero, plot everything
    if len(dates) == 0:
        # Plot everything, yo!
        pass
    elif len(dates) == 1:
        # Plot just this date
        data = data[dates[0]]
    elif len(dates) == 2:
        # Plot between these dates
        data = data[dates[0]:dates[1]]
    else:
        sys.exit("Dates are not properly configured.")
        
      
    # Add columns for time to enable simple diurnal trends to be found
    data['Time'] = data.index.map(lambda x: x.strftime("%H:%M"))
    
    # Group the data by time and grab the statistics
    grouped = data.groupby('Time').describe().unstack()
    
    # set the index to be a str
    grouped.index = pd.to_datetime(grouped.index.astype(str))