-
Notifications
You must be signed in to change notification settings - Fork 9
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
Add SFD map code to the DESI utilities #116
Conversation
…ts (desitarget in two places, and desispec, too, ultimately)
…es consistent with imaging
…ently produce E(B-V) values
This looks outstanding. My only comment is that you consider renaming the |
There are some very significant problems with this PR. But there is clearly still some active development going on, so please let me know when things are stable so I can review. |
@weaverba137: Looks like the critical unit tests are now passing, so feel free to elucidate the very significant problems. |
The last change came in just as I was about to start a review. |
Go for it with the review. That's a completely cosmetic change (hence the [ci skip]). I was just improving coding style, but it's nothing significant. |
A GitHub review needs to be attached to a particular commit. If a new commit comes in while the review is going on, you have to refresh the files changed view and sometimes all your review comments can be lost. |
Noted. In future I won't make commits while reviews are pending, or I'll wait until I'm done with all commits before requesting a review. Hopefully that didn't happen in this case. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In summary, the code should be rewritten to match DESI standards before it can be accepted.
py/desiutil/dust.py
Outdated
@@ -0,0 +1,384 @@ | |||
# Copied on Nov/20/2016 from https://github.com/kbarbary/sfdmap/ commit: bacdbbd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Desiutil already has a license, and we need to ensure that all code is compatible with that license. Maybe we were sloppy about that when the code was in desitarget, but desiutil is typically held to a much higher standard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remain uncertain as to what to do about reusing code licensed in this manner. Now that you've brought this to my attention I certainly wouldn't merge this until we know the implications. I'm hoping @sbailey has some bright ideas.
py/desiutil/dust.py
Outdated
desiutil.dust | ||
============= | ||
|
||
Get E(B-V) values from the Schlegel, Finkbeiner & Davis (1998) dust map. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be helpful to add a link to the paper itself, or the abstract on ADS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
py/desiutil/dust.py
Outdated
except ImportError: | ||
raise ImportError("could not import fitsio or astropy.io.fits") | ||
|
||
__all__ = ['SFDMap', 'ebv'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No one in DESI should be doing from desiutil.dust import *
, so this line is not necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed this line.
py/desiutil/dust.py
Outdated
raise ImportError("could not import fitsio or astropy.io.fits") | ||
|
||
__all__ = ['SFDMap', 'ebv'] | ||
__version__ = "0.1.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Desiutil already has a version, desiutil.__version__
, so this really shouldn't be here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed the version.
py/desiutil/dust.py
Outdated
__version__ = "0.1.0" | ||
|
||
|
||
def _isiterable(obj): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There has to be a function in the Python standard library that does this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used np.atleast_1d() instead
py/desiutil/dust.py
Outdated
|
||
# Create rotation matrix about a given axis (x, y, z) | ||
|
||
def zrotmat(angle): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All functions need documentation strings, so they can be processed by Sphinx.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have gone through the code and added sphinx-compliant doc strings. So, this should be solved, If unit tests pass.
py/desiutil/dust.py
Outdated
|
||
|
||
# constant ICRS --> FK5J2000 (See USNO Circular 179, section 3.5) | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this computation being performed at the module-level? There is even a comment below that notes that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed all of this code and use astropy.coordinates.SkyCoord
objects instead.
py/desiutil/dust.py
Outdated
|
||
|
||
# ----------------------------------------------------------------------------- | ||
# bilinear interpolation (because scipy.ndimage.map_coordinates is really slow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assertion should be justified, and if it is no longer true, we should use numpy/scipy/astropy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't actually checked that (as I have a stable and working new version of the code and don't want to mess around with it much further), but I have removed that assertion. If you feel really strongly that we should use scipy
then I'll assess this in detail.
py/desiutil/test/test_dust.py
Outdated
from .. import dust | ||
|
||
|
||
class TestDust(unittest.TestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming that DUST_DIR
is defined, do the tests actually cover the entire module? In other words, if we accept the module into desiutil, the total test coverage of desiutil should at least not decrease.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a unit test and coverage is now ~94%.
py/desiutil/dust.py
Outdated
import numpy as np | ||
|
||
# require a FITS reader of some sort. | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a common construction that I have seen in DESI software. In fact, desiutil already requires astropy, so there is no reason to add an additional dependency on fitsio.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have explicitly imported astropy.io.fits
instead of this construction.
An additional note as part of the previous review: as currently configured, no tests of this module are performed on Travis, because Data files are required to test this module, and would need to be brought into the Travis environment. There are a few ways this could happen:
|
@weaverba137: Regarding your additional note...I chopped the dust maps down to the first 10 columns to reduce them in size to ~150K and use these chopped dust maps as the data for explicit unit tests. Your option (2), in other words. |
The code changes all look good to me know. But let's make sure tests pass, & get feedback on license before merging. |
I'm going to clean up my code style, so give me 10 minutes before anyone looks at this. |
OK, I'll double-check when you're done. |
I'm done, now. There are a handful of other recommended code style alterations, but it's for a case where I think it's easier to read as-is. |
I'm trying to build the sphinx documentation on my own system and the dust module is not showing up. Watch for additional commits to fix that. |
@weaverba137 @geordie666 Is this ready to be merged? If so, @geordie666 can you update |
@moustakas: We're waiting for guidance on what to do about reconciling the license for this code with the DESI BSD license from @sbailey. |
While this PR is still open, should we take the time to add one or more extinction curves? Kyle Barbary has a very nice package which wraps on Cython for speed -- This package is MIT licensed, as was his implementation of reading the SFD dust maps, so we'd have to resolve the same licensing question(s). In addition, these curves would naturally go into the same |
+1 for adding at least one extinction curve. Schlaflay 2016 is also an option (code here). I doubt this would be a bottleneck for our applications, so straight numpy (w/o cython) should be sufficient if we impement this ourselves. |
Let's not pull in another package just to read the SFD maps. That should quite literally be no more than 5 lines of code. Convert to Galactic coordinates, linearly interpolate the 4 nearest pixels from Extinction curves are a different question, and should be a different issue. One needs to de-extinction the standard stars during calibration, but I'd argue to keep the spectra in as-observed fluxes (no de-extinction), analogous to how photometric fluxes are reported. Please include Schlafly on that issue. |
I'm joining this PR comment stream late, so apologies if I miss the point on something:
|
Thanks @sbailey.
Yes, but that coverage is not reported to coveralls.io. Thus the coverage reported is lower than it should be, and there is not the immediate feedback of the Travis tests. |
PS, should we tag desiutil after this merge? |
Agreed that having tests included in Travis is better when possible without heroic efforts. I'll merge this now. Please go ahead and make a new tag and install at NERSC. I'll let @weaverba137 do that in order to pick the appropriate level of version number incrementing. |
1.9.12 is installed on cori and edison. |
This PR transfers the dust map code from
desitarget.mock.sfdmap
todesiutil
.The context for porting this across is that the dust maps are now used in several places in
desitarget
(not just the mocks) and will likely also be needed for future updates todesispec
. Some notes:SFD_DIR
toDUST_DIR
desitarget