From bba72296cc776c802be0842cc7d0b1bf59465660 Mon Sep 17 00:00:00 2001 From: Vladislav Neverov Date: Thu, 23 Nov 2023 13:54:31 +0300 Subject: [PATCH 1/2] Fix parsing of the ADF15 metadata for H-like ions. --- CHANGELOG.md | 1 + cherab/openadas/parse/adf15.py | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9af7646d..fdb1a75e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ New: * Add PeriodicTransformXD and VectorPeriodicTransformXD functions to support the data simulated with periodic boundary conditions. (#387) * Add CylindricalTransform and VectorCylindricalTransform to transform functions from cylindrical to Cartesian coordinates. (#387) * Add the kind attribute to RayTransferPipelineXD that determines whether the ray transfer matrix is multiplied by sensitivity ('power') or not ('radiance'). (#412) +* Improved parsing of the ADAS ADF15 metadata for H-like ions. Raises a runtime error if the metadata cannot be parsed. (#424) Release 1.4.0 (3 Feb 2023) diff --git a/cherab/openadas/parse/adf15.py b/cherab/openadas/parse/adf15.py index b9fe42be..14103c04 100644 --- a/cherab/openadas/parse/adf15.py +++ b/cherab/openadas/parse/adf15.py @@ -67,11 +67,18 @@ def parse_adf15(element, charge, adf_file_path, header_format=None): # use simple electron configuration structure for hydrogen-like ions if header_format == 'hydrogen' or element == hydrogen: config = _scrape_metadata_hydrogen(file, element, charge) - elif header_format == 'hydrogen-like' or element.atomic_number - charge == 1: + elif header_format == 'hydrogen-like': config = _scrape_metadata_hydrogen_like(file, element, charge) + elif element.atomic_number - charge == 1: + config = _scrape_metadata_hydrogen_like(file, element, charge) + if not config: # try hydrogen header (works for 'bnd' files) + config = _scrape_metadata_hydrogen(file, element, charge) else: config = _scrape_metadata_full(file, element, charge) + if not config: + raise RuntimeError("Unable to parse ADF15 metadata.") + # process rate data rates = RecursiveDict() for cls in ('excitation', 'recombination', 'thermalcx'): From 53ef1d32cf274595c8f9a80dff87ad324e1d3a3c Mon Sep 17 00:00:00 2001 From: vsnever Date: Fri, 1 Dec 2023 17:13:46 +0300 Subject: [PATCH 2/2] Explicitly handle the 'bnd' ADF15 files when parsing the metadata. --- CHANGELOG.md | 2 +- cherab/openadas/parse/adf15.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdb1a75e..dcc88e10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ New: * Add PeriodicTransformXD and VectorPeriodicTransformXD functions to support the data simulated with periodic boundary conditions. (#387) * Add CylindricalTransform and VectorCylindricalTransform to transform functions from cylindrical to Cartesian coordinates. (#387) * Add the kind attribute to RayTransferPipelineXD that determines whether the ray transfer matrix is multiplied by sensitivity ('power') or not ('radiance'). (#412) -* Improved parsing of the ADAS ADF15 metadata for H-like ions. Raises a runtime error if the metadata cannot be parsed. (#424) +* Improved parsing of metadata from the ADAS ADF15 'bnd' files for H-like ions. Raises a runtime error if the metadata cannot be parsed. (#424) Release 1.4.0 (3 Feb 2023) diff --git a/cherab/openadas/parse/adf15.py b/cherab/openadas/parse/adf15.py index 14103c04..51bbcf6b 100644 --- a/cherab/openadas/parse/adf15.py +++ b/cherab/openadas/parse/adf15.py @@ -71,7 +71,8 @@ def parse_adf15(element, charge, adf_file_path, header_format=None): config = _scrape_metadata_hydrogen_like(file, element, charge) elif element.atomic_number - charge == 1: config = _scrape_metadata_hydrogen_like(file, element, charge) - if not config: # try hydrogen header (works for 'bnd' files) + if not config and 'bnd#' in adf_file_path: + # ADF15 files with the "bnd" suffix may have metadata in the "hydrogen" format config = _scrape_metadata_hydrogen(file, element, charge) else: config = _scrape_metadata_full(file, element, charge)