Hier ist mein Code:
Hier zunächst meine zuvor definierte Funktion zur Berechnung der Temperatur:
def local_atmospheric_temperature(altitude):
"""Calculates the temperature at given altitude
Args:
altitude: The specific altitude in meters [m] above sea level
Returns:
temperature: The temperature in [K] at a given altitude
"""
h = altitude # [m]
# CONSTANTS
# standart temperature Tb in [K]
t_0 = 288.15 #Troposphere
t_1 = 216.65 #Tropopause
t_2 = 216.65 #Stratosphere1
t_3 = 228.65 #Stratosphere2
t_4 = 270.65 #Stratopause
t_5 = 270.65 #Mesosphere1
t_6 = 214.65 #Mesosphere2
# referenz altitude hb in [m]
h_0 = 0 #Troposphere
h_1 = 11000 #Tropopause
h_2 = 20000 #Stratosphere1
h_3 = 32000 #Stratosphere2
h_4 = 47000 #Stratopause
h_5 = 51000 #Mesosphere1
h_6 = 71000 #Mesosphere2
# temperature descentrate Lb in [K/m]
L_0 = -0.0065 #Troposphere
L_1 = 0 #Tropopause
L_2 = 0.001 #Stratosphere1
L_3 = 0.0028 #Stratosphere2
L_4 = 0 #Stratopause
L_5 = -0.0028 #Mesosphere1
L_6 = -0.002 #Mesosphere2
#Calculations
#Troposphere
if (h_0 <= h < h_1):
t_b = t_0
h_b = h_0
L_b = L_0
#Tropopause
elif(h_1 <= h < h_2):
t_b = t_1
h_b = h_1
L_b = L_1
#Stratosphere1
elif(h_2 <= h < h_3):
t_b = t_2
h_b = h_2
L_b = L_2
#Stratosphere2
elif(h_3 <= h < h_4):
t_b = t_3
h_b = h_3
L_b = L_3
#Stratopause
elif(h_4 <= h < h_5):
t_b = t_4
h_b = h_4
L_b = L_4
#Mesosphere1
elif(h_5 <= h < h_6):
t_b = t_5
h_b = h_5
L_b = L_5
#Mesosphere2
elif(h_6 <= h <= 80000):
t_b = t_6
h_b = h_6
L_b = L_6
if(L_b != 0):
temperature = t_b + L_b*(h-h_b)
else:
temperature = t_b
return(temperature)
Als nächstes dann der Code zur Erzeugung meines Diagramms:
def plot_altitude_80km_temperature():
"""Creates a plot that shows the temperature at Different Altitudes from 0 km to 80 km.
Args:
no inputs
Returns:
plot of Temperature at Different Altitudes
"""
#Calculations
%matplotlib inline
y = np.linspace(0,80,10)
x = local_atmospheric_temperature(y*1000)
fig =plt.figure()
ax = fig.add_axes([0,0,1,1])
ax.plot(x,y)
ax.set_title("Temperature at Different Altitudes")
ax.set_ylabel("Altitude in [km]")
ax.set_xlabel("Temperature in [°C]\n ")
return()
und als Fehler bekomme ich dann :
ValueError Traceback (most recent call last)
<ipython-input-17-1962f763aa9a> in <module>
----> 1 plot_altitude_80km_temperature()
<ipython-input-16-b604d265f6eb> in plot_altitude_80km_temperature()
12 #%matplotlib inline
13 y = np.linspace(0,80,10)
---> 14 x = local_atmospheric_temperature(y*1000)
15
16 fig =plt.figure()
<ipython-input-8-c96009a83ccb> in local_atmospheric_temperature(altitude)
43
44 #Troposphere
---> 45 if (h_0 <= h < h_1):
46 t_b = t_0
47 h_b = h_0
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Ich hoffe, dass ihr mir hier weiterhelfen könnt. Danke im Voraus
