nexusformat / definitions

Definitions of the NeXus Standard File Structure and Contents
https://manual.nexusformat.org/
Other
26 stars 56 forks source link

Re-usable enumerations #1379

Open woutdenolf opened 7 months ago

woutdenolf commented 7 months ago

At NIAC telco https://github.com/nexusformat/wiki/blob/master/content/Telco_20240415.md it was requested to create this issue to gather all use-cases where a way of defining re-usable enumerations would be useful as opposed to creating base classes.

woutdenolf commented 7 months ago

The NXxas working group on improving NXxas has a use-case where re-usable enumerations are useful.

https://github.com/nexusformat/definitions/pull/1352

In XAS you use multi-electron states which are labelled K, L1, L2, L3, M1, M2, ... (these are atom states with one missing electron after a core-hole excitation) for several things:

  1. It is used to specify which absorption edge the experiment was targeting (e.g. Fe-K).
  2. It is used the specify one or more emission a.k.a. fluorescence lines (K-L2, K-L3, ...)

The first idea was to define a class NXxray_level with one field called name which has the enumeration K, L2, L3, ... as value. Then define a class NXemission_line which has two groups of class NXxray_level with the names initial and final. Then define a class NXemission_lines which can have many NXemission_line groups.

For example tp define the fact that you are measuring the Fe-K emission lines (which includes K-L2, K-L3, etc.) you would have the following HDF5 tree structure

element (NXchemical_element)
   name = Fe

edge (NXxray_level)

   name = K

emission (NXemission_lines)

  line1 (NXemission_line)
    initial (NXxray_level)
      name = K
    final (NXxray_level)
      name = L2

  line2 (NXemission_line)
    initial (NXxray_level)
      name = K
    final (NXxray_level)
      name = L3

...

This might be fine if you just have a few but when you have 10 or 20 this is no longer human readable. In the end a spectroscopist wants to see the list K-L2, K-L3, ...

Note that the enumeration of chemical elements is also something that should be re-usable across multiple application definitions. You could create a class NXchemical_element but this is again not practical when you have many elements (you would have 1 HDF5 group per elements with a single dataset that holds a single string with one or two characters).