Skip to content

Commit

Permalink
Added resolve from concatenating XANES and EXAFS in XASSpectra
Browse files Browse the repository at this point in the history
  • Loading branch information
JosePizarro3 committed Apr 16, 2024
1 parent b59ad77 commit efc82be
Showing 1 changed file with 38 additions and 9 deletions.
47 changes: 38 additions & 9 deletions src/nomad_simulations/properties/spectral_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,7 @@
import pint

from nomad import config
from nomad.units import ureg
from nomad.metainfo import (
Quantity,
SubSection,
MEnum,
Section,
Context,
JSON,
)
from nomad.metainfo import Quantity, SubSection, Section, Context

from ..utils import get_sibling_section
from ..physical_property import PhysicalProperty
Expand Down Expand Up @@ -481,5 +473,42 @@ def __init__(
# Set the name of the section
self.name = self.m_def.name

def resolve_from_concatenating(self, logger: BoundLogger) -> None:
"""
Resolve the `value` of the XAS spectra by concatenating the XANES and EXAFS parts. It also concatenates
the `Energy` grid points of the XANES and EXAFS parts.
Args:
logger (BoundLogger): The logger to log messages.
"""
if self.xanes_spectra is not None or self.exafs_spectra is not None:
# Concatenate XANE and EXAFS `Energy` grid points
for var in self.xanes_spectra.variables:
if isinstance(var, Energy):
xanes_energies = var.grid_points
break
for var in self.exafs_spectra.variables:
if isinstance(var, Energy):
exafs_energies = var.grid_points
break
self.variables = [
Energy(grid_points=np.concatenate([xanes_energies, exafs_energies]))
]
# Concatenate XANES and EXAFS `value` if they have the same shape
try:
self.value = np.concatenate(
[self.xanes_spectra.value, self.exafs_spectra.value]
)
except ValueError:
logger.error(
'The XANES and EXAFS `value` have different shapes. Could not concatenate the values.'
)

def normalize(self, archive, logger) -> None:
super().normalize(archive, logger)

if self.value is None:
logger.info(
'The `XASSpectra.value` is not stored. We will attempt to obtain it by combining the XANES and EXAFS parts if these are present.'
)
self.resolve_from_concatenating(logger)

0 comments on commit efc82be

Please sign in to comment.