-
Notifications
You must be signed in to change notification settings - Fork 14
[GH#71] Take into account identifier aliases #77
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
base: develop
Are you sure you want to change the base?
Conversation
…nto identifier_aliases
…entifier-aliases' into identifier_aliases
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.
Hi @dee-mew, @olivhoenen,
A little more comments than I'd have liked, sorry 😅 Let me know if anything's unclear, feel free to send me a message on Slack and/or set up a short call to discuss 🙂
…nto identifier_aliases
|
Hi @dee-mew, Sorry for taking over this PR and pushing to your branch :) Couple of comments why I changed things:
|
Thanks for the update @maarten-ic |
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.
Code looks okay now.
My only reservation is that most tests are skipped now (because imas-data-dictionaries 4.1.0 is not yet released).
@olivhoenen how do you wish to proceed here? We could wait until DD4.1.0 is released before merging this PR, or test this again after 4.1.0 is released and fix any issues that may be present?
Let's wait for 4.1.0, it shall come quickly now 🤞 |
| False | ||
| >>> # Alias comparison example with materials identifier | ||
| >>> mid = imas.identifiers.materials_identifier | ||
| >>> materials = imas.IDSFactory().materials() |
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.
materials ids is not present in the data dictionary. Could you use wall IDS which uses materials_indentfier.
| print(f"Same object: {uranium235_by_name is uranium235_by_attr}") | ||
| # When assigning to IDS structures, any alias works the same way | ||
| materials = imas.IDSFactory().materials() |
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.
materials ids is not present in the data dictionary. Could you use wall IDS which uses materials_indentfier.
| mid = identifiers.materials_identifier | ||
|
|
||
| # Create an actual IDS structure | ||
| factory = IDSFactory("4.0.0").camera_x_rays() |
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.
We could also add example of identifiers where it is used an arrays. Aliases are just example I added for test
import imas
mid = imas.identifiers.materials_identifier
wallids = imas.IDSFactory().wall()
wallids.description_ggd.resize(1)
wallids.description_ggd[0].material.resize(1)
wallids.description_ggd[0].material[0].grid_subset.resize(1)
names = wallids.description_ggd[0].material[0].grid_subset[0].identifiers.names
indices = wallids.description_ggd[0].material[0].grid_subset[0].identifiers.indices
descriptions = wallids.description_ggd[0].material[0].grid_subset[0].identifiers.descriptions
names.extend([""] * 5)
indices.resize(5)
descriptions.extend([""] * 5)
names[0]= mid["235U"].name
names[1]= mid["238U"].name
names[2]= mid["U_235"].name
names[3]= mid["67FGDFD"].name
names[4]= mid["GFHF34"].name
indices[0]= mid["235U"].index
indices[1]= mid["238U"].index
indices[2]= mid["U_235"].index
indices[3]= mid["67FGDFD"].index
indices[4]= mid["GFHF34"].index
descriptions[0]= mid["235U"].description
descriptions[1]= mid["238U"].description
descriptions[2]= mid["U_235"].description
descriptions[3]= mid["67FGDFD"].description
descriptions[4]= mid["GFHF34"].description
imas.util.inspect(wallids.description_ggd[0].material[0].grid_subset[0].identifiers)| # Test equality with canonical name | ||
| factory1 = IDSFactory("4.0.0").camera_x_rays() | ||
| mat1 = factory1.filter_window.material | ||
| mat1.name = "235U" |
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.
Should assignment come from identifiers and assert later?
mat1.name = mid.U_235.name
mat1.index = mid.U_235.index
mat1.description = mid.U_235.description| print(csid.total.description) | ||
| # Access identifiers with aliases (when available) | ||
| mid = imas.identifiers.materials_identifier |
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.
Should we always use name attribute? In the IDS it stored as str('materials_identifier.235U')
import imas
mid = imas.identifiers.materials_identifier
factory2 = imas.IDSFactory().camera_x_rays()
mat2 = factory2.filter_window.material
mat2.name = mid.U_235 # Should we always use name attribute?
mat2.index = mid.U_235.index
mat2.description = mid.U_235.description
imas.util.inspect(mat2)
╭───── IDS structure: filter_window/material (DD version 4.0.1.dev324+g5180c8270.d20251021) ──────╮
│ Material of the filter window │
│ ╭──────────────────────────────────────── Attributes ─────────────────────────────────────────╮ │
│ │ has_value = True │ │
│ │ metadata = <IDSMetadata for 'material'> │ │
│ ╰─────────────────────────────────────────────────────────────────────────────────────────────╯ │
│ ╭──────────────────────────────────────── Child nodes ────────────────────────────────────────╮ │
│ │ description = <IDSString0D (IDS:camera_x_rays, filter_window/material/description, STR_0D)> │ │
│ │ str('Uranium 235 isotope') │ │
│ │ index = <IDSInt0D (IDS:camera_x_rays, filter_window/material/index, INT_0D)> │ │
│ │ int(20) │ │
│ │ name = <IDSString0D (IDS:camera_x_rays, filter_window/material/name, STR_0D)> │ │
│ │ str('materials_identifier.235U') │ │
│ ╰─────────────────────────────────────────────────────────────────────────────────────────────╯ │
╰─────────────────────────────────────────────────────────────────────────────────────────────────╯| core_sources.source[0].identifier = 1 | ||
| # Identifiers can still be assigned with the old alias name for backward compatibility: | ||
| materials = imas.IDSFactory().materials() |
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.
materials ids is not present in the data dictionary. Could you use wall IDS which uses materials_indentfier.
| # Create an actual IDS structure | ||
| factory = IDSFactory("4.0.0").camera_x_rays() | ||
| mat = factory.filter_window.material | ||
| mat.name = "235U" |
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.
Should we add setter methods for setting name, index and description ?
for example
set_identifier("camera_x_rays.filter_window.material", "235U")
set_identifiers(wall.description_ggd[0].material[0].grid_subset[0].identifiers.names, ["235U", "U_238"]
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.
This already exists by assigning to the structure instead of a specific name/description/index node: https://imas-python.readthedocs.io/en/stable/identifiers.html#assigning-identifiers-in-imas-python
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.
Got it, thanks
For array of identifiers like this, do we need to use like this?
https://github.com/iterorganization/IMAS-Python/pull/77/files/ce507975c8fc1937d6e4507bdb7826cfc14197c6#r2448137366
wall.description_ggd[0].material[0].grid_subset[0].identifiers
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 think this is the only place in the DD that has an array of identifiers, and it's not used in any ITER dataset at the moment.
Unless there's a good use case, I wouldn't really bother to implement something for arrays of identifiers 🙂
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.
There are a few SOLPS cases that are currently handled within the Fortran code. For now, we’ll wait until there is a use case to use it in the Python code.
Updates in imas source and test files for handling alias information for identifiers as per issue #71.