-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: extract intensity components (#244)
* docs: write Result class step 1 to JSON * fix: change plot title to SciPy * refactor: only emit warning when over-defining parameters
- Loading branch information
Showing
9 changed files
with
327 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"""Extract physics info from data and fit output.""" | ||
|
||
from typing import Iterable, Sequence, Union | ||
|
||
import sympy as sp | ||
from expertsystem.amplitude.helicity import HelicityModel | ||
|
||
from tensorwaves.model import LambdifiedFunction, SympyModel | ||
|
||
|
||
def add_components( | ||
model: HelicityModel, | ||
components: Union[str, Iterable[str]], | ||
) -> sp.Expr: | ||
"""Coherently or incoherently add components of a helicity model.""" | ||
if isinstance(components, str): | ||
components = [components] | ||
for component in components: | ||
if component not in model.components: | ||
raise KeyError( | ||
f'Component "{component}" not in model components', | ||
list(model.components), | ||
) | ||
if any(map(lambda c: c.startswith("I"), components)) and any( | ||
map(lambda c: c.startswith("A"), components) | ||
): | ||
intensity_sum = add_components( | ||
model, | ||
components=filter(lambda c: c.startswith("I"), components), | ||
) | ||
amplitude_sum = add_components( | ||
model, | ||
components=filter(lambda c: c.startswith("A"), components), | ||
) | ||
return intensity_sum + amplitude_sum | ||
if all(map(lambda c: c.startswith("I"), components)): | ||
return sum(model.components[c] for c in components) | ||
if all(map(lambda c: c.startswith("A"), components)): | ||
return abs(sum(model.components[c] for c in components)) ** 2 | ||
raise ValueError('Not all component names started with either "A" or "I"') | ||
|
||
|
||
def create_intensity_component( | ||
model: HelicityModel, | ||
components: Union[str, Sequence[str]], | ||
backend: str, | ||
) -> LambdifiedFunction: | ||
"""Create a `.LambdifiedFunction` of a sum of helicity model components.""" | ||
added_components = add_components(model, components) | ||
sympy_model = SympyModel( | ||
expression=added_components, | ||
parameters=model.parameters, | ||
) | ||
return LambdifiedFunction(sympy_model, backend=backend) |
Oops, something went wrong.