-
Notifications
You must be signed in to change notification settings - Fork 2
/
Readingfilelinebyline.py
55 lines (36 loc) · 1.25 KB
/
Readingfilelinebyline.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
import pandas as pd
import os
# Global Variables
path_to_data_files = "./Data"
data = None
def get_data_files(dir_path):
return os.listdir(dir_path)
def get_df_from_file(file_path):
return pd.read_table(file_path, delim_whitespace= True)
def get_one_datapoint_from_df(df):
df = df[df.A5016 == 0.0]
df = df.iloc[:1]
return df.drop(columns=["A5334", "A5335", "A5016"], axis = 1)
def combine_datapoints_from_dfs(file_list, data):
for file in file_list:
my_file = path_to_data_files + "/" + file
df = get_df_from_file(my_file)
data_point = get_one_datapoint_from_df(df)
data = pd.concat([data, data_point], ignore_index=True)
return data
def shape_df(df):
df = df.astype({"Time": float, "P3114": float})
df['Time'] = pd.to_datetime(df['Time'], unit='D', origin='julian')
return df
def plot(df):
plot = df.plot.line(x = "Time", y = "P3114")
plot.set_ylabel("P3114: XMM-Newton solar array power [A]")
figure = plot.get_figure()
figure.savefig("XMM_solar_array_power_over_mission_lifetime.png")
def main():
data_files = get_data_files(path_to_data_files)
data_points = combine_datapoints_from_dfs(data_files, data)
data_points = shape_df(data_points)
plot(data_points)
if __name__ == '__main__':
main()