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:
# Simple Animation Demo
%% Cell type:code id: tags:
``` python
%load_ext autoreload
%autoreload 2
```
%% Cell type:code id: tags:
``` python
import numpy as np
import time
from IPython import display
from ipycanvas import canvas
from flatland.utils.rendertools import RenderTool
from flatland.envs.rail_env import RailEnv
from flatland.envs.rail_env import RailEnvActions as rea
from flatland.envs.persistence import RailEnvPersister
```
%% Cell type:code id: tags:
``` python
env, env_dict = RailEnvPersister.load_new("complex_scene_2.pkl", load_from_package="env_data.railway")
_ = env.reset()
env._max_episode_steps = 100
```
%% 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)...
This env file has no max_episode_steps (deprecated) - setting to 100
%% Cell type:code id: tags:
``` python
oRT = RenderTool(env, gl="PILSVG", jupyter=False, show_debug=True)
image_arr = oRT.get_image()
oCanvas = canvas.Canvas()
oCanvas.put_image_data(image_arr[:,:,0:3])
display.display(oCanvas)
done={"__all__":False}
while not done["__all__"]:
actions = {}
for agent_handle, agents in enumerate(env.agents):
actions.update({agent_handle:rea.MOVE_FORWARD})
obs, rew, done, info = env.step(actions)
oRT.render_env(show_observations=False,show_predictions=False)
gIm = oRT.get_image()
red_channel = gIm[:,:,0]
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)
oCanvas.put_image_data(gIm[:,:,0:3])
time.sleep(0.1)
```
%% 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