petitRADTRANS.__file_conversion
===============================

.. py:module:: petitRADTRANS.__file_conversion

.. autoapi-nested-parse::

   Stores functions that convert files from a format to another.

   The functions in this module are stored for the sake of keeping trace of changes made to files. They are intended to be
   used only once.



Attributes
----------

.. autoapisummary::

   petitRADTRANS.__file_conversion.prt_emcee_mode
   petitRADTRANS.__file_conversion.load_mpi
   petitRADTRANS.__file_conversion.load_mpi
   petitRADTRANS.__file_conversion.MPI
   petitRADTRANS.__file_conversion.rank
   petitRADTRANS.__file_conversion.comm
   petitRADTRANS.__file_conversion.comm


Functions
---------

.. autoapisummary::

   petitRADTRANS.__file_conversion.__get_prt2_input_data_subpaths
   petitRADTRANS.__file_conversion.__remove_files
   petitRADTRANS.__file_conversion._clean_input_data_mac_junk_files
   petitRADTRANS.__file_conversion.__print_missing_data_file_message
   petitRADTRANS.__file_conversion.__print_skipping_message
   petitRADTRANS.__file_conversion._chemical_table_dat2h5
   petitRADTRANS.__file_conversion._continuum_cia_dat2h5
   petitRADTRANS.__file_conversion._continuum_clouds_opacities_dat2h5
   petitRADTRANS.__file_conversion._correlated_k_opacities_dat2h5
   petitRADTRANS.__file_conversion._correlated_k_opacities_dat2h5_external_species
   petitRADTRANS.__file_conversion._get_base_cia_names
   petitRADTRANS.__file_conversion._get_base_cloud_names
   petitRADTRANS.__file_conversion._get_base_correlated_k_names
   petitRADTRANS.__file_conversion._get_base_line_by_line_names
   petitRADTRANS.__file_conversion._get_default_rebinning_wavelength_range
   petitRADTRANS.__file_conversion._get_prt2_cia_names
   petitRADTRANS.__file_conversion._get_prt2_cloud_names
   petitRADTRANS.__file_conversion._get_prt2_correlated_k_names
   petitRADTRANS.__file_conversion._get_prt2_line_by_line_names
   petitRADTRANS.__file_conversion._line_by_line_opacities_dat2h5
   petitRADTRANS.__file_conversion._phoenix_spec_dat2h5
   petitRADTRANS.__file_conversion._refactor_input_data_folder
   petitRADTRANS.__file_conversion._sort_pressure_temperature_grid
   petitRADTRANS.__file_conversion.bin_species_exok
   petitRADTRANS.__file_conversion.continuum_clouds_opacities_dat2h5
   petitRADTRANS.__file_conversion.continuum_clouds_opacities_dat2h5_external_species
   petitRADTRANS.__file_conversion.fits_output
   petitRADTRANS.__file_conversion.format2petitradtrans
   petitRADTRANS.__file_conversion.get_opacity_filename
   petitRADTRANS.__file_conversion.line_by_line_opacities_dat2h5
   petitRADTRANS.__file_conversion.load_dace
   petitRADTRANS.__file_conversion.load_exocross
   petitRADTRANS.__file_conversion.rebin_ck_line_opacities
   petitRADTRANS.__file_conversion.rebin_multiple_ck_line_opacities
   petitRADTRANS.__file_conversion.write_cia_opacities
   petitRADTRANS.__file_conversion.write_cloud_opacities
   petitRADTRANS.__file_conversion.write_correlated_k
   petitRADTRANS.__file_conversion.write_line_by_line
   petitRADTRANS.__file_conversion.convert_all


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

.. py:data:: prt_emcee_mode

.. py:data:: load_mpi
   :value: True


.. py:data:: load_mpi
   :value: False


.. py:data:: MPI
   :value: None


.. py:data:: rank
   :value: 0


.. py:data:: comm
   :value: None


.. py:data:: comm

.. py:function:: __get_prt2_input_data_subpaths() -> dict[str, str]

.. py:function:: __remove_files(old_files)

.. py:function:: _clean_input_data_mac_junk_files(path_input_data=petitradtrans_config_parser.get_input_data_path())

.. py:function:: __print_missing_data_file_message(obj, object_name, directory)

.. py:function:: __print_skipping_message(hdf5_opacity_file)

.. py:function:: _chemical_table_dat2h5(path_input_data=petitradtrans_config_parser.get_input_data_path(), rewrite=False, old_paths=False, clean=False)

.. py:function:: _continuum_cia_dat2h5(path_input_data=petitradtrans_config_parser.get_input_data_path(), rewrite=False, output_directory=None, old_paths=False, clean=False)

   Using ExoMol units for HDF5 files.


.. py:function:: _continuum_clouds_opacities_dat2h5(path_input_data=petitradtrans_config_parser.get_input_data_path(), rewrite=False, old_paths=False, clean=False)

   Using ExoMol units for HDF5 files.


.. py:function:: _correlated_k_opacities_dat2h5(path_input_data=petitradtrans_config_parser.get_input_data_path(), rewrite=False, old_paths=False, clean=False, external_single_species=False, path_to_external_species_opacity_folder=None, external_species_longname=None, external_species_doi=None, external_species_contributor=None, external_species_description=None, external_species_molmass=None)

.. py:function:: _correlated_k_opacities_dat2h5_external_species(path_to_species_opacity_folder, path_prt2_input_data, longname, doi=None, contributor=None, description=None, molmass=None)

.. py:function:: _get_base_cia_names()

.. py:function:: _get_base_cloud_names()

.. py:function:: _get_base_correlated_k_names()

   Only used for file conversion from pRT2 to pRT3.


.. py:function:: _get_base_line_by_line_names()

   Only used for file conversion from pRT2 to pRT3.


.. py:function:: _get_default_rebinning_wavelength_range()

.. py:function:: _get_prt2_cia_names()

.. py:function:: _get_prt2_cloud_names()

.. py:function:: _get_prt2_correlated_k_names()

.. py:function:: _get_prt2_line_by_line_names()

.. py:function:: _line_by_line_opacities_dat2h5(path_input_data=petitradtrans_config_parser.get_input_data_path(), memory_map_mode=False, rewrite=False, old_paths=False, clean=False)

   Using ExoMol units for HDF5 files.


.. py:function:: _phoenix_spec_dat2h5(path_input_data=petitradtrans_config_parser.get_input_data_path(), rewrite=False, old_paths=False, clean=False)

   Convert a PHOENIX stellar spectrum in .dat format to HDF5 format.


.. py:function:: _refactor_input_data_folder(path_input_data=petitradtrans_config_parser.get_input_data_path())

.. py:function:: _sort_pressure_temperature_grid(pressure_temperature_grid_file)

.. py:function:: bin_species_exok(species: list[str], resolution: float)

   This function uses exo-k to bin the c-k table of a
   multiple species to a desired (lower) spectral resolution.

   Args:
       species : string
           The name of the species
       resolution : int
           The desired spectral resolving power.


.. py:function:: continuum_clouds_opacities_dat2h5(input_directory, output_name, cloud_species, doi, cloud_species_mode=None, path_input_data=petitradtrans_config_parser.get_input_data_path(), description=None, cloud_path=None, path_input_files=None, path_reference_files=None, rewrite=False, clean=False)

   Using ExoMol units for HDF5 files.


.. py:function:: continuum_clouds_opacities_dat2h5_external_species(path_to_species_opacity_folder, longname, cloud_material_density, save_folder='converted_cloud_opacities', doi=None, description=None, wavelength_limit=None)

.. py:function:: fits_output(wavelength, spectrum, covariance, object_name, output_dir='', correlation=None)

   Generate a fits file that can be used as an input to a pRT retrieval.

   Args:
       wavelength : numpy.ndarray
           The wavelength bin centers in micron. dim(N)
       spectrum : numpy.ndarray
           The flux density in W/m2/micron at each wavelength bin. dim(N)
       covariance : numpy.ndarray
           The covariance of the flux in (W/m2/micron)^2 dim(N,N)
       object_name : string
           The name of the object, used for file naming.
       output_dir : string
           The parent directory of the output file.
       correlation : numpy.ndarray
           The correlation matrix of the flux points (See Brogi & Line 2018, https://arxiv.org/pdf/1811.01681.pdf)

   Returns:
       hdul : astropy.fits.HDUlist
           The HDUlist object storing the spectrum.


.. py:function:: format2petitradtrans(load_function, opacities_directory: str, natural_abundance: bool, source: str, doi: str, species: str, charge: str = '', cloud_info: str = '', contributor: str = None, description: str = None, opacity_files_extension: str = None, spectral_dimension_file: str = None, path_input_data: str = petitradtrans_config_parser.get_input_data_path(), rebin: bool = True, save_correlated_k: bool = True, correlated_k_resolving_power: float = 1000, samples: numpy.ndarray = None, weights: numpy.ndarray = None, save_line_by_line: bool = True, line_by_line_wavelength_boundaries: numpy.ndarray = None, standard_line_by_line_wavelength_boundaries: numpy.ndarray = None, rewrite: bool = False, use_legacy_correlated_k_wavenumbers_sampling: bool = False)

   Convert opacities loaded with the specified load function into petitRADTRANS line-by-line and correlated-k
   opacities.

   Args:
       load_function:
           String ('dace' or 'exocross'), or function loading the opacities.
           If 'dace', the DACE (https://dace.unige.ch/opacityDatabase/) opacity built-in loading function is used.
           If 'exocross', the ExoCross (https://github.com/Trovemaster/exocross) opacity built-in loading function is
           used.
           If a function is used, it must have the following arguments, in that order:
               - file: the file name of a file containing the opacities (automatically taken from opacities_directory)
               - file_extension: see opacity_files_extension below
               - molmass: molar mass of the species (automatically set)
               - wavelength_file: see spectral_dimension_file below
               - wavenumbers_petitradtrans_line_by_line: the petitRADTRANS wavenumber grid for line-by-line opacities
                 (automatically set)
               - save_line_by_line: see save_line_by_line below
               - rebin: see rebin below
               - selection: indices corresponding to the wavenumbers to be extracted
           Not all of the above arguments have to be used.
           The function must output the following, in that order:
               - cross_sections: (cm2/molecule) the cross-sections
               - cross_sections_line_by_line: (cm2/molecule), the cross-sections,
                   interpolated to wavenumbers_petitradtrans_line_by_line
               - wavenumbers: (cm-1) the wavenumbers corresponding to cross-sections
               - pressure: (bar) the pressure of the cross-sections
               - temperature: (K) the temperature of the cross-sections
           The cross_sections, cross_sections_line_by_line and wavenumbers must be returned in increasing wavenumber
           order.
       opacities_directory:
           Directory in which the opacity files are stored.
       natural_abundance:
           If True, the opacities are considered coming from the natural (Earth's) occurring isotopologue mix, instead
           of from a single isotope.
       source:
           Name of the opacities' source (e.g., 'POKAZATEL').
       doi:
           DOI of the opacities' source
       species:
           Chemical formula of the species (e.g. 'H2O')
       charge:
           Charge of the species (e.g. '2+')
       cloud_info:
           Cloud additional info (physical state, internal structure, space group). See the petitRADTRANS cloud
           filename convention for more information.
       contributor:
           Contributor that helped obtained the opacities.
       description:
           Additional description on the opacities.
       opacity_files_extension:
           The extension of the opacity files.
       spectral_dimension_file:
           File containing the opacities' wavelengths.
       path_input_data:
           Path to the input data directory.
       rebin:
           If true, rebin the opacities to the petitRADTRANS standard wavenumber grid. Should be True in most cases.
       save_correlated_k:
           If True, convert and save the opacities in correlated-k ('c-k') format.
       correlated_k_resolving_power:
           Resolving power at which to convert the opacities, for the correlated-k case.
       samples:
           Array containing the correlated-k samples.
       weights:
           Array containing the correlated-k weights.
       save_line_by_line:
           If True, convert and save the opacities in line-by-line ('lbl') format.
       line_by_line_wavelength_boundaries:
           Wavelength boundaries to use for the line-by-line conversion.
       standard_line_by_line_wavelength_boundaries:
           Wavelength boundaries to use when generating the lbl standard petitRADTRANS wavelengths.
       rewrite:
           if True, rewrite existing converted files
       use_legacy_correlated_k_wavenumbers_sampling:
           If True, use the legacy (pRT2) way to sample the correlated-k wavenumbers.


.. py:function:: get_opacity_filename(resolving_power, wavelength_boundaries, species_isotopologue_name, source, natural_abundance='', charge='', cloud_info='')

.. py:function:: line_by_line_opacities_dat2h5(directory, output_name, molmass, doi, path_input_data=petitradtrans_config_parser.get_input_data_path(), contributor=None, description=None, opacities_pressures=None, opacities_temperatures=None, line_paths=None, memory_map_mode=False, rewrite=False, clean=False)

   Using ExoMol units for HDF5 files.


.. py:function:: load_dace(file, file_extension, molmass, wavelength_file=None, wavenumbers_petitradtrans_line_by_line=None, save_line_by_line=False, rebin=True, selection=None)

   Read a DACE opacity file.


.. py:function:: load_exocross(file, file_extension, molmass=None, wavelength_file=None, wavenumbers_petitradtrans_line_by_line=None, save_line_by_line=False, rebin=True, selection=None)

.. py:function:: rebin_ck_line_opacities(input_file, target_resolving_power, wavenumber_grid=None, rewrite=False)

.. py:function:: rebin_multiple_ck_line_opacities(target_resolving_power, paths=None, species=None, rewrite=False)

.. py:function:: write_cia_opacities(hdf5_cia_file, molecules, wavenumbers, wavelengths, alpha, temperatures, doi='', description='')

.. py:function:: write_cloud_opacities(hdf5_opacity_file, cloud_species, wavenumbers, cloud_wavelengths, cloud_absorption_opacities, cloud_scattering_opacities, cloud_asymmetry_parameter, cloud_particles_densities, cloud_particles_radii, cloud_particles_radius_bins, doi='', description='')

.. py:function:: write_correlated_k(file, doi, wavenumbers, wavenumbers_bins_edges, cross_sections, mol_mass, species, opacities_pressures, opacities_temperatures, g_gauss, weights_gauss, wavelengths=None, n_g=None, contributor=None, description=None)

.. py:function:: write_line_by_line(file, doi, wavenumbers, opacities, mol_mass, species, opacities_pressures, opacities_temperatures, wavelengths=None, contributor=None, description=None)

.. py:function:: convert_all(path_input_data=petitradtrans_config_parser.get_input_data_path(), memory_map_mode=False, rewrite=False, old_paths=False, clean=False)

