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

"high-level" function for extinguishing spectra? #52

Open
eteq opened this issue Jan 19, 2018 · 9 comments
Open

"high-level" function for extinguishing spectra? #52

eteq opened this issue Jan 19, 2018 · 9 comments

Comments

@eteq
Copy link

eteq commented Jan 19, 2018

If I look at http://dust-extinction.readthedocs.io/en/latest/dust_extinction/extinguish.html it is extremely useful for understanding how to use the various models (and hence should not be removed even if the "high-level" functions are added)... But it also seems like it has a certain amount of repetitive work required to handle wavelengths.

So what I would like to see is the following:

import specutils
import dust_extinction

spec = specutils.Spectrum1D.read(...wherever my spectrum file is...)
ext = CCM89(Rv=3.1)

extspec = ext.extinguish(spec, EBmV=0.5)

and have extspec be a Spectrum1D. It's debatable whether this should be the actual extinguish method - maybe an extinguish_spectrum would make more sense... but I think it's one of the most straightforward use cases I can see with real data.

Caveat: the specutils APE was just merged last month. I believe Spectrum1D is compatible enough already that you could do this now, but it might be one more specutils release is required before it's worth putting in the effort to make this method.

It may be there are some other areas where this sort of "high-level" function/method might be useful, too (particularly given the package-scope discussion f #47), but this is the immediately obvious case that I saw.

@pllim
Copy link
Contributor

pllim commented Jan 19, 2018

You are pushing that Spectrum1D everywhere (spacetelescope/synphot_refactor#43 (comment)). 😉 I am linking the issue here for my own future reference when synphot uses this package. 😄

@eteq
Copy link
Author

eteq commented Jan 19, 2018

Spectrum1D all the things! 🙊

@karllark
Copy link
Owner

I have not looked at Spectrum1D yet. I will.

One concern I have is it would be nice to have functions that work with data other than Spectrum1D objects. Is there advice for how to do this or would it require two functions, one that accepts x and y and one that accepts a Spectrum1D object?

The current extinction functions that are members of each extinction model are more generic that what is being proposed here. Could just make a wrapper function around those called extinguish_spectrum1D.
(Side note: is it possible to get the readthedocs to include member functions that are inherited in the API documentation? I have not figured out how to do this yet).

Should there be a corresponding unextinguish function? The IDL versions of the code were all about this (called unredding there).

@pllim
Copy link
Contributor

pllim commented Jan 22, 2018

is it possible to get the readthedocs to include member functions that are inherited in the API documentation?

You mean something like http://docs.astropy.org/en/stable/api/astropy.utils.misc.InheritDocstrings.html ?

@karllark
Copy link
Owner

@pllim : something like that. But I thought we were no longer supposed to use six?
And will this work for the extinguish member function that is only defined in the base class, not the specific model (e.g., CCM89)?

@karllark
Copy link
Owner

@pllim : I checked if the inheritdocstrings added in the extinguish function to the docs for the different dust model classes. It did not. In fact, it made the building of documentation unhappy in the generation of the plots.

WARNING: /home/kgordon/Python_git/dust_extinction/build/lib.linux-x86_64-3.5/dust_extinction/dust_extinction.py:docstring of dust_extinction.dust_extinction.CCM89:25: (WARNING/2) Exception occurred in plotting dust_extinction-dust_extinction-CCM89-1
from /home/kgordon/Python_git/dust_extinction/docs/api/dust_extinction.dust_extinction.CCM89.rst:
Traceback (most recent call last):
File "/home/kgordon/anaconda3/lib/python3.5/site-packages/matplotlib/sphinxext/plot_directive.py", line 520, in run_code
six.exec_(code, ns)
File "", line 15, in
File "/home/kgordon/anaconda3/lib/python3.5/site-packages/astropy/modeling/core.py", line 401, in call
('equivalencies', None)])
File "/home/kgordon/anaconda3/lib/python3.5/site-packages/astropy/modeling/core.py", line 382, in call
return super(cls, self).call(*inputs, **kwargs)
TypeError: super(type, obj): obj must be an instance or subtype of type

@pllim
Copy link
Contributor

pllim commented Jan 23, 2018

But I thought we were no longer supposed to use six?

That six call appears to be in matplotlib/sphinxext/plot_directive.py, which is upstream of astropy.

will this work for the extinguish member function that is only defined in the base class

Ah, probably not that use case. How about using inherited-members in autodoc (See http://www.sphinx-doc.org/en/stable/ext/autodoc.html)?

@karllark
Copy link
Owner

That does work. But now there are lots of member functions - all of those associated with these classes inheriting the astropy model functions. Need to think about this and maybe just put such documentation manually in the docstring from each extinction model.

@pllim
Copy link
Contributor

pllim commented Jan 23, 2018

In my own projects, I usually go the "lazy" route of just stating "see base class doc for more info". Granted that is not very convenient but it is easy!

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

No branches or pull requests

3 participants