Skip to content
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

Latest Compendium materials JSON causes errors #324

Closed
markbandstra opened this issue Mar 24, 2022 · 0 comments · Fixed by #328
Closed

Latest Compendium materials JSON causes errors #324

markbandstra opened this issue Mar 24, 2022 · 0 comments · Fixed by #328

Comments

@markbandstra
Copy link
Member

The latest version of the materials data from the PNNL Compendium cannot be parsed by the current version of becquerel.

Downloading the latest JSON and placing it into becquerel/tools and calling bq.tools.force_load_and_write_materials_csv() causes the following error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File ".../becquerel/tools/materials.py", line 196, in force_load_and_write_materials_csv
    materials = _load_and_compile_materials()
  File ".../becquerel/tools/materials.py", line 26, in _load_and_compile_materials
    data_comp = fetch_compendium_data()
  File ".../becquerel/tools/materials_compendium.py", line 63, in fetch_compendium_data
    names = [datum["Name"] for datum in data]
  File ".../becquerel/tools/materials_compendium.py", line 63, in <listcomp>
    names = [datum["Name"] for datum in data]
TypeError: string indices must be integers

It seems from looking at a JSON from a few months ago and a JSON downloaded today that the difference is that the older JSON has a structure that parses into a list of dicts:

[
    {
        "Comment": "Material 1 data",
    },
    {
        "Comment": "Material 2 data",
    }
]

whereas the new format parses as a dict and the list of material data are inside of it:

{
    "siteVersion": "0.1.1",
    "data": [
        {
            "Comment": "Material 1 data",
        },
        {
            "Comment": "Material 2 data",
        }
    ]
}

So the solution is easy: to check for the data that get loaded and use data["data"] if it is the new format.

Both versions appear to contain 411 materials, but I have not checked whether any of the data for individual materials differ.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant