Closed 18360151678 closed 3 months ago
# Compute vapor density using temperature and relative humidity
vaporDens = rh2vaporDens(temp, rh)
# Compute CO2 density assuming a constant concentration of 410 ppm
co2 = co2ppm2dens(temp, 410)
# Calculate vapor pressure from vapor density and temperature
vapor_pressure = vaporDens2pres(epw_data["Dry Bulb Temperature (°C)"], vaporDens)
the three function can not function, and click on these three functions to display "canot find declaration to go to"
I have solve this problem by adding three functions,this code is shown below.
def rh2vaporDens(temp: np.ndarray, rh: np.ndarray) -> np.ndarray: """ Convert relative humidity to vapor density.
Args:
temp (np.ndarray): Temperature in Celsius.
rh (np.ndarray): Relative humidity in percentage (0-100).
Returns:
np.ndarray: Vapor density in kg/m^3.
"""
# Constants
MOLAR_GAS_CONSTANT = 8.3144598 # J mol^{-1} K^{-1}
CELSIUS_TO_KELVIN = 273.15 # K
MOLAR_MASS_WATER = 18.01528e-3 # kg mol^{-1}
SATURATION_PRESSURE_PARAMS = [610.78, 238.3, 17.2694, -6140.4, 273, 28.916]
# Calculate saturation vapor pressure of air at given temperature [Pa]
saturation_pressure = SATURATION_PRESSURE_PARAMS[0] * np.exp(
SATURATION_PRESSURE_PARAMS[2] * temp /
(temp + SATURATION_PRESSURE_PARAMS[1])
)
# Calculate partial pressure of vapor in air [Pa]
partial_pressure = (rh / 100) * saturation_pressure
# Convert to density using the ideal gas law: ρ = (P * M) / (R * T)
vaporDens = partial_pressure * MOLAR_MASS_WATER / \
(MOLAR_GAS_CONSTANT * (temp + CELSIUS_TO_KELVIN))
return vaporDens
def co2ppm2dens(temp: np.ndarray, ppm: float) -> np.ndarray: """ Convert CO2 molar concentration [ppm] to density [kg m^{-3}].
Args:
temp (np.ndarray): Given temperatures in Celsius.
ppm (float): CO2 concentration in air [ppm].
Returns:
np.ndarray: CO2 concentration in air [kg m^{-3}].
"""
# Constants
MOLAR_GAS_CONSTANT = 8.3144598 # J mol^{-1} K^{-1}
CELSIUS_TO_KELVIN = 273.15 # K
MOLAR_MASS_CO2 = 44.01e-3 # kg mol^{-1}
ATMOSPHERIC_PRESSURE = 101325 # Pa (assumed to be 1 atm)
# Calculate CO2 density using the ideal gas law
# ρ = (P * M) / (R * T) * (ppm * 10^-6)
co2 = (
ATMOSPHERIC_PRESSURE * MOLAR_MASS_CO2 * ppm * 1e-6 /
(MOLAR_GAS_CONSTANT * (temp + CELSIUS_TO_KELVIN))
)
return co2
def vaporDens2pres(temp: np.ndarray, vaporDens: np.ndarray) -> np.ndarray: """ Convert vapor density to vapor pressure.
Args:
temp (np.ndarray): Temperature in Celsius.
vaporDens (np.ndarray): Vapor density in kg/m^3.
Returns:
np.ndarray: Vapor pressure in Pascal.
"""
SATURATION_PRESSURE_PARAMS = [610.78, 238.3, 17.2694, -6140.4, 273, 28.916]
# Calculate relative humidity [0-1]
rh = vaporDens / rh2vaporDens(temp, 100)
# Calculate saturation vapor pressure of air at given temperature [Pa]
saturation_pressure = SATURATION_PRESSURE_PARAMS[0] * np.exp(
SATURATION_PRESSURE_PARAMS[2] * temp /
(temp + SATURATION_PRESSURE_PARAMS[1])
)
# Calculate vapor pressure
vapor_pressure = saturation_pressure * rh
return vapor_pressure
Start with a mature crop
keys: ['iGlob', 'tOut', 'vpOut', 'co2Out', 'wind', 'tSky', 'tSoOut', 'dayRadSum', 'isDay', 'isDaySmooth']
data_dict[keys[0]].shape: (2880, 2)
当前产量: 3.23 kg/m2
Traceback (most recent call last):
File "C:\Users\ma158\Desktop\GreenLightPlus-main\test\GreenLight_model.py", line 60, in
There's a new problem: the model iterates to the second time and then has problems.
The issues with the rh2vaporDens
, co2ppm2dens
, and vaporDens2pres
function names and imports have been fixed. Please pull the latest version.
the vapor density, CO2 density and vapor pressure can not be calculate. ![Uploading image.png…]()