src.plangym.utils
=================

.. py:module:: src.plangym.utils

.. autoapi-nested-parse::

   Generic utilities for working with environments.



Attributes
----------

.. autoapisummary::

   src.plangym.utils.USE_PIL


Classes
-------

.. autoapisummary::

   src.plangym.utils.GrayScaleObservation


Functions
---------

.. autoapisummary::

   src.plangym.utils.get_display
   src.plangym.utils.remove_time_limit_from_spec
   src.plangym.utils.remove_time_limit
   src.plangym.utils.process_frame_pil
   src.plangym.utils.process_frame_opencv
   src.plangym.utils.process_frame


Module Contents
---------------

.. py:data:: USE_PIL
   :value: True


.. py:function:: get_display(visible=False, size=(400, 400), **kwargs)

   Start a virtual display.


.. py:function:: remove_time_limit_from_spec(spec)

   Remove the maximum time limit of an environment spec.


.. py:function:: remove_time_limit(gym_env)

   Remove the maximum time limit of the provided environment.


.. py:function:: process_frame_pil(frame, width = None, height = None, mode = 'RGB')

   Resize an RGB frame to a specified shape and mode.

   Use PIL to resize an RGB frame to a specified height and width     or changing it to a different mode.

   :param frame: Target numpy array representing the image that will be resized.
   :param width: Width of the resized image.
   :param height: Height of the resized image.
   :param mode: Passed to Image.convert.

   :returns: The resized frame that matches the provided width and height.


.. py:function:: process_frame_opencv(frame, width = None, height = None, mode = 'RGB')

   Resize an RGB frame to a specified shape and mode.

   Use OpenCV to resize an RGB frame to a specified height and width     or changing it to a different mode.

   :param frame: Target numpy array representing the image that will be resized.
   :param width: Width of the resized image.
   :param height: Height of the resized image.
   :param mode: Passed to cv2.cvtColor.

   :returns: The resized frame that matches the provided width and height.


.. py:function:: process_frame(frame, width = None, height = None, mode = 'RGB')

   Resize an RGB frame to a specified shape and mode.

   Use either PIL or OpenCV to resize an RGB frame to a specified height and width     or changing it to a different mode.

   :param frame: Target numpy array representing the image that will be resized.
   :param width: Width of the resized image.
   :param height: Height of the resized image.
   :param mode: Passed to either Image.convert or cv2.cvtColor.

   :returns: The resized frame that matches the provided width and height.


.. py:class:: GrayScaleObservation(env, keep_dim = False)

   Bases: :py:obj:`gymnasium.ObservationWrapper`, :py:obj:`gymnasium.utils.RecordConstructorArgs`


   Convert the image observation from RGB to gray scale.

   .. rubric:: Example

   >>> import gymnasium as gym
   >>> from gymnasium.wrappers import GrayScaleObservation
   >>> env = gym.make("CarRacing-v2")
   >>> env.observation_space
   Box(0, 255, (96, 96, 3), uint8)
   >>> env = GrayScaleObservation(gym.make("CarRacing-v2"))
   >>> env.observation_space
   Box(0, 255, (96, 96), uint8)
   >>> env = GrayScaleObservation(gym.make("CarRacing-v2"), keep_dim=True)
   >>> env.observation_space
   Box(0, 255, (96, 96, 1), uint8)


   .. py:attribute:: keep_dim


   .. py:attribute:: obs_shape


   .. py:method:: observation(observation)

      Convert the colour observation to greyscale.

      :param observation: Color observations

      :returns: Grayscale observations



