# -*- coding: utf-8 -*- """ Created on Thursday, 24.05.2018 during COSPAR workshop Lecture 6.1/9 Generates plot of a 'Seiji' text file with several mixed columns (Text and floating point numbers) Further analysis and plots need to be added.... @author: Chr. Monstein """ #-------------------------------------------------------------------------------- from matplotlib import pyplot as plt import numpy as np import os #from Tkinter import Tk # Python 2.7 from tkinter import Tk #from tkFileDialog import askopenfilename from tkinter import filedialog #-------------------------------------------------------------------------------- Tk().withdraw() # #myfile = askopenfilename(title = 'Select a *.txt-file containing Time-/Frequency coordinates of type II burst') # show an "Open" dialog box and returns path&file # Python2.7 myfile = filedialog.askopenfilename(title = 'Select a *.txt-file containing Time-/Frequency coordinates of type II burst') # show an "Open" dialog box and return file #myfile = 'ft2.txt' # for testing only to avoid too many clicks... fnam = os.path.basename(myfile) # extract filename only in case it contains also the path """ #Date Time Height PA Xpix Ypix X" Y" 2013-10-05T073520.571 5.09 97.45 212 262 -4883.20 -638.40 2013-10-05T074547.663 6.17 99.39 203 259 -5891.20 -974.40 etc. or #TIME Frequency 2014-01-26T08:41:44, 16.242 2014-01-26T08:42:44, 14.140 etc... """ MyTime = [] # reserve a list for time Height = [] # reserve a list for Height import csv with open(myfile, 'r') as file: reader = csv.reader(file, delimiter=' ') next(reader, None) # skip the headers for row0 in reader: print (row0) row = [x for x in row0 if x] dt = row[0] y = float(row[1]) yy = dt[ 0: 4] # extract year MM = dt[ 5: 7] # extract month dd = dt[ 8:10] # extract day hh = dt[11:13] # get hours mm = dt[14:16] # get minutes ss = dt[17:19] # get seconds tx0 = float(hh) + float(mm)/60.0 + float(ss)/3600.0 # create decimal hour MyTime.append(tx0) # x-axis Height.append(y) # y-axis (Height or Frequency) #-------------------------------------------------------------------------------- tmin = np.min(MyTime) tx = (MyTime - tmin) # convert absolute into relative time fit=np.polyfit(tx,Height,1) speed=fit[0]*6.96e5/3600 tx2 = np.linspace(min(tx), max(tx), 100) height2 = np.poly1d(fit)(tx2) plt.figure(figsize=(10,7)) plt.plot(tx,Height,'o',color='red') #o,+, plt.plot(tx2,height2,color='red') plt.title(fnam,fontsize=16) plt.xlabel("Relative time [hour]",size=18) plt.ylabel("Height [Rs]",size=18) plt.title(yy + '-' + MM + '-' + dd, size=18) plt.grid(True) # an option plt.tick_params(labelsize=20) #plt.yscale('log') # this is an option to checkout st='Speed={:5.1f} km/s'.format(speed) plt.text(0.0,0.9*np.max(Height),st,color='blue',size=20) plt.show() plt.savefig('HeightTime_' + fnam + '.png')