Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def stack_all_commands(self):
"""create and stack command"""
params = ('lat', 'lon', 'alt', 'speed', 'heading', 'callsign')
for i, d in list(self.acpool.items()):
# check if all needed keys are in dict
if set(params).issubset(d):
acid = d['callsign']
# check is aircraft is already beening displayed
if(traf.id2idx(acid) < 0):
mdl = self.default_ac_mdl
v = aero.tas2cas(d['speed'], d['alt'] * aero.ft)
cmdstr = 'CRE %s, %s, %f, %f, %f, %d, %d' % \
(acid, mdl, d['lat'], d['lon'],
d['heading'], d['alt'], v)
stack.stack(cmdstr)
else:
cmdstr = 'MOVE %s, %f, %f, %d' % \
(acid, d['lat'], d['lon'], d['alt'])
stack.stack(cmdstr)
cmdstr = 'HDG %s, %f' % (acid, d['heading'])
stack.stack(cmdstr)
v_cas = aero.tas2cas(d['speed'], d['alt'] * aero.ft)
cmdstr = 'SPD %s, %f' % (acid, v_cas)
for idx, (sector, previnside) in enumerate(zip(self.sectors, self.acinside)):
inside = areafilter.checkInside(sector, traf.lat, traf.lon, traf.alt)
sectoreff = []
# Detect aircraft leaving and entering the sector
previds = set(previnside.acid)
ids = set(np.array(traf.id)[inside])
arrived = list(ids - previds)
left = previds - ids
# Split left aircraft in deleted and not deleted
left_intraf = left.intersection(traf.id)
left_del = list(left - left_intraf)
left_intraf = list(left_intraf)
arridx = traf.id2idx(arrived)
leftidx = traf.id2idx(left_intraf)
# Retrieve the current distance flown for arriving and leaving aircraft
arrdist = traf.distflown[arridx]
arrlat = traf.lat[arridx]
arrlon = traf.lon[arridx]
leftlat, leftlon, leftdist = self.delac.get(left_del)
leftlat = np.append(leftlat, traf.lat[leftidx])
leftlon = np.append(leftlon, traf.lon[leftidx])
leftdist = np.append(leftdist, traf.distflown[leftidx])
leftlat0, leftlon0, leftdist0 = previnside.get(left_del + left_intraf)
self.delac.delete(left_del)
if len(left) > 0:
q, d = geo.qdrdist(leftlat0, leftlon0, leftlat, leftlon)
# Exclude aircraft where origin = destination
return False
elif argtype == "wpt" or argtype == "latlon":
# wpt: Make 1 or 2 argument(s) into 1 position text to be used as waypoint
# latlon: return lat,lon to be used as a position only
# Examples valid position texts:
# lat/lon : "N52.12,E004.23","N52'14'12',E004'23'10"
# navaid/fix: "SPY","OA","SUGOL"
# airport: "EHAM"
# runway: "EHAM/RW06" "LFPG/RWY23"
# Default values
name = curargu
# Try aircraft first: translate a/c id into a valid position text with a lat,lon
idx = bs.traf.id2idx(name)
if idx >= 0:
name = str(bs.traf.lat[idx]) + "," + str(bs.traf.lon[idx])
# Check if lat/lon combination
elif islat(curargu):
# lat,lon ? Combine into one string with a comma
nextarg, args = getnextarg(args)
name = curargu + "," + nextarg
# apt,runway ? Combine into one string with a slash as separator
elif args[:2].upper() == "RW" and curargu in bs.navdb.aptid:
nextarg, args = getnextarg(args)
name = curargu + "/" + nextarg.upper()
# Return something different for the two argtypes:
def update(self):
"""Draw a new frame"""
# First check for keys & mouse
self.keyb.update()
# Navdisp mode: get center:
if self.swnavdisp:
i = bs.traf.id2idx(self.ndacid)
if i >= 0:
self.ndlat = bs.traf.lat[i]
self.ndlon = bs.traf.lon[i]
self.ndcrs = bs.traf.hdg[i]
else:
self.swnavdisp = False
else:
self.ndcrs = 0.0
# Simulation: keep track of timestep
# For measuring game loop frequency
self.dts.append(bs.sim.simdt)
if len(self.dts) > 20:
del self.dts[0]
# Radar window
def ResumeNav(self):
""" Decide for each aircraft in the conflict list whether the ASAS
should be followed or not, based on if the aircraft pairs passed
their CPA. """
# Conflict pairs to be deleted
delpairs = set()
changeactive = dict()
# Look at all conflicts, also the ones that are solved but CPA is yet to come
for conflict in self.resopairs:
idx1, idx2 = bs.traf.id2idx(conflict)
# If the ownship aircraft is deleted remove its conflict from the list
if idx1 < 0:
delpairs.add(conflict)
continue
if idx2 >= 0:
# Distance vector using flat earth approximation
re = 6371000.
dist = re * np.array([np.radians(bs.traf.lon[idx2] - bs.traf.lon[idx1]) *
np.cos(0.5 * np.radians(bs.traf.lat[idx2] +
bs.traf.lat[idx1])),
np.radians(bs.traf.lat[idx2] - bs.traf.lat[idx1])])
# Relative velocity vector
vrel = np.array([bs.traf.gseast[idx2] - bs.traf.gseast[idx1],
bs.traf.gsnorth[idx2] - bs.traf.gsnorth[idx1]])
if argtype == "txt": # simple, case insensitive text: preserve case
result = [curargu]
elif argtype == "word": # single case sensitive word
result = [curarg]
elif argtype == "string":
result = [self.argstring]
self.argstring = ""
return result
elif argtype == "acid": # aircraft id => parse index
if curargu in bs.traf.groups:
idx = bs.traf.groups.listgroup(curargu)
else:
idx = bs.traf.id2idx(curargu)
if idx < 0:
self.error += curargu + " not found"
return False
# Update ref position for navdb lookup
Argparser.reflat = bs.traf.lat[idx]
Argparser.reflon = bs.traf.lon[idx]
self.refac = idx
result = [idx]
# Empty arg or wildcard
elif curargu == "" or curargu == "*":
# If there was a matching additional argument stored previously use that one
if argtype in self.additional and curargu == "*":
result = [self.additional[argtype]]
# determine which aircraft need to be deleted.
insdel = areafilter.checkInside(self.delarea, traf.lat, traf.lon, traf.alt)
insexp = insdel if not self.exparea else \
areafilter.checkInside(self.exparea, traf.lat, traf.lon, traf.alt)
# Find all aircraft that were inside in the previous timestep, but no
# longer are in the current timestep
delidx = np.where(np.array(self.insdel) * (np.array(insdel) == False))[0]
self.insdel = insdel
# Count new conflicts where at least one of the aircraft is inside
# the experiment area
if traf.asas.confpairs_new:
newconf_unique = {frozenset(pair)
for pair in traf.asas.confpairs_new}
ac1, ac2 = zip(*newconf_unique)
idx1 = traf.id2idx(ac1)
idx2 = traf.id2idx(ac2)
newconf_inside = np.logical_or(insexp[idx1], insexp[idx2])
nnewconf_exp = np.count_nonzero(newconf_inside)
if nnewconf_exp:
self.confinside_all += nnewconf_exp
self.conflog.log(self.confinside_all)
# Register distance values upon entry of experiment area
newentries = np.logical_not(self.insexp) * insexp
self.dstart2D[newentries] = self.distance2D[newentries]
self.dstart3D[newentries] = self.distance3D[newentries]
self.workstart[newentries] = self.work[newentries]
self.entrytime[newentries] = sim.simt
# Log flight statistics when exiting experiment area
def resumenav(self, conf, ownship, intruder):
'''
Decide for each aircraft in the conflict list whether the ASAS
should be followed or not, based on if the aircraft pairs passed
their CPA.
'''
# Add new conflicts to resopairs and confpairs_all and new losses to lospairs_all
self.resopairs.update(conf.confpairs)
# Conflict pairs to be deleted
delpairs = set()
changeactive = dict()
# Look at all conflicts, also the ones that are solved but CPA is yet to come
for conflict in self.resopairs:
idx1, idx2 = bs.traf.id2idx(conflict)
# If the ownship aircraft is deleted remove its conflict from the list
if idx1 < 0:
delpairs.add(conflict)
continue
if idx2 >= 0:
# Distance vector using flat earth approximation
re = 6371000.
dist = re * np.array([np.radians(intruder.lon[idx2] - ownship.lon[idx1]) *
np.cos(0.5 * np.radians(intruder.lat[idx2] +
ownship.lat[idx1])),
np.radians(intruder.lat[idx2] - ownship.lat[idx1])])
# Relative velocity vector
vrel = np.array([intruder.gseast[idx2] - ownship.gseast[idx1],
intruder.gsnorth[idx2] - ownship.gsnorth[idx1]])
- bs.traf.vs[i]/nomspeed*nomlength*self.isoalt / \
self.dtopix_eq(1e5)*1e5
pg.draw.line(self.win,green,(trafx[i],trafy[i]),(spdvcx,spdvcy))
# ---- End of per aircraft i loop
# Draw conflicts: line from a/c to closest point of approach
nconf = len(bs.traf.asas.confpairs_unique)
n2conf = len(bs.traf.asas.confpairs)
if nconf>0:
for j in range(n2conf):
i = bs.traf.id2idx(bs.traf.asas.confpairs[j][0])
if i>=0 and i= 0:
for j in range(0,bs.traf.ap.route[i].nwp):
if j==0:
x1,y1 = self.ll2xy(bs.traf.ap.route[i].wplat[j], \
bs.traf.ap.route[i].wplon[j])