PAHFIT / pahfit

Model Decomposition for Near- to Mid-Infrared Spectroscopy of Astronomical Sources
https://pahfit.readthedocs.io/
18 stars 26 forks source link

starlight sub_model error #252

Open cwhitco opened 1 year ago

cwhitco commented 1 year ago

using dev branch version, there is an error when trying to get single component sub_models like the starlight continuum my code, after fitting a spectrum spec with model: starspec = model.sub_model(instrumentname=spec.meta['instrument'], redshift=spec.redshift, kind='starlight') PAHFITModelError: Fewer than 2 features! Single component models are no allowed!

drvdputt commented 1 year ago

Thank you for reminding me of this restriction I put in. I did this because there is some code that can't deal with a single-component model. (The resulting astropy model is no longer a multi-component model, so loops "over the components" won't work).

I would like a workaround for this, we also need to consider that

  1. We will remove sub_model and replace it with tabulate. See #249. (This will still have the same issue though...)
  2. A different fitting backend is being developed (not based on astropy). But this will take a while before it gets merged.

As a temporary workaround, you can go head and comment out these lines in the source code of model.py, in Model.__init__()

        # if len(features) < 2:
        #     raise PAHFITModelError(
        #         "Fewer than 2 features! Single component models are not allowed!"
        #     )

I did a quick test, and sub_model() will work for single components if you do this. It's just guess() and fit() that will fail, when those functions try to parse the components of the astropy model.