jwspecfit.constraints

Parameter constraints: tied kinematics and fixed flux ratios.

Constraints are applied as transformations on the free-parameter vector before the model is evaluated. This keeps the optimiser working in an unconstrained space while enforcing physical relationships.

Classes

ConstraintSet(line_names[, tie_nii, ...])

Collection of parameter constraints for a line fit.

class jwspecfit.constraints.ConstraintSet(line_names, tie_nii=True, tie_balmer_to_oiii=True, tie_uv_doublets=True, tie_uv_centroids=True, tie_uv_widths=True, blended_doublets=None, niv_doublet_ratio=None, ciii_doublet_ratio=None)[source]

Bases: object

Collection of parameter constraints for a line fit.

Parameters:
  • line_names (list[str])

  • tie_nii (bool)

  • tie_balmer_to_oiii (bool)

  • tie_uv_doublets (bool)

  • tie_uv_centroids (bool)

  • tie_uv_widths (bool)

  • blended_doublets (set[str] | None)

  • niv_doublet_ratio (float | None)

  • ciii_doublet_ratio (float | None)

line_names

Ordered line names matching the parameter vector layout.

Type:

list of str

tie_nii

Tie [NII] 6549 amplitude and kinematics to [NII] 6585.

Type:

bool

tie_balmer_to_oiii

Tie narrow Balmer (and [NII]) widths to [OIII] 5007 in velocity space.

Type:

bool

blended_doublets

Secondary line names of kinematic-tied doublets that are unresolved and should have their amplitude fixed to the low-density-limit ratio. Populated by the fitter based on spectral resolution.

Type:

set of str

apply(params)[source]

Apply constraints to a parameter vector (in-place copy).

Parameters:

params (np.ndarray) – Raw parameter vector [A_0..A_n, mu_0..mu_n, sigma_0..sigma_n].

Returns:

Constrained parameter vector.

Return type:

np.ndarray

blended_doublets: set[str] | None = None
ciii_doublet_ratio: float | None = None
expand_free_to_full(p_free)[source]

Insert free parameters into a full-length vector.

Constrained slots are filled with placeholder values that will be overwritten by apply().

Parameters:

p_free (np.ndarray) – Free parameter values.

Returns:

Full parameter vector (length 3 * n_lines).

Return type:

np.ndarray

free_mask()[source]

Boolean mask of free (unconstrained) parameters.

Parameters that are determined by constraints are marked False. The optimiser should only vary free parameters.

Returns:

Boolean array of length 3 * n_lines.

Return type:

np.ndarray

line_names: list[str]
niv_doublet_ratio: float | None = None
tie_balmer_to_oiii: bool = True
tie_nii: bool = True
tie_uv_centroids: bool = True
tie_uv_doublets: bool = True
tie_uv_widths: bool = True