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
17 changes: 6 additions & 11 deletions pypsa_validation_processing/statistics_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,19 @@ def Final_Energy_by_Sector__Transportation(

Notes
-----
The actual extraction of transportation final energy from the network
collection will be implemented by the user. A typical call would be::

network_collection.statistics.energy_balance(
comps=["Load"], carrier="transport"
)

The current implementation returns a dummy value of ``0.0 MWh`` for the
year 2020 so that the end-to-end workflow can be tested.
Includes all transportation-relevant carriers for component Load. Vehicle to Grid
does not need to be evaluated, as evaluation is restricted to Load-Components only.
"""
# sum over all transportation-relevant sectors - 2 different units involved.
result = (
res = (
n.statistics.energy_balance(
carrier=[
"land transport EV",
"land transport fuel cell",
"land transport oil",
"kerosene for aviation",
"shipping methanol",
"shipping oil",
],
components="Load",
groupby=["carrier", "unit", "country"],
Expand All @@ -113,4 +108,4 @@ def Final_Energy_by_Sector__Transportation(
.groupby(["country", "unit"])
.sum()
)
return result
return res
36 changes: 20 additions & 16 deletions tests/test_statistics_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
class TestFinalEnergyByCarrierElectricity:
"""Test suite for Final_Energy_by_Carrier__Electricity function."""

def test_returns_dataframe(self, mock_network: MockPyPSANetwork):
"""Test that the function returns a pandas DataFrame or Series."""
def test_returns_series(self, mock_network: MockPyPSANetwork):
"""Test that the function returns a pandas Series."""
result = Final_Energy_by_Carrier__Electricity(mock_network)
assert isinstance(result, (pd.DataFrame, pd.Series))
assert isinstance(result, pd.Series)

def test_has_country_and_unit_index(self, mock_network: MockPyPSANetwork):
"""Test that result has country and unit in the index."""
def test_has_country_and_unit_multiindex(self, mock_network: MockPyPSANetwork):
"""Test that result has MultiIndex with country and unit levels."""
result = Final_Energy_by_Carrier__Electricity(mock_network)
assert "country" in result.index.names
assert "unit" in result.index.names
assert isinstance(result.index, pd.MultiIndex)
assert result.index.names == ["country", "unit"]

def test_not_empty(self, mock_network: MockPyPSANetwork):
"""Test that result is not empty."""
Expand All @@ -53,7 +53,9 @@ def test_multiple_networks(self, mock_network_collection: MockNetworkCollection)
"""Test processing multiple networks from collection."""
for network in mock_network_collection:
result = Final_Energy_by_Carrier__Electricity(network)
assert isinstance(result, (pd.DataFrame, pd.Series))
assert isinstance(result, pd.Series)
assert isinstance(result.index, pd.MultiIndex)
assert result.index.names == ["country", "unit"]
assert len(result) > 0


Expand All @@ -65,16 +67,16 @@ def test_multiple_networks(self, mock_network_collection: MockNetworkCollection)
class TestFinalEnergyBySectorTransportation:
"""Test suite for Final_Energy_by_Sector__Transportation function."""

def test_returns_dataframe(self, mock_network: MockPyPSANetwork):
"""Test that the function returns a pandas DataFrame or Series."""
def test_returns_series(self, mock_network: MockPyPSANetwork):
"""Test that the function returns a pandas Series."""
result = Final_Energy_by_Sector__Transportation(mock_network)
assert isinstance(result, (pd.DataFrame, pd.Series))
assert isinstance(result, pd.Series)

def test_has_country_and_unit_index(self, mock_network: MockPyPSANetwork):
"""Test that result has country and unit in the index."""
def test_has_country_and_unit_multiindex(self, mock_network: MockPyPSANetwork):
"""Test that result has MultiIndex with country and unit levels."""
result = Final_Energy_by_Sector__Transportation(mock_network)
assert "country" in result.index.names
assert "unit" in result.index.names
assert isinstance(result.index, pd.MultiIndex)
assert result.index.names == ["country", "unit"]

def test_not_empty(self, mock_network: MockPyPSANetwork):
"""Test that result is not empty."""
Expand All @@ -97,5 +99,7 @@ def test_multiple_networks(self, mock_network_collection: MockNetworkCollection)
"""Test processing multiple networks from collection."""
for network in mock_network_collection:
result = Final_Energy_by_Sector__Transportation(network)
assert isinstance(result, (pd.DataFrame, pd.Series))
assert isinstance(result, pd.Series)
assert isinstance(result.index, pd.MultiIndex)
assert result.index.names == ["country", "unit"]
assert len(result) > 0
Loading