hyrax.verbs.visualize
=====================

.. py:module:: hyrax.verbs.visualize


Attributes
----------

.. autoapisummary::

   hyrax.verbs.visualize.logger


Classes
-------

.. autoapisummary::

   hyrax.verbs.visualize.Visualize


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

.. py:data:: logger

.. py:class:: Visualize(config)

   Bases: :py:obj:`hyrax.verbs.verb_registry.Verb`


   Verb to create a visualization

   .. py:method:: __init__

   Overall initialization for all verbs that saves the config


   .. py:attribute:: cli_name
      :value: 'visualize'



   .. py:attribute:: add_parser_kwargs


   .. py:attribute:: description
      :value: 'Generate a visualization of a latent space created by a UMAP reduction.'



   .. py:attribute:: REQUIRED_DATA_GROUPS
      :value: ('infer',)



   .. py:attribute:: OPTIONAL_DATA_GROUPS
      :value: ()



   .. py:method:: setup_parser(parser: argparse.ArgumentParser)
      :staticmethod:


      CLI not implemented for this verb



   .. py:method:: run_cli(args: argparse.Namespace | None = None)

      CLI not implemented for this verb



   .. py:method:: run(input_dir: Union[pathlib.Path, str] | None = None, *, return_verb: bool = False, make_lupton_rgb_opts: dict | None = None, **kwargs)

      Generate an interactive notebook visualization of a latent space that has been umapped down to 2d.

      The plot contains two holoviews objects, a scatter plot of the latent space, and a table of objects
      which can be populated by selecting from the scatter plot.

      :param input_dir: Directory holding the output from the 'umap' verb, by default None. When not provided, we use
                        [results][inference_dir] from config. If that's false; we the most recent umap in the current
                        results directory.
      :type input_dir: Optional[Union[Path, str]], optional
      :param return_verb: If True, also return the underlying Visualize instance for post-hoc access
                          to selection state. Defaults to False.
      :type return_verb: bool, optional
      :param make_lupton_rgb_opts: Dictionary of options to pass to astropy's make_lupton_rgb function for RGB image creation.
                                   Default is {"stretch": 5, "Q": 8}. Common parameters include stretch (brightness/contrast)
                                   and Q (softening parameter for asinh transformation).
      :type make_lupton_rgb_opts: dict, optional
      :param kwargs: Keyword arguments are passed through as options for the plot object as
                     ``plot_pane.opts(**plot_options)``. It is not recommended to override the "tools" plot option,
                     because that will break the integration between the plot selection operations and the table.

      :returns: * *Holoviews, if return_verb = True (defaul)* -- A Collection of Haloviews Panes
                * *tuple of (pane, Visualize), if return_verb = True* -- Returns a 2-tuple with the pane and the verb instance.



   .. py:method:: visible_points(x_range: Union[tuple, list], y_range: Union[tuple, list])

      Generate a hv.Points object with the points inside the bounding box passed.

      This is the event handler for moving or scaling the latent space plot, and is called by Holoviews.

      :param x_range: min and max x values
      :type x_range: tuple or list
      :param y_range: min and max y values
      :type y_range: tuple or list

      :returns: Points lying inside the bounding box passed
      :rtype: hv.Points



   .. py:method:: update_points(**kwargs) -> None

      This is the main UI event handler for selection tools on the plot. If you are a dynamic map
      in the layout of the visualizer who updates based on plot selection you MUST call this function.

      This function accepts the data values from all streams and uses the differences between the current
      call and prior calls to differentiate between different UI events.

      The self.prev_kwargs dictionary is used to store previous calls to this function, and the
      ``_called_*`` helpers perform the differencing for each case.

      Calling this function GUARANTEES that self.points, self.points_id, and self.points_idx
      are up-to-date with the user's latest selection, regardless of the order that Holoviews evaluates
      the DynamicMaps in.



   .. py:method:: _called_lasso(kwargs)


   .. py:method:: _called_tap(kwargs)


   .. py:method:: _called_box_select(kwargs)


   .. py:method:: poly_select_points(geometry) -> tuple[numpy.typing.ArrayLike, numpy.typing.ArrayLike, numpy.typing.ArrayLike]

      Select points inside a polygon.

      :param geometry: List of x/y points describing the verticies of the polygon
      :type geometry: list

      :returns: First element is an ndarray of x/y points in latent space inside the polygon
                Second element is an ndarray of corresponding object ids
      :rtype: Tuple



   .. py:method:: box_select_points(x_range: Union[tuple, list], y_range: Union[tuple, list]) -> tuple[numpy.typing.ArrayLike, numpy.typing.ArrayLike, numpy.typing.ArrayLike]

      Return the points and IDs for a box in the latent space

      :param x_range: min and max x values
      :type x_range: tuple or list
      :param y_range: min and max y values
      :type y_range: tuple or list

      :returns: First element is an ndarray of x/y points in latent space inside the box
                Second element is an ndarray of corresponding object ids
      :rtype: Tuple



   .. py:method:: box_select_indexes(x_range: Union[tuple, list], y_range: Union[tuple, list])

      Return the indexes inside of a particular box in the latent space

      :param x_range: min and max x values
      :type x_range: tuple or list
      :param y_range: min and max y values
      :type y_range: tuple or list

      :returns: Array of data indexes where the latent space representation falls inside the given box.
      :rtype: np.ndarray



   .. py:method:: selected_objects(**kwargs)

      Generate the holoview table for a selected set of objects based on input from the
      Lasso, Tap, and SelectionXY streams.

      :returns: Table with Object ID, x, y locations of the selected objects
      :rtype: hv.Table



   .. py:method:: _table_from_points()


   .. py:method:: _bounding_box(points)
      :staticmethod:



   .. py:method:: _even_aspect_bounding_box()


   .. py:method:: get_selected_df()

      Retrieve a pandas DataFrame containing the currently selected points and their associated metadata.

      :returns: A DataFrame with one row per selected point and columns:
                ["object_id", "x", "y", \*additional_fields].
      :rtype: pd.DataFrame



   .. py:method:: _load_images(**kwargs)


   .. py:method:: _make_image_pane(total_width: int = 500, *args, **kwargs)

      Sample up to 6 of the selected object_ids,
      load their FITS cutouts from [general][data_dir], and
      render as small hv.Image thumbnails in a grid.



