Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if j>=len(self.rtewpid):
self.rtewpid.append(txt)
self.rtewplabel.append(wplabel)
else:
self.rtewpid[j] = txt
self.rtewplabel[j] = wplabel
# In any case, blit the waypoint name
xtxt = x1 + 7
ytxt = y1 - 3
self.radbmp.blit(self.rtewplabel[j], (xtxt, ytxt), \
None, pg.BLEND_ADD)
# Line from aircraft to active waypoint
if bs.traf.ap.route[i].iactwp == j:
x0,y0 = self.ll2xy(bs.traf.lat[i],bs.traf.lon[i])
pg.draw.line(self.win, magenta,(x0,y0),(x1,y1))
# Draw aircraft trails which are on screen
if bs.traf.trails.active:
trlsel = list(np.where(
self.onradar(bs.traf.trails.lat0, bs.traf.trails.lon0) + \
self.onradar(bs.traf.trails.lat1, bs.traf.trails.lon1))[0])
x0, y0 = self.ll2xy(bs.traf.trails.lat0, bs.traf.trails.lon0)
x1, y1 = self.ll2xy(bs.traf.trails.lat1, bs.traf.trails.lon1)
for i in trlsel:
pg.draw.line(self.win, bs.traf.trails.col[i], \
(x0[i], y0[i]), (x1[i], y1[i]))
# END OF BACKGROUND DRAWING #
##############################################################################
# Blit background
self.win.blit(self.radbmp, (0, 0))
# Decide to redraw radar picture of a/c
syst = pg.time.get_ticks() * 0.001
redrawrad = self.redrawradbg or abs(syst - self.radt0) >= self.radardt
if redrawrad:
self.radt0 = syst # Update lats drawing time of radar
# Select which aircraft are within screen area
trafsel = np.where((bs.traf.lat > self.lat0) * (bs.traf.lat < self.lat1) * \
(bs.traf.lon > self.lon0) * (bs.traf.lon < self.lon1))[0]
# ------------------- Draw aircraft -------------------
# Convert lat,lon to x,y
trafx, trafy = self.ll2xy(bs.traf.lat, bs.traf.lon)
trafy -= bs.traf.alt*self.isoalt
if bs.traf.trails.active:
ltx, lty = self.ll2xy(bs.traf.trails.lastlat, bs.traf.trails.lastlon)
# Find pixel size of horizontal separation on screen
pixelrad=self.dtopix_eq(bs.traf.asas.R/2)
# Loop through all traffic indices which we found on screen
for i in trafsel:
# Check for valid Mach or CAS
if self.wpspd[wpidx] <2.0:
cas = mach2cas(self.wpspd[wpidx], alt)
else:
cas = self.wpspd[wpidx]
# Save it for next leg
bs.traf.actwp.nextspd[idx] = cas
# No speed specified for next leg
else:
bs.traf.actwp.nextspd[idx] = -999.
qdr, dist = geo.qdrdist(bs.traf.lat[idx], bs.traf.lon[idx],
bs.traf.actwp.lat[idx], bs.traf.actwp.lon[idx])
turnrad = bs.traf.tas[idx]*bs.traf.tas[idx]/tan(radians(25.)) / g0 / nm # [nm]default bank angle 25 deg
bs.traf.actwp.turndist[idx] = (bs.traf.actwp.flyby[idx] > 0.5) * \
turnrad*abs(tan(0.5*radians(max(5., abs(degto180(qdr -
self.wpdirfrom[self.iactwp])))))) # [nm]
bs.traf.swlnav[idx] = True
return True
else:
return False, "Waypoint " + wpnam + " not found"
def update(self):
up = np.where(self.lastupdate + self.trunctime < bs.sim.simt)
nup = len(up)
if self.transnoise:
self.lat[up] = bs.traf.lat[up] + np.random.normal(0, self.transerror[0], nup)
self.lon[up] = bs.traf.lon[up] + np.random.normal(0, self.transerror[0], nup)
self.alt[up] = bs.traf.alt[up] + np.random.normal(0, self.transerror[1], nup)
else:
self.lat[up] = bs.traf.lat[up]
self.lon[up] = bs.traf.lon[up]
self.alt[up] = bs.traf.alt[up]
self.trk[up] = bs.traf.trk[up]
self.tas[up] = bs.traf.tas[up]
self.gs[up] = bs.traf.gs[up]
self.vs[up] = bs.traf.vs[up]
self.lastupdate[up] = self.lastupdate[up] + self.trunctime
def delete(self, idx):
self.delac.extend(np.array(traf.id)[idx], traf.lat[idx], traf.lon[idx], traf.distflown[idx])
# n = len(idx) if isinstance(idx, Collection) else 1
# Decide to redraw radar picture of a/c
syst = pg.time.get_ticks() * 0.001
redrawrad = self.redrawradbg or abs(syst - self.radt0) >= self.radardt
if redrawrad:
self.radt0 = syst # Update lats drawing time of radar
# Select which aircraft are within screen area
trafsel = np.where((bs.traf.lat > self.lat0) * (bs.traf.lat < self.lat1) * \
(bs.traf.lon > self.lon0) * (bs.traf.lon < self.lon1))[0]
# ------------------- Draw aircraft -------------------
# Convert lat,lon to x,y
trafx, trafy = self.ll2xy(bs.traf.lat, bs.traf.lon)
trafy -= bs.traf.alt*self.isoalt
if bs.traf.trails.active:
ltx, lty = self.ll2xy(bs.traf.trails.lastlat, bs.traf.trails.lastlon)
# Find pixel size of horizontal separation on screen
pixelrad=self.dtopix_eq(bs.traf.asas.R/2)
# Loop through all traffic indices which we found on screen
for i in trafsel:
# Get index of ac symbol, based on heading and its rect object
isymb = int(round((bs.traf.hdg[i] - self.ndcrs) / 6.)) % 60
pos = self.acsymbol[isymb].get_rect()
# Draw aircraft symbol
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
mask = d > 10
sectoreff = list((leftdist[mask] - leftdist0[mask]) / d[mask] / nm)
names = np.array(left_del + left_intraf)[mask]
for name, eff in zip(names, sectoreff):
self.feff.write('{}, {}, {}\n'.format(sim.simt, name, eff))
def sectorcount(sw, name=''):
if sw == 'LIST':
if len(sectors) == 0:
return True, 'No registered sectors available'
else:
return True, 'Registered sectors:', str.join(', ', sectors)
elif sw == 'ADD':
# Add new sector to list.
if name in sectors:
return True, 'Sector %s already registered.' % name
elif areafilter.hasArea(name):
# Add new area to the sector list, and add an initial inside count of traffic
sectors.append(name)
inside = areafilter.checkInside(name, traf.lat, traf.lon, traf.alt)
previnside.append(set(np.array(traf.id)[inside]))
return True, 'Added %s to sector list.' % name
else:
return False, "No area found with name '%s', create it first with one of the shape commands" % name
else:
# Remove area from sector list
if name in sectors:
idx = sectors.index(name)
sectors.pop(idx)
previnside.pop(idx)
return True, 'Removed %s from sector list.' % name
else:
return False, "No sector registered with name '%s'." % name
# 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]])
# Check if conflict is past CPA
past_cpa = np.dot(dist, vrel) > 0.0
# hor_los:
# Aircraft should continue to resolve until there is no horizontal
# LOS. This is particularly relevant when vertical resolutions
# are used.
hdist = np.linalg.norm(dist)
hor_los = hdist < self.R
# Bouncing conflicts:
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
exits = self.insexp * np.logical_not(insexp)
if np.any(exits):
self.flst.log(
np.array(traf.id)[exits],
self.create_time[exits],
sim.simt - self.entrytime[exits],
self.dstart2D[exits] - self.distance2D[exits],
self.dstart3D[exits] - self.distance3D[exits],
self.workstart[exits] - self.work[exits],
traf.lat[exits],
traf.lon[exits],
traf.alt[exits],
traf.tas[exits],
traf.vs[exits],
traf.hdg[exits],
traf.asas.active[exits],
traf.pilot.alt[exits],
traf.pilot.tas[exits],
traf.pilot.vs[exits],
traf.pilot.hdg[exits])
# delete all aicraft in self.delidx
if len(delidx) > 0:
traf.delete(delidx)
# Autodelete for descending with swTaxi: