Skip to content

Commit

Permalink
rename "process" into "calculate" to better illustrate what is done
Browse files Browse the repository at this point in the history
  • Loading branch information
CPrescher committed Jul 29, 2024
1 parent 19e58e6 commit b7388aa
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion docs/apidoc/glassure.configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ glassure.configuration module
This module contains all configurations classes necessary for the glassure package.
The main entrypoints are the :class:`glassure.configuration.CalculationConfig` and :class: `glassure.configuration.DataModel`
pydantic models containing all necessary information for the analysis. These two configurations can then be used analysis
parameters for the *process* function in the :mod:`glassure.calc` module to perform the analysis. The output of the calculation
parameters for the :meth:`glassure.calc.calculate` calculate to perform the analysis. The output of the calculation
will be a :class:`glassure.configuration.Result` object containing the results of the analysis.
The models are then further split into submodels for better readability and maintainability.

Expand Down
4 changes: 2 additions & 2 deletions glassure/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def create_process_configs(
return data_config, calculation_config


def process(data_config: DataConfig, calculation_config: CalculationConfig) -> Pattern:
def calculate(data_config: DataConfig, calculation_config: CalculationConfig) -> Pattern:
"""
Process the input configuration and return the result.
"""
Expand Down Expand Up @@ -214,7 +214,7 @@ def process(data_config: DataConfig, calculation_config: CalculationConfig) -> P
)

res = Result(
calculation_config=config,
calculation_config=config.model_copy(deep=True),
sq=sq,
fr=fr,
gr=gr,
Expand Down
46 changes: 23 additions & 23 deletions tests/test_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np

from glassure.pattern import Pattern
from glassure.calc import process, create_process_configs
from glassure.calc import calculate, create_process_configs
from glassure.configuration import OptimizeConfig, IntNormalization


Expand All @@ -29,7 +29,7 @@ def prepare_input():
def test_process_input_base():
input = prepare_input()

res = process(*input)
res = calculate(*input)

assert len(res.sq.x) > 0
assert len(res.fr.x) > 0
Expand All @@ -38,108 +38,108 @@ def test_process_input_base():

def test_process_input_optimize_sq():
data_input, calculation_input = prepare_input()
res = process(data_input, calculation_input)
res = calculate(data_input, calculation_input)

calculation_input.optimize = OptimizeConfig()
res_optimize = process(data_input, calculation_input)
res_optimize = calculate(data_input, calculation_input)

assert not np.array_equal(res.sq.y, res_optimize.sq.y)


def test_process_input_norm_int():
data_input, calculation_input = prepare_input()
res = process(data_input, calculation_input)
res = calculate(data_input, calculation_input)

calculation_input.transform.normalization = IntNormalization()
res_int = process(data_input, calculation_input)
res_int = calculate(data_input, calculation_input)

assert not np.array_equal(res.sq.y, res_int.sq.y)


def test_process_input_modification_fcn():
data_input, calculation_input = prepare_input()
res = process(data_input, calculation_input)
res = calculate(data_input, calculation_input)

calculation_input.transform.use_modification_fcn = True
res_mod = process(data_input, calculation_input)
res_mod = calculate(data_input, calculation_input)

assert not np.array_equal(res.fr.y, res_mod.fr.y)


def test_process_input_linear_extrapolation():
data_input, calculation_input = prepare_input()
res = process(data_input, calculation_input)
res = calculate(data_input, calculation_input)

calculation_input.transform.extrapolation.method = "linear"
res_lin = process(data_input, calculation_input)
res_lin = calculate(data_input, calculation_input)

assert not np.array_equal(res.sq.y, res_lin.sq.y)


def test_process_input_spline_extrapolation():
data_input, calculation_input = prepare_input()
res = process(data_input, calculation_input)
res = calculate(data_input, calculation_input)

calculation_input.transform.extrapolation.method = "spline"
res_spline = process(data_input, calculation_input)
res_spline = calculate(data_input, calculation_input)

assert not np.array_equal(res.sq.y, res_spline.sq.y)


def test_process_input_poly_extrapolation():
data_input, calculation_input = prepare_input()
res = process(data_input, calculation_input)
res = calculate(data_input, calculation_input)

calculation_input.transform.extrapolation.method = "poly"
res_poly = process(data_input, calculation_input)
res_poly = calculate(data_input, calculation_input)

assert not np.array_equal(res.sq.y, res_poly.sq.y)


def test_process_extrapolation_with_s0():
data_input, calculation_input = prepare_input()
res = process(data_input, calculation_input)
res = calculate(data_input, calculation_input)

calculation_input.transform.extrapolation.method = "linear"
calculation_input.transform.extrapolation.s0 = 0.1
res_s0 = process(data_input, calculation_input)
res_s0 = calculate(data_input, calculation_input)

assert not np.array_equal(res.sq.y, res_s0.sq.y)


def test_process_input_kn_correction():
data_input, calculation_input = prepare_input()
res = process(data_input, calculation_input)
res = calculate(data_input, calculation_input)

calculation_input.transform.kn_correction = True
calculation_input.transform.wavelength = 0.22

res_kn = process(data_input, calculation_input)
res_kn = calculate(data_input, calculation_input)

assert not np.array_equal(res.sq.y, res_kn.sq.y)


def test_process_input_with_container_scattering():
data_input, calculation_input = prepare_input()
res = process(data_input, calculation_input)
res = calculate(data_input, calculation_input)

calculation_input.transform.normalization.container_scattering = {"C": 1}

res_container = process(data_input, calculation_input)
res_container = calculate(data_input, calculation_input)

assert not np.array_equal(res.sq.y, res_container.sq.y)


def test_process_input_with_container_scattering_and_kn():
data_input, calculation_input = prepare_input()
res = process(data_input, calculation_input)
res = calculate(data_input, calculation_input)
calculation_input.transform.kn_correction = True
calculation_input.transform.wavelength = 0.22

res = process(data_input, calculation_input)
res = calculate(data_input, calculation_input)

calculation_input.transform.normalization.container_scattering = {"C": 1}

res_container = process(data_input, calculation_input)
res_container = calculate(data_input, calculation_input)

assert not np.array_equal(res.sq.y, res_container.sq.y)

0 comments on commit b7388aa

Please sign in to comment.