asp_plot.stereo
===============

.. py:module:: asp_plot.stereo


Attributes
----------

.. autoapisummary::

   asp_plot.stereo.logger


Classes
-------

.. autoapisummary::

   asp_plot.stereo.StereoPlotter


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

.. py:class:: StereoPlotter(directory, stereo_directory, dem_gsd=None, dem_fn=None, reference_dem=None, **kwargs)

   Bases: :py:obj:`asp_plot.utils.Plotter`


   Visualize and analyze stereo processing results from ASP.

   This class provides methods for plotting and analyzing various outputs
   from ASP stereo processing, including DEMs, disparity maps, match points,
   and difference maps with reference DEMs.

   .. attribute:: directory

      Root directory for ASP processing

      :type: str

   .. attribute:: stereo_directory

      Directory containing stereo processing outputs

      :type: str

   .. attribute:: dem_gsd

      Ground sample distance of the DEM in meters

      :type: float or None

   .. attribute:: dem_fn

      Path to the DEM file

      :type: str or None

   .. attribute:: reference_dem

      Path to the reference DEM file

      :type: str or None

   .. attribute:: dem

      DEM data, loaded when needed

      :type: numpy.ma.MaskedArray or None

   .. attribute:: dem_extent

      Extent of the DEM for plotting

      :type: tuple or None

   .. attribute:: dem_hs

      Hillshade of the DEM, generated when needed

      :type: numpy.ma.MaskedArray or None

   .. attribute:: ref_dem

      Reference DEM data, loaded when needed

      :type: numpy.ma.MaskedArray or None

   .. attribute:: ref_dem_extent

      Extent of the reference DEM for plotting

      :type: tuple or None

   .. attribute:: dem_diff

      Difference between DEM and reference DEM

      :type: numpy.ma.MaskedArray or None

   .. rubric:: Examples

   >>> plotter = StereoPlotter('/path/to/asp', 'stereo', reference_dem='ref_dem.tif')
   >>> plotter.plot_dem_results(save_dir='plots', fig_fn='dem_results.png')
   >>> plotter.plot_disparity(save_dir='plots', fig_fn='disparity.png')


   .. py:method:: get_diff_vs_reference()

      Get the difference between the DEM and a reference DEM.

      Tries to find an existing DEM difference file, or generates
      a difference on-the-fly if a reference DEM is available.

      :returns: Masked array containing the difference between the DEM and
                reference DEM, or None if no reference DEM is available
      :rtype: numpy.ma.MaskedArray or None

      .. rubric:: Notes

      This method first looks for a DEM difference file with a pattern
      like *diff.tif. If found, it uses that. Otherwise, it computes
      the difference between the DEM and reference DEM on-the-fly using
      the Raster.compute_difference method.



   .. py:method:: get_match_point_df()

      Convert a binary match file to a DataFrame of match points.

      Reads the binary match file produced by ASP stereo processing
      and converts it to a DataFrame containing matched interest points
      from the left and right images.

      :returns: DataFrame with columns 'x1', 'y1', 'x2', 'y2' representing
                the coordinates of matched points in the left and right images,
                or None if the match file doesn't exist
      :rtype: pandas.DataFrame or None

      .. rubric:: Notes

      This method converts the binary match file to a CSV file with the
      same base name but '.csv' extension, then reads that CSV file into
      a DataFrame. If the CSV file already exists, it is read directly.



   .. py:method:: plot_dem_results(el_clim=None, ie_clim=None, diff_clim=None, save_dir=None, fig_fn=None)

      Plot DEM results with hillshade, error, and difference maps.

      Creates a figure with three subplots showing the DEM with hillshade,
      intersection error, and difference with reference DEM.

      :param el_clim: Color limits for elevation, default is None (auto)
      :type el_clim: tuple or None, optional
      :param ie_clim: Color limits for intersection error, default is None (auto)
      :type ie_clim: tuple or None, optional
      :param diff_clim: Color limits for difference map, default is None (auto)
      :type diff_clim: tuple or None, optional
      :param save_dir: Directory to save the figure, default is None (don't save)
      :type save_dir: str or None, optional
      :param fig_fn: Filename for the saved figure, default is None
      :type fig_fn: str or None, optional

      :returns: Displays the plot and optionally saves it
      :rtype: None

      .. rubric:: Notes

      This method creates a comprehensive visualization of the stereo
      DEM results, including:
      1. The DEM with hillshade overlay
      2. Triangulation intersection error
      3. Difference with reference DEM (if available)

      If any required files are missing, the corresponding subplot will
      display a message instead.



   .. py:method:: plot_detailed_hillshade(intersection_error_percentiles=[16, 50, 84], subset_km=1, save_dir=None, fig_fn=None)

      Create a detailed plot with DEM hillshade and subsets.

      Generates a detailed figure showing the full DEM hillshade with
      color overlay, plus three smaller subsets highlighting areas with
      different levels of intersection error. If the images are map-projected,
      it also shows the corresponding optical image for each subset.

      If the intersection error file is missing, it falls back to a plain
      hillshade plot without the detailed subsets.

      :param intersection_error_percentiles: Percentiles of intersection error to use for selecting subsets,
                                             default is [16, 50, 84]
      :type intersection_error_percentiles: list, optional
      :param subset_km: Size of the subset areas in kilometers, default is 1
      :type subset_km: float, optional
      :param save_dir: Directory to save the figure, default is None (don't save)
      :type save_dir: str or None, optional
      :param fig_fn: Filename for the saved figure, default is None
      :type fig_fn: str or None, optional

      :returns: Displays the plot and optionally saves it
      :rtype: None

      .. rubric:: Notes

      This method creates a detailed visualization with a large overview
      map at the top and six smaller subplots below (three hillshades and
      three optical images). The subsets are chosen based on the variance
      of intersection error, representing areas with different quality
      levels in the DEM.



   .. py:method:: plot_disparity(unit='pixels', remove_bias=True, quiver=True, save_dir=None, fig_fn=None)

      Plot disparity maps from stereo processing.

      Creates a figure with three subplots showing the x and y components
      of the disparity map and the disparity magnitude, with optional
      quiver plot overlay.

      :param unit: Unit for disparity values, either 'pixels' or 'meters', default is 'pixels'
      :type unit: str, optional
      :param remove_bias: Whether to remove the median offset from disparity values, default is True
      :type remove_bias: bool, optional
      :param quiver: Whether to overlay a quiver plot on the disparity magnitude plot,
                     default is True
      :type quiver: bool, optional
      :param save_dir: Directory to save the figure, default is None (don't save)
      :type save_dir: str or None, optional
      :param fig_fn: Filename for the saved figure, default is None
      :type fig_fn: str or None, optional

      :returns: Displays the plot and optionally saves it
      :rtype: None

      :raises ValueError: If unit is not 'pixels' or 'meters'

      .. rubric:: Notes

      The disparity map shows the pixel offset between corresponding points
      in the left and right images. This can be displayed in pixel units or
      converted to meters using the image GSD. The quiver plot shows the
      direction and magnitude of the disparity vectors.



   .. py:method:: plot_match_points(save_dir=None, fig_fn=None)

      Plot match points between the left and right images.

      Creates a figure with two subplots showing the left and right
      subsampled images with match points overlaid as small red circles.
      For mapprojected scenes, match points are rescaled using the GSD ratio.
      For non-mapprojected scenes, match points are transformed from original
      to aligned coordinate space using the alignment matrices, then rescaled
      to the subsampled image dimensions.

      :param save_dir: Directory to save the figure, default is None (don't save)
      :type save_dir: str or None, optional
      :param fig_fn: Filename for the saved figure, default is None
      :type fig_fn: str or None, optional

      :returns: Displays the plot and optionally saves it
      :rtype: None



   .. py:method:: read_ip_record(match_file)

      Read an interest point record from a binary match file.

      :param match_file: Open binary match file positioned at the start of an interest point record
      :type match_file: file object

      :returns: List containing the interest point record fields, including:
                - x, y: Floating point coordinates
                - xi, yi: Integer coordinates
                - orientation, scale, interest: Feature descriptors
                - polarity: Boolean flag
                - octave, scale_lvl: Feature scale information
                - ndesc: Number of descriptor values
                - desc: Feature descriptor values
      :rtype: list

      .. rubric:: Notes

      This method is used to parse the binary ASP match file format,
      which contains interest points from both images in a stereo pair.



   .. py:attribute:: align_left_fn


   .. py:attribute:: align_right_fn


   .. py:attribute:: dem_gsd
      :value: None



   .. py:attribute:: directory


   .. py:attribute:: disparity_fn


   .. py:attribute:: disparity_sub_fn


   .. py:attribute:: full_directory


   .. py:attribute:: intersection_error_fn


   .. py:attribute:: is_vantor
      :value: False



   .. py:attribute:: left_image_fn


   .. py:attribute:: left_image_sub_fn


   .. py:attribute:: match_point_fn


   .. py:attribute:: orthos
      :value: False



   .. py:attribute:: right_image_sub_fn


   .. py:attribute:: stereo_directory


.. py:data:: logger

