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

tweak/enhance auto data install #50

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

mperrin
Copy link
Collaborator

@mperrin mperrin commented Dec 18, 2024

Some enhancements building on the very nice data installation function added in spacetelescope/webbpsf#932 by @WilliamJamieson :

  • If the data was already installed into the default data path by some prior call to auto_download_stpsf_data, then there's no need to emit any warning, just use that automatically installed data.
  • Add a back compatibility function get_webbpsf_data_dir which is a deprecated equivalent for get_stpsf_data_dir. This is simply to allow any existing webbpsf user code that calls webbpsf.utils.get_webbpsf_data_dir() to continue to work without error. The deprecation is marked using the recently-added standard library @deprecated decorator, or the back ported equivalent depending on Python version.
  • Update the installation docs to include the information about the automatic data install, and no longer say that it's required to manually install the data.

@mperrin
Copy link
Collaborator Author

mperrin commented Dec 18, 2024

hmm, a side issue in this: I was hoping to use the recently-added standard library @deprecated decorator, but that's not yet in all the versions of Python we support. And the back port of that decorator in library typing_extensions isn't installed by default either. We could add that to the requirements but that feels like overkill.

Mostly I would like to avoid unnecessary effort writing our own deprecation warning machinery -- this very much feels like something we should be able to get from upstream somewhere.

Let me think about an alternative way to do that...

@mperrin
Copy link
Collaborator Author

mperrin commented Dec 18, 2024

OK, I think it will work to, in webbpsf.__init__.py, after doing the sys.modules magic, then we can do

webbpsf.utils.get_webbpsf_data_path = stpsf.utils.get_stpsf_data_path

and I think that works, based on some testing here. And, no particular deprecation warning is needed in this case, because it'll be covered under the overall deprecation warning at the top of webbpsf.

@mperrin mperrin mentioned this pull request Dec 18, 2024
3 tasks
@BradleySappington
Copy link
Collaborator

OK, I think it will work to, in webbpsf.__init__.py, after doing the sys.modules magic, then we can do

webbpsf.utils.get_webbpsf_data_path = stpsf.utils.get_stpsf_data_path

and I think that works, based on some testing here. And, no particular deprecation warning is needed in this case, because it'll be covered under the overall deprecation warning at the top of webbpsf.

get_webbpsf_data_path will not actually be used once webbpsf2.0.0 is released. Webbpsf will directly call get_stpsf_data_path.

Copy link
Collaborator

@BradleySappington BradleySappington left a comment

Choose a reason for hiding this comment

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

installation.rst changes are great
Please undo the utils.py changes for reasons in the comment


Files containing such information as the JWST pupil shape, instrument throughputs, and aperture positions are distributed separately from STPSF. To run STPSF, you must download these files and tell STPSF where to find them using the ``STPSF_PATH`` environment variable.
STPSF will now **automatically download and install these files** the first time it is run. By default these will be downloaded and installed into a folder ``$HOME/data/stpsf-data`` within the user's home directory. This directory will be created automatically if it doesn't exist already. If this path is acceptable to you, then no further action is needed on your part, and it'll all work automatically.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good addition! Thanks for cleaning up the docs!

path = auto_download_stpsf_data()

# Check if the data were already downloaded to the default path
default_path = get_default_data_path()
Copy link
Collaborator

Choose a reason for hiding this comment

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

This change isn't necessary as this logic already exists within auto_download_stpsf_data (which also sets the STPSF_PATH which is necessary)

auto_download_stpsf_data() will make a new default directory (only if one doesn't exist), and download the data (only if the directory is empty).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My point here was intentionally refactoring to allow checking for a prior successful call to auto_download_stpsf_data, prior to displaying the big giant warning message about trying to download the data. If the data has already been downloaded successfully, it’s incorrect to display a warning that says “stpsf will try to download the data”.

The current code will display the warning text every time the package is imported in a new Python session, even if the data is already indeed present and fine in the default directory. That’s excess warnings for no benefit to the user.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see your concern (deleted my previous reply because I misunderstood what download message you were referring to)

I think its important that the Environment variable $STPSF_PATH is not set! warning is still displayed.

May just make more sense to move the MISSING_STPSF_DATA_MESSAGE inside auto_download_stpsf_data inside the if not any(default_path.iterdir()): codeblock.

@mperrin
Copy link
Collaborator Author

mperrin commented Dec 19, 2024

get_webbpsf_data_path will not actually be used once webbpsf2.0.0 is released. Webbpsf will directly call get_stpsf_data_path.

My point is about existing user code that calls that function directly. That function is currently part of the public API of webbpsf, and I know for a fact there are existing notebooks and downstream scripts that call it directly. Not a lot but nonzero. I completely agree that all the internal code you updated to call get_stpsf_data_path. But again I’m trying to make sure we don’t break some existing notebooks or script that calls get_webbpsf_data_path directly.

@BradleySappington
Copy link
Collaborator

BradleySappington commented Dec 19, 2024

get_webbpsf_data_path will not actually be used once webbpsf2.0.0 is released. Webbpsf will directly call get_stpsf_data_path.

My point is about existing user code that calls that function directly. That function is currently part of the public API of webbpsf, and I know for a fact there are existing notebooks and downstream scripts that call it directly. Not a lot but nonzero. I completely agree that all the internal code you updated to call get_stpsf_data_path. But again I’m trying to make sure we don’t break some existing notebooks or script that calls get_webbpsf_data_path directly.

AH! Yes thats a good call. Overlooked that we should verify there are no other public API calls that specifically have "webbpsf" as part of the naming convention.

(just confirmed that its only auto_download_webbpsf_data and get_webbpsf_data_path)

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