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
init sankey #770
base: main
Are you sure you want to change the base?
init sankey #770
Conversation
Thanks for this PR :) |
Thanks @daymontas1 for stepping up here, much appreciated :) You should be able to test the PR as is and see how you like it's usefulness, but there are a few things that I would like to see happen before we merge it:
Please feel free to ask about any of these steps if you need help :) |
Hi all, to simplify here, I would simply limit this functionality to pyam > 2 - we can do a version check for this on the fly and raise an error. |
@@ -141,6 +141,7 @@ | |||
"message::costs", | |||
"message::emissions", | |||
), | |||
("message::sankey", "concat", "out::pyam", "in::pyam"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would get rid of this, and simply do the concatenation outside of reporter (e.g., in the jupyter notebook here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept this for now as I don't know what the Reporter actually does and it seems useful to just get the dataframe format we need from the Reporter. But please elaborate :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have created a new file, sankey.py, within the report directory, which extracts Sankey diagram functionality from init.py. Fridolin (@glatterf42), could you please confirm if this is what we want? Additionally, I have updated the westeros_sankey.ipynb file to ensure compatibility with the new sankey.py file in the report directory. I have annotated these changes in the westeros_sankey.ipynb below. Also, in this case, the following line inside the init.py file must be either removed or commented out:
("message::sankey", "concat", "out::pyam", "in::pyam")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @daymontas1, these changes sound good to me. For the line that has become redundant, please remove it rather than commenting it out, this keeps the code clean.
Could you please push your changes to the branch so that we can take a look and see how the tests are doing?
If you don't have write access to @mabudz's fork, please let us know so that we can figure out a solution :)
* In recent pyam versions, get_variable_components moved to pyam.str
Rebased onto current main and expanded the PR a bit :) The missing type hints (from the failing code quality check) probably indicate that we need to add |
The other main error I'm seeing just indicates that by adding this reporter step, we need to adapt the expected value of reporter steps in another test, which is no problem :) |
@@ -141,6 +141,7 @@ | |||
"message::costs", | |||
"message::emissions", | |||
), | |||
("message::sankey", "concat", "out::pyam", "in::pyam"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#''Sankey''
import logging
from functools import partial
from typing import Tuple, Mapping, List
from genno.operator import broadcast_map
from ixmp.report import Key
from .pyam import collapse_message_cols
# Assuming TASKS1 was where Sankey tasks were defined:
TASKS1 = (
("message::sankey", "concat", "out::pyam", "in::pyam"),
)
def get_sankey_tasks() -> List[Tuple[Tuple, Mapping]]:
"""Return a list of tasks for Sankey diagram reporting."""
to_add: List[Tuple[Tuple, Mapping]] = []
strict = dict(strict=True)
# This might include specific Sankey diagram configuration or additional tasks.
for t in TASKS1:
to_add.append((t, strict))
return to_add
class SankeyReporter:
"""A specialized reporter for generating Sankey diagrams."""
@staticmethod
def add_tasks(reporter, fail_action: str = "raise") -> None:
"""Add Sankey-related tasks to a given reporter."""
reporter.add_queue(get_sankey_tasks(), fail=fail_action)
```suggestion
("message::sankey", "concat", "out::pyam", "in::pyam"),
```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this suggestion, @daymontas1 :)
To clarify here: are these the contents of the new sankey.py
file you mentioned above? They probably don't need to include the suggestion
part, then.
If I understand correctly, what you want to suggest is deleting this line that is no longer needed here:
("message::sankey", "concat", "out::pyam", "in::pyam"), |
Create sankey diagram and add tutorial.
The approach here creates the sankey diagram by using the sankey plot function of the
pyam
package. This function requires a mapping dictionary. The mapping dict is created by using the newly created automatic reportmessage::sankey
and a utility functionsankey_mapper()
.This pull request is related to the draft pull request in message_data , which can be removed, since the sankey diagram has been implemented in the
pyam
package.How to review
General approach should be reviewed. Also, I am not sure if the util function
sankey_mapper()
is at the right place.PR checklist