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

refactor xb.get_keepbits with xarray #100

Merged
merged 37 commits into from May 11, 2022
Merged

refactor xb.get_keepbits with xarray #100

merged 37 commits into from May 11, 2022

Conversation

aaronspring
Copy link
Collaborator

@aaronspring aaronspring commented May 9, 2022

I thought this PR would be more readable and faster because of more xarray operations and less looping, but I was so wrong on speed and also readability didnt improve that much:

ds = xr.tutorial.load_dataset("air_temperature")
info_per_bit = xb.get_bitinformation(ds, dim="lon", masked_value=None)

image

The only thing it does is saving us a few lines of code... @observingClouds do you think it is useful. I'm ready to close this PR without merge also.

New:

  • get_keepbits now works on multi-dim inputs
  • tests - how could we forget them before???

@aaronspring aaronspring self-assigned this May 9, 2022
@aaronspring aaronspring requested review from observingClouds and removed request for observingClouds May 10, 2022 08:20
@aaronspring aaronspring marked this pull request as ready for review May 10, 2022 15:18
@observingClouds
Copy link
Owner

I currently get an error when trying

import xbitinfo as xb
import xarray as xr
ds = xr.tutorial.load_dataset("eraint_uvz")
info_per_bit = xb.get_bitinformation(ds, dim="longitude")
keepbits = xb.get_keepbits(info_per_bit, [0.999, 1.])

Seems like inflevel=1 is only allowed for single entries in this implementation.

@observingClouds
Copy link
Owner

I think refactoring this function would be great. I probably would prefer to split this function into smaller functions to have a better overview.

Copy link
Owner

@observingClouds observingClouds left a comment

Choose a reason for hiding this comment

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

This looks great now! Thanks for also adding the tests! LGTM.

@aaronspring aaronspring merged commit b616753 into main May 11, 2022
@aaronspring aaronspring deleted the get_keepbits_xarray branch May 11, 2022 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants