Skip to content

Commit

Permalink
Merge pull request #65 from mplemay/depreciation-fixes
Browse files Browse the repository at this point in the history
Various Depreciation/Bug Fixes
  • Loading branch information
tomsilver authored Jun 16, 2022
2 parents 9477049 + 6d038cf commit 142302c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion pddlgym/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

# Save users from having to separately import gym
def make(*args, **kwargs):
return gym.make(*args, **kwargs)
# env checker fails since obs is not an numpy array like object
return gym.make(*args, disable_env_checker=True, **kwargs)

def register_pddl_env(name, is_test_env, other_args):
dir_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "pddl")
Expand Down
14 changes: 11 additions & 3 deletions pddlgym/rendering/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@ def get_asset_path(asset_name):
asset_dir_path = os.path.join(dir_path, 'assets')
return os.path.join(asset_dir_path, asset_name)

def fig2data(fig, dpi=150):
def fig2data(fig, dpi: int = 150):
fig.set_dpi(dpi)
fig.canvas.draw()
data = np.fromstring(fig.canvas.tostring_argb(), dtype=np.uint8, sep='')
data = data.reshape(fig.canvas.get_width_height()[::-1] + (4,))

# copy image data from buffer
data = np.frombuffer(fig.canvas.tostring_argb(), dtype=np.uint8).copy()

# get the dpi adjusted figure dimensions
width, height = map(int, fig.get_size_inches() * fig.get_dpi())
data = data.reshape(height, width, 4)

data[..., [0, 1, 2, 3]] = data[..., [1, 2, 3, 0]]

return data

def initialize_figure(height, width, fig_scale=1., grid_colors=None):
Expand Down Expand Up @@ -66,6 +73,7 @@ def render_from_layout(layout, get_token_images, dpi=150, grid_colors=None):

im = Image.fromarray(im)
new_width, new_height = (int(im.size[0] * IM_SCALE), int(im.size[1] * IM_SCALE))
# TODO : switch resize method to Image.Resampling.LANCZOS when pillow>=10 is supported
im = im.resize((new_width, new_height), Image.ANTIALIAS)
im = np.array(im)

Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
matplotlib
pillow
gym
pillow>=8,<10
gym>=0.24.0
imageio
networkx
scikit-image

0 comments on commit 142302c

Please sign in to comment.