Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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))
sendeff = True
# print('{} aircraft left sector {}, distance flown (acid:dist):'.format(len(left), sector))
# for a, d0, d1, e in zip(left, leftdist0, leftdist, sectoreff):
# print('Aircraft {} flew {} meters (eff = {})'.format(a, round(d1-d0), e))
# Update inside data for this sector
previnside.delete(left)
def minTLOS(asas, traf, i, i_other, x1, y1, x, y):
""" This function calculates the aggregated TLOS for all resolution points """
# Get speeds of other AC in range
x_other = traf.gseast[i_other]
y_other = traf.gsnorth[i_other]
# Get relative bearing [deg] and distance [nm]
qdr, dist = geo.qdrdist(traf.lat[i], traf.lon[i], traf.lat[i_other], traf.lon[i_other])
# Convert to SI
qdr = np.deg2rad(qdr)
dist *= nm
# For vectorization, store lengths as W and L
W = np.shape(x)[0]
L = np.shape(x_other)[0]
# Relative speed-components
du = np.dot(x_other.reshape((L,1)),np.ones((1,W))) - np.dot(np.ones((L,1)),x.reshape((1,W)))
dv = np.dot(y_other.reshape((L,1)),np.ones((1,W))) - np.dot(np.ones((L,1)),y.reshape((1,W)))
# Relative speed + zero check
vrel2 = du * du + dv * dv
vrel2 = np.where(np.abs(vrel2) < 1e-6, 1e-6, vrel2) # limit lower absolute value
# X and Y distance
dx = np.dot(np.reshape(dist*np.sin(qdr),(L,1)),np.ones((1,W)))
dy = np.dot(np.reshape(dist*np.cos(qdr),(L,1)),np.ones((1,W)))
# Time to CPA
# User has entered an altitude for this waypoint
if alt >= -0.01:
bs.traf.actwp.nextaltco[i] = alt # [m]
if not bs.traf.swlnav[i]:
bs.traf.actwp.spd[i] = -999.
# VNAV spd mode: use speed of this waypoint as commanded speed
# while passing waypoint and save next speed for passing next wp
# Speed is now from speed! Next speed is ready in wpdata
if bs.traf.swvnavspd[i] and bs.traf.actwp.spd[i]> 0.0:
bs.traf.selspd[i] = bs.traf.actwp.spd[i]
# Update qdr and turndist for this new waypoint for ComputeVNAV
qdr[i], dummy = geo.qdrdist(bs.traf.lat[i], bs.traf.lon[i],
bs.traf.actwp.lat[i], bs.traf.actwp.lon[i])
# Update turndist so ComputeVNAV works, is there a next leg direction or not?
if bs.traf.actwp.next_qdr[i] < -900.:
local_next_qdr = qdr[i]
else:
local_next_qdr = bs.traf.actwp.next_qdr[i]
# Calculate turn dist (and radius which we do not use) now for scalar variable [i]
bs.traf.actwp.turndist[i], dummy = \
bs.traf.actwp.calcturn(bs.traf.tas[i], bs.traf.bank[i],
qdr[i], local_next_qdr) # update turn distance for VNAV
# VNAV = FMS ALT/SPD mode incl. RTA
self.ComputeVNAV(i, toalt, bs.traf.actwp.xtoalt[i], bs.traf.actwp.torta[i],
def distcalc(lat0, lon0, lat1, lon1):
try:
qdr, dist = geo.qdrdist(lat0, lon0, lat1, lon1)
return True, "QDR = %.2f deg, Dist = %.3f nm" % (qdr % 360.0, dist)
except:
return False, "Error in dist calculation."
def getnextqdr(self):
# get qdr for next leg
if -1 < self.iactwp < self.nwp - 1:
nextqdr, dist = geo.qdrdist(\
self.wplat[self.iactwp], self.wplon[self.iactwp],\
self.wplat[self.iactwp+1],self.wplon[self.iactwp+1])
else:
nextqdr = -999.
return nextqdr
# Convert lat/lon to pixel x,y
# Normal case
if self.lon1 > self.lon0:
x = self.width * (lon - self.lon0) / (self.lon1 - self.lon0)
# Wrap around:
else:
dellon = 180. - self.lon0 + self.lon1 + 180.
xlon = lon + (lon < 0.) * 360.
x = (xlon - self.lon0) / dellon * self.width
y = self.height * (self.lat1 - lat) / (self.lat1 - self.lat0)
else:
# NAVDISP mode:
qdr, dist = geo.qdrdist(self.ndlat, self.ndlon, lat, lon)
alpha = np.radians(qdr - self.ndcrs)
base = 30. * (self.lat1 - self.lat0)
x = dist * np.sin(alpha) / base * self.height + self.width / 2
y = -dist * np.cos(alpha) / base * self.height + self.height / 2
return np.rint(x), np.rint(y)