r""" Computes average normalized fluorescence values for element lines that are part of the reference sample and listed in ``quant_fluor_data_dict["element_lines"]`` and present in the ``xrf_map_dict`` and writes the result to ``quant_fluor_data_dict["element_lines"][ ][
(quant_fluor_data_dict, *, xrf_map_dict, scaler_name)
| 496 | |
| 497 | |
| 498 | def fill_quant_fluor_data_dict(quant_fluor_data_dict, *, xrf_map_dict, scaler_name): |
| 499 | r""" |
| 500 | Computes average normalized fluorescence values for element lines that are part of |
| 501 | the reference sample and listed in ``quant_fluor_data_dict["element_lines"]`` and |
| 502 | present in the ``xrf_map_dict`` and writes the result to |
| 503 | ``quant_fluor_data_dict["element_lines"][<element_line>]["fluorescence"]``. |
| 504 | Fluorescence is set to None for the element lines that are not present in ``xrf_map_dict``. |
| 505 | Element lines that are present in ``xrf_map_dict``, but not part of the reference |
| 506 | standard, are ignored. If `scaler_name` is one of the keys of ``xrf_map_dict``, then |
| 507 | fluorescence map is normalized by the scaler before average value is computed. If |
| 508 | ``scaler_name`` is not one of the keys of ``xrf_map_dict`` or set to None, then |
| 509 | the average fluorescence is computed without normalization. |
| 510 | |
| 511 | Pixels along the edges of the map are very likely to contain outliers, so the edges |
| 512 | are not used in computation whenever sufficient data is available (if map contains |
| 513 | more than 2 pixels along a dimension, the first and the last pixels are not used |
| 514 | for averaging) |
| 515 | |
| 516 | Parameters |
| 517 | ---------- |
| 518 | |
| 519 | quant_fluor_data_dict: dict |
| 520 | Dictionary with XRF reference sample data. This dictionary is modified by the function. |
| 521 | The dictionary must satisfy the '_xrf_quant_fluor_schema' schema. |
| 522 | |
| 523 | xrf_map_dict: dict(array) |
| 524 | The dictionary of 2D ndarrays, which contain XRF maps for element lines and scalers. |
| 525 | Dictionary keys are the names of the emission lines (e.g. Fe_K, S_K, Au_M etc.) |
| 526 | |
| 527 | scaler_name: str |
| 528 | Scaler name. In order for the scaler to be applied, the name must match one of the |
| 529 | keys of `xrf_map_dict'. If the scaler name is not one of the list keys or set to None, |
| 530 | then fluorescence is not normalized |
| 531 | |
| 532 | Returns |
| 533 | |
| 534 | No value is returned. The computed fluorescence for the element lines is saved to |
| 535 | ``quant_fluor_data_dict["element_lines"][<element_line>]["fluorescence"]`` |
| 536 | |
| 537 | """ |
| 538 | |
| 539 | if not scaler_name: |
| 540 | logger.warning("No scaler is selected for computing quantitative coefficients. Data is not normalized.") |
| 541 | elif scaler_name not in xrf_map_dict: |
| 542 | logger.warning("Scaler '{scaler_name}' is not in XRF map dictionary. Normalization can not be performed.") |
| 543 | scaler_name = None |
| 544 | |
| 545 | # Clear ALL fluorescence values. Don't touch any other data |
| 546 | for eline, info in quant_fluor_data_dict["element_lines"].items(): |
| 547 | info["fluorescence"] = None |
| 548 | |
| 549 | # Save the scaler name |
| 550 | quant_fluor_data_dict["scaler_name"] = scaler_name |
| 551 | |
| 552 | # Compute fluorescence of the emission lines |
| 553 | eline_list = tuple(quant_fluor_data_dict["element_lines"].keys()) |
| 554 | for eline, map in xrf_map_dict.items(): |
| 555 | if eline in eline_list: |