Commit 6bc536e6 authored by Andrea Giannetti's avatar Andrea Giannetti
Browse files

Added docstrings.

parent 1f6864bc
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -15,7 +15,8 @@ from sqlalchemy.orm import Session
from sqlalchemy.dialects.postgresql import insert
from hashlib import sha1
from typing import (List,
                    Union)
                    Union,
                    Tuple)
from astropy import units as u
from assets.constants import (radmc_grid_map,
                              radmc_coord_system_map,
@@ -395,7 +396,15 @@ def get_value_if_specified(parameters_dict: dict,
        return None


def parse_input_main():
def parse_input_main() -> Tuple[str, str, float, float, list, int]:
    """
    Parse the stg and mdl configuration files, as well as the main one, to apply overrides, compute the arrays of
    temperatures and number densities and the type of models defined in the grid (isothermal/uniform density vs.
    power-law profiles)
    :return: a tuple containing the dust profile type (isothermal/heated), the density profile (homogeneous/spherical),
        the distinct values of dust temperatures and densities in the grid, the line pairs used to compute ratios,
        and the number of processes to be used in case of multiprocessing
    """
    stg_config = load_config_file(os.path.join('stg', 'config', 'config.yml'))
    pl_density_idx = float(stg_config['grid']['density_powerlaw_idx'])
    pl_dust_temperature_idx = float(stg_config['grid']['dust_temperature_powerlaw_idx'])
+53 −4
Original line number Diff line number Diff line
@@ -30,9 +30,9 @@ from astropy.io import fits
logger = setup_logger(name='STG')


def write_radmc_input(filename,
                      quantity,
                      grid_metadata,
def write_radmc_input(filename: str,
                      quantity: np.array,
                      grid_metadata: dict,
                      path: Union[None, str] = None,
                      override_defaults: Union[None, dict] = None,
                      flatten_style: Union[None, str] = None):
@@ -86,6 +86,11 @@ def write_radmc_lines_input(line_config: dict,

def copy_additional_files(files_to_transfer: Union[None, List[str]] = None,
                          dst_path: Union[str, None] = None):
    """
    Copy constant files from cache
    :param files_to_transfer: list of files to transfer
    :param dst_path: destination path of the files
    """
    _dst_path = validate_parameter(dst_path, default=os.path.join('mdl', 'radmc_files'))
    _files_to_transfer = validate_parameter(files_to_transfer, default=['dustkappa_silicate.inp',
                                                                        'dustopac.inp'])
@@ -133,6 +138,11 @@ def get_solid_body_rotation_y(grid_metadata):


def get_profiles(grid_metadata: dict) -> dict:
    """
    Function that computes the profiles of the physical quantities needed for the model.
    :param grid_metadata: the grid metadata obtained parsing the config file
    :return: a dictionary of arrays containing the profiles of physical quantities
    """
    density_ref = get_reference_value(grid_metadata=grid_metadata,
                                      quantity_name='density',
                                      desired_unit='cm^-3')
@@ -211,6 +221,14 @@ def get_profiles(grid_metadata: dict) -> dict:
def get_reference_value(grid_metadata: dict,
                        quantity_name: str,
                        desired_unit: str) -> dict:
    """
    Compile a dictionary of reference values for the grid, applying a conversion, if necessary
    :param grid_metadata: the grid metadata
    :param quantity_name: the quantity to process
    :param desired_unit: the output unit to use
    :return: the dictionary with the value at reference in the desired units and the distance reference used to scale
        the power law
    """
    try:
        reference_value_dict = {
            'value_at_reference': (
@@ -231,6 +249,13 @@ def write_grid_input_files(profiles: dict,
                           grid_metadata: dict,
                           wavelengths_micron: np.array,
                           path: Union[str, None] = None):
    """
    Write the grid input files needed by RADMC3d
    :param profiles: the dictionary of profiles for physical quantities that define the model
    :param grid_metadata: the grid metadata
    :param wavelengths_micron: the array of wavelengths to model
    :param path: the output path
    """
    _path = validate_parameter(path, default=os.path.join('mdl', 'radmc_files'))

    quantity_mapping = {
@@ -268,6 +293,14 @@ def write_molecular_number_density_profiles(profiles: dict,
                                            line_config: dict,
                                            grid_metadata: dict,
                                            path: Union[str, None] = None):
    """
    Write the molecular number density profiles. A different function is used wrt the other profiles because the
    molecular ones depend on the others, and on the abundance (profiles)
    :param profiles: the dictionary of profiles for physical quantities that define the model
    :param line_config: the dictionary of the line configurations, for the abundances
    :param grid_metadata: the grid metadata
    :param path: the output path
    """
    _path = validate_parameter(path, default=os.path.join('mdl', 'radmc_files'))
    hot_core_specs = read_abundance_variation_schema(line_config=line_config)
    for species in line_config['species_to_include'] + line_config['collision_partners']:
@@ -282,7 +315,13 @@ def write_molecular_number_density_profiles(profiles: dict,
                          grid_metadata=grid_metadata)


def read_abundance_variation_schema(line_config):
def read_abundance_variation_schema(line_config: dict) -> dict:
    """
    Read and fill the abundance variation schema, defined as a step function
    :param line_config: the dictionary of the line configurations, for the abundances
    :return: the dictionary of the abundance variations per species, with the abundance jump factot and the temperature
        threshold at which evaporation happens
    """
    species_list = list(line_config['molecular_abundances'].keys())
    results_dict = {}
    for species in species_list:
@@ -301,6 +340,16 @@ def compute_molecular_number_density_hot_core(gas_number_density_profile: np.arr
                                              temperature_profile: np.array,
                                              threshold: float,
                                              abundance_jump: Union[float, int]) -> np.array:
    """
    Compute the molecular number density, using a step function abundance, changing above a specific temperature to
    simulate evaporation
    :param gas_number_density_profile: the gas number density profile array
    :param abundance: the gas abundance of the species
    :param temperature_profile: the temperature profile of the source
    :param threshold: the threshold at which the species evaporate
    :param abundance_jump: the factor describing the abundance variation wrt the bas level
    :return: the array of molecular gas density computed using a step function profile
    """
    return np.where(temperature_profile < threshold,
                    gas_number_density_profile * abundance,
                    gas_number_density_profile * abundance * abundance_jump)