petitRADTRANS.synthetic_photometry
==================================

.. py:module:: petitRADTRANS.synthetic_photometry

.. autoapi-nested-parse::

   Module for downloading filter data from the website
   of the SVO Filter Profile Service. Reimplemented from
   species: https://github.com/tomasstolker/species to
   avoid circular dependencies between species and petitRADTRANS.



Classes
-------

.. autoapisummary::

   petitRADTRANS.synthetic_photometry.ReadFilter
   petitRADTRANS.synthetic_photometry.SyntheticPhotometry


Functions
---------

.. autoapisummary::

   petitRADTRANS.synthetic_photometry._db_lock
   petitRADTRANS.synthetic_photometry.add_vega
   petitRADTRANS.synthetic_photometry.add_filter_profile
   petitRADTRANS.synthetic_photometry.download_filter


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

.. py:function:: _db_lock(database_path: str) -> filelock.FileLock

.. py:class:: ReadFilter(filter_name: str)

   Class for reading a filter profile from the database.


   .. py:attribute:: filter_name


   .. py:attribute:: database


   .. py:attribute:: data_folder


   .. py:attribute:: vega_mag


   .. py:method:: get_filter() -> numpy.ndarray

      Select a filter profile from the database.

      Returns
      -------
      np.ndarray
          Array with the wavelengths and filter transmission. The
          array has 2 dimensions with the shape (n_wavelengths, 2).



   .. py:method:: interpolate_filter() -> scipy.interpolate.interp1d

      Interpolate a filter profile with the `interp1d <https://
      docs.scipy.org/doc/scipy/reference/generated/
      scipy.interpolate.interp1d.html>`_ function from
      ``scipy.interpolate`` and linear kind of interpolation.

      Returns
      -------
      scipy.interpolate.interp1d
          Linearly interpolated filter profile.



   .. py:method:: wavelength_range() -> Tuple[Union[numpy.float32, numpy.float64], Union[numpy.float32, numpy.float64]]

      Extract the wavelength range of the filter profile.

      Returns
      -------
      float
          Minimum wavelength (:math:`\mu\mathrm{m}`).
      float
          Maximum wavelength (:math:`\mu\mathrm{m}`).



   .. py:method:: mean_wavelength() -> Union[numpy.float32, numpy.float64]

      Calculate the weighted mean wavelength of the filter profile.

      Returns
      -------
      float
          Mean wavelength (:math:`\mu\mathrm{m}`).



   .. py:method:: effective_wavelength() -> Union[numpy.float32, numpy.float64]

      Calculate the effective wavelength of the filter profile.
      The effective wavelength is calculated as the weighted
      average based on the filter profile and the spectrum of Vega.

      Returns
      -------
      float
          Effective wavelength (:math:`\mu\mathrm{m}`).



   .. py:method:: filter_fwhm() -> Optional[float]

      Calculate the full width at half maximum (FWHM)
      of the filter profile.

      Returns
      -------
      float, None
          Full width at half maximum (:math:`\mu\mathrm{m}`).
          Returns ``None`` if the filter has only one wavelength.
          with a non-zero transmission.



   .. py:method:: effective_width() -> Union[numpy.float32, numpy.float64]

      Calculate the effective width of the filter profile. The
      effective width is equivalent to the horizontal size of a
      rectangle with height equal to the maximum transmission and
      with the same area as the one covered by the filter profile.

      Returns
      -------
      float
          Effective width (:math:`\mu\mathrm{m}`).



   .. py:method:: detector_type() -> str

      Return the detector type.

      Returns
      -------
      str
          Detector type ('energy' or 'photon').



.. py:class:: SyntheticPhotometry(filter_name: str, zero_point: Optional[float] = None)

   Class for calculating synthetic photometry from a spectrum and also
   for converting between magnitudes and fluxes. Any filter from the
   `SVO Filter Profile Service <http://svo2.cab.inta-csic.es/svo/
   theory/fps/>`_ will be automatically downloaded and added to the
   database. Also the detector type (energy- or photon-counting) will
   be fetched. For a photon-counting detector, an additional
   wavelength factor is included in the integral for calculating the
   synthetic photometry, although typically the impact of the factor
   on the calculated flux is negligible. It is also important to note
   that by default the magnitude of Vega is set to 0.03 for all
   filters. The value can be adjusted in the `configuration file
   <https://species.readthedocs.io/en/latest/configuration.html>`_.


   .. py:attribute:: filter_name


   .. py:attribute:: zero_point
      :value: None



   .. py:attribute:: filter_interp
      :value: None



   .. py:attribute:: wavel_range
      :value: None



   .. py:attribute:: database


   .. py:attribute:: data_folder


   .. py:attribute:: vega_mag


   .. py:attribute:: det_type


   .. py:method:: calc_zero_point() -> Union[float, numpy.float64]

      Internal function for calculating the zero point of the
      provided ``filter_name``. The zero point is here defined
      as the flux of Vega, which by default is set to a
      magnitude of 0.03 for all filters.

      Returns
      -------
      float
          Zero-point flux (:math:`\mathrm{W}`
          :math:`\mathrm{m}^{-2}` :math:`\mu\mathrm{m}^{-1}`).



   .. py:method:: spectrum_to_flux(wavelength: numpy.ndarray, flux: numpy.ndarray, error: Optional[numpy.ndarray] = None, threshold: Optional[float] = 0.01) -> Tuple[Union[float, numpy.float32, numpy.float64], Optional[Union[float, numpy.float32, numpy.float64]]]

      Function for calculating the average flux from a spectrum and
      a filter profile. The uncertainty is propagated by sampling
      200 random values from the error distributions.

      Parameters
      ----------
      wavelength : np.ndarray
          Wavelength points (um).
      flux : np.ndarray
          Flux (:math:`\mathrm{W}` :math:`\mathrm{m}^{-2}`
          :math:`\mu\mathrm{m}^{-1}`).
      error : np.ndarray, None
          Uncertainty (:math:`\mathrm{W}` :math:`\mathrm{m}^{-2}`
          :math:`\mu\mathrm{m}^{-1}`). Not used if set to ``None``.
      threshold : float, None
          Transmission threshold (value between 0 and 1). If the
          minimum transmission value is larger than the threshold,
          a NaN is returned. This will happen if the input spectrum
          does not cover the full wavelength range of the filter
          profile. The parameter is not used if set to ``None``
          (default: 0.01).

      Returns
      -------
      float
          Average flux (:math:`\mathrm{W}` :math:`\mathrm{m}^{-2}`
          :math:`\mu\mathrm{m}^{-1}`).
      float, None
          Uncertainty (:math:`\mathrm{W}` :math:`\mathrm{m}^{-2}`
          :math:`\mu\mathrm{m}^{-1}`).



.. py:function:: add_vega(input_path: str, database: h5py._hl.files.File) -> None

   Function for adding a flux-calibrated spectrum of Vega to the
   database. The latest spectrum (alpha_lyr_stis_011.fits) is
   downloaded from the STScI archive (see `CALSPEC page <https://
   www.stsci.edu/hst/instrumentation/reference-data-for-calibration
   -and-tools/astronomical-catalogs/calspec>`_ for details).

   Parameters
   ----------
   input_path : str
       Path of the data folder.
   database : h5py._hl.files.File
       Database.

   Returns
   -------
   NoneType
       None


.. py:function:: add_filter_profile(input_path: str, database: h5py._hl.files.File, filter_name: str) -> None

   Function for downloading and adding a filter profile
   to the HDF5 database.

   Parameters
   ----------
   input_path : str
       Folder where the data is located.
   database : h5py._hl.files.File
       Database.
   filter_name : str
       Filter name from the SVO Filter Profile Service (e.g.,
       'Paranal/NACO.Lp') or a user-defined name if a ``filename``
       is specified.

   Returns
   -------
   None
       NoneType


.. py:function:: download_filter(filter_id: str, input_path: str) -> Tuple[Optional[numpy.ndarray], Optional[numpy.ndarray], Optional[str]]

   Function for downloading filter profile data
   from the SVO Filter Profile Service.

   Parameters
   ----------
   filter_id : str
       Filter name as listed on the website of the `SVO
       Filter Profile Service
       <http://svo2.cab.inta-csic.es/svo/theory/fps/>`_.
   input_path : str
       Folder where the data is located.

   Returns
   -------
   np.ndarray
       Wavelength (um).
   np.ndarray
       Fractional transmission.
   str
       Detector type ('energy' or 'photon').


