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

adding the maps subdirectory to the dustdir variable #119

Merged
merged 7 commits into from Sep 6, 2018
Merged

Conversation

geordie666
Copy link
Contributor

This PR updates the default directory used by desiutil.dust to add the /maps subdirectory to the $DUST_DIR environment variable.

@geordie666
Copy link
Contributor Author

@moustakas: is this what you had in mind to fix #118? If so, ask @weaverba137 for a review prior to any merge.

Copy link
Member

@weaverba137 weaverba137 left a comment

Choose a reason for hiding this comment

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

I think we need to think more carefully about the case where DUST_DIR is not defined.

@@ -189,7 +190,8 @@ def __init__(self, mapdir=None, north="SFD_dust_4096_ngp.fits",
south="SFD_dust_4096_sgp.fits", scaling=1.):

if mapdir is None:
mapdir = os.environ.get('DUST_DIR', '')
dustdir = os.environ.get('DUST_DIR', '')
Copy link
Member

Choose a reason for hiding this comment

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

So if DUST_DIR is not set, dustdir = '', and mapdir = '/maps'. I think it would be better to raise an exception saying that the maps can't be found, rather than wait until a somewhat obscure error is raised when looking for fits files in a directory that doesn't exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the rapid feedback. I've added some better error handling.

@@ -189,7 +190,8 @@ def __init__(self, mapdir=None, north="SFD_dust_4096_ngp.fits",
south="SFD_dust_4096_sgp.fits", scaling=1.):

if mapdir is None:
mapdir = os.environ.get('DUST_DIR', '')
dustdir = os.environ.get('DUST_DIR', '')
mapdir = "{}/maps".format(dustdir)
Copy link
Member

Choose a reason for hiding this comment

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

Use mapdir = os.path.join(dustdir, 'maps').

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's a better choice. Done.

@geordie666
Copy link
Contributor Author

Oops, @weaverba137 I just found a minor typo. Please hold off any further review.

@geordie666
Copy link
Contributor Author

OK, @weaverba137, I'm done with my review response. Thanks.

Copy link
Member

@weaverba137 weaverba137 left a comment

Choose a reason for hiding this comment

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

I don't think you're raising the exception in the best possible way.

dustdir = os.environ.get('DUST_DIR')
if dustdir is None:
log.critical('Pass mapdir or set $DUST_DIR')
raise IOError
Copy link
Member

Choose a reason for hiding this comment

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

Typically when raising an exception, you pass a message to it. In this case, the same message as the log message will do.

Also IOError might not be ideal here because the exception hierarchy is different between 2 & 3. I recommend carefully reading https://docs.python.org/3/library/exceptions.html to see if that's what you really want. For example, ValueError might be just as appropriate.

Please also make sure that the unit tests actually test the case where an invalid value is passed during initialization.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I now raise a ValueError with a message, and I've added a unit test to check that ValueErrors are thrown appropriately when DUST_DIR doesn't exist or when a meaningless map directory is passed.

@weaverba137
Copy link
Member

Looks good. Merge when tests are done. I will tag after the merge.

@weaverba137
Copy link
Member

desiutil/1.9.13 is installed on cori and edison.

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.

None yet

2 participants