Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def navdata_load_rwythresholds():
rwythresholds = dict()
curthresholds = None
zfile = ZipFile(os.path.join(settings.navdata_path, 'apt.zip'))
print("Reading apt.dat from apt.zip")
with zfile.open('apt.dat', 'r') as f:
for line in f:
elems = line.decode(encoding="ascii", errors="ignore").strip().split()
if len(elems) == 0:
continue
# 1: AIRPORT
if elems[0] == '1':
# Add airport to runway threshold database
curthresholds = dict()
rwythresholds[elems[4]] = curthresholds
continue
if elems[0] == '100':
# Only asphalt and concrete runways
def init():
# Load the palette file selected in settings
pfile = path.join(settings.gfx_path, 'palettes', settings.colour_palette)
if path.isfile(pfile):
print('Loading palette ' + settings.colour_palette)
exec(compile(open(pfile).read(), pfile, 'exec'), globals())
return True
else:
print('Palette file not found ' + pfile)
return False
def main():
"""
Start BlueSky: Create gui and simulation objects
"""
# When importerror gives different name than (pip) install needs, also advise latest version
missingmodules = {"OpenGL": "pyopengl and pyopengl-accelerate", "PyQt4": "pyqt5"}
# Catch import errors
try:
# Initialize bluesky modules
bs.init()
# Start gui if this is the main process
if bs.settings.is_gui:
from bluesky.ui import qtgl
qtgl.start()
elif bs.settings.is_sim:
bs.sim.start()
# Give info on missing module
except ImportError as error:
modulename = missingmodules.get(error.name) or error.name
print("Bluesky needs", modulename)
print("Install using e.g. pip install", modulename)
print('BlueSky normal end.')
# scaling factors for drag (FAA_2005 SAGE)
# order of flight phases: TO, IC, CR ,AP, LD ,LD gear
self.d_CD0j = [1.476, 1.143,1.0, 1.957, 3.601, 1.037]
self.d_kj = [1.01, 1.071, 1.0 ,0.992, 0.932, 1.0]
self.d_CD0t = [1.220, 1.0, 1.0, 1.279, 1.828, 0.496]
self.d_kt = [0.948, 1.0, 1.0, 0.94, 0.916, 1.0]
# bank angles per phase. Order: TO, IC, CR, AP, LD. Currently already in CTraffic
# self.bank = np.deg2rad(np.array([15,35,35,35,15]))
# flag: did we already warn about invalid input unit?
self.warned = False
# parse AC files
path = os.path.join(settings.perf_path, 'BS/aircraft')
files = os.listdir(path)
for fname in files:
acdoc = ElementTree.parse(os.path.join(path, fname))
#actype = doc.find('ac_type')
self.atype.append(acdoc.find('ac_type').text)
# engine
self.etype.append(int(acdoc.find('engine/eng_type').text))
# store jet and turboprop aircraft in seperate lists for accessing specific engine data
if int(acdoc.find('engine/eng_type').text) ==1:
self.j_ac.append(acdoc.find('ac_type').text)
elif int(acdoc.find('engine/eng_type').text) ==2:
self.tp_ac.append(acdoc.find('ac_type').text)
from time import time, gmtime, strftime
import numpy as np
import matplotlib.pyplot as plt
from math import degrees
import collections
from collections import defaultdict
import itertools as IT
import bluesky as bs
from bluesky.tools import geo
from bluesky.tools.misc import tim2txt
from bluesky.tools.aero import *
from bluesky import settings
# Register settings defaults
settings.set_variable_defaults(log_path='output')
"""
This module seems to work as follows:
It looks like this used to be a submodule of the traffic module
Now it is a full module under the sim package
Apparently the creation of this module also called into life the concept of a research area.
A research area is something which is not specific to the metrics module and could be used by different modules.
However, the area command in the stack module saves data in the metric instance.
If the area function and metric module are to be seperatly used, then they should be untangled.
Classes:
Metric, metric_Area, metric_CoCa, metric_HB
Each has a constructor
Requirements for instance creation:
Metric: -
def reset(self):
super().reset()
self.clearconfdb()
self.confpairs_all.clear()
self.lospairs_all.clear()
self.rpz = bs.settings.asas_pzr * nm
self.hpz = bs.settings.asas_pzh * ft
self.dtlookahead = bs.settings.asas_dtlookahead
self.dtnolook = 0.0
self.rated_thrust = [] # rated Thrust (one engine)
self.ffto = [] # fuel flow takeoff
self.ffcl = [] # fuel flow climb
self.ffcr = [] # fuel flow cruise
self.ffid = [] # fuel flow idle
self.ffap = [] # fuel flow approach
self.SFC = [] # specific fuel flow cruise
# b. turboprops
self.P = [] # max. power (Turboprops, one engine)
self.PSFC_TO = [] # SFC takeoff
self.PSFC_CR = [] # SFC cruise
# parse engine files
path = os.path.join(settings.perf_path, 'BS/engines/')
files = os.listdir(path)
for fname in files:
endoc = ElementTree.parse(os.path.join(path, fname))
self.enlist.append(endoc.find('engines/engine').text)
# thrust
# a. jet engines
if int(endoc.find('engines/eng_type').text) ==1:
# store engine in jet-engine list
self.jetenlist.append(endoc.find('engines/engine').text)
# thrust
self.rated_thrust.append(self.convert(endoc.find('engines/Thr').text, endoc.find('engines/Thr').attrib['unit']))
# bypass ratio
BPRc = int(endoc.find('engines/BPR_cat').text)
# different SFC for different bypass ratios (reference: Raymer, p.36)
def __init__(self):
self.state = bs.INIT
self.prevstate = None
# System time [seconds]
self.syst = -1.0
# Benchmark time and timespan [seconds]
self.bencht = 0.0
self.benchdt = -1.0
# Simulation time [seconds]
self.simt = 0.0
# Simulation timestep [seconds]
self.simdt = bs.settings.simdt
# Simulation timestep multiplier: run sim at n x speed
self.dtmult = 1.0
# Simulated UTC clock time
self.utc = datetime.datetime.utcnow().replace(hour=0, minute=0, second=0, microsecond=0)
# Flag indicating running at fixed rate or fast time
self.ffmode = False
self.ffstop = None
# Flag indicating whether timestep can be varied to ensure realtime op
self.rtmode = False
import numpy as np
try:
from collections.abc import Collection
except ImportError:
# In python <3.3 collections.abc doesn't exist
from collections import Collection
import bluesky as bs
from bluesky.tools import geo
from bluesky.tools.simtime import timed_function
from bluesky.tools.position import txt2pos
from bluesky.tools.aero import ft, nm, vcasormach2tas, tas2cas
from bluesky.tools.trafficarrays import TrafficArrays, RegisterElementParameters
from bluesky.tools.replaceable import ReplaceableSingleton
from .route import Route
bs.settings.set_variable_defaults(fms_dt=1.0)
class Autopilot(ReplaceableSingleton, TrafficArrays):
def __init__(self):
TrafficArrays.__init__(self)
# Standard self.steepness for descent
self.steepness = 3000. * ft / (10. * nm)
# From here, define object arrays
with RegisterElementParameters(self):
# FMS directions
self.trk = np.array([])
self.spd = np.array([])
self.tas = np.array([])
self.alt = np.array([])