Skip to content

KeyError when accessing section_text for certain sections #17

Open

Description

@ahnaf-tahmid-chowdhury

Description

I encountered a KeyError while trying to access specific sections of an ENDF material. Below is a summary of the issue:

Steps to Reproduce:

  1. Load a material using endf.Material(), for example:

    import endf
    mat = endf.Material('n-092_U_235.endf')
  2. The following warnings appear:

    /path/to/venv/lib/python3.12/site-packages/endf/material.py:228: UserWarning: MF=31, MT=452 ignored
      warn(f"{MF=}, {MT=} ignored")
    /path/to/venv/lib/python3.12/site-packages/endf/material.py:228: UserWarning: MF=31, MT=456 ignored
      warn(f"{MF=}, {MT=} ignored")
    /path/to/venv/lib/python3.12/site-packages/endf/material.py:228: UserWarning: MF=35, MT=18 ignored
      warn(f"{MF=}, {MT=} ignored")
    
  3. Attempt to access a specific section:

    print(mat.section_text[12, 75])

    This raises the following error:

    KeyError: (12, 75)
    
  4. Attempting to access other sections like:

    mat.section_data[3, 16]

    works as expected and returns data.

Expected Behavior:

mat.section_text[12, 75] should return the corresponding section data, or provide a clearer error if this section is not available.

Actual Behavior:

A KeyError is raised when trying to access section_text for certain sections.

System Information:

  • Python version: 3.12
  • endf version: 0.1.4 through pip
  • ENDF file used: n-092_U_235.endf

Additional Context:

The warnings related to MF=31 and MF=35 might be linked to the issue, but it's unclear if this is the cause.

Activity

  1. MicahGale commented on Oct 10, 2024

    @MicahGale

    Which nuclear data library are you using? I want to verify that the data are present first.

    The MF=31/35 warnings are not relevant here. MF 31/35 would appear much later in the file and would have no impact on MF=12.

  2. MicahGale commented on Oct 10, 2024

    @MicahGale

    So MF=12, MT=75 is there for U-235 in ENDF/B-VIII.0, but not ENDF/B-VII.1. I suspect this is what is causing the KeyError. If this is in fact the root cause a clearer error message like:

    raise MissingDataError(f"The requested data: MAT={MAT}, MF={MF}, MT={MT} does not exist in this ENDF.")

    would be a good idea.

  3. paulromano commented on Oct 10, 2024

    @paulromano
    Owner

    The sections attribute on a Material object tells you what sections are available in a file. If a section is not present, to me KeyError is already conveying the right information.

  4. MicahGale commented on Oct 10, 2024

    @MicahGale

    Maybe the KeyError could be a little bit more verbose to make it clear this is user Error?

  5. ahnaf-tahmid-chowdhury commented on Oct 11, 2024

    @ahnaf-tahmid-chowdhury
    Author

    Yes, I think it will be a nice feature. We can develop a fallback function that provides verbose logs about the file, which will also help people like me who are just starting to learn about different data formats.

  6. MicahGale commented on Oct 11, 2024

    @MicahGale

    Logging seems look far too big of a hammer. Like @paulromano said the information is there for the user, and I don't see the value in producing a log that would duplicate would could be queried directly.

  7. ahnaf-tahmid-chowdhury commented on Oct 11, 2024

    @ahnaf-tahmid-chowdhury
    Author

    @MicahGale, I apologize if I wasn’t clear in my earlier comment, and I appreciate your feedback. I didn’t mean to suggest extensive logging. My idea was more about having a fallback function that triggers when a KeyError is raised. The goal is to provide additional context, without overwhelming the system with logs.

    Instead of full logging, this fallback could simply explain why the error occurred and, perhaps, point out which sections are available for the material being queried. It wouldn’t duplicate what’s already in place but would help users better understand the issue when encountering missing data.

  8. MicahGale commented on Oct 11, 2024

    @MicahGale

    Oh ok that makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions