Skip to content

Commit

Permalink
Tabulated Data Added
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeDeWaal committed Apr 15, 2019
1 parent b459044 commit d79900b
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 15 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ Contents:
- Atmospheric Model up to 110km
- Accurate Calculations for Temperature, Pressure and Density
- Custom defined atmospheric conditions
- Tabulate your data to save future computation time
- Save tabulated data in .csv or .xlsx files


With this module, it is possible to calculate, using the 1976 standard atmosphere model, the Temperature,
Density and Pressure at any point in the atmosphere from 0 up to 110,000 [m].

This package is useful for Aerospace and Aeronautical Engineers who wish to run simulations.
This package is useful for Aerospace and Aeronautical Engineers who wish to run simulations using atmospheric data.

To use this package, follow these steps:

Expand Down
1 change: 1 addition & 0 deletions isacalc/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from isacalc.main_executable import calculate_at_h, get_atmosphere
from isacalc.table_maker import tabulate
27 changes: 24 additions & 3 deletions isacalc/src/atmosphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,35 @@ def __init__(self, *args, **kwargs):
self.__layers = []
self.__build()

def get_height_boundaries(self):
"""
Method to calculate for which range the atmosphere model can be used
:return: Min, Max Height
"""
return self.__Hn[0], self.__Hn[-1]

@staticmethod
def __get_lapse(Hn, Tn) -> list:
"""
Static Method to calculate the layer types of all layers
:param Hn: Heights
:param Tn: Temperatures
:return: Layer Types
"""

types = []

for i in range(len(Hn)-1):
lapse = (Tn[i+1] - Tn[i])/(Hn[i+1] - Hn[i])
delta_T = Tn[i+1] - Tn[i]

lapse = delta_T/(Hn[i+1] - Hn[i])

if lapse != 0:
types.append(1)
if abs(delta_T) > 0.5:
types.append(1)

else:
types.append(0)

elif lapse == 0:
types.append(0)
Expand Down Expand Up @@ -95,9 +113,12 @@ def calculate(self, h) -> list:
if h == self.__Hn[idx+1]:
return self.__layers[idx].get_ceiling_values()

elif h == self.__Hn[idx]:
return self.__layers[idx].get_base_values()

elif self.__Hn[idx] < h < self.__Hn[idx + 1]:
return self.__layers[idx].get_intermediate_values(h)

elif h >= self.__Hn[idx + 1]:
elif h > self.__Hn[idx + 1]:
continue

32 changes: 24 additions & 8 deletions isacalc/src/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Layer(object):
"""

def __init__(self, base_height: float, base_temperature: float, base_pressure: float, base_density: float,
max_height: float, name: str = ''):
max_height: float, name: str = '', **kwargs):
"""
All Properties of a layer, excluding its type, which will be expressed
by making separate objects for the different layers
Expand All @@ -18,9 +18,21 @@ def __init__(self, base_height: float, base_temperature: float, base_pressure: f
:param max_height: Height up to which the layer extends
"""

self.g0 = 9.80665
self.R = 287.0
self.gamma = 1.4
if kwargs:
try:
self.g0 = kwargs['g0']
self.R = kwargs['R']
self.gamma = kwargs['gamma']

except KeyError:
self.g0 = 9.80665
self.R = 287.0
self.gamma = 1.4

else:
self.g0 = 9.80665
self.R = 287.0
self.gamma = 1.4

self.__h0 = base_height
self.__T0 = base_temperature
Expand Down Expand Up @@ -99,14 +111,16 @@ def __init__(self, base_height: float,
base_pressure: float,
base_density: float,
max_height: float,
name: str = ''):
name: str = '',
**kwargs):

super().__init__(base_height=base_height,
base_temperature=base_temperature,
base_pressure=base_pressure,
base_density=base_density,
max_height=max_height,
name=name)
name=name,
**kwargs)

def get_ceiling_values(self) -> list:
"""
Expand Down Expand Up @@ -160,14 +174,16 @@ def __init__(self, base_height: float,
base_density: float,
max_height: float,
top_temperature: float,
name: str = ''):
name: str = '',
**kwargs):

super().__init__(base_height=base_height,
base_temperature=base_temperature,
base_pressure=base_pressure,
base_density=base_density,
max_height=max_height,
name=name)
name=name,
**kwargs)

self.__T_top = top_temperature

Expand Down
98 changes: 98 additions & 0 deletions isacalc/table_maker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import numpy as np
import pandas as pd
from isacalc.main_executable import get_atmosphere, calculate_at_h


def __extract_desired_params(boolean_list: list, parameter_list: list):
"""
Function which takes 2 lists, one with booleans and one with any other data types.
Returns a list with all values of the parameter list which had the same indices as
the True booleans in the boolean list
:param boolean_list: List of True or False
:param parameter_list: List of parameters
:return: List of parameters that coincide with True items in boolean list
"""

if len(boolean_list) != len(parameter_list):
raise IndexError("Input sizes do not match")

result = []

for boolean, item in zip(boolean_list, parameter_list):
if boolean is True:
result.append(item)

return result


def tabulate(height_range: tuple, atmosphere_model=get_atmosphere(), export_as: str = '', params: list = []):
"""
Function to tabulate all the calculated data.
For large projects where the ISA data needs to be calculated and accessed a lot, this will be
a beneficial tradeoff of space against time. Storing in a csv or xlsx file is optional
:param height_range: Range of heights, (start, stop, step) format is required
:param atmosphere_model: Model on which the computations need to be performed
:param export_as: If left blank, will not be saved to file
:param params: List of all desired parameters to be recorded
:return: Numpy Array of all values calculated [Height, Temp, Press, Dens, SOS, Visc]
"""

param_names = ['Temperature [K]',
'Pressure [Pa]',
'Density [kg/m^3]',
'Speed of Sound [m/s]',
'Dynamic Viscosity [kg/(m*s)]']

start, stop, step = height_range
heights = np.arange(start=start, stop=stop+step, step=step)

params = [a.lower() for a in params if type(a) == str and len(params) != 0]

boolean_record_list = [True]*5

if params:
if 't' not in params:
boolean_record_list[0] = False

if 'p' not in params:
boolean_record_list[1] = False

if 'd' not in params:
boolean_record_list[2] = False

if 'a' not in params:
boolean_record_list[3] = False

if 'mu' not in params:
boolean_record_list[4] = False

table_shape = (len(heights), sum(boolean_record_list)+1)
result = np.zeros(table_shape, dtype=float)

for idx, height in enumerate(heights):

parameters = __extract_desired_params(boolean_record_list, list(calculate_at_h(height, atmosphere_model=atmosphere_model)))
result[idx,:] = [height] + parameters

if export_as:

param_names = __extract_desired_params(boolean_record_list, param_names)

extension = export_as.split('.')[-1]

df_result = pd.DataFrame(data=result,
index=range(0, table_shape[0]),
columns=['Height [m]']+param_names)

if extension == 'csv':
df_result.to_csv(export_as)

else:
df_result.to_excel(export_as)

return result


if __name__ == "__main__":

table = tabulate((0, 110000, 100), export_as=r'test1.csv', params=['T', 'mu', 'p'])
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ def readme():
setup(
name = 'isacalc', # How you named your package folder (MyLib)
packages = ['isacalc'], # Chose the same as "name"
version = 'v1.2.0', # Start with a small number and increase it with every change you make
version = 'v1.2.1', # Start with a small number and increase it with every change you make
license='GNU GPLv3', # Chose a license from here: https://help.github.com/articles/licensing-a-repository
description = 'Standard International Atmosphere Calculator', # Give a short description about your library
long_description=readme(),
author = 'Luke de Waal', # Type in your name
author_email = '[email protected]', # Type in your E-Mail
url = 'https://github.com/LukeDeWaal/ISA_Calculator', # Provide either the link to your github or to your website
download_url = 'https://github.com/LukeDeWaal/ISA_Calculator/archive/v1.2.0.tar.gz', # I explain this later on
download_url = 'https://github.com/LukeDeWaal/ISA_Calculator/archive/v1.2.1.tar.gz', # I explain this later on
keywords = ['ISA','Aerospace','Aeronautical','Atmosphere'], # Keywords that define your package best
install_requires=[ # I get to this in a second
'numpy',
'numpy', 'pandas'
],
classifiers=[
'Development Status :: 3 - Alpha', # Chose either "3 - Alpha", "4 - Beta" or "5 - Production/Stable" as the current state of your package
Expand Down

0 comments on commit d79900b

Please sign in to comment.