{"database": "github", "table": "issues", "is_view": false, "human_description_en": "where \"closed_at\" is on date 2021-07-29, state_reason = \"completed\" and user = 35968931 sorted by updated_at descending", "rows": [[552500673, "MDU6SXNzdWU1NTI1MDA2NzM=", 3709, "Feature Proposal: `xarray.interactive` module", 35968931, "closed", 0, null, null, 36, "2020-01-20T20:42:22Z", "2023-10-27T18:24:49Z", "2021-07-29T15:37:21Z", "MEMBER", null, null, null, "## Feature proposal: `xarray.interactive` module\r\n\r\nI'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.\r\n\r\n### Motivation:\r\n\r\nFor most users who are exploring their data, it will be common to find themselves rerunning the same cells repeatedly but with slightly different values.\r\nIn `xarray`'s case that will often be in an `.isel()` or `.sel()` call, or selecting variables from a dataset.\r\nIPython widgets allow you to interact with your functions in a very intuitive way, which we could exploit.\r\nThere 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.\r\n\r\n\r\n### Relationship to other libraries:\r\n\r\nSome 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.\r\nThis 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.\r\nI'll come back to this idea later.\r\n\r\nThe 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).\r\n\r\n### Usage examples:\r\n\r\n```python\r\n# imports\r\nimport ipywidgets as widgets\r\nimport xarray.plot as xplot\r\nimport xarray.interactive as interactive\r\n\r\n# Load tutorial data\r\nds = xr.tutorial.open_dataset('air_temperature')['air']\r\n```\r\n\r\nPlotting against multiple dimensions interactively\r\n```python\r\ninteractive.isel(da, xplot.plot, lat=10, lon=50)\r\n```\r\n![isel_lat_and_lon](https://user-images.githubusercontent.com/35968931/72755645-e632bb00-3bc2-11ea-8056-eb448e957bb0.gif)\r\n\r\n\r\nInteractively select a range from a dimension\r\n```python\r\ndef plot_mean_over_time(da):\r\n    da.mean(dim=time)\r\ninteractive.isel(da, plot_mean_over_time, time=slice(100, 500))\r\n```\r\n![mean_over_time_slice](https://user-images.githubusercontent.com/35968931/72755638-e337ca80-3bc2-11ea-9d66-efb8dd0d4fca.gif)\r\n\r\n\r\nAnimate over one dimension\r\n```python\r\nfrom ipywidgets import Play\r\ninteractive.isel(da, xplot.plot, time=Play())\r\n```\r\n![Play](https://user-images.githubusercontent.com/35968931/72755630-de731680-3bc2-11ea-9d0f-46da96d6efda.gif)\r\n\r\n### API ideas:\r\n\r\nWe can write a function like this\r\n\r\n```python\r\ninteractive.isel(da, func=xplot.plot, time=10)\r\n```\r\n\r\nwhich could also be used as a decorator something like this\r\n```python\r\n@interactive.isel(da, time=10)\r\ndef plot(da)\r\n    return xplot.plot(da)\r\n```\r\n\r\nIt would be nicer to be able to do this\r\n```python\r\n@Interactive(da).isel(time=10)\r\ndef plot(da)\r\n    return xplot.plot(da)\r\n```\r\nbut [Guido forbade it](https://seriously.dontusethiscode.com/2013/04/21/lambda-decorators.html).\r\n\r\nBut we can attach these functions to an accessor to get\r\n```python\r\nda.interactive.isel(xplot.plot, time=10)\r\n```\r\n\r\n### Other ideas\r\n\r\nSelect variables from datasets\r\n```python\r\n@interactive.data_vars(da1=ds['n'], da2=ds['T'], ...)\r\ndef correlation(da1, da2, ...)\r\n    ...\r\n\r\n# Would produce a dropdown list of variables for each dataset\r\n```\r\n\r\nChoose dimensions to apply functions over\r\n```python\r\n@interactive.dims(dim='time')\r\ndef mean(da, dim)\r\n    ...\r\n    \r\n# Would produce a dropdown list of dimensions in the dataarray\r\n```\r\n\r\nGeneral `interactive.explore()` method to see variation over any number of dimensions, the default being all of them.\r\n\r\nWhat 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}", null, "completed", 13221727, "issue"]], "truncated": false, "filtered_table_rows_count": 1, "expanded_columns": [], "expandable_columns": [[{"column": "repo", "other_table": "repos", "other_column": "id"}, "name"], [{"column": "milestone", "other_table": "milestones", "other_column": "id"}, "title"], [{"column": "assignee", "other_table": "users", "other_column": "id"}, "login"], [{"column": "user", "other_table": "users", "other_column": "id"}, "login"]], "columns": ["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"], "primary_keys": ["id"], "units": {}, "query": {"sql": "select 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 from issues where date(\"closed_at\") = :p0 and \"state_reason\" = :p1 and \"user\" = :p2 order by updated_at desc limit 101", "params": {"p0": "2021-07-29", "p1": "completed", "p2": "35968931"}}, "facet_results": {"state": {"name": "state", "type": "column", "hideable": false, "toggle_url": "/github/issues.json?closed_at__date=2021-07-29&state_reason=completed&user=35968931", "results": [{"value": "closed", "label": "closed", "count": 1, "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?closed_at__date=2021-07-29&state_reason=completed&user=35968931&state=closed", "selected": false}], "truncated": false}, "repo": {"name": "repo", "type": "column", "hideable": false, "toggle_url": "/github/issues.json?closed_at__date=2021-07-29&state_reason=completed&user=35968931", "results": [{"value": 13221727, "label": "xarray", "count": 1, "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?closed_at__date=2021-07-29&state_reason=completed&user=35968931&repo=13221727", "selected": false}], "truncated": false}, "type": {"name": "type", "type": "column", "hideable": false, "toggle_url": "/github/issues.json?closed_at__date=2021-07-29&state_reason=completed&user=35968931", "results": [{"value": "issue", "label": "issue", "count": 1, "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?closed_at__date=2021-07-29&state_reason=completed&user=35968931&type=issue", "selected": false}], "truncated": false}}, "suggested_facets": [{"name": "created_at", "type": "date", "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?closed_at__date=2021-07-29&state_reason=completed&user=35968931&_facet_date=created_at"}, {"name": "updated_at", "type": "date", "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?closed_at__date=2021-07-29&state_reason=completed&user=35968931&_facet_date=updated_at"}, {"name": "closed_at", "type": "date", "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?closed_at__date=2021-07-29&state_reason=completed&user=35968931&_facet_date=closed_at"}], "next": null, "next_url": null, "private": false, "allow_execute_sql": true, "query_ms": 29.826021287590265}