Blame view

src/utils/celme/atmosphere.py 5.04 KB
4f8cc5f0   aklotz   Package CelMe Cel...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import doctest
from celme.mechanics import Mechanics
from celme.home import Home

# ========================================================
# ========================================================
# === ATMOSPHERE
# ========================================================
# ========================================================

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
# ========================================================
    
    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__()