Skip to content
Snippets Groups Projects
Commit 1d64d2a5 authored by adrian_egli2's avatar adrian_egli2
Browse files

Jupyter notebooks are ready for flatland3.

But they should be overworked. Might just one example per use case would be much more clear. TODO - cleanup
parent 0b150fe0
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Simple Animation Demo # Simple Animation Demo
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
%load_ext autoreload %load_ext autoreload
%autoreload 2 %autoreload 2
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import numpy as np import numpy as np
import time import time
from IPython import display from IPython import display
from ipycanvas import canvas from ipycanvas import canvas
from flatland.utils.rendertools import RenderTool from flatland.utils.rendertools import RenderTool
from flatland.envs.rail_env import RailEnv from flatland.envs.rail_env import RailEnv
from flatland.envs.rail_env import RailEnvActions as rea from flatland.envs.rail_env import RailEnvActions as rea
from flatland.envs.persistence import RailEnvPersister from flatland.envs.persistence import RailEnvPersister
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
env, env_dict = RailEnvPersister.load_new("complex_scene_2.pkl", load_from_package="env_data.railway") env, env_dict = RailEnvPersister.load_new("complex_scene_2.pkl", load_from_package="env_data.railway")
_ = env.reset() _ = env.reset()
env._max_episode_steps = 100 env._max_episode_steps = 100
``` ```
%% Output %% Output
pickle failed to load file: complex_scene_2.pkl trying msgpack (deprecated)... pickle failed to load file: complex_scene_2.pkl trying msgpack (deprecated)...
pickle failed to load file: complex_scene_2.pkl trying msgpack (deprecated)... pickle failed to load file: complex_scene_2.pkl trying msgpack (deprecated)...
pickle failed to load file: complex_scene_2.pkl trying msgpack (deprecated)... pickle failed to load file: complex_scene_2.pkl trying msgpack (deprecated)...
This env file has no max_episode_steps (deprecated) - setting to 100 This env file has no max_episode_steps (deprecated) - setting to 100
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
oRT = RenderTool(env, gl="PILSVG", jupyter=False, show_debug=True) oRT = RenderTool(env, gl="PILSVG", jupyter=False, show_debug=True)
image_arr = oRT.get_image() image_arr = oRT.get_image()
oCanvas = canvas.Canvas() oCanvas = canvas.Canvas()
oCanvas.put_image_data(image_arr[:,:,0:3]) oCanvas.put_image_data(image_arr[:,:,0:3])
display.display(oCanvas) display.display(oCanvas)
done={"__all__":False} done={"__all__":False}
while not done["__all__"]: while not done["__all__"]:
actions = {} actions = {}
for agent_handle, agents in enumerate(env.agents): for agent_handle, agents in enumerate(env.agents):
actions.update({agent_handle:rea.MOVE_FORWARD}) actions.update({agent_handle:rea.MOVE_FORWARD})
obs, rew, done, info = env.step(actions) obs, rew, done, info = env.step(actions)
oRT.render_env(show_observations=False,show_predictions=False) oRT.render_env(show_observations=False,show_predictions=False)
gIm = oRT.get_image() gIm = oRT.get_image()
red_channel = gIm[:,:,0] oCanvas.put_image_data(gIm[:,:,0:3])
blue_channel = gIm[:,:,1]
green_channel = gIm[:,:,2]
image_data = np.stack((red_channel, blue_channel, green_channel), axis=2)
oCanvas.put_image_data(image_data)
time.sleep(0.1) time.sleep(0.1)
``` ```
%% Output %% Output
......
source diff could not be displayed: it is too large. Options to address this: view the blob.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment