Skip to content
Snippets Groups Projects
Commit 636518f4 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 62bc4406
No related branches found
No related tags found
No related merge requests found
from typing import List, NamedTuple
import numpy as np
from IPython import display
from ipycanvas import canvas
......@@ -111,7 +112,12 @@ class EnvCanvas():
def render(self):
self.oRT.render_env(show_rowcols=True, show_inactive_agents=False, show_observations=False)
self.oCan.put_image_data(self.oRT.get_image()[:, :, 0:3])
gIm = self.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)
self.oCan.put_image_data(image_data)
def step(self):
dAction = self.behaviour.getActions()
......
%% 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)
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()
oCanvas.put_image_data(gIm[:,:,0:3])
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)
time.sleep(0.1)
```
%% Cell type:code id: tags:
``` python
.shape
```
%% Cell type:code id: tags:
%% Output
``` python
```
......
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