greenpeer / GreenLightPlus

GreenLightPlus is a ToolKit for greenhouse environment simulation and energy consumption-yield analysis. It combines the original GreenLight model with the EnergyPlus simulation tool to investigate the energy consumption and output of different greenhouse structures.
GNU General Public License v3.0
12 stars 2 forks source link

the convert_epw2csv.py of service_functions not function #5

Closed 18360151678 closed 2 months ago

18360151678 commented 2 months ago

the vapor density, CO2 density and vapor pressure can not be calculate. ![Uploading image.png…]()

18360151678 commented 2 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"

18360151678 commented 2 months ago

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
18360151678 commented 2 months ago

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 gl = model.run_model(gl_params=init_state, season_length=season_length, File "C:\Users\ma158.conda\envs\GreenLightPlus2\lib\site-packages\GreenLightPlus\core\green_light_model.py", line 305, in run_model solver_instance = ODESolver(self.u, self.gl) File "C:\Users\ma158.conda\envs\GreenLightPlus2\lib\site-packages\GreenLightPlus\create_green_light_model\ode.py", line 36, in init self.d = self.convert_dict_to_array(self.gl['d']).copy() # Convert 'd' dict to array and copy File "C:\Users\ma158.conda\envs\GreenLightPlus2\lib\site-packages\GreenLightPlus\create_green_light_model\ode.py", line 49, in convert_dict_to_array num_rows = data_dict[keys[0]].shape[0] # Get number of rows from the first array IndexError: tuple index out of range keys: ['iGlob', 'tOut', 'vpOut', 'co2Out', 'wind', 'tSky', 'tSoOut', 'dayRadSum', 'isDay', 'isDaySmooth'] data_dict[keys[0]].shape: ()

There's a new problem: the model iterates to the second time and then has problems.

greenpeer commented 2 months ago

The issues with the rh2vaporDens, co2ppm2dens, and vaporDens2pres function names and imports have been fixed. Please pull the latest version.