id,node_id,number,title,user,state,locked,assignee,milestone,comments,created_at,updated_at,closed_at,author_association,active_lock_reason,draft,pull_request,body,reactions,performed_via_github_app,state_reason,repo,type 552500673,MDU6SXNzdWU1NTI1MDA2NzM=,3709,Feature Proposal: `xarray.interactive` module,35968931,closed,0,,,36,2020-01-20T20:42:22Z,2023-10-27T18:24:49Z,2021-07-29T15:37:21Z,MEMBER,,,,"## Feature proposal: `xarray.interactive` module I've been experimenting with [ipython widgets](https://github.com/jupyter-widgets/ipywidgets) in jupyter notebooks, and I've been [working on](https://github.com/TomNicholas/xarray-interactive) how we might use them to make xarray more interactive. ### Motivation: For most users who are exploring their data, it will be common to find themselves rerunning the same cells repeatedly but with slightly different values. In `xarray`'s case that will often be in an `.isel()` or `.sel()` call, or selecting variables from a dataset. IPython widgets allow you to interact with your functions in a very intuitive way, which we could exploit. There are lots of tutorials on how to interact with `pandas` data (e.g. [this great one](https://towardsdatascience.com/interactive-controls-for-jupyter-notebooks-f5c94829aee6)), but I haven't seen any for interacting with `xarray` objects. ### Relationship to other libraries: Some downstream plotting libaries (such as @hvplot) [already use widgets](https://hvplot.holoviz.org/user_guide/Gridded_Data.html) when interactively plotting xarray-derived data structures, but they don't seem to go the full N dimensions. This also isn't something that should be confined to plotting functions - you often choose slices or variables at the start of analysis, not just at the end. I'll come back to this idea later. The default ipython widgets are pretty good, but we could write an `xarray.interactive` module in such a way that downstream developers can easily replace them with [their own widgets](https://hvplot.holoviz.org/user_guide/Widgets.html). ### Usage examples: ```python # imports import ipywidgets as widgets import xarray.plot as xplot import xarray.interactive as interactive # Load tutorial data ds = xr.tutorial.open_dataset('air_temperature')['air'] ``` Plotting against multiple dimensions interactively ```python interactive.isel(da, xplot.plot, lat=10, lon=50) ``` ![isel_lat_and_lon](https://user-images.githubusercontent.com/35968931/72755645-e632bb00-3bc2-11ea-8056-eb448e957bb0.gif) Interactively select a range from a dimension ```python def plot_mean_over_time(da): da.mean(dim=time) interactive.isel(da, plot_mean_over_time, time=slice(100, 500)) ``` ![mean_over_time_slice](https://user-images.githubusercontent.com/35968931/72755638-e337ca80-3bc2-11ea-9d66-efb8dd0d4fca.gif) Animate over one dimension ```python from ipywidgets import Play interactive.isel(da, xplot.plot, time=Play()) ``` ![Play](https://user-images.githubusercontent.com/35968931/72755630-de731680-3bc2-11ea-9d0f-46da96d6efda.gif) ### API ideas: We can write a function like this ```python interactive.isel(da, func=xplot.plot, time=10) ``` which could also be used as a decorator something like this ```python @interactive.isel(da, time=10) def plot(da) return xplot.plot(da) ``` It would be nicer to be able to do this ```python @Interactive(da).isel(time=10) def plot(da) return xplot.plot(da) ``` but [Guido forbade it](https://seriously.dontusethiscode.com/2013/04/21/lambda-decorators.html). But we can attach these functions to an accessor to get ```python da.interactive.isel(xplot.plot, time=10) ``` ### Other ideas Select variables from datasets ```python @interactive.data_vars(da1=ds['n'], da2=ds['T'], ...) def correlation(da1, da2, ...) ... # Would produce a dropdown list of variables for each dataset ``` Choose dimensions to apply functions over ```python @interactive.dims(dim='time') def mean(da, dim) ... # Would produce a dropdown list of dimensions in the dataarray ``` General `interactive.explore()` method to see variation over any number of dimensions, the default being all of them. What do people think about this? Is it something that makes sense to include within xarray itself? (Dependencies aren't a problem because it's fine to have `ipywidgets` as an optional dependency just for this module.)","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/3709/reactions"", ""total_count"": 6, ""+1"": 3, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 3, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue