Skip to content

Commit

Permalink
Fix: Bugs in processing loop data
Browse files Browse the repository at this point in the history
  • Loading branch information
kcwongaz committed Aug 30, 2022
1 parent 6df4c33 commit 4cda087
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
6 changes: 3 additions & 3 deletions air_traffic/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ def loop_write(dataset, savename):

df = df.loc[df["distance"] <= 200]
dist = df["distance"].to_numpy()
time = df["time"].to_numpy()

min_loc = lp.locate_loops(dist)

_, min_time = lp.find_minima_spacetime(dist[:,1], dist[:,0],
min_loc)
_, min_time = lp.find_minima_spacetime(dist, time, min_loc)

# Skip if no loop is found
if len(min_time) == 0:
continue

_, exit_time = lp.find_exitpoint(dist[:,1], dist[:,0], min_loc)
_, exit_time = lp.find_exitpoint(dist, time, min_loc)

# Determine entry direction thus the holding area
if df["longitude"].iloc[0] < 114:
Expand Down
50 changes: 24 additions & 26 deletions air_traffic/loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,39 +107,14 @@ def find_exitpoint(dist, time, min_loc):
return exit_dist, exit_time


def label_flight_loops(flight_dict):
"""
Generate a dict labeling where the loops locate in each flight.
This is done by finding which candidate regions out of 'locations' has
the most numbr of loops.
If there are no loop, it will just label the flight to have the first
loop region. This should not cause a problem, because upon find_minima()
in the area, the loop search will return [].
It is acutally not necessary to complete distinguish the three loops area,
just locating whether the loops are in the upper of lower region in the
spacetime graph is sufficent for my purpose. The tricker part is flight
from North always produces a 'fake' loop.
"""

min_loc = {}

for key in flight_dict:
min_loc[key] = locate_loops(flight_dict[key])

return min_loc


def locate_loops(flight):
def locate_loops(dist):
"""
Locate the loop location for a single flight.
"""

# It is not necessary to completely distinguish the three loops areas
locations = [(70, 80), (90, 130)]

dist = flight[:, 1]
loop_num = [len(find_minima(dist, loc)) for loc in locations]
min_loc = locations[np.argmax(loop_num)]

Expand Down Expand Up @@ -216,6 +191,29 @@ def detect_selection_problem(flight_min, flight_exit, tol=60):
# they should probably be removed.
# --------------------------------------------------------------------------- #
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
def label_flight_loops(flight_dict):
"""
Generate a dict labeling where the loops locate in each flight.
This is done by finding which candidate regions out of 'locations' has
the most numbr of loops.
If there are no loop, it will just label the flight to have the first
loop region. This should not cause a problem, because upon find_minima()
in the area, the loop search will return [].
It is acutally not necessary to complete distinguish the three loops area,
just locating whether the loops are in the upper of lower region in the
spacetime graph is sufficent for my purpose. The tricker part is flight
from North always produces a 'fake' loop.
"""

min_loc = {}

for key in flight_dict:
min_loc[key] = locate_loops(flight_dict[key])

return min_loc


def sort_flight_keys(flight_dict, min_loc):

Expand Down

0 comments on commit 4cda087

Please sign in to comment.