|
| 1 | +__coding__ = "utf-8" |
| 2 | +__author__ = "Brian R. Pauw" |
| 3 | +__copyright__ = "MoDaCor team" |
| 4 | +__license__ = "BSD3" |
| 5 | +__date__ = "23/05/2025" |
| 6 | +__version__ = "20250523.1" |
| 7 | +__status__ = "Development" # "Development", "Production" |
| 8 | + |
| 9 | + |
| 10 | +from pathlib import Path |
| 11 | + |
| 12 | +from modacor import ureg |
| 13 | +from modacor.dataclasses.databundle import DataBundle |
| 14 | +from modacor.dataclasses.process_step import ProcessStep |
| 15 | +from modacor.dataclasses.process_step_describer import ProcessStepDescriber |
| 16 | +from modacor.dataclasses.processingdata import ProcessingData |
| 17 | +from modacor.math.variance_calculations import divide |
| 18 | + |
| 19 | + |
| 20 | +class MultiplyByVariable(ProcessStep): |
| 21 | + """ |
| 22 | + Adding Poisson uncertainties to the data |
| 23 | + """ |
| 24 | + |
| 25 | + documentation = ProcessStepDescriber( |
| 26 | + calling_name="Multiply by data source variable", |
| 27 | + calling_id="MultiplyByVariable", |
| 28 | + calling_module_path=Path(__file__), |
| 29 | + calling_version=__version__, |
| 30 | + required_data_keys=["signal"], |
| 31 | + works_on={"signal": ["normalization_factor", "variances"]}, |
| 32 | + calling_arguments={"scalar": None, "scalar_units": None, "scalar_uncertainty": None}, |
| 33 | + step_keywords=["multiply", "variable", "scalar"], |
| 34 | + step_doc="Multiply by a variable loaded from a data source", |
| 35 | + step_reference="DOI 10.1088/0953-8984/25/38/383201", |
| 36 | + step_note="""This loads a scalar (value, units and uncertainty) |
| 37 | + from an IOSource and applies it to the data""", |
| 38 | + ) |
| 39 | + |
| 40 | + def calculate(self) -> dict[str, DataBundle]: |
| 41 | + """ """ |
| 42 | + self.processing_data: ProcessingData |
| 43 | + key = self.configuration.get("with_processing_keys") |
| 44 | + data: DataBundle = self.processing_data[key] |
| 45 | + |
| 46 | + # apply factor to the data |
| 47 | + f, v = divide( |
| 48 | + data["signal"].normalization_factor, |
| 49 | + data["signal"].normalization_factor_variances, |
| 50 | + self.configuration.get("scalar"), |
| 51 | + self.configuration.get("scalar_uncertainty", 0), |
| 52 | + ) |
| 53 | + data["signal"].normalization_factor = f |
| 54 | + # propagate uncertainties into normalization_factor_ |
| 55 | + data["signal"].normalization_factor_variances = v |
| 56 | + # propagate units into normalization_factor_units |
| 57 | + data["signal"].normalization_factor_units /= ureg.Unit( |
| 58 | + self.configuration.get("units", "dimensionless") |
| 59 | + ) |
| 60 | + |
| 61 | + return {key: data} |
0 commit comments