Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

[Feature] New Edge Attribute: AttributeFromNode #95

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from

Conversation

icedoom888
Copy link

@icedoom888 icedoom888 commented Dec 17, 2024

@icedoom888 icedoom888 self-assigned this Dec 17, 2024
@icedoom888 icedoom888 changed the title Implemented new attribute [Feature] New Edge Attribute: AttributeFromNode Dec 17, 2024
@icedoom888 icedoom888 requested review from JPXKQX and OpheliaMiralles and removed request for OpheliaMiralles December 17, 2024 18:41
@icedoom888 icedoom888 added the enhancement New feature or request label Dec 17, 2024
Copy link
Member

@JPXKQX JPXKQX left a comment

Choose a reason for hiding this comment

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

Hi Alberto! Thanks for the PR! I have commented on some suggestions for the structure of the new classes. Let me know if you want to comment on any of them. I would also like to add at least some minimal testing and some comments to docs/graphs/edge_attributes.rst.

@icedoom888 icedoom888 requested a review from JPXKQX December 18, 2024 15:06
@icedoom888
Copy link
Author

Hey @JPXKQX! Thanks for reviewing this!
I implemented the changes you requested!

How do you want to proceed regarding tests and comments of here: docs/graphs/edge_attributes.rst ?

Copy link
Member

@JPXKQX JPXKQX left a comment

Choose a reason for hiding this comment

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

For the docstring, I would expect something similar to the EdgeDirection or EdgeLength, with a short explanation of the 2 methods (fromSource, fromTarget) and an example like the following

nodes:
     data:
         node_builder: ...
         attributes:
             cutout_mask: 
                 __target__ : anemoi.graphs.nodes.attributes.CutOutMask

edges:
     - source_name: ...
       target_name: ...
       edge_builders: ...
       attributes:
         comes_from_lam:
            _target_: anemoi.graphs.edges.attributes.AttributeFromSourceNode
            node_attr_name: cutout_mask


edge_index = graph[(source_name, "to", target_name)].edge_index
assert hasattr(graph[node_name], self.node_attr_name)
val = getattr(graph[node_name], self.node_attr_name).numpy()[edge_index[self.idx]]
Copy link
Member

Choose a reason for hiding this comment

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

I would say that direct attribute selection is preferred when possible.

Suggested change
val = getattr(graph[node_name], self.node_attr_name).numpy()[edge_index[self.idx]]
return graph[node_name][self.node_attr_name].numpy()[edge_index[self.idx]]

In this case, if we want to test whether the attribute is in the graph, it may be better to use try/catch, with an appropriate error message like.
"{super().__class__.__name__} failed because the attribute {} is not defined for the {} nodes.

Copy link
Author

Choose a reason for hiding this comment

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

Done ✅

icedoom888 and others added 8 commits December 18, 2024 18:50
Co-authored-by: Mario Santa Cruz <48736305+JPXKQX@users.noreply.github.com>
Co-authored-by: Mario Santa Cruz <48736305+JPXKQX@users.noreply.github.com>
Co-authored-by: Mario Santa Cruz <48736305+JPXKQX@users.noreply.github.com>
Co-authored-by: Mario Santa Cruz <48736305+JPXKQX@users.noreply.github.com>
@icedoom888 icedoom888 requested a review from JPXKQX December 18, 2024 18:13
@@ -44,3 +44,77 @@ latitude and longitude coordinates of the source and target nodes.
attributes:
edge_length:
_target_: anemoi.graphs.edges.attributes.EdgeDirection

*********************
Copy link
Member

@JPXKQX JPXKQX Dec 19, 2024

Choose a reason for hiding this comment

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

I would group all new documentation under the same header "Attribute from Node" (or "Attribute from Source/Target Node"), so we get the left sidebar with the 3 types of attributes: Edge direction, edge length, attribute from node. Now:
Screenshot 2024-12-19 at 09 08 05
I would drop the 1st and 3rd yaml examples, and also the subheaders. If you think it needs some explanation, you can also add a comment after a "#" in the yaml example.

Copy link
Author

Choose a reason for hiding this comment

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

Done ✅

CHANGELOG.md Outdated
@@ -24,6 +24,7 @@ Keep it human-readable, your future self will thank you!
- feat: Support for multiple edge builders between two sets of nodes (#70)
- feat: Support for providing lon/lat coordinates from a text file (loaded with numpy loadtxt method) to build the graph `TextNodes` (#93)
- feat: Build 2D graphs with `Voronoi` in case `SphericalVoronoi` does not work well/is an overkill (LAM). Set `flat=true` in the nodes attributes to compute area weight using Voronoi with a qhull options preventing the empty region creation (#93)
- feat: Add `AttributeFromSourceNode` and `AttributeFromTargetNode` edge attribute to copy attribute from source or target node. Set `node_attr_name` in the config to specify which attribute to copy from the source | target node (#94)
Copy link
Member

Choose a reason for hiding this comment

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

This should go in the Unreleased section.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed ✅

@icedoom888 icedoom888 requested a review from JPXKQX December 19, 2024 17:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
contributor enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] New Edge Attribute: EdgeFromSourceNodeAttribute
2 participants