How to use `get_bus_and_carrier_and_bus_carrier` instead of setting 'aggregate_bus' to False?

91 views
Skip to first unread message

gktho...@gmail.com

unread,
Dec 2, 2024, 9:20:59 AM12/2/24
to pypsa
Dear group,

I saw that in the newer pypsa realeases, it is not possible anymore to set aggregate_bus to False in the statistics.energy_balances module. Instead, it says to use 'get_bus_and_carrier_and_bus_carrier', yet I struggle to find out how to apply it. Could you give me a hint, how I can get hourly and bus specific energy balances with this function?

Many thanks in advance!

Best,
Georg

Fabian Hofmann

unread,
Dec 3, 2024, 2:52:09 AM12/3/24
to py...@googlegroups.com

Hey Georg,

the idea is:



s = n.stastics


s.energy_balance(aggregate_time=False, groupby=s.groupers.get_bus_and_carrier_and_bus_carrier)

Could you check this code? It works on the latest master, and should work on the latest version.

Best wishes!
Fabian Hofmann

--
You received this message because you are subscribed to the Google Groups "pypsa" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pypsa+un...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/pypsa/26d09161-0356-4a47-bc4b-1408d91812a6n%40googlegroups.com.
--- Dr. Fabian Hofmann Senior Energy System Modeller Open Energy Transition https://openenergytransition.org/ http://fabianhofmann.org/

gktho...@gmail.com

unread,
Dec 4, 2024, 5:06:44 AM12/4/24
to pypsa
Hi Fabian,

Worked like  a charm, thanks!

Best,
Georg

Wasserstoffatlas

unread,
Mar 10, 2025, 8:56:19 AM3/10/25
to pypsa
Hey Fabian or group,

I have a similiar issue. I am trying to group by "bus" with the former functionality of "aggregate_buts=False". The suggested call does not work, since I get the error:  Traceback (most recent call last): File "<string>", line 1, in <module> AttributeError: 'Network' object has no attribute 'groupers'

At the moment, I try to work around energy_balance due to this issue, but still wanted to ask, whether the functionality still exists. Also, I did not find any documentation on  get_bus_and_carrier_and_bus_carrier.
Where did I miss it? Any help or guidance is appreciated!

Best,
Falk

Fabian Hofmann

unread,
Mar 10, 2025, 9:30:31 AM3/10/25
to py...@googlegroups.com

Hey Falk,


sounds like something is off. Could you share your lines of code where you get the error?


Best wishes

Fabian

To view this discussion, visit https://groups.google.com/d/msgid/pypsa/f3eee33d-f10c-44fc-b460-d8f47abb26d4n%40googlegroups.com.
-- 
Dr. Fabian Hofmann 

Senior Energy System Modeller
Open Energy Transition
https://openenergytransition.org/

http://fabianhofmann.org/

Wasserstoffatlas

unread,
Mar 10, 2025, 9:54:28 AM3/10/25
to pypsa
Hey Fabian,

thanks for the quick reply!
I am currently working in the debug modus, does this help?


As can be seen, we have 13 buses in the network and I would like to keep the buses.
With 
n.statistics.energy_balance()
I get the output
component carrier bus_carrier Generator biomass AC 116501.44132 elGen_dump AC -116501.44132
which is where I got stuck. Does energy_balance() already group here?
The suggestion you made earlier runs into the following error.
What am I doing wrong? 

Thank you.

Best regards,
Falk

Wasserstoffatlas

unread,
Mar 12, 2025, 10:02:09 AM3/12/25
to pypsa
Now I have managed to write a workaround which produces the desired output (left). In contast the old output with energy_balance() can be seen on the right. Is there a way to get to the result with energy_balance()? 

This is my nc file 
network_solved_biomass_entire_10_elGen_2020_DE11.nc

energyLS

unread,
Mar 12, 2025, 1:15:09 PM3/12/25
to pypsa
Dear Falk,
dear Fabian,

I am confident the solution is `
n.statistics.energy_balance(groupby=["carrier", "bus"])
`

Best,

Leon

Wasserstoffatlas

unread,
Mar 13, 2025, 4:16:17 AM3/13/25
to pypsa
Dear All,

thanks Leon, worked for me!

Reply all
Reply to author
Forward
0 new messages