Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
junzis
GitHub Repository: junzis/openap
Path: blob/master/scripts/wrap_csv_to_fwf.py
592 views
1
import os
2
import glob
3
import yaml
4
import numpy as np
5
import pandas as pd
6
7
8
from tabulate import tabulate
9
def to_fwf(df, fname):
10
content = tabulate(df.values.tolist(), list(df.columns), tablefmt="plain", numalign="left", stralign="left")
11
open(fname, "w").write(content)
12
pd.DataFrame.to_fwf = to_fwf
13
14
root = os.path.dirname(os.path.realpath(__file__))
15
16
phases = {
17
'TO': 'takeoff',
18
'IC': 'initial_climb',
19
'CL': 'climb',
20
'CR': 'cruise',
21
'DE': 'descent',
22
'FA': 'final_approach',
23
'LD': 'landing',
24
}
25
26
prop = {
27
'to_v_lof': 'Liftoff speed' ,
28
'to_d_tof': 'Takeoff distance' ,
29
'to_acc_tof': 'Mean takeoff accelaration' ,
30
'ic_va_avg': 'Mean airspeed' ,
31
'ic_vs_avg': 'Mean vertical rate' ,
32
'ic_va_std': 'Standard deviation of airspeed' ,
33
'ic_vs_std': 'Standard deviation of vertical rate ' ,
34
'cl_d_range': 'Climb range' ,
35
'cl_v_cas_const': 'Constant CAS' ,
36
'cl_v_mach_const': 'Constant Mach' ,
37
'cl_h_cas_const': 'Constant CAS crossover altitude' ,
38
'cl_h_mach_const': 'Constant Mach crossover altitude' ,
39
'cl_vs_avg_pre_cas': 'Mean climb rate, pre-constant-CAS' ,
40
'cl_vs_avg_cas_const': 'Mean climb rate, constant-CAS' ,
41
'cl_vs_avg_mach_const': 'Mean climb rate, constant-Mach' ,
42
'cr_d_range': 'Cruise range' ,
43
'cr_v_cas_mean': 'Mean cruise CAS' ,
44
'cr_v_cas_max': 'Maximum cruise CAS' ,
45
'cr_v_mach_mean': 'Mean cruise Mach' ,
46
'cr_v_mach_max': 'Maximum cruise Mach' ,
47
'cr_h_init': 'Initial cruise altitude' ,
48
'cr_h_mean': 'Mean cruise altitude' ,
49
'cr_h_max': 'Maximum cruise altitude' ,
50
'de_d_range': 'Descent range' ,
51
'de_v_mach_const': 'Constant Mach' ,
52
'de_v_cas_const': 'Constant CAS' ,
53
'de_h_cas_const': 'Constant CAS crossover altitude' ,
54
'de_h_mach_const': 'Constant Mach crossover altitude' ,
55
'de_vs_avg_cas_const': 'Mean descent rate, constant-CAS' ,
56
'de_vs_avg_mach_const': 'Mean descent rate, constant-Mach' ,
57
'de_vs_avg_after_cas': 'Mean descent rate, after-constant-CAS' ,
58
'fa_va_avg': 'Mean airspeed' ,
59
'fa_vs_avg': 'Mean vertical rate' ,
60
'fa_va_std': 'Standard deviation of airspeed' ,
61
'fa_vs_std': 'Standard deviation of vertical rate' ,
62
'fa_agl': 'Approach angle' ,
63
'ld_v_app': 'Touchdown speed' ,
64
'ld_d_brk': 'Braking distance' ,
65
'ld_acc_brk': 'Mean braking acceleration' ,
66
}
67
68
69
files = sorted(glob.glob('input/wrap/*.csv'))
70
71
for f in files:
72
mdl = f[-8:-4]
73
print(mdl)
74
df = pd.read_csv(f)
75
76
for i, r in df.iterrows():
77
df.loc[i, 'phase'] = phases[r.phase]
78
df.loc[i, 'note'] = prop[r.param]
79
80
df = df[['param', 'phase', 'note', 'opt', 'min', 'max', 'model', 'pm']]
81
df.columns = ['variable', 'flight phase', 'name', 'opt', 'min', 'max', 'model', 'parameters']
82
83
df.to_fwf(root+'/../openap/data/wrap/%s.txt' % mdl)
84
85