Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update colour.SpectralDistribution.interpolate method to use continuous-based integration. #1328

Merged
merged 1 commit into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions colour/colorimetry/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -1177,17 +1177,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 +1192,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 +1200,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
Loading