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

Fix capacity factor timeseries in convert.py #346

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

TimFuermann
Copy link

The method convert and aggregate was adopted, so the capacity factor timeseries is returned and all functionality, such as return capacity and per_unit are kept.

Closes # (if applicable).

Change proposed in this Pull Request

Description

Motivation and Context

How Has This Been Tested?

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I tested my contribution locally and it seems to work fine.
  • I locally ran pytest inside the repository and no unexpected problems came up.
  • I have adjusted the docstrings in the code appropriately.
  • I have documented the effects of my code changes in the documentation doc/.
  • I have added newly introduced dependencies to environment.yaml file.
  • I have added a note to release notes doc/release_notes.rst.
  • I have used pre-commit run --all to lint/format/check my contribution

The method convert and aggregate was adopted, so the capacity factor timeseries is returned and all functionality, such as return capacity and per_unit are kept.
@FabianHofmann
Copy link
Contributor

thanks for the PR @TimFuermann, I will try to have a look at it soon

@FabianHofmann
Copy link
Contributor

FabianHofmann commented Jul 11, 2024

Thanks again @TimFuermann, this makes really sense. The function itself is a mess (not your changes!), and it builds one critical core of all our analyses, which is why I postponed the review so long. But it looks good. I would like to have a second pair of eyes looking at it. @lkstrp could you also have a look if the main logics are preserved? It is mainly tracking the action steps within the function being subject to the set of arguments... there is no time pressure on this

Copy link
Member

@lkstrp lkstrp left a comment

Choose a reason for hiding this comment

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

One more sorry that this took so long @TimFuermann ! I full on lost that one.
But atlite will get more love from now on again.

I'll merge the fixed pre-commit and tests first, but this looks good.

Thank you!

Comment on lines 128 to 140
if capacity_factor or capacity_factor_timeseries:
if capacity_factor_timeseries:
res = da.rename("capacity factor")
else:
res = da.mean("time").rename("capacity factor")
res.attrs["units"] = "p.u."
return maybe_progressbar(res, show_progress, **dask_kwargs)

if capacity_factor or capacity_factor_timeseries:
if capacity_factor_timeseries:
results = da.rename("capacity factor")
else:
res = da.sum("time", keep_attrs=True)
return maybe_progressbar(res, show_progress, **dask_kwargs)
results = da.mean("time").rename("capacity factor")
results.attrs["units"] = "p.u."

else:
results = da.sum("time", keep_attrs=True)
Copy link
Member

Choose a reason for hiding this comment

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

Removing the return means that we no longer end the function here, which leads to undefined issues later. I know, this one is open for quite a while now, but could you have another look?

Otherwise this function is quite a mess and could get a general refactoring with your proposed changes included

Copy link
Author

Choose a reason for hiding this comment

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

@lkstrp: I need to check it locally, but could you explain which undefined issues will occur later? I know the fix is not ideal, and was actually just done that kind of messy to not restructure the whole function.

Copy link
Member

Choose a reason for hiding this comment

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

Further down, matrix is not defined. If you merge the current master, this will hopefully show up in the tests. They may not run through because of a missing cdsapi token, as this branch was derived earlier. But you can run them locally in any case using pytest ..

if index is None:
    index = pd.RangeIndex(matrix.shape[0])

But as you said, restructuring the whole function is better. If you have already looked at it, feel free. Otherwise I will deal with it at some point.

Copy link
Author

Choose a reason for hiding this comment

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

@lkstrp I restructured the function and tested it. I commit it soon. Nevertheless, this would need to change some things in the origional test files, too and in the usage. I explain it with the commit, Best, Tim

Copy link
Member

Choose a reason for hiding this comment

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

Sounds great! Thank you @TimFuermann

Copy link
Author

@TimFuermann TimFuermann Nov 20, 2024

Choose a reason for hiding this comment

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

@lkstrp Just uploaded a new version of how the convert and aggregate could be used more consistently. Nevertheless this includes heavy changes in the input flags, but allows for a more consistent way of using them. A default capacity layout is used if no capacities are provided. This is a constant 1MW per gridcell (which should be the same as looking for capacity factors). With this new implementation, capacity factors for regions, per gridcell, aswell as aggregated can be calculated.

I furthermore added minor changes to the pytest test_preparation_and_conversion, since the output format slightly changes now, as well as the way how the input flags need to be set.

- add per_gridcell aggregation
- add default capacity layout
- add consistent behaviour of capacity_factor or aggregation
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.

3 participants