yippy.offax
===========

.. py:module:: yippy.offax

.. autoapi-nested-parse::

   Base class for all offax_psfs.fits files.

   This has been deprecated. Please use OffJAX instead.



Classes
-------

.. autoapisummary::

   yippy.offax.OffAx


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

.. py:class:: OffAx(yip_dir, offax_data_file, offax_offsets_file, pixel_scale_arcsec, x_symmetric, y_symmetric, downsample_shape = None)

   Base class for off-axis PSF handling.

   Handles YIP data loading, offset parsing, and symmetry detection.
   ``OffJAX`` inherits from this class and overrides ``create_psf`` /
   ``create_psfs`` with JAX-accelerated implementations.

   The pure-Python ``create_psf`` and ``create_psfs`` methods on this class
   are retained as a reference implementation but are not used in production.
   All ``Coronagraph`` instances now use ``OffJAX`` exclusively.

   This class loads and processes PSF data from the yield input package (YIP).
   It currently supports oneD and quarter symmetric PSF YIPs. The primary use
   is to interpolate the PSF data to a given x/y position. This is done by
   calling the OffAx object with the x/y position as arguments, which itself
   calls the psf object after converting units.

   Attributes:
       pixel_scale_arcsec (Quantity):
           Pixel scale of the PSF data in lambda/D.
       center_x (Quantity):
           Central x position in the PSF data.
       center_y (Quantity):
           Central y position in the PSF data.
       psf:
           Instance of the appropriate PSF class (e.g., OneD, TwoD) based on input YIP.

   Args:
       yip_dir (Path):
           Path to the directory containing PSF and offset data.
       logger (Logger):
           Logger for logging events and information.
       offax_data_file (str):
           Name of the file containing the PSF data.
       offax_offsets_file (str):
           Name of the file containing the offsets data.
       pixel_scale_arcsec (Quantity):
           Pixel scale of the PSF data in lambda/D.


   .. py:attribute:: pixel_scale_arcsec


   .. py:attribute:: x_symmetric


   .. py:attribute:: y_symmetric


   .. py:attribute:: center_x


   .. py:attribute:: center_y


   .. py:attribute:: max_offset_in_image


   .. py:attribute:: flat_psfs
      :value: None



   .. py:attribute:: flat_offsets
      :value: None



   .. py:attribute:: n_psfs


   .. py:attribute:: x_inds


   .. py:attribute:: y_inds


   .. py:attribute:: offset_to_flat_idx


   .. py:attribute:: x_offsets


   .. py:attribute:: y_offsets


   .. py:attribute:: x_range


   .. py:attribute:: y_range


   .. py:attribute:: psf_shape


   .. py:method:: get_psf_by_offset_idx(x_idx, y_idx)

      Get PSF at the given offset indices.

      Args:
          x_idx (int):
              Index into x_offsets array.
          y_idx (int):
              Index into y_offsets array.

      Returns:
          np.ndarray:
              The PSF at the given offset indices, or None if no PSF exists
              at that combination.



   .. py:method:: create_psf(x, y)

      Create and return the PSF at the specified off-axis position.

      .. deprecated::
          The pure-Python implementation is deprecated.  Use
          ``Coronagraph`` (which uses ``OffJAX``) instead.

      Interpolates and returns the Point Spread Function (PSF) at the specified
      off-axis position (x, y). If the exact (x, y) position matches one of the
      PSFs in the YIP, that PSF is returned directly. Otherwise, the PSFs
      from the surrounding positions are combined using Gaussian weighting and
      Fourier interpolation to produce an interpolated PSF.

      Args:
          x (float):
              The x-coordinate of the off-axis position.
          y (float):
              The y-coordinate of the off-axis position.

      Returns:
          np.ndarray:
              The interpolated PSF corresponding to the input (x, y) position.

      Notes:
          - If `self.type` is "1d", the (x, y) position is converted to a
          radial separation and angle for interpolation.
          - If `self.type` is "2dq", the (x, y) position is mirrored to the
          first quadrant, and the PSF is flipped accordingly after
          interpolation.
          - Gaussian weighting is used to combine the nearest PSFs when the
          exact (x, y) position does not match any precomputed PSF. The
          weighting is based on the distance from the input position.
          - The PSFs are shifted to align with the input position before
          combining, and the final PSF is normalized by the cumulative weight
          for each pixel.




   .. py:method:: create_psfs(x, y)

      Create and return the PSFs at the specified off-axis positions.

      .. deprecated::
          The pure-Python implementation is deprecated.  Use
          ``Coronagraph`` (which uses ``OffJAX``) instead.



   .. py:method:: create_psfs_parallel(x, y, lam=None, D=None, dist=None, workers = 4)

      Compute PSFs for batches of (x, y) arrays using multiprocessing.

      .. deprecated::
          The pure-Python implementation is deprecated.  Use
          ``Coronagraph`` (which uses ``OffJAX``) instead.

      Args:
          x (np.ndarray):
              Array of x positions.
          y (np.ndarray):
              Array of y positions.
          lam (astropy.units.Quantity):
              Wavelength of the observation
          D (astropy.units.Quantity):
              Diameter of the telescope
          dist (astropy.units.Quantity):
              Distance to the system
          workers (int):
              Number of parallel processes to use.

      Returns:
          np.ndarray:
              A stacked numpy array of the computed PSFs with shape (N,
              height, width), where N = len(x).



   .. py:method:: __call__(x, y, lam=None, D=None, dist=None)

      Return the PSF at the given x/y position.

      This function (via util.convert_to_lod) has the following assumptions
      on the x/y values provided:
          - If units are pixels, they follow the 00LL convention. As in the
            (0,0) point is the lower left corner of the image.
          - If the x/y values are in lambda/D, angular, or length units the
            (0,0) point is the center of the image, where the star is
            (hopefully) located.

      Args:
          x (astropy.units.Quantity):
              x position. Can be either units of pixel, lod, an angular
              unit (e.g. arcsec), or a length unit (e.g. AU)
          y (astropy.units.Quantity):
              y position. Can be either units of pixel, lod, an angular
              unit (e.g. arcsec), or a length unit (e.g. AU)
          lam (astropy.units.Quantity):
              Wavelength of the observation
          D (astropy.units.Quantity):
              Diameter of the telescope
          dist (astropy.units.Quantity):
              Distance to the system

      Returns:
          NDArray:
              The PSF at the given x/y position



