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

Deal with warnings #361

Merged
merged 4 commits into from
Dec 9, 2024
Merged

Deal with warnings #361

merged 4 commits into from
Dec 9, 2024

Conversation

troyraen
Copy link
Contributor

@troyraen troyraen commented Dec 5, 2024

Clean up warnings in the spectra_generator notebook:

  • MAST: NoResultsWarning -- Suppress these since we don't expect all-sky coverage and we explicitly handle the no-results cases.
  • Keck and SDSS: RuntimeWarning: divide by zero -- These occur in error calculations when the inverse variance is zero, resulting in infinite error. Leave this bad data in and ignore the warning.

@troyraen troyraen added the use case: spectroscopy Spectroscopy use case label Dec 5, 2024
@troyraen
Copy link
Contributor Author

troyraen commented Dec 5, 2024

So far I've just added comments (including the full warning message) in the code where they're raised. I'd like feedback on how to deal with them.

  • NoResultsWarning: My sense is that the MAST queries are just being extra noisy we can safely suppress these, but I'm not sure.
  • RuntimeWarning: divide by zero: Seems like we need to fix these. But as I recall, we ran into these with the light curves notebook and no one was concerned about it. So again, not sure.

@bsipocz and @jkrick what are your thoughts?

@@ -336,6 +340,9 @@ def HST_get_spec(sample_table, search_radius_arcsec, datadir, verbose,
continue

# Download
# Observations.download_products prints an info message for every download, like:
Copy link
Member

Choose a reason for hiding this comment

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

There should be a kwarg in astroquery.mast to shut these up, if it's missing then please open an issue and we'll get it fixed.

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 don't see a kwarg, so I'll open an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, there's a kwarg verbose=False that will do this, but we need the latest "dev" version of astroquery (0.4.8.dev9474) to get it. Fornax has 0.4.7 which is the latest version available through pip unless you add the --pre flag. @bsipocz have we figured out how to handle these "dev" dependencies in requirements.txt files?
I see astroquery>=0.4.8.dev0 in the light_curves requirements. Do I remember correctly that if there is any dev version already installed (like on the ISP) it won't be upgraded, but that's still the best option because something like astroquery>=0.4.8.dev9474 won't work? A slightly older version (0.4.8.dev9306) throws an error, so we'd need more than "dev0" to ensure a working version.

Copy link
Member

Choose a reason for hiding this comment

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

I plan to do a release before the end of the year, so for now update your install manually.
And in the new year astroquery will get a new packaging overhaul and a better system for frequent releases, so no workaround will be needed

spectroscopy/code_src/mast_functions.py Outdated Show resolved Hide resolved
Base automatically changed from raen/cleanup/spectra_generator to main December 5, 2024 19:39
@jkrick
Copy link
Contributor

jkrick commented Dec 5, 2024

I'll defer to you both @bsipocz and @troyraen as to which things are important enough to fix and which things aren't really broken. I know Brigitta doesn't want to teach us to ignore warnings, and while my codes may not do it explicitly, my brain certainly does ignore warnings in terms of skimming over them when looking for output.

@bsipocz
Copy link
Member

bsipocz commented Dec 5, 2024

my brain certainly does ignore warnings in terms of skimming over them when looking for output.

and thus we should reduce the noise in tutorial notebooks, and only expose the ones that a user should do something about, as sometimes they contain useful info :) (this is so much easier to say than to do though, I heavily rely on CI turning warning to exceptions at a lot of places, but that works much better in libraries than with notebooks)

@troyraen
Copy link
Contributor Author

troyraen commented Dec 6, 2024

The 'divide by zero' warnings are occurring in error calculations when the inverse variance is zero, so the error is infinite. I think we decided in the light curves notebook to leave bad data in. The plotting function in this notebook masks these bad data points, so there's no problem leaving them in from a coding standpoint. So I've used the np.errstate context manager to ignore the warnings.

@troyraen troyraen marked this pull request as ready for review December 6, 2024 08:32
@troyraen troyraen requested a review from bsipocz December 6, 2024 08:32
@troyraen
Copy link
Contributor Author

troyraen commented Dec 8, 2024

@bsipocz I think this is ready to merge.

Copy link
Member

@bsipocz bsipocz left a comment

Choose a reason for hiding this comment

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

Look good to me, thank you for doing this cleanup!

Comment on lines +67 to +70
# Inverse variances may be zero, resulting in infinite error.
# We'll leave these in and ignore the "divide by zero" warning.
with np.errstate(divide='ignore'):
error_cgs = np.sqrt(1 / spec["IVAR"][0]) * flux_cgs.unit
Copy link
Member

Choose a reason for hiding this comment

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

This maybe a good example for a docs of good practices, e.g. deal with expected Warnings that are due to the nature of the functionality (e.g. either this or the occasional no result warning coming from astroquery when we loop through a list of coordinates where we expect to have no matches!); and any warnings the end user should/can do nothing about.

@bsipocz bsipocz merged commit 53f71e2 into main Dec 9, 2024
3 checks passed
@bsipocz bsipocz deleted the raen/warnings/spectra_generator branch December 9, 2024 19:25
github-actions bot pushed a commit that referenced this pull request Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
use case: spectroscopy Spectroscopy use case
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants