Skip to content
New issue

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

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

Already on GitHub? # to your account

add option for download_data to use the astropy cache #211

Merged
merged 2 commits into from
Feb 19, 2020

Conversation

eteq
Copy link
Contributor

@eteq eteq commented Aug 16, 2019

This PR closes #208 by making it possible to use the astropy download cache.

One caveat: There are no unit tests. I started trying to make one but then realized it's not clear to me that we can really test this properly without accidentally messing with the users' "true" cache. The related tests in astropy test the cache machinery by downloading a "fake" file and then clearing just that file, but here we can't do it because we actually want the correct file. So that's awkward. I can concoct some sort of complicated scheme like what we used to have in astropy where we fake the cache location, run the test, and then un-fake it, but that seems like it might be overkill for this. @pllim do you agree and/or have a simpler idea for how I might test this? Or alternatively I can add a quick test that would have the side-effect of potentially deleting the user's actual copy of the data (which is normally considered bad behavior for a test...)

(Note I did test it in the sense of actually running it myself... )

EDIT: Also fix #188

@eteq eteq requested a review from pllim August 16, 2019 21:27
@pllim

This comment has been minimized.

Copy link
Contributor

@pllim pllim left a comment

Choose a reason for hiding this comment

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

Thank you! Overall, the logic seems fine.

However, the caching mechanism only works if user opts out of using the synphot.cfg altogether? I don't see how something like this will work:

  • Vega -- Download and cache
  • Extinction files -- Download and save to somewhere

Also, the cache location is not easy to find, so how do you envision the situation where synphot user wants to invalidate the cache (force a re-download) for whatever reason?

Would you have time to add user-facing doc for this PR as well?

synphot/utils.py Outdated Show resolved Hide resolved
@pllim

This comment has been minimized.

@pllim pllim added this to the 0.3 milestone Nov 19, 2019
add clarifying note about cfg

Add changelog entry
@pllim
Copy link
Contributor

pllim commented Feb 19, 2020

I'll push follow-up commits and wrap this up. I think testing is possible if we stick to dry run mode and maybe some Mock (not sure but will try).

@pllim pllim self-assigned this Feb 19, 2020
synphot/utils.py Outdated
@@ -252,14 +252,20 @@ def merge_wavelengths(waveset1, waveset2, threshold=1e-12):
return out_wavelengths


def download_data(cdbs_root, verbose=True, dry_run=False):
"""Download CDBS data files to given root directory.
def download_data(path_root=None, verbose=True, dry_run=False):
Copy link
Contributor

Choose a reason for hiding this comment

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

I am reverting the code to make path_root optional. It changes the default behavior and might confuse users.

@pllim
Copy link
Contributor

pllim commented Feb 19, 2020

I cannot find an easy way for "cache only" option to work with synphot.cfg, so I updated to the doc to tell user to make a choice.


# See https://github.com/astropy/astropy/issues/8524
for cfgitem in conf.__class__.__dict__.values():
if (not isinstance(cfgitem, ConfigItem) or
not cfgitem.name.endswith('file')):
continue

url = cfgitem()
url = cfgitem.defaultvalue
Copy link
Contributor

Choose a reason for hiding this comment

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

This line fixes #188 but also changes the behavior reflected in the diff for test_download_data. I think the behavior change is a small price to pay for this fix.

Copy link
Contributor

@pllim pllim left a comment

Choose a reason for hiding this comment

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

LGTM now. Thanks, @eteq !

@pllim pllim merged commit 4576548 into spacetelescope:master Feb 19, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
2 participants