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 unstack #67

Merged
merged 11 commits into from
Sep 9, 2022
Merged

Fix unstack #67

merged 11 commits into from
Sep 9, 2022

Conversation

juliettelavoie
Copy link
Contributor

@juliettelavoie juliettelavoie commented Sep 8, 2022

Pull Request Checklist:

  • pre-commit hooks are installed/active in my local clone ($ pre-commit install)
  • This PR addresses an already opened issue (for bug fixes / features)
    • This PR fixes #xyz
  • (If applicable) Documentation has been added / updated (for bug fixes / features)
  • If a merge request has been made in parallel to this PR in xscen-notebooks, it is merged and the submodules have been updated.
  • HISTORY.rst has been updated (with summary of main changes)
    • Link to issue (:issue:number) and pull request (:pull:number) has been added

What kind of change does this PR introduce?

  • xs.utils.stack_drop_nans/ xs.utils.unstack_fill_nan format the to_file/coords string to add the domain and the initial shape.
  • The initial shape is added to the lat and lon attrs to be able to retrive it when it is time to unstack.
  • Redifining lon and lat to fix bug in xarray (reset_index not resetting levels of MultiIndex pydata/xarray#6946)

Does this PR introduce a breaking change?

I don't think so. If you pass a string without {domain} or {shape} as before, the formatting will be ignored.

Other information:

@juliettelavoie juliettelavoie marked this pull request as draft September 8, 2022 18:00
@juliettelavoie juliettelavoie marked this pull request as ready for review September 9, 2022 18:16
Copy link
Collaborator

@aulemahal aulemahal left a comment

Choose a reason for hiding this comment

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

Ça me semble une bonne solution!
Petit questionnement sur la généricité (?) à conserver?

xscen/utils.py Outdated Show resolved Hide resolved
xscen/utils.py Outdated
@@ -106,13 +116,39 @@ def stack_drop_nans(
--------
unstack_fill_nan : The inverse operation.
"""

original_shape = f"{len(ds.lon)}x{len(ds.lat)}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Je sais pas à quel point c'était utile, mais l'ancienne version de cette fonction était indépendante des noms de dimensions. On utilise mask.dims.
Est-ce que ça serait à garder?
Si oui, je propose:

Suggested change
original_shape = f"{len(ds.lon)}x{len(ds.lat)}"
original_shape = "x".join(map(str, mask.shape))

et il faudrait rendre le reste du code générique aux dims de mask...

Et si non, il faudrait juste le dire dans la fonction qu'on s'attend à lat et lon.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah ben oui ça serait bien de garder cette flexibilité là. Je vais faire les changements.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The changes I have added will fail if one of the dimensions of ds_stack have an unrelated attrs also named original_shape, but that feels very unlikely...

juliettelavoie and others added 2 commits September 9, 2022 14:29
Co-authored-by: Pascal Bourgault <bourgault.pascal@ouranos.ca>
@juliettelavoie juliettelavoie merged commit 1c30d58 into main Sep 9, 2022
@juliettelavoie juliettelavoie deleted the fix-unstack branch September 9, 2022 19:17
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