Skip to content

Examples require usage of pickled objects #4

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

Closed
Jashcraf opened this issue Mar 24, 2025 · 3 comments
Closed

Examples require usage of pickled objects #4

Jashcraf opened this issue Mar 24, 2025 · 3 comments

Comments

@Jashcraf
Copy link

This issue is part of my JOSS review: openjournals/joss-reviews#7917

Hello, thanks for having me as a reviewer - super cool to see an optical propagation library tailored to modeling starshades!

I was running the examples to verify functionality, and encountered the following in visualize_throughput.py

PyStarshade % python examples/visualize_throughput.py
Traceback (most recent call last):
  File "/Users/kaladin/joss_reviews/PyStarshade/examples/visualize_throughput.py", line 22, in <module>
    data = np.load(file_path_on)
  File "/opt/anaconda3/envs/joss/lib/python3.10/site-packages/numpy/lib/_npyio_impl.py", line 486, in load
    raise ValueError(
ValueError: This file contains pickled (object) data. If you trust the file you can load it unsafely using the `allow_pickle=` keyword argument or `pickle.load()`.

Unless I'm mistaken, it looks like the HWO pupil models are written as binaries using the .npz extension, and that's what is being "un-pickled" here. The error above to prevent users from executing pickled data is because pickling is unsafe.

I would suggest switching the data required to use PyStarshade to another format so that users don't need to worry about pickles (what a funny world we live in). I don't have a particular preference on what PyStarshade uses, but here are some options:

@xiaziyna
Copy link
Owner

Hi Jaren! Thanks for agreeing to review PyStarshade :)

From what I can tell, if an .npz file only contains Numpy arrays, they do not get pickled. If saving dicts or objects, they get pickled.

I have checked all files in PyStarshade (as well as those in this example) load with the 'allow_pickle = False' setting in np.load, and also made sure they only contain numpy arrays. I have also tried a fresh install.

Can you tell me any other info around this error (did you create a new pupil file/did you git clone and use LFS to download the files)?
Thanks - I'm sorry about this!

@Jashcraf
Copy link
Author

Jashcraf commented Apr 7, 2025

Sorry for dropping off of this - had a bit of a work sprint at an observatory and I dropped every other ball I was "juggling"

Ah I think my error was not installing the files via LFS - so np.load() was looking for a file that didn't exist and threw the pickle error. I'm currently downloading the files now and will re-run the examples to verify functionality. Will close issue once I've run all the examples.

@Jashcraf
Copy link
Author

Jashcraf commented Apr 7, 2025

No longer getting the pickle issue! Closing

@Jashcraf Jashcraf closed this as completed Apr 7, 2025
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

No branches or pull requests

2 participants