pahfit icon indicating copy to clipboard operation
pahfit copied to clipboard

Piecewise/partial integration of drvdputt/experimental

Open drvdputt opened this issue 10 months ago • 6 comments

github.com/drvdputt/pahfit/tree/experimental has diverged quite far from master. But it is in working order, and I am actively using it for my science goals. There are many aspects which we want to integrate into the master branch, but we should do so piece wise to avoid breakage.

Here is an overview of the changes I made so far.

Major features or structures

  • Implemented Fitter abstract base class, and APFitter subclass. All astropy-fitting-specific code was moved into this class. See #270 for more details.
  • Rewrite of model.plot, which makes use of tabulate() and (indirectly) the Fitter API where possible (current version crashes when no attenuation is in the model). Remove old plotting code from base.py.
  • Use of the Fitter API in the Model class. Model building is much more straightforward. Removed old building code from base.py.
  • Complete removal of pahfit.base. All functionality is split between Model and Fitter (and APFitter).
  • Internal unit system. The file proposed in #259 was included, and used in various locations. Particularly important for the Power features above. caveat: So far, I only support MJy / sr or equivalent units (intensity). It is checked that the user-provided spectrum is compatible with the right physical quantity, and then the conversion is made internally. I did not find an obvious way to switch the Power feature classes dynamically based on the given unit type, so not flux units (Jy) yet.
  • PowerGaussian and PowerDrude implementation (like #225, but unit conversions are much more clearly formulated, as the internal unit system can be used)
  • Empty draft for Asymmetric features (just to test adding an asymmetry parameter to the YAML file)

Other bug / usability fixes

  • Better exclusion algorithm for the features. Takes into account both the instrument model and the given wavelength range of the data. Having too many features outside of the data range makes the fitting unreliable (too many parameters with zero effect on the chi2).
  • Always use "BoundedMaskedColumn" in the features table. This works around #266 (and #273, which are of the same origin)
  • Rewrote the pretty print function of BoundedParTableFormatter to address #273. Was needed in combination with the above fix.
  • Tried out different fitting algorithms. Slightly "better" results with TRFLSQFitter (less sticky to the bounds), but it seems more prone to getting stuck in local minima. Running both TRFLSQFitter and LevMarLSQFitter (one after the other) might provide the best of both worlds.
  • Automatic documentation generation for the Model class.

drvdputt avatar May 03 '24 17:05 drvdputt