dust_extinction icon indicating copy to clipboard operation
dust_extinction copied to clipboard

Inconsistent spline boundary conditions

Open ado8 opened this issue 1 year ago • 1 comments

Issue

The spline evaluation in shapes._curve_F99_method uses scipy.interpolate.splrep and splev, where the splrep documentation states

The default boundary condition is ‘not-a-knot’, i.e. the first and second segment at a curve end are the same polynomial. More boundary conditions are available in CubicSpline.

This is inconsistent with Fitzpatrick's IDL routine which uses CSPLINE, which uses SPL_INIT with default YP0 and YP1 arguments, which ultimately results in a spline with 'natural' boundary conditions (second derivative is 0 at ends) rather than 'not-a-knot' boundary conditions.

Severity of issue

The _curve_F99_method is called in the F99 and F04 dust laws. The differences due to the boundary conditions is on the order of millimags, but varies with RV and wavelength as shown in the attached figure. image

Proposed change

This can be fixed by replacing

spline_rep = interpolate.splrep(spline_x, spline_y)
axav[indxs_opir] = interpolate.splev(x[indxs_opir], spline_rep, der=0)

with

axav[indxs_opir] = interpolate.CubicSpline(spline_x, spline_y, bc_type='natural')(x[indxs_opir])

ado8 avatar Oct 11 '24 13:10 ado8

Thanks for raising this issue! This is a detail I was not aware of. I'll have a look and evaluate in a week or so. Hope this is soon enough.

karllark avatar Oct 11 '24 14:10 karllark