petitRADTRANS.physics
=====================

.. py:module:: petitRADTRANS.physics

.. autoapi-nested-parse::

   Stores useful physical functions.



Functions
---------

.. autoapisummary::

   petitRADTRANS.physics.calculate_distance_from_luminosity
   petitRADTRANS.physics.compute_effective_temperature
   petitRADTRANS.physics.doppler_shift
   petitRADTRANS.physics.flux_cm2flux_hz
   petitRADTRANS.physics.flux_hz2flux_cm
   petitRADTRANS.physics.flux2irradiance
   petitRADTRANS.physics.frequency2wavelength
   petitRADTRANS.physics.hz2um
   petitRADTRANS.physics.ism_extinction
   petitRADTRANS.physics.apply_ism_ext
   petitRADTRANS.physics.planck_function_cm
   petitRADTRANS.physics.planck_function_hz
   petitRADTRANS.physics.planck_function_hz_temperature_derivative
   petitRADTRANS.physics.shift_wavelengths_by_radial_velocity
   petitRADTRANS.physics.um2hz
   petitRADTRANS.physics.wavelength2frequency


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

.. py:function:: calculate_distance_from_luminosity(t_irr, dist, t_star, r_star, mode, mode_what)

.. py:function:: compute_effective_temperature(wavelengths: jax.typing.ArrayLike, flux: jax.typing.ArrayLike, orbit_semi_major_axis: float = 1.0, planet_radius: float = 1.0, use_si_units: bool = False) -> float

   Calculates the effective temperature by integrating the model and using the stefan boltzmann law.

   Args:
       wavelengths : numpy.ndarray
           Wavelength grid
       flux : numpy.ndarray
           Flux density grid
       orbit_semi_major_axis : Optional(float)
           Distance to the object. Must have same units as planet_radius
       planet_radius : Optional(float)
           Object radius. Must have same units as orbit_semi_major_axis
       use_si_units : Optional(bool)
           If the flux is in W/m2/micron, this should be true


.. py:function:: doppler_shift(wavelength_0: [jax.typing.ArrayLike, float], velocity: [jax.typing.ArrayLike, float]) -> [jax.Array, float]

   Calculate the Doppler-shifted wavelength for electromagnetic waves.

   A negative velocity means that the source is going toward the observer. A positive velocity means the source is
   going away from the observer.

   Args:
       wavelength_0: (cm) wavelength of the wave in the referential of the source
       velocity: (cm.s-1) velocity of the source relative to the observer

   Returns:
       (cm) the wavelength of the source as measured by the observer


.. py:function:: flux_cm2flux_hz(flux_cm: [jax.typing.ArrayLike, float], wavelength: [jax.typing.ArrayLike, float]) -> [jax.Array, float]

   Convert a flux from [flux units]/cm to [flux units]/Hz at a given wavelength.
   Flux units can be, e.g., erg.s-1.cm-2.

   Steps:
       [cm] = c[cm.s-1] / [Hz]
       => d[cm]/d[Hz] = d(c / [Hz])/d[Hz]
       => d[cm]/d[Hz] = c / [Hz]**2
       integral of flux must be conserved: flux_cm * d[cm] = flux_hz * d[Hz]
       flux_hz = flux_cm * d[cm]/d[Hz]
       => flux_hz = flux_cm * wavelength**2 / c

   Args:
       flux_cm: ([flux units]/cm)
       wavelength: (cm)

   Returns:
       ([flux units]/Hz) the radiosity in converted units


.. py:function:: flux_hz2flux_cm(flux_hz: [jax.typing.ArrayLike, float], frequency: [jax.typing.ArrayLike, float]) -> [jax.Array, float]

   Convert a flux from [flux units]/Hz to [flux units]/cm at a given frequency.
   Flux units can be, e.g., erg.s-1.cm-2.

   Steps:
       [cm] = c[cm.s-1] / [Hz]
       => d[cm]/d[Hz] = d(c / [Hz])/d[Hz]
       => d[cm]/d[Hz] = c / [Hz]**2
       => d[Hz]/d[cm] = [Hz]**2 / c
       integral of flux must be conserved: flux_cm * d[cm] = flux_hz * d[Hz]
       flux_cm = flux_hz * d[Hz]/d[cm]
       => flux_cm = flux_hz * frequency**2 / c

   Args:
       flux_hz: (erg.s-1.cm-2.sr-1/Hz)
       frequency: (Hz)

   Returns:
       (erg.s-1.cm-2.sr-1/cm) the radiosity in converted units


.. py:function:: flux2irradiance(flux: [jax.typing.ArrayLike, float], source_radius: float, target_distance: float) -> [jax.Array, float]

   Calculate the spectral irradiance of a spherical source on a target from its flux (spectral radiosity).

   Args:
       flux: (M.L-1.T-3) flux of the source
       source_radius: (L) radius of the spherical source
       target_distance: (L) distance from the source to the target

   Returns:
       The irradiance of the source on the target (M.L-1.T-3).


.. py:function:: frequency2wavelength(frequency: [jax.typing.ArrayLike, float]) -> [jax.Array, float]

   Convert frequencies into wavelength in centimeter.

   Args:
       frequency: frequency: (Hz) the frequency to convert

   Returns:
       (cm) the corresponding wavelengths


.. py:function:: hz2um(frequency: [jax.typing.ArrayLike, float]) -> [jax.Array, float]

   Convert frequencies into wavelengths in micrometer.

   Args:
       frequency: (Hz) the frequency to convert

   Returns:
       (um) the corresponding wavelengths


.. py:function:: ism_extinction(av_mag, rv_red, wavelengths)

   Function for calculating the optical and IR extinction
   with the empirical relation from `Cardelli et al. (1989)
   <https://ui.adsabs.harvard.edu/abs/1989ApJ...345..245C/abstract>`_.
   Reimplemented from species.utils.dust_utils to avoid circular
   dependencies.

   Parameters
   ----------
   av_mag : float
       Extinction (mag) in the $V$ band.
   rv_red : float
       Reddening in the $V$ band, ``R_V = A_V / E(B-V)``.
   wavelengths : np.ndarray, list(float), float
       Array or list with the wavelengths (um) for which
       the extinction is calculated. It is also possible
       to provide a single value as float.

   Returns
   -------
   np.ndarray
       Extinction (mag) at ``wavelengths``.


.. py:function:: apply_ism_ext(wavelengths, flux, v_band_ext, v_band_red)

   Function for applying ISM extinction to a spectrum.
   Reimplemented from species.utils.dust_utils to avoid circular
   dependencies.

   wavelengths : jnp.ndarray
       Wavelengths (um) of the spectrum.
   flux : jnp.ndarray
       Fluxes (W m-2 um-1) of the spectrum.
   v_band_ext : float
       Extinction (mag) in the $V$ band.
   v_band_red : float
       Reddening in the $V$ band.

   Returns
   -------
   jnp.ndarray
       Fluxes (W m-2 um-1) with the extinction applied.


.. py:function:: planck_function_cm(temperature: float, wavelength: [jax.typing.ArrayLike, float]) -> [jax.Array, float]

   Returns the Planck function :math:`B_{\lambda}(T)` in units of
   :math:`\rm erg/s/cm^2/cm/steradian`.

   Args:
       temperature (float):
           Temperature in K.
       wavelength:
           Array containing the wavelength in cm.


.. py:function:: planck_function_hz(temperature: float, frequency: [jax.typing.ArrayLike, float]) -> [jax.Array, float]

   Returns the Planck function :math:`B_{\nu}(T)` in units of
   :math:`\rm erg/s/cm^2/Hz/steradian`.

   Args:
       temperature (float):
           Temperature in K.
       frequency:
           Array containing the frequency in Hz.


.. py:function:: planck_function_hz_temperature_derivative(temperature: float, frequency: [jax.typing.ArrayLike, float]) -> [jax.Array, float]

   Returns the derivative of the Planck function with respect to the temperature in units of
   :math:`\rm erg/s/cm^2/Hz/steradian`.

   Args:
       temperature:
           Temperature in K.
       frequency:
           Array containing the frequency in Hz.
   Returns:



.. py:function:: shift_wavelengths_by_radial_velocity(radial_velocity)

.. py:function:: um2hz(wavelength: [jax.typing.ArrayLike, float]) -> [jax.Array, float]

   Convert wavelengths in micrometer into frequencies.

   Args:
       wavelength: (um) the wavelengths to convert

   Returns:
       (Hz) the corresponding frequencies


.. py:function:: wavelength2frequency(wavelength: [jax.typing.ArrayLike, float]) -> [jax.Array, float]

   Convert wavelengths in centimeter to frequencies.

   Args:
       wavelength: (cm) the wavelengths to convert

   Returns:
       (Hz) the converted frequencies


