Coverage for local_installation/dynasor/post_processing/weights.py: 63%
23 statements
« prev ^ index » next coverage.py v7.3.2, created at 2024-08-05 09:53 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2024-08-05 09:53 +0000
1from typing import Dict
4class Weights:
5 """
6 Class holding weights and support functions for weighting of samples
8 Parameters
9 ----------
10 weights_coh
11 A dict with keys and values representing the atom types and their corresponding
12 coherent scattering length, ``{'A': b_A }``.
13 weights_incoh
14 A dict with keys and values representing the atom types and their corresponding
15 incoherent scattering length, ``{'A': b_A }``.
16 supports_currents
17 whether or not the coherent weights should be applied to current-correlation functions
18 """
20 def __init__(
21 self,
22 weights_coh: Dict[str, float],
23 weights_incoh: Dict[str, float] = None,
24 supports_currents: bool = True,
25 ):
26 self._weights_coh = weights_coh
27 self._weights_incoh = weights_incoh
28 self._supports_currents = supports_currents
30 def get_weight_coh(self, atom_type, q_norm=None):
31 """Get the coherent weight for a given atom type and q-vector norm."""
32 return self._weights_coh[atom_type]
34 def get_weight_incoh(self, atom_type, q_norm=None):
35 """Get the incoherent weight for a given atom type and q-vector norm."""
36 return self._weights_incoh[atom_type]
38 @property
39 def supports_currents(self):
40 """
41 Wether or not this :class:`Weights` object supports weighting of current correlations.
42 """
43 return self._supports_currents
45 @property
46 def supports_incoherent(self):
47 """
48 Whether or not this :class:`Weights` object supports weighting of incoherent
49 correlation functions.
50 """
51 return self._weights_incoh is not None
53 def __str__(self):
54 s = ['weights coherent:']
55 for key, val in self._weights_coh.items():
56 s.append(f' {key}: {val}')
57 s = ['weights incoherent:']
58 for key, val in self._weights_incoh.items():
59 s.append(f' {key}: {val}')