further clean-up and added pressure-
conversion import from single-source
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
from pressure_conversion import pressure_conversion
|
||||
import numpy as np
|
||||
|
||||
#importing pressure conversion function
|
||||
import sys
|
||||
import os
|
||||
current = os.path.dirname(os.path.realpath(__file__))
|
||||
parent = os.path.dirname(current)
|
||||
sys.path.append(parent)
|
||||
from functions.pressure_conversion import pressure_conversion
|
||||
|
||||
|
||||
class Druckrohrleitung_class:
|
||||
# units
|
||||
acceleration_unit = r'$\mathrm{m}/\mathrm{s}^2$'
|
||||
|
||||
@@ -2,19 +2,26 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"from Druckrohrleitung_class_file import Druckrohrleitung_class\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"from pressure_conversion import pressure_conversion"
|
||||
"\n",
|
||||
"#importing pressure conversion function\n",
|
||||
"import sys\n",
|
||||
"import os\n",
|
||||
"current = os.path.dirname(os.path.realpath('Main_Programm.ipynb'))\n",
|
||||
"parent = os.path.dirname(current)\n",
|
||||
"sys.path.append(parent)\n",
|
||||
"from functions.pressure_conversion import pressure_conversion"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -98,7 +105,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -126,7 +133,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -182,7 +189,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -210,7 +217,7 @@
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3.8.13 ('Georg_DT_Slot3')",
|
||||
"display_name": "Python 3.8.13 ('DT_Slot_3')",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
@@ -229,7 +236,7 @@
|
||||
"orig_nbformat": 4,
|
||||
"vscode": {
|
||||
"interpreter": {
|
||||
"hash": "84fb123bdc47ab647d3782661abcbe80fbb79236dd2f8adf4cef30e8755eb2cd"
|
||||
"hash": "4a28055eb8a3160fa4c7e4fca69770c4e0a1add985300856aa3fcf4ce32a2c48"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
# convert to Pa
|
||||
def bar_to_pa(p):
|
||||
return p*1e5
|
||||
|
||||
def mWS_to_pa(p):
|
||||
return p*9.80665*1e3
|
||||
|
||||
def torr_to_pa(p):
|
||||
return p*133.322
|
||||
|
||||
def atm_to_pa(p):
|
||||
return p*101.325*1e3
|
||||
|
||||
def psi_to_pa(p):
|
||||
return p*6894.8
|
||||
|
||||
# convert from Pa
|
||||
def pa_to_bar(p):
|
||||
return p*1e-5
|
||||
|
||||
def pa_to_mWS(p):
|
||||
return p*1/(9.80665*1e3)
|
||||
|
||||
def pa_to_torr(p):
|
||||
return p/133.322
|
||||
|
||||
def pa_to_atm(p):
|
||||
return p*1/(101.325*1e3)
|
||||
|
||||
# converstion function
|
||||
|
||||
def pa_to_psi(p):
|
||||
return p/6894.8
|
||||
|
||||
def pressure_conversion(pressure, input_unit = 'bar', target_unit = 'Pa'):
|
||||
p = pressure
|
||||
if input_unit.lower() == 'bar':
|
||||
p_pa = bar_to_pa(p)
|
||||
elif input_unit.lower() == 'mws':
|
||||
p_pa = mWS_to_pa(p)
|
||||
elif input_unit.lower() == 'torr':
|
||||
p_pa = torr_to_pa(p)
|
||||
elif input_unit.lower() == 'atm':
|
||||
p_pa = atm_to_pa(p)
|
||||
elif input_unit.lower() == 'psi':
|
||||
p_pa = psi_to_pa(p)
|
||||
elif input_unit.lower() == 'pa':
|
||||
p_pa = p
|
||||
else:
|
||||
raise Exception('Given input unit not recognised. \n Known units are: Pa, bar, mWs, Torr, atm, psi')
|
||||
|
||||
if target_unit.lower() == 'bar':
|
||||
return pa_to_bar(p_pa), target_unit
|
||||
elif target_unit.lower() == 'mws':
|
||||
return pa_to_mWS(p_pa), target_unit
|
||||
elif target_unit.lower() == 'torr':
|
||||
return pa_to_torr(p_pa), target_unit
|
||||
elif target_unit.lower() == 'atm':
|
||||
return pa_to_atm(p_pa), target_unit
|
||||
elif target_unit.lower() =='psi':
|
||||
return pa_to_psi(p_pa), target_unit
|
||||
elif target_unit.lower() == 'pa':
|
||||
return p_pa, target_unit
|
||||
else:
|
||||
raise Exception('Given target unit not recognised. \n Known units are: Pa, bar, mWs, Torr, atm, psi')
|
||||
|
||||
# testing_pressure_conversion
|
||||
if __name__ == '__main__':
|
||||
p = 1
|
||||
|
||||
unit_dict = ['Pa','Bar','Torr','Atm','MWS','psi']
|
||||
|
||||
for input_unit in unit_dict:
|
||||
for target_unit in unit_dict:
|
||||
converted_p = pressure_conversion(p,input_unit,target_unit)
|
||||
print(input_unit,target_unit)
|
||||
print(converted_p)
|
||||
Reference in New Issue
Block a user