Source code for celme.atmosphere
import doctest
from .mechanics import Mechanics
from .home import Home
# ========================================================
# ========================================================
# === ATMOSPHERE
# ========================================================
# ========================================================
[docs]class Atmosphere(Mechanics):
""" Class to describe an atmosphere
"""
# ========================================================
# === attributs
# ========================================================
_pressure_pascal = 101325
_temperature_kelvin = 288
_humidity_percent = 50
# ========================================================
# === internal methods : Generals
# ========================================================
def _init_atmosphere(self):
""" Object initialization
"""
altitude_m = 0.0
self.atmosphere_standard(altitude_m)
# ========================================================
# === internal methods :
# ========================================================
# ========================================================
# === Atmosphere methods
# ========================================================
def atmosphere(self, pressure_pascal, temperature_kelvin, humidity_percent):
self._set_pressure(pressure_pascal)
self._set_temperature(temperature_kelvin)
self._set_humidity(humidity_percent)
def atmosphere_standard(self, home_or_altitude):
if isinstance(home_or_altitude, Home) == True:
altitude_m = home_or_altitude.altitude
elif isinstance(home_or_altitude, (int, float, str)) == True:
altitude_m = float(home_or_altitude)
else:
raise Exception
return ""
self._temperature_kelvin, self._pressure_pascal = self._mc_altitude2tp(altitude_m)
self._humidity_percent = 50
# ========================================================
# === get/set methods
# ========================================================
def _get_pressure(self):
return self._pressure_pascal
def _set_pressure(self, pressure_pascal):
if (pressure_pascal<0):
pressure_pascal=0
self._pressure_pascal = pressure_pascal
def _get_temperature(self):
return self._temperature_kelvin
def _set_temperature(self, temperature_kelvin):
if (temperature_kelvin<0):
temperature_kelvin = 0
self._temperature_kelvin = temperature_kelvin
def _get_humidity(self):
return self._humidity_percent
def _set_humidity(self, humidity_percent):
if humidity_percent<0:
humidity_percent=0
if humidity_percent>100:
humidity_percent=100
self._humidity_percent = humidity_percent
pressure = property(_get_pressure, _set_pressure)
temperature = property(_get_temperature, _set_temperature)
humidity = property(_get_humidity, _set_humidity)
# ========================================================
# === debug methods
# ========================================================
[docs] def infos(self, action) -> None:
""" To get informations about this class
:param action: A command to run a debug action (see examples).
:type action: string
:Example:
Atmosphere().infos("doctest")
Atmosphere().infos("doc_methods")
Atmosphere().infos("internal_attributes")
Atmosphere().infos("public_methods")
"""
if (action == "doc_methods"):
publics = [x for x in dir(self) if x[0]!="_"]
for public in publics:
varname = "{}".format(public)
if (callable(getattr(self,varname))==True):
print("\n{:=^40}".format(" method "+varname+" "))
t = "Atmosphere()."+varname+".__doc__"
tt =eval(t)
print(tt)
if (action == "doctest"):
if __name__ == "__main__":
print("\n{:~^40}".format("doctest"))
doctest.testmod(verbose=False)
if (action == "internal_attributes"):
internals = [x for x in dir(self) if x[0]=="_" and x[1]!="_"]
for internal in internals:
varname = "{}".format(internal)
#if (hasattr(self,varname)==True):
if (callable(getattr(self,varname))==False):
print(varname + "=" + str(getattr(self,varname)))
if (action == "public_methods"):
publics = [x for x in dir(self) if x[0]!="_"]
for public in publics:
varname = "{}".format(public)
if (callable(getattr(self,varname))==True):
print(varname)
# ========================================================
# === special methods
# ========================================================
def __init__(self):
""" Object initialization
"""
self._init_atmosphere()
# super().__init__()