Skip to content

Planckian and exponential fits depend on data units; Planck signal and domain-based images lack axis information #74

Closed

Description

@PierreRaybaut

Context

Several issues reported by DataLab 1.3.0 users, all rooted in Sigima, concern the blackbody (Planck) signal, the Planckian fit, and synthetic images. An exponential fit defect found while investigating is included as well.

1. Automatic Planckian fit returns its initial guess (bug)

With the default Planck signal (500 points, wavelengths in meters), planckian_fit returns a curve whose peak is 147.4 times lower than the data, without any warning:

import sigima.objects as so
from sigima.tools.signal import fitting

s = so.create_signal_from_param(so.PlanckParam.create(T=296.0))
y_fit, params = fitting.planckian_fit(s.x, s.y)
print(s.y.max() / y_fit.max())  # 147.41... = exp(5) - 1

Root cause: PlanckianFitComputer.compute_initial_params seeds amp with the data range, but with sigma = 1 and x0 = x_peak the model peaks at amp / (exp(5) - 1). With x ~ 1e-5 and amp ~ 1e7, curve_fit stops on xtol at the first iteration and returns p0 unchanged. The amp bounds ([0.01, 100] × dy) do not even contain the solution for sigma = 1. The fit converges as soon as x is expressed in µm, which confirms a conditioning/initial-guess problem rather than a model error.

2. Exponential fit fails for short time constants (bug)

import numpy as np
from sigima.tools.signal import fitting

x = np.linspace(0, 5e-3, 500)  # seconds
y = 2.0 * np.exp(-x / 1e-3) + 0.1  # tau = 1 ms
y_fit, params = fitting.exponential_fit(x, y)
# UserWarning: Optimization failed: Initial guess is outside of provided bounds
# relative RMS residual: 0.72

The bounds on b are hard-coded to [-10, 10] and evaluate clips b itself to ±50, so the fit depends on the X unit.

3. Planck signal has no axis labels or units (enhancement)

PlanckParam computes a spectral radiance as a function of wavelength in meters, but leaves X/Y labels and units empty (periodic signals, by contrast, default to xunit = "s"). The func docstring also gives a wrong unit (W m⁻² sr⁻¹ Hz⁻¹ instead of W sr⁻¹ m⁻³ for B_λ).

4. Domain-based synthetic images are displayed in pixel coordinates (enhancement)

Gaussian, 2D ramp, sinusoidal grating, ring pattern, Siemens star and 2D sinc images are computed over [xmin, xmax] × [ymin, ymax], but create_image_from_param does not set the image coordinates (x0 = y0 = 0, dx = dy = 1). Center, width and frequency parameters are therefore expressed in a different scale than the displayed axes: e.g. a grating with fx = 0.1 over [0, 100] on 1024 pixels shows 10 periods across axes labelled 0–1023.

5. Fit model formulas are not available programmatically (enhancement)

The interactive fit dialogs cannot show which formula is used. Users have to read the source code to find it.

Proposed changes

  • PlanckianFitComputer: initial guess consistent with the model (x0 = x_peak · W / 5, amp = dy · (exp(W) − 1) · (W/5)⁵ with W ≈ 4.965, Wien's constant), bounds centered on it, and fit performed on normalized x/y then mapped back. Document the derived quantities (peak ≈ 1.007 · x0 / sigma; for x in meters, T = h c sigma / (5 k_B x0)). The 4-parameter model and the fit_params schema are unchanged (the degeneracy remains tracked in Planckian fit is exactly non-identifiable: x0 and sigma cannot be determined separately #43).
  • ExponentialFitComputer: clip the exponent b · x (overflow protection) instead of b, and scale the b bounds with 1 / Δx.
  • FitComputer.FORMULA: rich-text model formula on every fit computer (single source of truth for SigimaX, DataLab and DataLab-Web).
  • PlanckParam: default labels and units (Wavelength [m], Spectral radiance [W·sr⁻¹·m⁻³]); fix the func docstring.
  • Domain-based image parameters: new "Physical coordinates" option (default on) applying the domain to the image coordinates; test data helpers keep pixel coordinates.
  • Regression tests and French translations.

Related

Activity

  1. added this to the V1.3.0 milestone on Oct 19, 2026
  2. PierreRaybaut commented on Oct 20, 2026

    @PierreRaybaut
    ContributorAuthor

    Fix proposed in #75, DataLab-Platform/SigimaX#10 and DataLab-Platform/DataLab#401 (merge order: Sigima, then SigimaX, then DataLab). The PRs target develop, so this issue will not be closed automatically on merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions