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

create to_labeled_stacked_array helper function #15

Open
OriolAbril opened this issue Sep 24, 2024 · 0 comments · May be fixed by #25
Open

create to_labeled_stacked_array helper function #15

OriolAbril opened this issue Sep 24, 2024 · 0 comments · May be fixed by #25

Comments

@OriolAbril
Copy link
Member

xarray has a to_stacked_array method, which is very handy. However, given the extra conventions and features in ArviZ, we could have an improved version of that, something like:

idata = az.load_arviz_data("centered_eight")

labeled_stack = idata.posterior.to_stacked_array("label", sample_dims=("chain", "draw"), name="posterior")
labels = [az.labels.BaseLabeller().make_label_flat(var_name, sel, isel) for var_name, sel, isel in az.sel_utils.xarray_sel_iter(idata.posterior, skip_dims={"chain", "draw"})]
labeled_stack = labeled_stack.reset_index("label").assign_coords(label=labels).set_xindex("variable").set_xindex("school")

were instead of a multiindex we use explicit indexes, use the labeller, and automatically set the name to the group name if available.

I think the function should have some similarities to extract with respect to the signature (i.e. accept idata or dataset, probably filtering vars too) but be an independent function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

1 participant