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

🩹 Fix deprecation warning for using xr.Dataset.dim #267

Merged
merged 1 commit into from
Jun 22, 2024

Conversation

s-weigand
Copy link
Member

@s-weigand s-weigand commented Jun 7, 2024

This change fixes the deprecation warning:

FutureWarning: The return type of `Dataset.dims` will be changed to return a set of dimension names in future, in order to be more consistent with `DataArray.dims`. To access a mapping from dimension names to lengths, please use `Dataset.sizes`.
  center_λ = min(res.dims["spectral"], round(res.dims["spectral"] / 2))

When center_λ has its default value of None.

However, when fixing this I found that we have a bug.
First of all:

min(res.sizes["spectral"], round(res.sizes["spectral"] / 2))

will always return round(res.sizes["spectral"] / 2) since res.sizes["spectral"] is the length of the spectral coordinate (same goes for the current and past behavior of res.dims["spectral"])

But since this value is later used with xr.DataArray.sel it leads to a wrong behavior since now center_λ isn't a spectral value but the index of it, resulting in the first wavelength being selected.

Example plot for the 4TT case study

Current behavior with omitted center_λ

image

Current behavior with set center_λ

image

So I think we should change the fallback to:

center_λ = res.coords["spectral"].mean().item()

or

center_λ = res.coords["spectral"].isel(spectral=res.sizes["spectral"]//2).item()

to take none equidistant spectral axes into account.

Change summary

Checklist

  • ✔️ Passing the tests (mandatory for all PR's)

@s-weigand s-weigand requested a review from a team as a code owner June 7, 2024 14:30
Copy link
Contributor

github-actions bot commented Jun 7, 2024

Binder 👈 Launch a binder notebook on branch s-weigand/pyglotaran-extras/fix-deprecations

Copy link
Contributor

sourcery-ai bot commented Jun 7, 2024

🧙 Sourcery is reviewing your pull request!


Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

We've reviewed this pull request using the Sourcery rules engine. If you would also like our AI-powered code review then let us know.

@jsnel
Copy link
Member

jsnel commented Jun 7, 2024

Historically we've always selected the first wavelength if not explicitly provided.

Copy link

codecov bot commented Jun 8, 2024

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 44.77%. Comparing base (b880df9) to head (751a859).
Report is 20 commits behind head on main.

Files with missing lines Patch % Lines
pyglotaran_extras/plotting/plot_overview.py 0.00% 1 Missing ⚠️
pyglotaran_extras/plotting/utils.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #267   +/-   ##
=======================================
  Coverage   44.77%   44.77%           
=======================================
  Files          27       27           
  Lines        1043     1043           
  Branches      162      162           
=======================================
  Hits          467      467           
  Misses        568      568           
  Partials        8        8           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@jsnel jsnel left a comment

Choose a reason for hiding this comment

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

We need to get rid of those spammy deprecations warnings.

Later we'll figure out other improvements.

@jsnel jsnel merged commit c53418c into glotaran:main Jun 22, 2024
30 checks passed
@s-weigand s-weigand deleted the fix-deprecations branch June 24, 2024 15:36
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