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

Standardize units (extended) #284

Merged
merged 12 commits into from
May 10, 2024
Merged

Standardize units (extended) #284

merged 12 commits into from
May 10, 2024

Conversation

drvdputt
Copy link
Contributor

@drvdputt drvdputt commented May 9, 2024

This includes the exact same commits as #259 , but adds a few extra changes

  • Units for 'power' columns. Set to 'amplitude units' for now, i.e. units.intensity or MJy / sr. After the "power gaussian" and "power drude" have been implemented, we will switch this to units.intensity_power
  • error message that makes clear that only units compatible with MJy / sr are supported
  • conversion of the spectrum and wavelengths to internal units when the user input is parsed

Copy link
Contributor

@jdtsmith jdtsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall. Let's save the docstring stuff for another PR. I'd like to merge this one first, then can try for #283 and fix conflicts.

Comment on lines 82 to 83
The value and bounds as a 3 element tuple (value, min, max).
Any missing bound is replaced with the numpy `masked' value.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These doc changes seem out of bounds here. And this last one is not true. Any missing value is replaced.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I can rebase and drop the "docstring improvements" commit (35944ee)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use magit this is the perfect opportunity for branch spin-out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds interesting, but I love the interactive rebase interface of magit too ;). Rebased branch has been pushed.


Note that each parameter has an associated `kind', and that each
kind has an associated set of allowable parameters (see
`KIND_PARAMS`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing close )

Comment on lines 131 to 163
If reading a YAML file, read it in as a science pack and
return the new table. Otherwise, use astropy's normal Table
Parameters
----------

file : str
The name of the file to read, either a full valid path,
or named file in the PAHFIT science_packs directory.

Returns
-------
table : Features
A filled `~pahfit.features.Features` table.

Notes
-----
If reading a YAML file, reads it in as a science pack and
return the new table. Otherwise, uses astropy's normal Table
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's set aside all the docstring improvements to increase the chance that #283 and this one merge cleanly. Can do those in a subsequent PR.

Comment on lines +332 to +325
if kind == "_ratios":
continue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is my first foray into tied parameters. I suppose we can leave it in as harmless for now.

Comment on lines +294 to +295
The unit of the input spectrum has to be a multiple of MJy / sr,
the internal intensity unit. The output of this function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to allow flux units at some point. FYI, I haven't really looked much through Model, so don't get too wedded to any particular aspects.

pahfit/model.py Outdated
"""
if not spec.flux.unit.is_equivalent(units.intensity):
raise PAHFITModelError("PAHFIT only supports intensity units, i.e. convertible to MJy / sr.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now ;)

@jdtsmith jdtsmith mentioned this pull request May 9, 2024
@drvdputt
Copy link
Contributor Author

drvdputt commented May 9, 2024

I do realize now that a lot of our test spectra are loaded in Jy units... So all the test are failing there because of my new MJy / sr requirement. I will try to adjust the read_spectrum function so that it converts the example spectra.

@jdtsmith
Copy link
Contributor

jdtsmith commented May 9, 2024

I guess the issue of dual support for flux or intensity units is that you ought to be able to apply a model to any spectrum? And that the spectrum "arrives late" on use.

One idea is to have the units for power column be written on output from a fit. I.e. have the table adapt to the thing being fitted. So it can start with no power or tau units, then as fits occur, if the units differ, have them update. Or be strict: the user must decide when making a Model whether they want flux or intensity units. The column gets updated, and any cross-species uses results in an error. It's "frozen". One strange thing about the model is that naturally tau_star and tau_MBB are unitless, and they scale spectra components with real intensity units. I don't even remember what I did about that originally. We didn't use those for much.

@drvdputt
Copy link
Contributor Author

drvdputt commented May 9, 2024

I have pushed a temporary fix to read_spectrum() (in helpers.py). It assumes a solid angle of 9 square arcseconds to turn the flux_density spectra into intensity. This at least makes the tests work, and should be removed once dual unit support is achieved, so that the example data are more "true to life" again.

Once the power-based features are implemented, I will have a better grip on how to design this. Somehow, the power-based feature classes will need to be configurable for both units. The unit type can definitely be an option at the initialization of Model, just like other keywords e.g. to choose the fitter backend. These keywords can then be passed to configure Fitter in the right way, so that it can determine how to set up the power-based components (in practice, this will come down to setting a few scaling factors for the evaluation function).

@jdtsmith jdtsmith changed the base branch from master to dev May 10, 2024 03:02
@jdtsmith
Copy link
Contributor

Switched this to target dev; let me know when you feel it's ready.

@drvdputt
Copy link
Contributor Author

The tests work on my machine with astropy==6.0.1, but I found that astropy 6.1.0 causes an issue with using features_table.loc[feature_name]. I will fix this issue in one of the other pull requests, before we merge dev into master.

So I think we're good to go here.

@jdtsmith jdtsmith merged commit 6ec9596 into PAHFIT:dev May 10, 2024
4 of 15 checks passed
@jdtsmith
Copy link
Contributor

OK merged. We do need to get all our tox tests working at some point.

@drvdputt drvdputt deleted the units-standard branch June 25, 2024 17:37
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

Successfully merging this pull request may close these issues.

2 participants