Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add absorption to the model and set upper and lower limits #303

Open
unknowner-m opened this issue Dec 7, 2024 · 6 comments
Open

Comments

@unknowner-m
Copy link

I am a graduate student and I am trying to fit the NIRSPEC g395h spectrum using PAHFIT. According to Lai+2020, I added the short wavelength feature in the yaml file.

PAH_3.3:
  kind: dust_feature
  wavelength: 3.29
  fwhm: 0.0418

PAH_3.4:
  kind: dust_feature
  wavelength: 3.4
  fwhm: 0.0299

PAH_3.47:
  kind: dust_feature
  wavelength: 3.47
  fwhm: 0.1
##########################
# Absorption Model      #
##########################
H2O_absorption:
  kind: absorption
  tau: 2.5
  wavelength: 3.05
  fwhm: 0.406

CO2_absorption:
  kind: absorption
  tau: 1.532
  wavelength: 4.27
  fwhm: 0.033

CO_absorption:
  kind: absorption
  tau: 0.4
  wavelength: 4.67
  fwhm: 0.1

When I start running the script

model = Model.from_yaml('model.yaml')
model.guess(spec)
model.fit(spec, maxiter=10000)
display(model)
model.plot(spec)

I got the following error

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
Cell In[67], [line 12](vscode-notebook-cell:?execution_count=67&line=12)
     [10](vscode-notebook-cell:?execution_count=67&line=10) model.fit(spec, maxiter=10000)
     [11](vscode-notebook-cell:?execution_count=67&line=11) display(model)
---> [12](vscode-notebook-cell:?execution_count=67&line=12) model.plot(spec)

File d:\Anaconda\envs\pahfit\Lib\site-packages\pahfit\model.py:538, in Model.plot(self, spec, redshift, use_instrument_fwhm, label_lines, scalefac_resid, **errorbar_kwargs)
    [535] ext_model = S07_attenuation(tau_sil=tau)(lam_mod)
    [537](file:///D:/Anaconda/envs/pahfit/Lib/site-packages/pahfit/model.py:537) if has_abs:
--> [538](file:///D:/Anaconda/envs/pahfit/Lib/site-packages/pahfit/model.py:538)     raise NotImplementedError(
    [539](file:///D:/Anaconda/envs/pahfit/Lib/site-packages/pahfit/model.py:539)         "plotting absorption features not implemented yet"
    [540](file:///D:/Anaconda/envs/pahfit/Lib/site-packages/pahfit/model.py:540)     )
    [542](file:///D:/Anaconda/envs/pahfit/Lib/site-packages/pahfit/model.py:542) if has_att or has_abs:
    [543](file:///D:/Anaconda/envs/pahfit/Lib/site-packages/pahfit/model.py:543)     ax_att = ax.twinx()  # axis for plotting the extinction curve

NotImplementedError: plotting absorption features not implemented yet

Does this mean that the absorption feature cannot be applied in the current version?

In addition, I checked the feature table and found that the wavelength and fwhm of the features I added did not have upper and lower limits set. How should I set them correctly?

@drvdputt
Copy link
Contributor

The fitting of the absorption features should be working normally. What you're seeing is just a plotting issue.

The error you posted is old code. The current plotting code definitely has something else under if has_abs.
Recently a lot of development in the dev branch was merged into master, but no official release was made.

Can you try installing the master branch? You can use pip install git+https://github.com/drvdputt/pahfit.git

@unknowner-m
Copy link
Author

unknowner-m commented Feb 26, 2025

The fitting of the absorption features should be working normally. What you're seeing is just a plotting issue.

The error you posted is old code. The current plotting code definitely has something else under if has_abs. Recently a lot of development in the dev branch was merged into master, but no official release was made.

Can you try installing the master branch? You can use pip install git+https://github.com/drvdputt/pahfit.git

Thanks for your comment! I reinstalled PAHFIT using pip install git+https://github.com/drvdputt/pahfit.git but still got the same problem.

Then I checked out the other branch and installed it again using pip install git+https://github.com/PAHFIT/pahfit.git@dev, and now the code works perfectly.

However, I noticed that some checks for this branch were unsuccessful, as indicated on the github page, so perhaps this branch is temporarily unavailable?

@drvdputt
Copy link
Contributor

Which checks are you referring to? I am not a aware of any particular problems.

@unknowner-m
Copy link
Author

Which checks are you referring to? I am not a aware of any particular problems.

I am referring to the red crosses shown on the https://github.com/PAHFIT/pahfit/tree/dev page. Since I am a beginner, I don't know what this symbol means, but I guess it doesn't matter and the code works fine.

@drvdputt
Copy link
Contributor

drvdputt commented Mar 3, 2025

Thanks for bringing this up, it looks like one of the tests was not adapted to a recent format change of the Features table, and is therefore failing. Should be a quick fix in the testing code.

So this does not mean that anything is wrong, and since I am actively using the dev branch for my research (+ my changes committed on top of it), I assume it should also work for you.

@unknowner-m
Copy link
Author

Thanks for bringing this up, it looks like one of the tests was not adapted to a recent format change of the Features table, and is therefore failing. Should be a quick fix in the testing code.

So this does not mean that anything is wrong, and since I am actively using the dev branch for my research (+ my changes committed on top of it), I assume it should also work for you.

Thank you for your answer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants