Skip to content

Commit

Permalink
Update colour.SpectralDistribution.interpolate, `colour.SpectralDis…
Browse files Browse the repository at this point in the history
…tribution.align`, `colour.MultiSpectralDistributions.interpolate`, and,`colour.MultiSpectralDistributions.align` method to use *Continuous*-based integration.
  • Loading branch information
KelSolaar committed Jan 26, 2025
1 parent 4349fb7 commit 8f0311d
Show file tree
Hide file tree
Showing 2 changed files with 440 additions and 435 deletions.
31 changes: 16 additions & 15 deletions colour/colorimetry/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,9 @@ def interpolate(
Interpolator class type to use as interpolating function.
interpolator_kwargs
Arguments to use when instantiating the interpolating function.
interpolation_method
Interpolation method, ``Continuous`` uses the underlying continuous
signal and supports fractional steps.
Returns
-------
Expand Down Expand Up @@ -1177,17 +1180,10 @@ def interpolate(
]
)

# Defining proper interpolation bounds.
# TODO: Provide support for fractional interval like 0.1, etc...
if np.around(shape_start) != shape_start or np.around(shape_end) != shape_end:
runtime_warning("Fractional bound encountered, rounding will occur!")

shape.start = max([shape.start, np.ceil(shape_start)])
shape.end = min([shape.end, np.floor(shape_end)])
shape.start = max([shape.start, shape_start])
shape.end = min([shape.end, shape_end])

if interpolator is None:
# User has specifically chosen the interpolator thus it is used
# instead of those from *CIE 167:2005* recommendation.
if self.interpolator not in (
SpragueInterpolator,
CubicSplineInterpolator,
Expand All @@ -1199,8 +1195,6 @@ def interpolate(
interpolator = CubicSplineInterpolator

if interpolator_kwargs is None:
# User has specifically chosen the interpolator thus its keyword
# arguments are used.
if self.interpolator not in (
SpragueInterpolator,
CubicSplineInterpolator,
Expand All @@ -1209,12 +1203,19 @@ def interpolate(
else:
interpolator_kwargs = {}

wavelengths, values = self.wavelengths, self.values
self_interpolator, self.interpolator = self.interpolator, interpolator
self_interpolator_kwargs, self.interpolator_kwargs = (
self.interpolator_kwargs,
interpolator_kwargs,
)

values = self[shape.wavelengths]

self.domain = shape.wavelengths
self.range = interpolator(wavelengths, values, **interpolator_kwargs)(
self.domain
)
self.values = values

self.interpolator = self_interpolator
self.interpolator_kwargs = self_interpolator_kwargs

return self

Expand Down
Loading

0 comments on commit 8f0311d

Please sign in to comment.