mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-01 14:10:30 +00:00
* Remove additional ignores from flake8 * Remove all unused imports * Remove all unused imports * Update flake8 and pyupgrade * F841, removed unused variables * E731, removed lambda assignment to variables * Remove E731, F403, F405, F524 * Remove E722, bare exceptions * Remove E712, compare variable == True or == False to is True or is False * Remove E402, module level import not at top of file * Added --pre-file-ignores * Add --per-file-ignores removing E741, E302 and E704 * Add E741, do not use variables named ‘l’, ‘O’, or ‘I’ to ignore issues in classic control * Fixed issues for pytest==6.2 * Remove unnecessary # noqa * Edit comment with the removal of E302 * Added warnings and declared module, attr for pyright type hinting * Remove unused import * Removed flake8 E302 * Updated flake8 from 3.9.2 to 4.0.1 * Remove unused variable
34 lines
976 B
Python
34 lines
976 B
Python
import numpy as np
|
|
|
|
from gym import ObservationWrapper
|
|
from gym.spaces import Box
|
|
|
|
|
|
class TimeAwareObservation(ObservationWrapper):
|
|
r"""Augment the observation with current time step in the trajectory.
|
|
|
|
.. note::
|
|
Currently it only works with one-dimensional observation space. It doesn't
|
|
support pixel observation space yet.
|
|
|
|
"""
|
|
|
|
def __init__(self, env):
|
|
super().__init__(env)
|
|
assert isinstance(env.observation_space, Box)
|
|
assert env.observation_space.dtype == np.float32
|
|
low = np.append(self.observation_space.low, 0.0)
|
|
high = np.append(self.observation_space.high, np.inf)
|
|
self.observation_space = Box(low, high, dtype=np.float32)
|
|
|
|
def observation(self, observation):
|
|
return np.append(observation, self.t)
|
|
|
|
def step(self, action):
|
|
self.t += 1
|
|
return super().step(action)
|
|
|
|
def reset(self, **kwargs):
|
|
self.t = 0
|
|
return super().reset(**kwargs)
|