asp_plot.processing_parameters
==============================

.. py:module:: asp_plot.processing_parameters


Attributes
----------

.. autoapisummary::

   asp_plot.processing_parameters.logger


Classes
-------

.. autoapisummary::

   asp_plot.processing_parameters.ProcessingParameters


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

.. py:class:: ProcessingParameters(processing_directory, bundle_adjust_directory=None, stereo_directory=None)

   Extract and manage processing parameters from ASP log files.

   This class extracts parameters from ASP processing log files,
   including bundle adjustment, stereo, and point2dem logs. It provides
   methods to parse these logs and obtain command lines, run times, and
   other relevant processing information.

   .. attribute:: processing_directory

      Root directory of ASP processing

      :type: str

   .. attribute:: bundle_adjust_directory

      Subdirectory containing bundle adjustment outputs

      :type: str or None

   .. attribute:: stereo_directory

      Subdirectory containing stereo outputs

      :type: str or None

   .. attribute:: full_ba_directory

      Full path to bundle adjustment directory

      :type: str or None

   .. attribute:: full_stereo_directory

      Full path to stereo directory

      :type: str or None

   .. attribute:: bundle_adjust_log

      Path to bundle adjustment log file

      :type: str or None

   .. attribute:: stereo_logs

      List of paths to stereo log files

      :type: list or None

   .. attribute:: point2dem_log

      Path to point2dem log file

      :type: str or None

   .. attribute:: processing_parameters_dict

      Dictionary to store extracted parameters

      :type: dict

   .. rubric:: Examples

   >>> params = ProcessingParameters('/path/to/asp', 'ba', 'stereo')
   >>> params_dict = params.from_log_files()
   >>> print(params_dict['bundle_adjust'])  # Print bundle adjustment command line
   >>> print(params_dict['stereo_run_time'])  # Print stereo processing time


   .. py:method:: from_bundle_adjust_log()

      Extract parameters from the bundle adjustment log file.

      Parses the bundle adjustment log file to extract the command line,
      identifies the reference DEM, and calculates the run time.

      :returns: A tuple containing (bundle_adjust_params, run_time, reference_dem)
                where:
                - bundle_adjust_params: str, the bundle adjustment command line
                - run_time: str, formatted run time (e.g., "2 hours and 15 minutes")
                - reference_dem: str, path to the reference DEM used
      :rtype: tuple

      :raises ValueError: If the bundle adjustment log file cannot be found



   .. py:method:: from_log_files()

      Extract processing parameters from log files.

      Parses the bundle adjustment, stereo, and point2dem log files
      to extract command lines, run times, and other parameters.

      :returns: Dictionary containing processing parameters:
                - processing_timestamp: When processing was performed
                - reference_dem: Path to reference DEM
                - bundle_adjust: Bundle adjustment command line
                - bundle_adjust_run_time: Time to run bundle adjustment
                - stereo: Stereo command line
                - stereo_run_time: Time to run stereo
                - point2dem: point2dem command line
                - point2dem_run_time: Time to run point2dem
      :rtype: dict

      .. rubric:: Notes

      If bundle adjustment was not run, its command and run time are set
      to placeholder values. Reference DEM is searched for in either
      bundle adjustment or stereo logs, depending on availability.



   .. py:method:: from_point2dem_log()

      Extract parameters from the point2dem log file.

      Parses the point2dem log file to extract the command line
      and calculates the run time.

      :returns: A tuple containing (point2dem_params, run_time) where:
                - point2dem_params: str, the point2dem command line
                - run_time: str, formatted run time (e.g., "0 hours and 45 minutes")
      :rtype: tuple

      :raises ValueError: If the point2dem log file cannot be found



   .. py:method:: from_stereo_log(search_for_reference_dem=False)

      Extract parameters from the stereo log files.

      Parses the stereo log files to extract command lines, processing timestamp,
      and optionally searches for reference DEM information. This method uses
      both the preprocessing (pprc) and triangulation (tri) logs to get
      start/end times and stereo parameters.

      :param search_for_reference_dem: Whether to search for reference DEM in the log files, default is False
      :type search_for_reference_dem: bool, optional

      :returns: If search_for_reference_dem is False, returns:
                (processing_timestamp, stereo_params, run_time) where:
                - processing_timestamp: datetime, when processing started
                - stereo_params: str, the stereo command line
                - run_time: str, formatted run time

                If search_for_reference_dem is True, additionally returns:
                - reference_dem: str, path to the reference DEM used
      :rtype: tuple

      :raises ValueError: If stereo log files cannot be found

      .. rubric:: Notes

      The stereo process proceeds through several steps:
      1. stereo_pprc - preprocessing
      2. stereo_corr - correlation
      3. stereo_blend - tile blending (logs in tile/ dirs)
      4. stereo_rfne - refinement (logs in tile/ dirs)
      5. stereo_fltr - filtering
      6. stereo_tri - triangulation

      This method uses the pprc log for start time and the tri log for
      end time to calculate total runtime.



   .. py:method:: get_asp_version()

      Extract the ASP version string from the first available log file.

      :returns: ASP version string (e.g., "3.4.0-alpha"), or "N/A" if not found.
      :rtype: str



   .. py:method:: get_reference_dem(logfile, starting_string='DEM:')

      Extract reference DEM path from a log file.

      Searches for the reference DEM path in a log file using a
      pattern matching approach.

      :param logfile: Path to the log file to search
      :type logfile: str
      :param starting_string: String pattern that precedes the DEM path in the log,
                              default is "DEM:"
      :type starting_string: str, optional

      :returns: Path to the reference DEM if found, empty string otherwise
      :rtype: str

      .. rubric:: Notes

      This is a helper method used by from_bundle_adjust_log and
      from_stereo_log to extract reference DEM information.
      Different log file types use different patterns to indicate
      reference DEMs, hence the configurable starting_string parameter.



   .. py:method:: get_run_time(logfiles)

      Calculate the run time from timestamps in log files.

      Extracts the earliest timestamp from the first log file and the
      latest timestamp from the last log file to compute the total
      execution time.

      :param logfiles: Paths to log files to analyze. The first file is used to find
                       the start time, and the last file is used to find the end time.
      :type logfiles: list of str

      :returns: Formatted run time as "X hours and Y minutes", or "N/A" if
                timestamps couldn't be found
      :rtype: str

      .. rubric:: Notes

      This is a helper method used by other methods to calculate
      processing run times. It expects log files to have timestamps
      in the format "YYYY-MM-DD HH:MM:SS".

      If only one log file is provided, it will be used for both
      start and end times. This is useful for single-stage processes.



   .. py:attribute:: bundle_adjust_directory
      :value: None



   .. py:attribute:: full_ba_directory


   .. py:attribute:: full_stereo_directory


   .. py:attribute:: processing_directory


   .. py:attribute:: processing_parameters_dict


   .. py:attribute:: stereo_directory
      :value: None



.. py:data:: logger

