Commit 8a7d9487 authored by Andrea Giannetti's avatar Andrea Giannetti
Browse files

Refactored grid creation, adding config file.

parent aa5f457b
Loading
Loading
Loading
Loading
+32 −4
Original line number Diff line number Diff line
import logging
import sys
import astropy.units
import yaml
import numpy as np
@@ -11,6 +13,26 @@ from assets.constants import (radmc_grid_map,
                              leiden_url_mapping)


def setup_logger(name: str,
                 log_level: str = None) -> logging.Logger:
    """
    Configure default logger
    :param name: Logger name
    :param log_level: Logging levels, as defined by logging
    :return: the logger object
    """
    log_level = 'DEBUG' if log_level is None else log_level
    """general logger configurator"""
    logger = logging.getLogger(name)
    logger.setLevel(log_level)
    handler = logging.StreamHandler(sys.stdout)
    handler.setLevel(log_level)
    formatter = logging.Formatter("%(asctime)s - %(name)-7s - %(levelname)s - %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
    handler.setFormatter(formatter)
    logger.addHandler(handler)
    return logger


def validate_parameter(param_to_validate,
                       default):
    return param_to_validate if param_to_validate is not None else default
@@ -182,16 +204,22 @@ def get_physical_px_size(grid_metadata: dict) -> List[u.Quantity]:
    return physical_px_size


def get_moldata(species_names: list):
def get_moldata(species_names: list,
                logger: logging.Logger):
    """
    Downloads the molecular data from the Leiden molecular database; check whether the molecule in mapped in
        leiden_url_mapping
    :param species_names: the names of the species for which to download data
    :param logger: logger for output printing
    """
    for species in species_names:
        if not os.path.isfile(os.path.join('mdl', 'radmc_files', f'molecule_{species}.inp')):
            logger.info(f'Downloading file molecule_{species}.inp...')
            data = urllib.request.urlopen(leiden_url_mapping[species]).read().decode()
            with open(os.path.join('mdl', 'radmc_files', f'molecule_{species}.inp'), 'w') as outfile:
                outfile.writelines(data)
        else:
            logger.info(f'File molecule_{species}.inp found, skipping download...')


def convert_frequency_to_wavelength(frequency: astropy.units.Quantity,

etl/config/config.yml

0 → 100644
+9 −0
Original line number Diff line number Diff line
overrides:
    dust_temperature_grid_type: 'linear'
    dust_temperature_limits: [10, 30]
    dust_temperature_step: 5
    gas_density_grid_type: 'log'
    gas_density_limits: [1e4, 1e8]
    gas_density_step: 10
    gas_density_unit: cm^-3
    lines_to_process: [87, 86]
+23 −3
Original line number Diff line number Diff line
import os
import numpy as np
from itertools import product
from assets.commons import load_config_file
from stg.stg_radmc_input_generator import main as stg_main
from mdl.mdl_prepare_radmc_command import main as create_radmc_script
from mdl.mdl_save_results_as_fits import main as save_results
from prs.prs_compute_integrated_fluxes_and_ratios import main as prs_main

config = load_config_file(os.path.join('config', 'config.yml'))


def parse_grid_overrides(par_name: str,
                         config: dict) -> np.array:
    config_overrides = config['overrides']
    if config_overrides[f'{par_name}_grid_type'] == 'linear':
        grid_values = np.arange(float(config_overrides[f'{par_name}_limits'][0]),
                                float(config_overrides[f'{par_name}_limits'][1]),
                                float(config_overrides[f'{par_name}_step']))
    else:
        grid_values = 10 ** np.arange(np.log10(float(config_overrides[f'{par_name}_limits'][0])),
                                      np.log10(float(config_overrides[f'{par_name}_limits'][1])),
                                      np.log10(float(config_overrides[f'{par_name}_step'])))
    return grid_values


# grid definition
dust_temperatures = np.arange(10, 25, 5)
central_densities = np.array([1e4, 1e5, 1e6])
lines = [86, 87]
dust_temperatures = parse_grid_overrides(par_name='dust_temperature',
                                         config=config)
central_densities = parse_grid_overrides(par_name='gas_density',
                                         config=config)
lines = config['lines_to_process']

for (tdust, nH2) in product(dust_temperatures, central_densities):
    overrides = {
+1 −1
Original line number Diff line number Diff line
@@ -4,6 +4,6 @@ radmc:
    iline: 2
    central_frequency: 230.538
    frequency_units: GHz
    width_kms: 15
    width_kms: 10
    nchannels: 100
    npix: 200
+7 −7
Original line number Diff line number Diff line
@@ -4,23 +4,23 @@ grid:
    central_density: 1e6
    density_unit: "cm^-3"
    density_powerlaw_idx: 0
#    density_value_at_reference: 1e6
#    distance_reference: 0.5
#    distance_reference_unit: 'pc'
    density_value_at_reference: 1e6
    distance_reference: 0.5
    distance_reference_unit: 'pc'
    dust_temperature: 15
    dust_temperature_unit: 'K'
    dust_temperature_powerlaw_idx: 0
    microturbulence: 5
    microturbulence: 1.5
    microturbulence_unit: 'km/s'
    dim1: {"size":0.1, "size_units": "pc", "shape": 5, "refpix": 2}
    dim1: {"size":1, "size_units": "pc", "shape": 3, "refpix": 1}
    velocity_field: 'solid'
    velocity_gradient: 0.1
    velocity_gradient: 2
    velocity_gradient_unit: "km/s/pc"

lines:
    species_to_include: ['e-ch3oh']
    molecular_abundances: {
                              "e-ch3oh": 1e-7,
                              "e-ch3oh": 1e-8,
                              "p-h2": 0.25,
    }
    lines_mode: 3
Loading