Skip to content
Snippets Groups Projects
Commit f3b6bf5a authored by Egli Adrian (IT-SCI-API-PFI)'s avatar Egli Adrian (IT-SCI-API-PFI)
Browse files

testing

parent ae2799cc
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Plot the Env and some trees # Plot the Env and some trees
%% 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 jpy_canvas import jpy_canvas
import random import random
import time import time
import sys import sys
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# in case you need to tweak your PYTHONPATH... # in case you need to tweak your PYTHONPATH...
sys.path.append("../flatland") sys.path.append("../flatland")
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import flatland.core.env import flatland.core.env
import flatland.utils.rendertools as rt import flatland.utils.rendertools as rt
from flatland.envs.rail_env import RailEnv, random_rail_generator from flatland.envs.rail_env import RailEnv, random_rail_generator
from flatland.envs.observations import TreeObsForRailEnv from flatland.envs.observations import TreeObsForRailEnv
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from IPython.core.display import display, HTML from IPython.core.display import display, HTML
display(HTML("<style>.container { width:90% !important; }</style>")) display(HTML("<style>.container { width:90% !important; }</style>"))
``` ```
%% Output
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Generate # Generate
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
nAgents = 3 nAgents = 3
fnMethod = random_rail_generator(cell_type_relative_proportion=[1] * 11) fnMethod = random_rail_generator(cell_type_relative_proportion=[1] * 11)
env = RailEnv(width=20, env = RailEnv(width=20,
height=10, height=10,
rail_generator=fnMethod, rail_generator=fnMethod,
number_of_agents=nAgents, number_of_agents=nAgents,
obs_builder_object=TreeObsForRailEnv(max_depth=2)) obs_builder_object=TreeObsForRailEnv(max_depth=2))
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Render # Render
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
oRT = rt.RenderTool(env,gl="PILSVG") oRT = rt.RenderTool(env,gl="PILSVG")
oRT.render_env() oRT.render_env(show_observations=True,show_predictions=False)
img = oRT.get_image() img = oRT.get_image()
``` ```
%% Output
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-7-5e6388f30b6b> in <module>
1 oRT = rt.RenderTool(env,gl="PILSVG")
2 oRT.render_env()
----> 3 img = oRT.get_image()
c:\users\u216993\appdata\local\programs\python\python36\lib\site-packages\flatland_rl-0.2.0-py3.6.egg\flatland\utils\rendertools.py in get_image(self)
418
419 def get_image(self):
--> 420 return self.gl.get_image()
421
422 def render_env_pil(self,
c:\users\u216993\appdata\local\programs\python\python36\lib\site-packages\flatland_rl-0.2.0-py3.6.egg\flatland\utils\graphics_pil.py in get_image(self)
216 with layer 0 at the "back".
217 """
--> 218 img = self.alpha_composite_layers()
219 return array(img)
220
c:\users\u216993\appdata\local\programs\python\python36\lib\site-packages\flatland_rl-0.2.0-py3.6.egg\flatland\utils\graphics_pil.py in alpha_composite_layers(self)
209 img = self.layers[0]
210 for img2 in self.layers[1:]:
--> 211 img = Image.alpha_composite(img, img2)
212 return img
213
c:\users\u216993\appdata\local\programs\python\python36\lib\site-packages\PIL\Image.py in alpha_composite(im1, im2)
2703 im1.load()
2704 im2.load()
-> 2705 return im1._new(core.alpha_composite(im1.im, im2.im))
2706
2707
ValueError: images do not match
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
jpy_canvas.Canvas(img) jpy_canvas.Canvas(img)
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
oRT = rt.RenderTool(env,gl="PIL") oRT = rt.RenderTool(env,gl="PIL")
oRT.render_env() oRT.render_env()
img = oRT.get_image() img = oRT.get_image()
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
jpy_canvas.Canvas(img) jpy_canvas.Canvas(img)
``` ```
......
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