Class for handling weights when calculating spectra
Implement a class that takes a set of species and type of probe (neutron, electron, X-ray) and returns coherent and incoherent cross sections. Should be able to return energy dependent cross sections.
The object should be used as an optional input to neutron_cross_section
. If no cross sections are supplied, the fall back should be to use the table cross sections
This avoids breaking changes, but still allows expert users to set the cross section manually.
Additional comments/notes
- notes on interface design
-
ncrystal
allows one to calculate the energy dependence with account for the (crystal) structure - neutron and X-ray cross sections from NIST are available via the
periodictable
package
Interface suggestion
Class sketch
class Weights:
def __init__(
self,
weights_coh: dict[str, float],
weights_incoh: dict[str, float] = None,
include_currents: bool = True,
):
self._include_currents = include_currents
@property
def include_currents(self) -> bool:
return self._include_currents
def get_weight(self, atom_type: str, q_norm: float):
...
class NeutronCrossSections(Weights):
# energy dependence, probe dependence, q-point
def __init__(
self,
...,
):
self._include_currents = False
self._weights = fetch_from_database(...)
def get_weight(self, atom_type: str, q_norm: float):
...
Use pattern
from post_processing import get_weighted_sample, NeutronCrossSections, XrayFormFactors
# mass/charges
weights = Weights(weights_coh=dict(Al=2.0, Si=-2.0), weights_incoh=dict(...))
weighted_sample = get_weighted_sample(sample, weights)
# neutrons
weights = NeutronCrossSections(...)
= get_weighted_sample(sample, weights)
# X-rays
weights = XrayFormFactors(...)
predicted_xray_spectra = get_weighted_sample(sample, weights)
Related to #55
Edited by Paul Erhart