Piecewise Conversion Calculations¶
- class ionworkspipeline.calculations.SlopesToKnots(base_parameter_name: str, breakpoint_values: list[float], breakpoint_parameter_name: str)¶
Converts slopes and initial value to knot values for piecewise linear interpolation.
This calculation takes as input: - An initial value at the first breakpoint - Slopes for each segment between consecutive breakpoints
And outputs: - The value at each breakpoint (knot values)
The conversion follows: y_{i+1} = y_i + slope_i * (x_{i+1} - x_i)
Parameters¶
- base_parameter_namestr
The name of the parameter (e.g., “Particle diffusion time [s]”)
- breakpoint_valueslist[float]
List of breakpoint values (e.g., [0.0, 0.5, 1.0])
- breakpoint_parameter_namestr
Name of the breakpoint parameter (e.g., “SOC”, “Temperature [K]”)
Examples¶
>>> import ionworkspipeline as iwp >>> calc = iwp.calculations.SlopesToKnots( ... base_parameter_name="Particle diffusion time [s]", ... breakpoint_values=[0.0, 0.5, 1.0], ... breakpoint_parameter_name="SOC", ... ) >>> params = iwp.ParameterValues({ ... "Particle diffusion time at SOC 0 [s]": 500.0, ... "Particle diffusion time slope from SOC 0 to 0.5 [s]": 1000.0, ... "Particle diffusion time slope from SOC 0.5 to 1 [s]": 2000.0, ... }) >>> result = calc.run(params) >>> result["Particle diffusion time at SOC 0 [s]"] 500.0 >>> result["Particle diffusion time at SOC 0.5 [s]"] 1000.0 >>> result["Particle diffusion time at SOC 1 [s]"] 2000.0
Extends:
ionworkspipeline.calculations.calculation.Calculation- property inputs¶
Returns the list of input parameters needed for this calculation.
This includes the initial value and all slopes.
- property outputs¶
Returns the list of output parameters produced by this calculation.
This includes all knot values at the breakpoints.
- run(parameter_values: ParameterValues) ParameterValues¶
Convert slopes and initial value to knot values.
Parameters¶
- parameter_valuesdict
Dictionary containing: - Initial value at first breakpoint - Slopes for each segment
Returns¶
- dict
Dictionary containing knot values at all breakpoints
- class ionworkspipeline.calculations.SlopesToKnots2D(base_parameter_name: str, breakpoint1_values: list[float], breakpoint1_parameter_name: str, breakpoint2_values: list[float], breakpoint2_parameter_name: str)¶
Converts slopes and initial value to knot values for 2D piecewise linear interpolation.
This calculation takes as input: - An initial value at (bp1_0, bp2_0) - Slopes along dimension 1 for the first row (at bp2_0) - Slopes along dimension 2 for all subsequent rows
And outputs: - The value at each 2D grid point (knot values)
The conversion follows the same strategy as PiecewiseInterpolation2D slopes mode: 1. Start with initial value at (bp1_0, bp2_0) 2. Use bp1-slopes to fill first row 3. Use bp2-slopes to fill remaining rows
Parameters¶
- base_parameter_namestr
The name of the parameter (e.g., “Diffusivity [m2.s-1]”)
- breakpoint1_valueslist[float]
List of first dimension breakpoint values (e.g., [0.0, 0.5, 1.0])
- breakpoint1_parameter_namestr
Name of the first breakpoint parameter (e.g., “SOC”)
- breakpoint2_valueslist[float]
List of second dimension breakpoint values (e.g., [273.15, 298.15])
- breakpoint2_parameter_namestr
Name of the second breakpoint parameter (e.g., “Temperature [K]”)
Examples¶
>>> import ionworkspipeline as iwp >>> calc = iwp.calculations.SlopesToKnots2D( ... base_parameter_name="Diffusivity [m2.s-1]", ... breakpoint1_values=[0.0, 1.0], ... breakpoint1_parameter_name="SOC", ... breakpoint2_values=[273.15, 323.15], ... breakpoint2_parameter_name="Temperature [K]", ... ) >>> params = iwp.ParameterValues({ ... "Diffusivity at SOC 0, Temperature [K] 273.15 [m2.s-1]": 1e-14, ... "Diffusivity SOC-slope from SOC 0 to 1 at Temperature [K] 273.15 [m2.s-1]": 2e-14, ... "Diffusivity Temperature [K]-slope from Temperature [K] 273.15 to 323.15 at SOC 0 [m2.s-1]": 2e-15, ... "Diffusivity Temperature [K]-slope from Temperature [K] 273.15 to 323.15 at SOC 1 [m2.s-1]": 2e-15, ... }) >>> result = calc.run(params) >>> result["Diffusivity at SOC 0, Temperature [K] 273.15 [m2.s-1]"] 1e-14
Extends:
ionworkspipeline.calculations.calculation.Calculation- property inputs¶
Returns the list of input parameters needed for this calculation.
This includes the initial value and all slopes.
- property outputs¶
Returns the list of output parameters produced by this calculation.
This includes all knot values at the 2D grid points.
- run(parameter_values: ParameterValues) ParameterValues¶
Convert 2D slopes and initial value to knot values.
Parameters¶
- parameter_valuesdict
Dictionary containing: - Initial value at (bp1_0, bp2_0) - bp1-slopes for first row - bp2-slopes for all columns
Returns¶
- dict
Dictionary containing knot values at all 2D grid points