Skip to content

Commit

Permalink
Merge pull request #394 from UU-ER/develop_0.1.7
Browse files Browse the repository at this point in the history
Develop 0.1.7
  • Loading branch information
JeanWi authored Dec 10, 2024
2 parents a6ed4ba + b44e8a6 commit 0cbf4be
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
10 changes: 8 additions & 2 deletions adopt_net0/data_management/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,21 @@

def calculate_dni(data: pd.DataFrame, lon: float, lat: float) -> pd.Series:
"""
Calculate direct normal irradiance from ghi and dhi
Calculate direct normal irradiance from ghi and dhi. The function assumes that
the ghi and dhi are given as an average value for the timestep and dni is
calculated using the position of the sun in the middle of the timestep.
:param pd.DataFrame data: climate data with columns ghi and dhi
:param float lon: longitude
:param float lat: latitude
:return data: climate data including dni
:rtype: pd.Series
"""
zenith = pvlib.solarposition.get_solarposition(data.index, lat, lon)
timesteps = pd.to_datetime(data.index)
timestep_length = pd.to_datetime(data.index[1]) - pd.to_datetime(data.index[0])
timesteps = timesteps + (timestep_length / 2)

zenith = pvlib.solarposition.get_solarposition(timesteps, lat, lon)
data["dni"] = pvlib.irradiance.dni(
data["ghi"].to_numpy(), data["dhi"].to_numpy(), zenith["zenith"].to_numpy()
)
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ highspy==1.8.1 ; python_version >= "3.12" and python_version < "4.0"
idna==3.10 ; python_version >= "3.12" and python_version < "4.0"
joblib==1.4.2 ; python_version >= "3.12" and python_version < "4.0"
networkx==3.4.2 ; python_version >= "3.12" and python_version < "4.0"
numpy==2.1.3 ; python_version >= "3.12" and python_version < "4.0"
numpy==2.2.0 ; python_version >= "3.12" and python_version < "4.0"
openpyxl==3.1.5 ; python_version >= "3.12" and python_version < "4.0"
packaging==24.2 ; python_version >= "3.12" and python_version < "4.0"
pandas==2.2.3 ; python_version >= "3.12" and python_version < "4.0"
Expand All @@ -24,9 +24,9 @@ python-dateutil==2.9.0.post0 ; python_version >= "3.12" and python_version < "4.
pytz==2024.2 ; python_version >= "3.12" and python_version < "4.0"
requests==2.32.3 ; python_version >= "3.12" and python_version < "4.0"
scandir==1.10.0 ; python_version >= "3.12" and python_version < "4.0"
scikit-learn==1.5.2 ; python_version >= "3.12" and python_version < "4.0"
scikit-learn==1.6.0 ; python_version >= "3.12" and python_version < "4.0"
scipy==1.14.1 ; python_version >= "3.12" and python_version < "4.0"
six==1.16.0 ; python_version >= "3.12" and python_version < "4.0"
six==1.17.0 ; python_version >= "3.12" and python_version < "4.0"
statsmodels==0.14.4 ; python_version >= "3.12" and python_version < "4.0"
threadpoolctl==3.5.0 ; python_version >= "3.12" and python_version < "4.0"
timezonefinder==6.5.7 ; python_version >= "3.12" and python_version < "4"
Expand Down
16 changes: 16 additions & 0 deletions tests/test_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os

import adopt_net0.data_preprocessing as dp
from adopt_net0.data_management.utilities import calculate_dni
from adopt_net0.data_management.utilities import check_input_data_consistency
from tests.utilities import (
select_random_list_from_list,
Expand Down Expand Up @@ -52,9 +53,24 @@ def test_data_climate_data_loading(request):
/ node
/ "ClimateData.csv",
sep=";",
index_col=0,
)
assert not climate_data[period][node].empty

# calculate dni and check if its ok
node_locations = pd.read_csv(
case_study_folder_path / "NodeLocations.csv", sep=";", index_col=0
)
lon = node_locations.loc[node, "lon"]
lat = node_locations.loc[node, "lat"]

climate_data_check = climate_data[period][node]
climate_data_check["dni_correct"] = climate_data_check["dni"]
climate_data_check = climate_data_check.drop(columns=["dni"])
climate_data_check["dni_check"] = calculate_dni(
climate_data_check, lon, lat
)


def test_data_fill_carrier_data(request):
"""
Expand Down

0 comments on commit 0cbf4be

Please sign in to comment.