Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port consideration in statistics module #860

Merged
merged 2 commits into from
Apr 18, 2024

Conversation

FabianHofmann
Copy link
Collaborator

@FabianHofmann FabianHofmann commented Apr 8, 2024

  • The statistics module introduces a new keyword argument at_port to all functions. This allows considering the port of a component when calculating statistics. Depending on the function, the default of at_port is set to True or False, for example for the dispatch all ports are considered.

  • The statistics module now supports an optional port argument in groupby functions. This allows to group statistics while considering the port of a component.

  • The statistics.revenue function introduces a new keyword argument kind to optionally calculate the revenue based on the input commodity or the output commodity of a component.

Checklist

  • Code changes are sufficiently documented; i.e. new functions contain docstrings and further explanations may be given in doc.
  • Unit tests for new features were added (if applicable).
  • Newly introduced dependencies are added to environment.yaml, environment_docs.yaml and setup.py (if applicable).
  • A note for the release notes doc/release_notes.rst of the upcoming release is included.
  • I consent to the release of this PR's code under the MIT license.

@@ -119,6 +129,11 @@ def get_ports(n, c):
return [col[3:] for col in n.df(c) if col.startswith("bus")]


def get_stacked_ports(n, c):
Copy link
Contributor

@p-glaum p-glaum Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this function, because currently it is not used?

elif isinstance(groupby, str):
by = n.df(c)[groupby]
elif isinstance(groupby, dict):
# TODO: fix kwargs behavior. what is this used for again?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was formerly used for the energy balance, where we wanted group by the index levels so we needed something like {"level":["bus", "carrier", "bus_carrier"]}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can now remove it


ports = n.df(c).loc[df.index, f"bus{port}"]
port_carriers = ports.map(n.buses.carrier)
if isinstance(bus_carrier, str):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here it would be nice to have somehing like I did before, that we fist check if the string is in n.buses.carrier.unique() and if not we look if the bus_carriers contain the string

Comment on lines +291 to +292
if isinstance(bus_carrier, str):
return df[port_carriers == bus_carrier]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something like:

Suggested change
if isinstance(bus_carrier, str):
return df[port_carriers == bus_carrier]
if isinstance(bus_carrier, str):
if bus_carrier in n.buses.carrier.unique():
return df[port_carriers == bus_carrier]
else:
return df[bus_carrier in port_carriers]

return [n.df(c)[bus].rename("bus"), get_carrier(n, c, nice_names=nice_names)]


def get_bus_unit_and_carrier(n, c, port="", nice_names=True):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should add it to Groupers

if kind is not None:
if kind == "input":
df = df.clip(lower=0)
elif kind == "output":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the wrong way round

Suggested change
elif kind == "output":
df = df.clip(upper=0)

df = aggregate_components(
n,
func,
if aggregate_bus:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe also add the other attributes from dispatch like groupbyto the energy_balance and add warning that with aggregate_bus=True, this attribute will be ignored

@p-glaum p-glaum mentioned this pull request Apr 16, 2024
5 tasks
@FabianHofmann FabianHofmann merged commit b1e15c7 into master Apr 18, 2024
16 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants