asp_plot.planetary_source
=========================

.. py:module:: asp_plot.planetary_source

.. autoapi-nested-parse::

   Planetary (LOLA/MOLA) altimetry sources.

   Owns the planetary-altimetry side of :class:`asp_plot.altimetry.Altimetry`:
   loading LOLA (Moon) and MOLA (Mars) point clouds from ODE GDS CSV exports,
   sampling the ASP DEM at those points, and exporting a pc_align-ready CSV.

   The body-agnostic machinery (DEM differencing, pc_align export, the shared CSV
   reader) lives on :class:`PlanetarySource`; the per-body CSV loaders live on its
   :class:`LolaSource` (Moon) and :class:`MolaSource` (Mars) subclasses. Each
   instance holds its own data (``planetary_points``) and reads the cross-cutting
   ``dem_fn`` / ``directory`` / ``aligned_dem_fn`` from the coordinating
   :class:`Altimetry` instance passed at construction.



Attributes
----------

.. autoapisummary::

   asp_plot.planetary_source.GDS_BASE_URL
   asp_plot.planetary_source.MARS_IAU_SPHERE_RADIUS
   asp_plot.planetary_source.MOON_IAU_SPHERE_RADIUS
   asp_plot.planetary_source.logger


Classes
-------

.. autoapisummary::

   asp_plot.planetary_source.LolaSource
   asp_plot.planetary_source.MolaSource
   asp_plot.planetary_source.PlanetarySource


Functions
---------

.. autoapisummary::

   asp_plot.planetary_source.gds_query_async


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

.. py:class:: LolaSource(alt)

   Bases: :py:obj:`PlanetarySource`


   LOLA (Moon) altimetry source.

   Parses a LOLA RDR CSV from the ODE GDS into height above the IAU 1737.4 km
   lunar sphere. The Moon is nearly spherical (1.4 km equatorial-vs-polar
   variation), so LOLA TOPOGRAPHY ≈ Pt_Radius − 1737.4 km — either column
   gives the same dh against an ASP lunar DEM to <1 m.


   .. py:method:: load_planetary_csv(csv_path)

      Parse a LOLA topo/RDR CSV into ``self.planetary_points``.

      Stores height above the IAU lunar sphere on ``height`` and the
      planetary radius on ``radius_m`` (used by pc_align).

      :param csv_path: Path to a LOLA RDR CSV from the ODE GDS API.
      :type csv_path: str



   .. py:attribute:: instrument
      :value: 'LOLA'



.. py:class:: MolaSource(alt)

   Bases: :py:obj:`PlanetarySource`


   MOLA (Mars) altimetry source.

   Parses a MOLA PEDR CSV from the ODE GDS, using the PLANET_RAD column to
   compute height above the IAU Mars sphere (3,396,190 m):
   ``height = PLANET_RAD - 3,396,190``. This is the same reference as ASP
   DEMs, so dh = MOLA − DEM is directly meaningful at all latitudes.


   .. py:method:: load_planetary_csv(csv_path)

      Parse a MOLA PEDR CSV into ``self.planetary_points``.

      TOPOGRAPHY (in ``*_topo_csv.csv``) is referenced to the MOLA oblate
      areoid and produces a latitude-dependent offset of up to ~10 km against
      an ASP DEM, so it is rejected here. Pass the ``*_pts_csv.csv`` from the
      ODE GDS download instead — it carries PLANET_RAD.

      :param csv_path: Path to a MOLA PEDR CSV from the ODE GDS API. Must include
                       a ``PLANET_RAD`` column (use the ``*_pts_csv.csv`` file).
      :type csv_path: str



   .. py:attribute:: instrument
      :value: 'MOLA'



.. py:class:: PlanetarySource(alt)

   Bases: :py:obj:`asp_plot.altimetry_source.AltimetrySource`


   Body-agnostic planetary altimetry against an ASP DEM.

   Holds the machinery shared by every planetary instrument: sampling the DEM
   at the loaded points, differencing, outlier filtering, and exporting a
   pc_align-ready CSV. The CSV *loader* is body-specific and lives in the
   :class:`LolaSource` (Moon) and :class:`MolaSource` (Mars) subclasses; the
   coordinator instantiates the right one from the DEM's body. The base
   :meth:`load_planetary_csv` raises, so an Earth DEM that reaches here is
   pointed back at ICESat-2.

   :param alt: The coordinating :class:`asp_plot.altimetry.Altimetry` instance.
               Cross-cutting paths (``dem_fn``, ``directory``, ``aligned_dem_fn``)
               are read from it so a single source of truth describes the DEM
               under analysis.
   :type alt: Altimetry


   .. py:method:: load_planetary_csv(csv_path)

      Load a planetary altimetry CSV (overridden per body).

      The base implementation raises: only :class:`LolaSource` and
      :class:`MolaSource` know how to parse a GDS CSV. The CSV is obtained
      via the ``request_planetary_altimetry`` CLI tool, which submits an
      async query to the ODE GDS API and emails the user a download link;
      the user downloads and unzips the result, then passes the
      ``*_topo_csv.csv`` / ``*_pts_csv.csv`` file to the body source.

      :param csv_path: Path to a CSV file from the ODE GDS.
      :type csv_path: str



   .. py:method:: planetary_to_dem_dh(n_sigma=3)

      Compute height differences between planetary altimetry and DEM.

      Reprojects ``self.planetary_points`` to the DEM CRS, interpolates
      DEM heights at altimetry locations, and computes the difference
      ``altimetry_minus_dem = height - dem_height``. When
      ``aligned_dem_fn`` is set, also populates ``aligned_dem_height``
      and ``altimetry_minus_aligned_dem`` so pre/post-alignment plots can
      share a single sample. Outliers beyond ``n_sigma`` × std from the
      mean (computed on the unaligned dh) are removed by default.

      :param n_sigma: Remove dh outliers beyond this many standard deviations from
                      the mean. Default 3. Pass None to skip outlier filtering.
      :type n_sigma: float or None, optional
      :param The results are stored as new columns on ``self.planetary_points``.:



   .. py:method:: to_csv_for_pc_align_planetary(filename_prefix='planetary_for_pc_align')

      Export ``self.planetary_points`` to a CSV for pc_align.

      Writes columns ``lon, lat, radius_m`` (planetary radius from the
      body center, in meters). Used as the ``planetary_csv`` argument
      to :meth:`asp_plot.alignment.Alignment.pc_align_dem_to_planetary_csv`.

      :param filename_prefix: Prefix for the output CSV filename. Saved in
                              ``self.alt.directory``.
      :type filename_prefix: str, optional

      :returns: Absolute path to the created CSV file.
      :rtype: str



   .. py:attribute:: instrument
      :value: None



   .. py:attribute:: planetary_points
      :value: None



.. py:function:: gds_query_async(query_type, bounds, results_code, email=None, **extra_params)

   Submit an async query to the ODE GDS REST API.

   :param query_type: GDS query type, e.g. ``"lolardr"`` or ``"molapedr"``.
   :type query_type: str
   :param bounds: Dictionary with ``westernlon``, ``easternlon``, ``minlat``,
                  ``maxlat`` keys.
   :type bounds: dict
   :param results_code: GDS results format code (e.g. ``"u"`` for LOLA, ``"v"`` for MOLA).
   :type results_code: str
   :param email: Email for notification when query finishes.
   :type email: str or None, optional
   :param \*\*extra_params: Additional GDS query parameters (e.g. ``channel="ttttt"``).

   :returns: Job ID for polling.
   :rtype: str


.. py:data:: GDS_BASE_URL
   :value: 'https://oderest.rsl.wustl.edu/livegds'


.. py:data:: MARS_IAU_SPHERE_RADIUS

.. py:data:: MOON_IAU_SPHERE_RADIUS

.. py:data:: logger

