dn2dem#

demregpy.dn2dem(
dn_in,
edn_in,
tresp,
tresp_logt,
temps,
reg_tweak=1.0,
max_iter=10,
gloci=0,
rgt_fact=1.5,
dem_norm0=None,
nmu=40,
warn=False,
emd_int=False,
emd_ret=False,
l_emd=False,
non_pos=False,
)[source]#

Recover a differential emission measure from channel counts.

This is the main public wrapper around the lower-level regularised inversion routines. It accepts arrays whose last axis is filter/channel, with up to three leading spatial or temporal axes.

Parameters:
  • dn_in (array_like) – Input channel counts. The last axis must be filter/channel, so valid shapes include (nf,), (n, nf), (nx, ny, nf), and (n0, n1, n2, nf).

  • edn_in (array_like) – Uncertainties on dn_in with the same shape and units.

  • tresp (array_like) – Temperature response matrix with shape (nt_resp, nf).

  • tresp_logt (array_like) – Log10 temperature grid for the first axis of tresp.

  • temps (array_like) – Temperature-bin edges at which to recover the DEM.

  • reg_tweak (float, optional) – The initial normalised chisq target. Default is 1.0.

  • max_iter (int, optional) – The maximum number of iterations to attempt, code iterates if negative DEM is produced. If max iter is reached before a suitable solution is found then the current solution is returned instead (which may contain negative values). Default is only 10 - although non_pos=True will set as 1.

  • gloci (int or array_like, optional) – Weighting mode used when dem_norm0 is not supplied. A scalar 0 uses the self-normalised weighting scheme, a scalar 1 uses all EM loci curves, and a length-nf 0/1 mask selects which filters contribute to the EM loci weighting. Default is 0.

  • rgt_fact (float, optional) – The factor by which rgt_tweak increases each iteration. As the target chisq increases there is more flexibility allowed on the DEM. Default is 1.5.

  • dem_norm0 (array_like, optional) – Initial DEM-shaped weighting for the constraint matrix. Only the relative values matter. If omitted, the weighting is determined from gloci. Default is None.

  • nmu (int, optional) – Number of reg param samples to calculate (default (or <=40) 500 for 0D, 42 for map). Default is 40.

  • warn (bool, optional) – Print out any warnings (always warn for 1D, default no for higher dim data). Default is False.

  • emd_int (bool, optional) – Perform the inversion in emission measure distribution space rather than DEM space. Default is False.

  • emd_ret (bool, optional) – Return the result in EMD units instead of DEM units. Default is False.

  • l_emd (bool, optional) – Remove the square-root factor in the constraint matrix. This is mainly useful with emd_int=True. Default is False.

  • non_pos (bool, optional) – Return the first solution even if it contains negative values. This is implemented by forcing max_iter=1. Default is False.

Returns:

  • dem (ndarray) – Recovered DEM or EMD. The output shape matches the input shape with the filter axis replaced by temperature bin.

  • edem (ndarray) – Vertical uncertainties on dem.

  • elogt (ndarray) – Horizontal temperature resolution estimates in log10(T).

  • chisq (ndarray) – Final reduced chi-squared values.

  • dn_reg (ndarray) – Counts reconstructed from the recovered solution, with the same shape as dn_in.