CIRADA-Tools / RM-Tools

RM-synthesis, RM-clean and QU-fitting on polarised radio spectra
MIT License
42 stars 23 forks source link

Stokes I renormalisation failure case #125

Closed AlecThomson closed 5 months ago

AlecThomson commented 5 months ago

In 1D RMsynth, if a custom model is provided the renormalize_StokesI_model causes a KeyError in the fitDict.

Chasing down these errors hurts, so I've got a PR ready that does away with the dictionary if favour of a NamedTuple. Feels nice and rusty 🦀

The main fix looks something like:

    if lam0Sq_m2 == 0:  # Rudnick-Cotton adapatation
        freq0_Hz = fit_result.reference_frequency_Hz
    else:  # standard RM-synthesis
        freq0_Hz = C / m.sqrt(lam0Sq_m2)
        if modStokesI is None:
            fit_result = renormalize_StokesI_model(fit_result, freq0_Hz)
        else:
            fit_result = fit_result.with_options(
                reference_frequency_Hz=freq0_Hz
            )

So a catch for the modStokesI variable.

As an aside, we may want to move away from the many dictionaries that are currently floating around. Its really hard to maintain state in these. NamedTuples are a very nice alternative.

In any case, PR incoming.