Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#-------------------------------------------------
#phase CR[3]: in climb above 2000ft, in descent
# above 8000ft and below 8000ft if V>=Vmincr + 10kts
# a. climb
Caalt = np.array(alt >= (2000. * ft))
Cavs = np.array(delalt >= 0.)
cra = np.logical_and.reduce([Caalt, Cavs]) * 1
#b. above 8000ft
crb = np.array(alt > (8000. * ft)) * 1
#c. descent
Ccalt = np.array(alt <= (8000. * ft))
Ccvs = np.array(delalt <= 0.)
Ccspd = np.array(cas >= (vmcr + 10. * kts))
crc = np.logical_and.reduce([Ccalt, Ccvs, Ccspd]) * 1
# merge climb and descent phase
cr = np.maximum(cra, np.maximum(crb, crc)) * 3
#-------------------------------------------------
# phase AP[4]
#a. alt<8000, Speed between Vmcr+10 and Vmapp+10, v<>0
#altitude check
Aaalt = np.array((alt > ft) & (alt <= (8000. * ft)))
Aaspd = np.array(cas < (vmcr + 10. * kts))
Aavs = np.array(delalt <= 0.)
apa = np.logical_and.reduce([Aaalt, Aaspd , Aavs]) * 1
def convert(self, value, unit):
factors = {'kg': 1., 't':1000., 'lbs': lbs, 'N': 1., 'W': 1, \
'm':1.,'km': 1000., 'inch': inch,'ft': ft, \
'sqm': 1., 'sqft': sqft, 'sqin': 0.0254*0.0254 ,\
'm/s': 1., 'km/h': 1./3.6, 'kts': kts, 'fpm': fpm, \
"kg/s": 1., "kg/m": 1./60., 'mug/J': 0.000001, 'mg/J': 0.001 ,
"kW": 1000.,"kN":1000.,
"":1.}
if unit in factors:
converted = factors[unit] * float(value)
else:
converted = float(value)
if not self.warned:
print("traf/perf.py convert function: Unit mismatch. Could not find ", unit)
self.warned = True
return converted
self.warned = True
else:
print("Flight " + bs.traf.id[-1] + " has an unknown aircraft type, " + actype + ", BlueSky then uses default B747-400 performance.")
coeffidx = np.array(coeffidx)
# note: coefficients are initialized in SI units
self.coeffidxlist[-n:] = coeffidx
self.mass[-n:] = coeffBS.MTOW[coeffidx] # aircraft weight
self.Sref[-n:] = coeffBS.Sref[coeffidx] # wing surface reference area
self.etype[-n:] = coeffBS.etype[coeffidx] # engine type of current aircraft
self.engines[-n:] = [coeffBS.engines[c] for c in coeffidx]
# speeds
self.refma[-n:] = coeffBS.cr_Ma[coeffidx] # nominal cruise Mach at 35000 ft
self.refcas[-n:] = vtas2cas(coeffBS.cr_spd[coeffidx], 35000*ft) # nominal cruise CAS
self.gr_acc[-n:] = coeffBS.gr_acc[coeffidx] # ground acceleration
self.gr_dec[-n:] = coeffBS.gr_dec[coeffidx] # ground acceleration
# calculate the crossover altitude according to the BADA 3.12 User Manual
self.atrans[-n:] = ((1000/6.5)*(T0*(1-((((1+gamma1*(self.refcas[-n:]/a0)*(self.refcas[-n:]/a0))** \
(gamma2))-1) / (((1+gamma1*self.refma[-n:]*self.refma[-n:])** \
(gamma2))-1))**((-(beta)*R)/g0))))
# limits
self.vm_to[-n:] = coeffBS.vmto[coeffidx]
self.vm_ld[-n:] = coeffBS.vmld[coeffidx]
self.mmo[-n:] = coeffBS.max_Ma[coeffidx] # maximum Mach
self.vmo[-n:] = coeffBS.max_spd[coeffidx] # maximum CAS
self.hmaxact[-n:] = coeffBS.max_alt[coeffidx] # maximum altitude
# self.vmto/vmic/vmcr/vmap/vmld/vmin are initialised as 0 by super.create
confidx = 0
zdata = zip(data.id, data.ingroup, data.inconf, data.tcpamax, data.trk, data.gs,
data.cas, data.vs, data.alt, data.lat, data.lon)
for i, (acid, ingroup, inconf, tcpa, trk, gs, cas, vs, alt, lat, lon) in enumerate(zdata):
if i >= MAX_NAIRCRAFT:
break
# Make label: 3 lines of 8 characters per aircraft
if actdata.show_lbl >= 1:
rawlabel += '%-8s' % acid[:8]
if actdata.show_lbl == 2:
if alt <= data.translvl:
rawlabel += '%-5d' % int(alt / ft + 0.5)
else:
rawlabel += 'FL%03d' % int(alt / ft / 100. + 0.5)
vsarrow = 30 if vs > 0.25 else 31 if vs < -0.25 else 32
rawlabel += '%1s %-8d' % (chr(vsarrow), int(cas / kts + 0.5))
else:
rawlabel += 16 * ' '
if inconf:
if actdata.ssd_conflicts:
selssd[i] = 255
color[i, :] = palette.conflict + (255,)
lat1, lon1 = geo.qdrpos(lat, lon, trk, tcpa * gs / nm)
cpalines[4 * confidx : 4 * confidx + 4] = [lat, lon, lat1, lon1]
confidx += 1
else:
# Get custom color if available, else default
rgb = palette.aircraft
if ingroup:
# dets and orig al already done, skip them here
if iwp == 0 and route.wpname[iwp] == bs.traf.ap.orig[i]:
continue
if iwp == route.nwp - 1 and route.wpname[iwp] == bs.traf.ap.dest[i]:
continue
# add other waypoints
cmdline = "ADDWPT " + bs.traf.id[i] + " "
wpname = route.wpname[iwp]
if wpname[: len(bs.traf.id[i])] == bs.traf.id[i]:
wpname = repr(route.wplat[iwp]) + "," + repr(route.wplon[iwp])
cmdline = cmdline + wpname + ","
if route.wpalt[iwp] >= 0.0:
cmdline = cmdline + repr(route.wpalt[iwp] / ft) + ","
else:
cmdline = cmdline + ","
if route.wpspd[iwp] >= 0.0:
if route.wpspd[iwp] > 1.0:
cmdline = cmdline + repr(route.wpspd[iwp] / kts)
else:
cmdline = cmdline + repr(route.wpspd[iwp])
f.write(timtxt + cmdline + "\n")
# Saveic: save file
savefile = f
return True
def set_taxi(self, flag,alt=1500*ft):
''' Taxi ON/OFF to autodelete below a certain altitude if taxi is off'''
self.swtaxi = flag # True = taxi allowed, False = autodelete below swtaxialt
self.swtaxialt = alt
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)
stack.stack(cmdstr)
return
# To be safe show both when we do not know what
if not (swalt or swspd):
swalt = True
swspd = True
# Show altitude
if swalt:
if self.wpalt[wpidx] < 0:
txt += "-----"
elif self.wpalt[wpidx] > 4500 * ft:
fl = int(round((self.wpalt[wpidx] / (100. * ft))))
txt += "FL" + str(fl)
else:
txt += str(int(round(self.wpalt[wpidx] / ft)))
if swspd:
txt += "/"
# Show speed
if swspd:
if self.wpspd[wpidx] < 0:
txt += "---"
else:
txt += str(int(round(self.wpspd[wpidx] / kts)))
# Type
if swalt and swspd:
if self.wptype[wpidx] == Route.orig:
txt += "[orig]"
elif self.wptype[wpidx] == Route.dest:
# Type code never larger than 20
if itype not in list(wptypedict.keys()):
continue # Next line
wptype = wptypedict[itype]
# Select types to read
if wptype not in ["NDB","VOR","DME","TACAN"]:
continue # Next line
wptdata["wptype"].append(wptype)
wptdata["wplat"].append(float(fields[1])) # latitude [deg]
wptdata["wplon"].append(float(fields[2])) # longitude [deg]
wptdata["wpelev"].append(float(fields[3])*ft) # elevation [ft]
if wptype=="NDB":
wptdata["wpfreq"].append(int(fields[4])) # NDB freq in kHz
elif wptype in ["VOR","DME","TACAN"]:
wptdata["wpfreq"].append(float(fields[4])/100.) # VOR freq in MHz
else:
wptdata["wpfreq"].append(0.0)
if wptype in ["VOR","NDB"]:
wptdata["wpvar"].append(float(fields[6])) # Magnetic variation in degrees
wptdata["wpid"].append(fields[7]) # Id
elif wptype in ["DME","TACAN"]:
wptdata["wpvar"].append(0.0) # Magnetic variation not given
wptdata["wpid"].append(fields[7]) # Id
hsep=traf.asas.R # [m] horizontal separation minimum
hseplat=hsep/mperdeg
wallsep=1.1 #factor of extra space in the wall
traf.create("OWNSHIP","WALL",0,-distance,90, 20000, 200)
for i in range(20):
acid="OTHER"+str(i)
traf.create(acid,"WALL",(i-10)*hseplat*wallsep,distance,270,20000,200)
if savescenarios:
fname="wall"
cmd.saveic(fname,sim,traf)
elif command == "TESTCIRCLE":
scr.swtestarea = True #show circles in testing area
scr.redrawradbg=True #draw the background again
traf.asas=CASAScircle.Dbconf(traf,300., 5.*nm, 1000.*ft)
#change the ASAS system with one that incorporates
#the circular testing area
traf.asas.Rtest=50*nm #Testing area radius
traf.asas.Rinit=65*nm #Initialization area radius
# Toggle the display of certain elements in screen
elif command == "DISP":
if numargs == 0:
scr.echo(callsign+"DISP ")
else:
sw = commandargs[1]
#show separation circles between aircraft of 2.5 nm radius
if sw == "SEP":
scr.swsep = not scr.swsep
elif sw == "SPD":