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

Disabled FITS & UnitsWarnings by default for ESASky module #2550

Merged
merged 3 commits into from
Oct 5, 2022

Conversation

imbasimba
Copy link
Contributor

As suggested by @bsipocz here, some warnings are not useful to the users. Thus, the suggested warning as well as some extra warnings are now disabled by default, but can be enabled via the verbose parameter.

Also, some minor pep8 formatting.

@codecov
Copy link

codecov bot commented Oct 3, 2022

Codecov Report

Merging #2550 (3409715) into main (b0d9f5f) will decrease coverage by 0.01%.
The diff coverage is 19.23%.

@@            Coverage Diff             @@
##             main    #2550      +/-   ##
==========================================
- Coverage   63.99%   63.97%   -0.02%     
==========================================
  Files         132      132              
  Lines       16969    16984      +15     
==========================================
+ Hits        10859    10866       +7     
- Misses       6110     6118       +8     
Impacted Files Coverage Δ
astroquery/esasky/core.py 18.37% <19.23%> (-0.04%) ⬇️
astroquery/cadc/core.py 81.18% <0.00%> (+0.95%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

verbose=verbose,
if not verbose:
commons.suppress_vo_warnings()
warnings.filterwarnings("ignore", category=astropy.units.core.UnitsWarning)
Copy link
Member

Choose a reason for hiding this comment

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

This is modifying the warnings filter globally, it would be better to use the warnings.catch_warnings() context manager.

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 teaching me something new today! I've now added a context manger. Do you have any opinions regarding the suppression of specific warnings like done above or if it is more in line with the astroquery guidelines to use warnings.simplefilter("ignore") instead? @bsipocz

Copy link
Member

Choose a reason for hiding this comment

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

Recently I did this very specific ignore for windows, and don't have a better suggestion for this case either. Make the ignore module or small code part specific, and be as specific as possible to not overcatch and ignore warnings:

https://github.com/astropy/astroquery/blob/main/astroquery/sdss/core.py#L940

As for units related issues, other modules are casting them over for a fix (e.g. nasa_exoplanet_archive), but I think that's less applicable for the esasky case as here you may run into much more, and less predictable unit issues (for them it's about one set of units the remote services uses that they need to cast into valid astropy units, while here it's some non standard compliancy of the votables in the response).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright! Let's keep it as is then. It is unfeasable for ESASky to repair FITS file data, since ESASky is exposing data from so many missions.

@bsipocz bsipocz added the esasky label Oct 3, 2022
@bsipocz bsipocz added this to the v0.4.7 milestone Oct 3, 2022
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.

minor things only

if verbose:
return fits.open(path)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
Copy link
Member

Choose a reason for hiding this comment

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

hmm, we may overcatch with this one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe... Since ESASky exposes FITS files from so many missions, I feel that we still need a quite broad filter. I did some quick searches in astropy.io.fits and it seems that ignoring VerifyWarning might be better suited for this use case. That would let through AstropyDeprecationWarning, AstropyUserWarning, and potentially others.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, start with something small, and we can always add other specific ones. Otherwise, we indeed would miss the important and relevant ones, like deprecations, etc.

commons.suppress_vo_warnings()
warnings.filterwarnings("ignore", category=astropy.units.core.UnitsWarning)
job = self._tap.launch_job(query=query, output_file=output_file, output_format=output_format,
verbose=verbose, dump_to_file=output_file is not None)
Copy link
Member

Choose a reason for hiding this comment

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

Extreme nitpick, but you're already inside the conditional, I think it's fair to use verbose=False here? and verbose=True in the else.

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.

Thank you @imbasimba!

@bsipocz bsipocz merged commit f74e7c0 into astropy:main Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants