diff --git a/notebooks/flatland-animate.ipynb b/notebooks/flatland-animate.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..cc523f45ff2019da2ed6baca0af8b47e1f668c13 --- /dev/null +++ b/notebooks/flatland-animate.ipynb @@ -0,0 +1,226 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Simple Animation Demo" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%load_ext autoreload\n", + "%autoreload 2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from flatland.utils.rendertools import RenderTool\n", + "import ipycanvas\n", + "import time\n", + "from flatland.envs.rail_env import RailEnv\n", + "from flatland.envs.rail_env import RailEnvActions as rea\n", + "from flatland.envs.persistence import RailEnvPersister" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "env, env_dict = RailEnvPersister.load_new(\"test_env_loop.pkl\", load_from_package=\"env_data.tests\")\n", + "oRT = RenderTool(env)\n", + "oRT.render_env()\n", + "image_arr = oRT.get_image()\n", + "canvas = ipycanvas.Canvas()\n", + "canvas.put_image_data(image_arr)\n", + "display(canvas)\n", + "\n", + "for iEp in range(5):\n", + " env.reset(False, False, True)\n", + " env._max_episode_steps = 100\n", + "\n", + " done={\"__all__\":False}\n", + " while not done[\"__all__\"]:\n", + " obs, rew, done, info = env.step(action_dict_={int(0):rea.MOVE_FORWARD})\n", + " oRT.render_env()\n", + " gIm = oRT.get_image()\n", + " canvas.put_image_data(gIm)\n", + " time.sleep(0.1)" + ] + } + ], + "metadata": { + "hide_input": false, + "kernelspec": { + "display_name": "ve367", + "language": "python", + "name": "ve367" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.7" + }, + "latex_envs": { + "LaTeX_envs_menu_present": true, + "autoclose": false, + "autocomplete": true, + "bibliofile": "biblio.bib", + "cite_by": "apalike", + "current_citInitial": 1, + "eqLabelWithNumbers": true, + "eqNumInitial": 1, + "hotkeys": { + "equation": "Ctrl-E", + "itemize": "Ctrl-I" + }, + "labels_anchors": false, + "latex_user_defs": false, + "report_style_numbering": false, + "user_envs_cfg": false + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": true, + "sideBar": true, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": true, + "toc_window_display": false + }, + "varInspector": { + "cols": { + "lenName": 16, + "lenType": 16, + "lenVar": 40 + }, + "kernels_config": { + "python": { + "delete_cmd_postfix": "", + "delete_cmd_prefix": "del ", + "library": "var_list.py", + "varRefreshCmd": "print(var_dic_list())" + }, + "r": { + "delete_cmd_postfix": ") ", + "delete_cmd_prefix": "rm(", + "library": "var_list.r", + "varRefreshCmd": "cat(var_dic_list()) " + } + }, + "types_to_exclude": [ + "module", + "function", + "builtin_function_or_method", + "instance", + "_Feature" + ], + "window_display": false + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": { + "2433ff4d1b324fac968f6109f0a61185": { + "model_module": "@jupyter-widgets/base", + "model_module_version": "1.2.0", + "model_name": "LayoutModel", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": "500px", + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": "700px" + } + }, + "f2dc1da3e8c74208b9627e97e8630a5f": { + "model_module": "ipycanvas", + "model_module_version": "^0.4.1", + "model_name": "CanvasModel", + "state": { + "_dom_classes": [], + "_model_module": "ipycanvas", + "_model_module_version": "^0.4.1", + "_model_name": "CanvasModel", + "_view_count": null, + "_view_module": "ipycanvas", + "_view_module_version": "^0.4.1", + "_view_name": "CanvasView", + "image_data": null, + "layout": "IPY_MODEL_2433ff4d1b324fac968f6109f0a61185", + "size": [ + 700, + 500 + ], + "sync_image_data": false + } + } + }, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}