spotter.star
============

.. py:module:: spotter.star

.. autoapi-nested-parse::

   Star object and related utilities for HEALPix-based stellar surface modeling.

   Defines the Star class, which encapsulates a HEALPix map, limb darkening,
   orientation, and physical properties. Includes visualization and transit utilities.



Classes
-------

.. autoapisummary::

   spotter.star.Star


Functions
---------

.. autoapisummary::

   spotter.star.show
   spotter.star.video
   spotter.star.transited_star


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

.. py:class:: Star(y: jax.typing.ArrayLike | None = None, u: jax.typing.ArrayLike | None = None, inc: float | None = None, obl: float | None = None, period: float | None = None, radius: float | None = None, wv: float | None = None)

   Bases: :py:obj:`equinox.Module`


   A Star object whose surface is described by HEALPix map(s).

   The HEALPix maps can be a 2D array with a shape of (wavelengths, pixels), or a
   1D array with a shape of (pixels).

   When providing polynomial limb darkening coefficients, different options are possible:

   * u is 1D and y is 1D: Single set of limb darkening coefficients and a single map.
   * u is 1D and y is 2D: The same limb darkening coefficients are applied to all wavelength maps.
   * u is 2D and y is 1D: The limb darkening coefficients are different for each wavelength but the map is the same.
   * ``u.shape[0]`` == ``y.shape[0]``: u and y are 2D arrays specifying the limb darkening coeffs and maps for each wavelength.

   :param y: HEALPix map of the star, with shape (pixels,) or (wavelengths, pixels). Must be provided.
   :type y: ArrayLike or None, optional
   :param u: Polynomial limb darkening coefficients with shape (order,) or (wavelengths, order). By default None.
             If provided, must either be coefficients applied to all wavelengths, or have the same length as y
             (i.e. defined for the same number of wavelengths).
   :type u: ArrayLike or None, optional
   :param inc: Inclination of the star, in radians. 0 is pole-on, pi/2 is equator-on. By default None.
   :type inc: float or None, optional
   :param obl: Obliquity of the star, in radians. 0 is no obliquity, pi/2 is maximum obliquity. By default None.
   :type obl: float or None, optional
   :param period: Period of the star, in days. By default None.
   :type period: float or None, optional
   :param radius: Radius of the star, in solar radii. By default None.
   :type radius: float or None, optional
   :param wv: Wavelength of the star maps, in meters. By default None. If provided, must be compatible with either
              the shape of u and/or y.
   :type wv: float or None, optional

   .. attribute:: y

      HEALPix map of the star, with shape (wavelengths, pixels).

      :type: ArrayLike

   .. attribute:: u

      Polynomial limb darkening coefficients with shape (wavelengths, order).

      :type: ArrayLike or None

   .. attribute:: period

      Period of the star, in days.

      :type: float or None

   .. attribute:: inc

      Inclination of the star, in radians. 0 is pole-on, pi/2 is equator-on.

      :type: float or None

   .. attribute:: obl

      Obliquity of the star, in radians. 0 is no obliquity, pi/2 is maximum obliquity.

      :type: float or None

   .. attribute:: radius

      Radius of the star, in solar radii.

      :type: float or None

   .. attribute:: wv

      Wavelength of the star maps, in meters.

      :type: float or None

   .. attribute:: sides

      Number of HEALPix sides.

      :type: int

   .. rubric:: Examples

   .. plot::

       import numpy as np
       from spotter.star import Star, show

       star = Star.from_sides(30, inc=0.5, u=(0.4, 0.3), obl=0.5)
       show(star)


   .. py:attribute:: y
      :type:  jax.typing.ArrayLike

      HEALPix map of the star, with shape (wavelengths, pixels).


   .. py:attribute:: u
      :type:  jax.typing.ArrayLike | None
      :value: None


      Polynomial limb darkening coefficients with shape (wavelengths, order).


   .. py:attribute:: period
      :type:  float | None
      :value: None


      Period of the star, in days.


   .. py:attribute:: inc
      :type:  float | None
      :value: None


      Inclination of the star, in radians. 0 is pole-on, pi/2 is equator-on.


   .. py:attribute:: obl
      :type:  float | None
      :value: None


      Obliquity of the star, in radians. 0 is no obliquity, pi/2 is maximum obliquity.


   .. py:attribute:: radius
      :type:  float | None
      :value: None


      Radius of the star, in solar radii.


   .. py:attribute:: wv
      :type:  float | None
      :value: None


      Wavelength of the star maps, in meters.


   .. py:attribute:: sides
      :type:  int

      Number of HEALPix sides.


   .. py:property:: N
      Return the number of sides of the star map.


   .. py:property:: x
      Return the xyz coordinates of the star pixels.


   .. py:property:: size
      Return the number of pixels in the star map.


   .. py:property:: resolution
      Return the approximate size of a single map pixel in radians.


   .. py:method:: __getitem__(key)

      Return a new Star with selected wavelength(s).

      :param key: Index or indices to select.
      :type key: int, slice, or array_like

      :returns: New Star object with selected map(s).
      :rtype: Star



   .. py:method:: from_sides(sides: int, **kwargs)
      :classmethod:


      Create a Star object with a given number of sides.

      :param sides: Number of sides of the HEALPix map.
      :type sides: int
      :param \*\*kwargs: Additional keyword arguments for Star.

      :returns: Star object with the given number of sides.
      :rtype: Star



   .. py:method:: phase(time: jax.typing.ArrayLike | None) -> jax.typing.ArrayLike

      Compute the rotation phase for a given time.

      :param time: Time(s) in days.
      :type time: array_like or None

      :returns: **phase** -- Rotation phase(s) in radians.
      :rtype: float or array_like



   .. py:method:: __mul__(other)

      Multiply the star map by another Star or scalar.

      :param other: Object to multiply with.
      :type other: Star or scalar

      :returns: Resulting Star object.
      :rtype: Star



   .. py:method:: __rmul__(other)

      Multiply the star map by another Star or scalar (right-mult).

      :param other: Object to multiply with.
      :type other: Star or scalar

      :returns: Resulting Star object.
      :rtype: Star



   .. py:method:: __add__(other)

      Add another Star or scalar to the star map.

      :param other: Object to add.
      :type other: Star or scalar

      :returns: Resulting Star object.
      :rtype: Star



   .. py:method:: __radd__(other)

      Add another Star or scalar to the star map (right-add).

      :param other: Object to add.
      :type other: Star or scalar

      :returns: Resulting Star object.
      :rtype: Star



   .. py:method:: __sub__(other)

      Subtract another Star or scalar from the star map.

      :param other: Object to subtract.
      :type other: Star or scalar

      :returns: Resulting Star object.
      :rtype: Star



   .. py:method:: __rsub__(other)

      Subtract the star map from another Star or scalar (right-sub).

      :param other: Object to subtract from.
      :type other: Star or scalar

      :returns: Resulting Star object.
      :rtype: Star



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

      Return a Star object with updated attributes.

      :param \*\*kwargs: Attributes to update.

      :returns: Star object with updated attributes.
      :rtype: Star



   .. py:method:: spot(lat: float, lon: float, radius: float, sharpness: float = 20)

      Return a HEALPix map with a spot.

      :param lat: Latitude of the spot, in radians.
      :type lat: float
      :param lon: Longitude of the spot, in radians.
      :type lon: float
      :param radius: Radius of the spot, in radians.
      :type radius: float
      :param sharpness: Sharpness of the spot edge (default 20).
      :type sharpness: float, optional

      :returns: HEALPix map with a spot.
      :rtype: ArrayLike



   .. py:property:: coords
      Return the coordinates of the star pixels.

      :returns: **coords** -- Cartesian coordinates of pixels.
      :rtype: ndarray


.. py:function:: show(star: Star, phase: jax.typing.ArrayLike = 0.0, ax=None, xsize=800, rv=False, **kwargs)

   Show the star map. If `star.y` is 2D, the first map is shown.

   :param star: Star object to show.
   :type star: Star
   :param phase: Phase of the star map to show (default 0.0).
   :type phase: ArrayLike, optional
   :param ax: Axis to plot the star map (default None).
   :type ax: matplotlib axis, optional
   :param xsize: Output image size (default 800).
   :type xsize: int, optional
   :param \*\*kwargs: Additional keyword arguments for viz.show.


.. py:function:: video(star: Star, duration: int = 4, fps: int = 10, rv=False, **kwargs)

   Create an HTML video of the star map (for Jupyter notebooks).

   :param star: Star object to show.
   :type star: Star
   :param duration: Duration of the video in seconds (default 4).
   :type duration: int, optional
   :param fps: Frames per second (default 10).
   :type fps: int, optional
   :param \*\*kwargs: Additional keyword arguments for viz.video.


.. py:function:: transited_star(star: Star, x: float = 0.0, y: float = 0.0, z: float = 0.0, r: float = 0.0, time: float = None)

   Return a star transited by a circular opaque disk.

   :param star: Star object to be transited.
   :type star: Star
   :param x: x coordinate of the disk center (default 0.0).
   :type x: float, optional
   :param y: y coordinate of the disk center (default 0.0).
   :type y: float, optional
   :param z: z coordinate of the disk center (default 0.0).
   :type z: float, optional
   :param r: Radius of the disk (default 0.0).
   :type r: float, optional
   :param time: Time in days (default None).
   :type time: float, optional

   :returns: Star object transited by the disk.
   :rtype: Star


