-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathread.py
More file actions
executable file
·99 lines (90 loc) · 4.56 KB
/
Copy pathread.py
File metadata and controls
executable file
·99 lines (90 loc) · 4.56 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import pandas as pd
import numpy as np
import os
data = pd.DataFrame()
for root, directory, files in os.walk('./para/'):
for i, filename in enumerate(files):
if filename.endswith('.csv'):
if 'Para' not in filename:
continue
if i % 100 == 0:
print("File: ", i, " / ", len(files))
# TODO: Check filter conditionals
try:
df = pd.read_csv('para/' + filename, sep=';', dtype={
'n_ships': int,
'own_mmsi': int,
'obst_mmsi': int,
'own_name': str,
'obst_name': str,
'own_callsign': str,
'obst_callsign': str,
'own_length': float,
'obst_length': float,
'own_width': float,
'obst_width': float,
'own_type': float,
'obst_type': float,
'own_nav_status': float,
'obst_nav_status': float,
'own_speed': float,
'obst_speed': float,
'multi_man_own': bool,
'maneuver_made_own': bool,
'maneuver_index_own': int,
'maneuver_stop_idx_own': int,
'r_maneuver_own': float,
'pre_man_dist_own': float,
'post_man_dist_own': float,
'delta_speed_own': float,
'delta_course_own': float,
'multi_man_obst': bool,
'maneuver_made_obst': bool,
'maneuver_index_obst': int,
'maneuver_stop_idx_obst': int,
'r_maneuver_obst': float,
'pre_man_dist_obst': float,
'post_man_dist_obst': float,
'delta_speed_obst': float,
'delta_course_obst': float,
'alpha_start': float,
'beta_start': float,
'r_cpa': float,
'alpha_cpa': float,
'beta_cpa': float,
'lon_maneuver': float,
'lat_maneuver': float,
'COLREG': float,
'single_COLREG_type': bool,
'time': str,
'cpa_idx': int,
'start_idx': int,
'stop_idx': int
}, parse_dates=['date_cpa'], infer_datetime_format=True)
df = df[df['maneuver_index_own'] != df['stop_idx']]
df = df[df['maneuver_index_own'] > df['start_idx']].reset_index(drop=True)
except Exception as ex:
print('Filename: ', filename, '\n Esception: ', ex, '\n')
continue
if len(df) == 0:
continue
not_filt = []
for k in range(len(df)):
not_filt.append(len(df.loc[(df['own_mmsi'] == df['own_mmsi'][k]) & (
(df['start_idx'] <= df['stop_idx'][k]) & (df['stop_idx'] >= df['start_idx'][k]))]))
df['COLREGS_not_filt'] = not_filt
df = df.loc[df['own_speed'] >= 1]
df = df.loc[df['obst_speed'] >= 1].reset_index(drop=True)
filt = []
for k in range(len(df)):
filt.append(len(df.loc[(df['own_mmsi'] == df['own_mmsi'][k]) & (
(df['start_idx'] >= df['stop_idx'][k]) | (df['stop_idx'] >= df['start_idx'][k]))]))
df['COLREGS_filt'] = filt
data = data.append(df)
print(data)
# Delete? Move to another place?
#data = data.loc[data.apply(lambda x:
# x['r_cpa'] > 4*np.min(np.array([x['own_width'], x['obst_width']]))
# if np.min(np.array([x['own_width'], x['obst_width']])) != 0
# else x['r_cpa'] > 4, axis=1)]
data.to_csv('superPara.csv', sep=';', index=False)