Skip to content

Add global attributes#6

Merged
samueljackson92 merged 5 commits intosamueljackson92:mainfrom
JoelLucaAdams:global-attributes-support
Jan 30, 2026
Merged

Add global attributes#6
samueljackson92 merged 5 commits intosamueljackson92:mainfrom
JoelLucaAdams:global-attributes-support

Conversation

@JoelLucaAdams
Copy link
Copy Markdown
Contributor

@JoelLucaAdams JoelLucaAdams commented Jan 26, 2026

Add the global attributes (from dataset.attrs) to a sub node titled Attributes (num_attrs) under the File Information node.

This is recursive as the attributes might contain sub dicts. This is the case in sdf-xarray as we add the simulation setup file to the attributes as a dictionary.

@JoelLucaAdams JoelLucaAdams changed the title Add global attributes to "File Information" node Add global attributes Jan 26, 2026
@samueljackson92 samueljackson92 added the enhancement New feature or request label Jan 29, 2026
@samueljackson92 samueljackson92 self-requested a review January 29, 2026 08:12
@samueljackson92
Copy link
Copy Markdown
Owner

Looks good, but I think this would make more sense to be under the root node (alongside Dimensions, Coordinates, Data Variables, Groups) rather than in the File info section?

@JoelLucaAdams
Copy link
Copy Markdown
Contributor Author

Looks good, but I think this would make more sense to be under the root node (alongside Dimensions, Coordinates, Data Variables, Groups) rather than in the File info section?

The reason I placed it inside the file info node is because (at least in sdf-xarray) all global attributes came from file header information so it made sense to put it under the file info section but I'm happy to move it if you think it's more appropriate at the top level

@samueljackson92
Copy link
Copy Markdown
Owner

Not the top level, but within the root dataset node. So, at the same level as dimensions and coordinates on Root in this screenshot:

image

I think this makes the most sense as that is essentially where they live within the tree structure (regardless of what backend loaded those attributes)?

@JoelLucaAdams
Copy link
Copy Markdown
Contributor Author

Yeah, in agreement with that. Sorry a bit on the tired side and this didn't quite parse through my brain right when I read it earlier. Additionally I think the attributes should be an empty node e.g. Attributes (0) if no attributes are present in case a new developer is wondering why their attributes aren't showing (see my classic blunder) although happy to simply hide the node if there are no attributes

@samueljackson92
Copy link
Copy Markdown
Owner

👍 I agree.

@JoelLucaAdams
Copy link
Copy Markdown
Contributor Author

This is how the new attributes look and it does work nicely with nested data such as the deck setup file.
image

NOTE: full deck support is not currently implemented in sdf-xarray but can be quickly hardcoded (you will also need to install epydeck from uv.) by updating the open_datatree(...) at the end:

dt.attrs = ds.attrs

with open("/Users/joel/Source/sdf-xarray/docs/tutorial_dataset_2d/input.deck") as f:
    import epydeck

    dt.attrs["deck"] = epydeck.load(f)

@samueljackson92
Copy link
Copy Markdown
Owner

One minor thing: I think may attributes should be above the Groups and Data Variables not below?

@JoelLucaAdams
Copy link
Copy Markdown
Contributor Author

Done!

@samueljackson92 samueljackson92 merged commit 71f7b6f into samueljackson92:main Jan 30, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants