Title: NEW FEATURE: Export projects as python scripts · Issue #4 · psyplot/psyplot · GitHub
Open Graph Title: NEW FEATURE: Export projects as python scripts · Issue #4 · psyplot/psyplot
X Title: NEW FEATURE: Export projects as python scripts · Issue #4 · psyplot/psyplot
Description: Summary psyplot projects should be exportable directly to python scripts, not only as pickle files. Reason When trying to reproduce a plot created through the GUI, it would be helpful to have a python script to generate it, such that it ...
Open Graph Description: Summary psyplot projects should be exportable directly to python scripts, not only as pickle files. Reason When trying to reproduce a plot created through the GUI, it would be helpful to have a pyt...
X Description: Summary psyplot projects should be exportable directly to python scripts, not only as pickle files. Reason When trying to reproduce a plot created through the GUI, it would be helpful to have a pyt...
Opengraph URL: https://github.com/psyplot/psyplot/issues/4
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"NEW FEATURE: Export projects as python scripts","articleBody":"### Summary\r\npsyplot projects should be exportable directly to python scripts, not only as\r\npickle files.\r\n\r\n### Reason\r\nWhen trying to reproduce a plot created through the GUI, it would be helpful\r\nto have a python script to generate it, such that it can be copy-pasted to\r\nanother python script.\r\n\r\n### Detailed explanation\r\nOne strength of psyplot is the short and easy syntax for formatoptions and\r\nthe structured data handling. And since anyway most of the formatoption \r\ncome in standard python objects like lists, strings, etc. it would be \r\nstraight-forward with python `repr` function to reproduce them in a script.\r\n\r\n#### Challenges\r\n1. Only datasets that have been stored to disc can be opened in the\r\n script\r\n2. The matplotlib axes setup has to be reproduced\r\n3. Some formatoptions do require more complex data structures, such \r\n as colormaps or numpy arrays\r\n\r\n#### Proposed methodology to generate the script\r\n\r\n1. open the netCDF dataset from disk (if it is stored on the disk, otherwise leaf that\r\n empty such that the user can fill this in\r\n\r\n ```python\r\n ds1 = xr.open_dataset('nc-file1.nc')\r\n ds2 = xr.open_dataset('nc-file2.nc')\r\n ds3 = # dataset has not been stored on the disc\r\n ```\r\n The number ``ds\u003cnumber\u003e`` should be determined by the \r\n `psyplot.data.DatasetAccessor.num` attribute\r\n2. We should not use the `psyplot.project.plot` API directly, since the plot methods\r\n can have diverse calling signatures. So we extract the data and create the plot for \r\n each array in the project from scratch. Therefore, for each data object in the project,\r\n export a script to\r\n\r\n 1. reproduce the DataArray (or InteractiveList) from the datasets `ds1, ds2, ...`\r\n 2. Create the matplotlib axes that is visualized (if there is a plotter)\r\n 3. open the plotter class from psyplot (if there is a plotter)\r\n\r\n3. Concatenate all the extracted data arrays/lists into one project\r\n\r\n#### Proposed API additions:\r\n\r\n1. A new method `psyplot.data.ArrayList.to_script()` to top-level API method that \r\n generates the python script to reproduce the list/project. It should create the part\r\n to open the datasets and call the `to_script` method of the contents\r\n2. A new abstract method `psyplot.script.InteractiveBase.to_script()` that \r\n generates the string to generate this data structure. If the object has a \r\n plotter, it should call the `to_script` method of the plotter\r\n3. A new abstract method `psyplot.plotter.Plotter.to_script()` method, that\r\n\r\n 1. Creates the matplotlib axes\r\n 2. Creates the plotter by first checking the `prepare_string` methods of the\r\n formatoptions and then the `as_string` method\r\n4. A new `psyplot.plotter.Formatoption.prepare_string` method, that returns\r\n a string with necssary preparations for the formatoption. In case of a \r\n colormap instance, for example, this could be the example how the colormap is\r\n created. So by default, this should be an empty string\r\n5. A new `psyplot.plotter.Formatoption.as_string` method, that is called after\r\n the `prepare_string` method and sets the value for the formatoption in the \r\n `Plotter(...)` initialization. By default, this should just be ``repr(self.value)``\r\n\r\n### Examples\r\nParaview for example has this functionality with [Tools-\u003eStart Trace](https://www.paraview.org/python/)\r\n","author":{"url":"https://github.com/Chilipp","@type":"Person","name":"Chilipp"},"datePublished":"2018-04-11T15:37:02.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/4/psyplot/issues/4"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e0773c68-4edd-4276-91df-b42ae59044fa |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B24A:35A28D:D4F16:114229:698D1358 |
| html-safe-nonce | 9d4e9a45b8f72a84842754f8bc0eb3b63061f30d4579daf83396c008412237dc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMjRBOjM1QTI4RDpENEYxNjoxMTQyMjk6Njk4RDEzNTgiLCJ2aXNpdG9yX2lkIjoiMzA5OTMwMjE0NTQ5MDIyODA1NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2810ed7cfb8f7ff5d06a1c88ebb7cd68e63d67b56398cec1f34a8157afb49aac |
| hovercard-subject-tag | issue:313378779 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/psyplot/psyplot/4/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2e04c4d0c0eb709d1c0f4ceab2ee075e92af7a8a27af049ae2bc11ab336cddfc/psyplot/psyplot/issues/4 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2e04c4d0c0eb709d1c0f4ceab2ee075e92af7a8a27af049ae2bc11ab336cddfc/psyplot/psyplot/issues/4 |
| og:image:alt | Summary psyplot projects should be exportable directly to python scripts, not only as pickle files. Reason When trying to reproduce a plot created through the GUI, it would be helpful to have a pyt... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Chilipp |
| hostname | github.com |
| expected-hostname | github.com |
| None | c25395580e1e3bf82d705e0982a1b24255366088720fef945f1493d5e3e67954 |
| turbo-cache-control | no-preview |
| go-import | github.com/psyplot/psyplot git https://github.com/psyplot/psyplot.git |
| octolytics-dimension-user_id | 60222268 |
| octolytics-dimension-user_login | psyplot |
| octolytics-dimension-repository_id | 87944102 |
| octolytics-dimension-repository_nwo | psyplot/psyplot |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 87944102 |
| octolytics-dimension-repository_network_root_nwo | psyplot/psyplot |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 94219dcb9c044792ec271fd5b23c73419858bef7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width