# -*- coding: utf-8 -*-
"""
Created on Tue Jan 26 14:08:58 2016

@author: dlivelyb
"""

import numpy as np
import numpy.matlib as M

import tkinter as tk
import tkinter.filedialog as tkfd

import matplotlib.pyplot as plt

# *** use tkinter to open a file dialog box to select file ***
root = tk.Tk()
root.withdraw()
file_path_string = tkfd.askopenfilename()

file=open(file_path_string,"r")
fl=list(file)
file.close()

#populate data list. Each elment is a list version of the values in a line
#of snlist.txt. Removed columns Type and Disc. Converted numbers to floats.
#data=[['#SN', 'Galaxy', 'RAG_h', 'RAG_m', 'RAG_s', 'DEG_d','DEG_m','DEG_s',\
#'HRV (km/s)', 'z', 'Bmag (mag)', 'logD25 (0.1arcmin)', 'MaxMag (mag)','Type']]\
data = [[0]*15 for i in range(len(fl)-2)]

# something different, make a vector of 'pointers' (ngcptr) into rows of data
#    thusly chopped corresponding to galaxies that contain NGC in name
# this assumes of course you have galaxies and HRV, etc already loaded
ngcgalx = []
ngcptr = []        
j = 0
for i in galaxies:
    if i[:3] == "NGC":
        ngcgalx += [i]
        ngcptr += [j]
    j = j+1

# point to HRV values only for ngc galaxies (for fun)
HRVngc = [HRV[el] for el in ngcptr]
maxmagngc = [maxmag[el] for el in ngcptr]


#%%
# some plotting tricks, how to make labels, set axes limits, 'plot hold', etc
# plot maxmags vs HRVs for all galaxies
plt.figure(1)
print(len(HRV),len(maxmag))
plt.plot(HRV,maxmag,'bo')
plt.xlabel('HRV')
plt.ylabel('maxmag')
plt.xlim(-5000,250000)
plt.ylim(0,30)
plt.grid('on')
plt.hold('on') # this allows 'overplotting' on same axis
# plot NGC galaxies as red stars on same plot, see where NGC 'spectra' is
plt.plot(HRVngc,maxmagngc,'r*')
plt.show
plt.hold('off')
# 4)

# this shows how to open a second figure window (plt.figure(2)) and plot
# something else there...
plt.figure(2)
RA_deg = []
Dec_deg = []
for i in range(len(RAG_H)):
    RA_deg += [15*(RAG_H[i] + RAG_M[i]/60 + RAG_S[i]/3600)]
    Dec_deg += [(np.abs(DEG_D[i]) + DEG_M[i]/60 + DEG_S[i]/3600)*(np.abs(DEG_D[i])/DEG_D[i])]

plt.scatter(RA_deg,Dec_deg)
plt.xlim(0,360)
plt.grid('on')
plt.xlabel('RA_deg')
plt.ylabel('Dec_deg')
plt.show