forked from maikebauer/STEREO-HI-Data-Processing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrack_cme.py
79 lines (58 loc) · 2.53 KB
/
track_cme.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import matplotlib.pyplot as plt
from matplotlib import image
import pickle
import matplotlib.dates as mdates
import datetime
import numpy as np
import pandas as pd
import time
from pandas.plotting import register_matplotlib_converters
import os
from functions import read_sav
import sys
import cv2
import glob
register_matplotlib_converters()
line = 0
file = open('config.txt', 'r')
config = file.readlines()
path = config[0].splitlines()[0]
ftpsc = config[3].splitlines()[0]
instrument = config[4].splitlines()[0]
bflag = config[5].splitlines()[0]
start = config[6+line].splitlines()[0]
savepath = path + 'jplot/' + bflag + '/'
param_fil = glob.glob(savepath+'hi1hi2/' + start[0:4] + '/params/'+'jplot_hi1hi2_'+start+'*'+bflag[0]+'_params.pkl')
param_fil = param_fil[0]
with open(param_fil, 'rb') as f:
time_beg1, time_end1, time_beg2, time_end2, e1_beg, e1_end, e2_beg, e2_end = pickle.load(f)
file_h1 = glob.glob(savepath+'hi_1/'+ start[0:4] + '/jplot_hi1_'+start+'_'+'*'+'UT_'+bflag[0]+'.png')[0]
file_h2 = glob.glob(savepath+'hi_2/'+ start[0:4] + '/jplot_hi2_'+start+'_'+'*'+'UT_'+bflag[0]+'.png')[0]
jplot1 = image.imread(file_h1)
jplot2 = image.imread(file_h2)
fig, ax = plt.subplots(figsize=(10, 5))
plt.ylim(4, 80)
plt.gca().xaxis.set_major_locator(mdates.HourLocator(byhour=range(0, 24, 24)))
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%d/%m/%y'))
ax.xaxis_date()
plt.xlabel('Date (d/m/y)')
plt.ylabel('Elongation (°)')
ax.imshow(jplot1, cmap='gray', extent=[time_beg1, time_end1, e1_beg, e1_end], aspect='auto')
ax.imshow(jplot2, cmap='gray', extent=[time_beg2, time_end2, e2_beg, e2_end], aspect='auto')
data = []
inp = fig.ginput(n=-1, timeout=0, mouse_add=1, mouse_pop=3, mouse_stop=2 )
data.append(inp)
elon = [data[0][i][1] for i in range(len(data[0]))]
date_time_obj = [mdates.num2date(data[0][i][0]) for i in range(len(data[0]))]
date_time_obj.sort()
date = [datetime.datetime.strftime(x, '%Y-%b-%d %H:%M:%S.%f') for x in date_time_obj]
elon_stdd = np.zeros(len(data[0]))
SC = [ftpsc for x in range(len(data[0]))]
pd_data = {'TRACK_DATE': date, 'ELON': elon, 'ELON_STDD': elon_stdd, 'SC': SC}
csv_path = savepath + '/hi1hi2/' + start[0:4] + '/Tracks/' + start + '/'
if not os.path.exists(csv_path):
os.makedirs(csv_path)
prev_files = glob.glob(csv_path + start + '_' + bflag[0] + '_track' + '_*.csv')
num = len(prev_files) + 1
df = pd.DataFrame(pd_data, columns=['TRACK_DATE', 'ELON', 'SC', 'ELON_STDD'])
df.to_csv(csv_path + start + '_' + bflag[0] + '_track' + '_' + str(num) +'.csv', index=False, date_format='%Y-%m-%dT%H:M:S')