Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 58 additions & 56 deletions pages/lib/extract_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,66 +399,68 @@ def create_df(lst, file_name):


# convert function
def temperature(df, name):
df[name] = df[name] * 1.8 + 32


def pressure(df, name):
df[name] = df[name] * 0.000145038


def irradiation(df, name):
df[name] = df[name] * 0.3169983306


def illuminance(df, name):
df[name] = df[name] * 0.0929


def zenith_illuminance(df, name):
df[name] = df[name] * 0.0929


def speed(df, name):
df[name] = df[name] * 196.85039370078738


def visibility(df, name):
df[name] = df[name] * 0.6215


def enthalpy(df, name):
df[name] = df[name] * 0.0004
def convert_SI_to_IP(df: pd.DataFrame, name: str) -> None:
"""Convert SI to IP based on column name."""
if name not in df.columns:
print(
f"[convert_SI_to_IP] Column '{name}' not found in DataFrame. Skipping conversion."
)
return
match name:
case (
ColNames.DBT
| ColNames.DPT
| ColNames.T_WB
| ColNames.T_DP
| ColNames.UTCI_SUN_WIND
| ColNames.UTCI_NO_SUN_WIND
| ColNames.UTCI_SUN_NO_WIND
| ColNames.UTCI_NO_SUN_NO_WIND
| ColNames.ADAPTIVE_COMFORT
| ColNames.ADAPTIVE_CMF_80_LOW
| ColNames.ADAPTIVE_CMF_80_UP
| ColNames.ADAPTIVE_CMF_90_LOW
| ColNames.ADAPTIVE_CMF_90_UP
):
df[name] = df[name] * 1.8 + 32

case ColNames.P_ATM | ColNames.P_VAP | ColNames.P_SAT:
df[name] = df[name] * 0.000145038

case (
ColNames.EXTR_HOR_RAD
| ColNames.HOR_IR_RAD
| ColNames.GLOB_HOR_RAD
| ColNames.DIR_NOR_RAD
| ColNames.DIF_HOR_RAD
):
df[name] = df[name] * 0.3169983306

case ColNames.GLOB_HOR_ILL | ColNames.DIR_NOR_ILL | ColNames.DIF_HOR_ILL:
df[name] = df[name] * 0.0929

case ColNames.ZLUMI:
df[name] = df[name] * 0.0929

case ColNames.WIND_SPEED:
df[name] = df[name] * 196.85039370078738

case ColNames.VIS:
df[name] = df[name] * 0.6215

case ColNames.EH:
df[name] = df[name] * 0.000429923

case _:
# No conversion needed for this column
pass


def convert_data(df, mapping_json):
convert_t_to_f(df, ColNames.ADAPTIVE_COMFORT)
convert_t_to_f(df, ColNames.ADAPTIVE_CMF_80_LOW)
convert_t_to_f(df, ColNames.ADAPTIVE_CMF_80_UP)
convert_t_to_f(df, ColNames.ADAPTIVE_CMF_90_LOW)
convert_t_to_f(df, ColNames.ADAPTIVE_CMF_90_UP)

mapping_dict = json.loads(mapping_json)
for key in json.loads(mapping_json):
if ColNames.CONVERSION_FUNCTION in mapping_dict[key]:
conversion_function_name = mapping_dict[key][ColNames.CONVERSION_FUNCTION]
if conversion_function_name is not None:
conversion_function = globals()[conversion_function_name]
conversion_function(df, key)
return json.dumps(mapping_dict)


def convert_t_to_f(df: pd.DataFrame, name: str):
"""Convert temperature from Celsius to Fahrenheit in-place for a given column.

Args:
df: The DataFrame containing the temperature column.
name: Column name to convert.

Returns:
None. The DataFrame is modified in-place.
"""
df[name] = df[name] * 1.8 + 32
for key in mapping_dict:
convert_SI_to_IP(df, key)
return mapping_json


def expand_to_hours(value: any, hours: int = 8760) -> list[any]:
Expand Down
10 changes: 9 additions & 1 deletion pages/lib/global_column_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ class ColNames:
RH = "RH" # Relative Humidity
HI_RH = "hiRH" # High Relative Humidity
LO_RH = "loRH" # Low Relative Humidity
HR = "hr"
HR = "hr" # Absolute Humidity
EH = "h" # Enthalpy
P_ATM = "p_atm" # Atmospheric Pressure
P_VAP = "p_vap" # Vapor partial Pressure
P_SAT = "p_sat" # Saturation Pressure
T_WB = "t_wb" # Wet Bulb Temperature
T_DP = "t_dp" # Dew Point Temperature

# ==================== Radiation-related column ====================
EXTR_HOR_RAD = "extr_hor_rad" # Extraterrestrial Horizontal Radiation
Expand Down Expand Up @@ -52,9 +57,11 @@ class ColNames:
# SnowD = "SnowD" # Snow Depth
# DaySSnow = "DaySSnow" # Daily Snow
ELEVATION = "elevation" # Elevation
EQUATION_OF_TIME = "equation_of_time" # Equation of time
APPARENT_ELEVATION = "apparent_elevation" # Apparent Elevation
APPARENT_ZENITH = "apparent_zenith" # Apparent Zenith
AZIMUTH = "azimuth" # Azimuth
ZENITH = "zenith" # Zenith
MRT = "MRT"
DELTA_MRT = "delta_mrt"
UTCI_SUN_WIND = "utci_Sun_Wind" # Utci Sun Wind
Expand Down Expand Up @@ -110,3 +117,4 @@ class ColNames:
GEOMETRY_COORDINATES = "geometry.coordinates"
PROP_ID = "prop_id"
SITE_ELEVATION = "site_elevation"
NONE = "None"
Loading
Loading