Skip to content

Use segment-local log-log interpolation for profiles with zero-density tail points #2

Description

@IvanChernyshov

Problem

interpolate_density(..., mode="loglog") currently uses log-log interpolation only when all density values are strictly positive:

if mode_value == "loglog" and np.all(rho_arr > 0):
    ...
else:
    out = np.interp(...)

Therefore, one numerical zero anywhere in the far tail switches the entire profile to linear interpolation. In the released pbe0_sfx2c_dyallv4z_h-lr_spherical_v2 data, neutral He, F, and Ne contain underflow zeros only at very large radii, so their chemically relevant positive-density regions are nevertheless interpolated linearly.

The present default also returns fill_value=0 below the first grid point. Consequently, a query at r = 0 returns zero rather than the first tabulated near-nuclear density.

Proposed behavior

Make the interpolation rule local to each interval:

  • reject negative density values;
  • for a positive-positive interval, interpolate in log(r)log(rho) space;
  • for a positive-zero interval, interpolate linearly to zero;
  • for a zero-zero interval, return zero;
  • preserve exact tabulated values at grid knots;
  • for 0 <= r < r_min, return rho(r_min) by default;
  • for r > r_max, retain the documented right-side fill behavior, with zero as the current default;
  • keep mode="linear" available with its existing meaning.

Non-finite and negative query radii should raise ValueError.

Acceptance criteria

  • A zero in the final profile tail no longer changes interpolation in earlier positive-positive intervals.
  • Regression tests cover a synthetic positive-positive-positive-zero profile.
  • Regression tests cover the released neutral He, F, and Ne profiles.
  • r = 0 returns the first tabulated density rather than zero.
  • Exact grid-point queries reproduce the stored values.
  • Existing fully positive log-log and explicit linear-mode behavior remain covered.
  • The numerical contract is documented in the API and methods documentation.

This should require only a helper/API correction and tests; the released profile data do not need to be recomputed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions