Loading etl/assets/commons/__init__.py +4 −0 Original line number Diff line number Diff line Loading @@ -128,6 +128,7 @@ def compute_power_law_radial_profile( central_value: float, power_law_index: float, distance_matrix: np.array, maximum_radius: Union[float, None] = None, value_at_reference: Union[float, None] = None, distance_reference: Union[float, u.Quantity] = 1.0, fill_reference_pixel: bool = True) -> np.array: Loading @@ -136,6 +137,7 @@ def compute_power_law_radial_profile( :param central_value: value in the center of the grid :param power_law_index: index of the power law used to scale the profile :param distance_matrix: the matrix of distances from the reference point :param maximum_radius: the maximum radius to populate with gas within the grid :param value_at_reference: value of the profile at the reference distance; defaults to central value if not provided :param distance_reference: value of the reference distance :param fill_reference_pixel: whether to fill the reference point with central_value and set this to the maximum in Loading @@ -153,6 +155,8 @@ def compute_power_law_radial_profile( # If the routine fills the 0-distance point (the centre), it fixes the profile making the central value the maximum if fill_reference_pixel is True: profile = np.where(profile > central_value, central_value, profile) if maximum_radius is not None: profile = np.where(distance_matrix > maximum_radius + maximum_radius/1e5, 0, profile) return profile Loading etl/mdl/mdl_execute_radmc_command.py +4 −3 Original line number Diff line number Diff line Loading @@ -181,12 +181,13 @@ def main(grid_tarfile: str, # This is necessary, because the lines_mode is needed both in the lines.inp and radmc3d.inp files # The reason for splitting the main input file from the rest is that some parameters can be changed # independently of the grid for the modeling. The mdl hash should depend on all the mdl parameters, not a subset _override_config = validate_parameter(override_config, default={'grid_lines': {}, 'model': {}}) executed_on = datetime.now() config_stg = load_config_file(os.path.join('stg', 'config', 'config.yml'), override_config=override_config['grid_lines']) override_config=_override_config['grid_lines']) config_lines = config_stg['lines'] config_mdl = load_config_file(os.path.join('mdl', 'config', 'config.yml'), override_config=override_config['model']) override_config=_override_config['model']) write_radmc_main_input_file(config_mdl=config_mdl, config_lines=config_lines, path=os.path.join('mdl', 'radmc_files')) Loading @@ -194,7 +195,7 @@ def main(grid_tarfile: str, with open(os.path.join('mdl', 'radmc3d_postprocessing.sh'), 'w') as outfile: outfile.write('cd mdl/radmc_files\n') options_set = get_command_options(config_mdl) radmc_command = f'radmc3d image {" ".join(options_set)}' radmc_command = f'radmc3d image setthreads 4 {" ".join(options_set)}' outfile.write(radmc_command) engine = get_pg_engine(logger=logger) Loading etl/stg/config/config.yml +7 −5 Original line number Diff line number Diff line grid: grid_type: regular coordinate_system: cartesian central_density: 1e6 central_density: 1e8 density_unit: "cm^-3" density_powerlaw_idx: 0 density_powerlaw_idx: -1.5 density_value_at_reference: 1e6 maximum_radius: 1 maximum_radius_unit: 'pc' distance_reference: 0.5 distance_reference_unit: 'pc' dust_temperature: 15 Loading @@ -12,7 +14,7 @@ grid: dust_temperature_powerlaw_idx: 0 microturbulence: 1.5 microturbulence_unit: 'km/s' dim1: {"size":1, "size_units": "pc", "shape": 3, "refpix": 1} dim1: {"size":1.2, "size_units": "pc", "shape": 21, "refpix": 10} velocity_field: 'solid' velocity_gradient: 2 velocity_gradient_unit: "km/(s pc)" Loading @@ -20,8 +22,8 @@ grid: lines: species_to_include: ['e-ch3oh'] molecular_abundances: { "e-ch3oh": 1e-8, "p-h2": 0.25, "e-ch3oh": 1e-10, "p-h2": 1, } lines_mode: 'lvg' collision_partners: ['p-h2'] etl/stg/stg_radmc_input_generator.py +4 −3 Original line number Diff line number Diff line Loading @@ -121,7 +121,7 @@ def get_profiles(grid_metadata): (float(grid_metadata['density_value_at_reference']) * u.Unit(grid_metadata['density_unit'])) .to(u.cm ** -3)).value, 'distance_reference': (float(grid_metadata['distance_reference']) * u.Unit( grid_metadata['distance_reference_unit']).to(u.cm)).value grid_metadata['distance_reference_unit'])).to(u.cm).value } except (KeyError, AttributeError): density_ref = { Loading Loading @@ -151,8 +151,8 @@ def get_profiles(grid_metadata): }, 'escprob_lengthscale': { # FIXME: make the unit consistent with the max via indexing 'central_value': (max(grid_metadata['grid_size']) * u.Unit(grid_metadata['grid_size_units'][0])) .to(u.cm).value, 'central_value': min((max(grid_metadata['grid_size']) * u.Unit(grid_metadata['grid_size_units'][0])) .to(u.cm).value, (grid_metadata['maximum_radius'] * u.Unit(grid_metadata['maximum_radius_unit'])).to(u.cm).value), 'power_law_index': 0, 'value_at_reference': None, 'distance_reference': 1.0 Loading Loading @@ -186,6 +186,7 @@ def get_profiles(grid_metadata): distance_matrix=grid_metadata['distance_matrix'], value_at_reference=profiles_mapping[profile]['value_at_reference'], distance_reference=profiles_mapping[profile]['distance_reference'], maximum_radius=grid_metadata['maximum_radius'] * u.Unit(grid_metadata['maximum_radius_unit']).to(u.cm) ) if grid_metadata['velocity_field'] == 'solid': Loading etl/tests/test_commons.py +11 −1 Original line number Diff line number Diff line Loading @@ -163,6 +163,16 @@ class Test(TestCase): indices=indices) self.assertTrue(np.array_equal(expected_results, distance_matrix)) def test_get_distance_matrix_symmetric(self): grid_metadata = { 'grid_shape': [5, 5, 5], 'physical_px_size': [1 * u.cm, 1 * u.cm, 1 * u.cm] } indices = np.indices(grid_metadata['grid_shape']) - 3 distance_matrix = get_distance_matrix(grid_metadata=grid_metadata, indices=indices) self.assertTrue(np.array_equal(distance_matrix, distance_matrix.T)) def test_get_centered_indices(self): grid_metadata = { 'grid_shape': [5, 3], Loading Loading @@ -232,7 +242,7 @@ class Test(TestCase): 'DB_PORT': 5432, } credentials = get_credentials(logger=self.logger, credentials_filename=os.path.join('tests', 'test_files', 'credentials.yaml'), credentials_filename=os.path.join('test_files', 'credentials.yaml'), set_envs=True) self.assertDictEqual(credentials, expected_results) for key in expected_results: Loading Loading
etl/assets/commons/__init__.py +4 −0 Original line number Diff line number Diff line Loading @@ -128,6 +128,7 @@ def compute_power_law_radial_profile( central_value: float, power_law_index: float, distance_matrix: np.array, maximum_radius: Union[float, None] = None, value_at_reference: Union[float, None] = None, distance_reference: Union[float, u.Quantity] = 1.0, fill_reference_pixel: bool = True) -> np.array: Loading @@ -136,6 +137,7 @@ def compute_power_law_radial_profile( :param central_value: value in the center of the grid :param power_law_index: index of the power law used to scale the profile :param distance_matrix: the matrix of distances from the reference point :param maximum_radius: the maximum radius to populate with gas within the grid :param value_at_reference: value of the profile at the reference distance; defaults to central value if not provided :param distance_reference: value of the reference distance :param fill_reference_pixel: whether to fill the reference point with central_value and set this to the maximum in Loading @@ -153,6 +155,8 @@ def compute_power_law_radial_profile( # If the routine fills the 0-distance point (the centre), it fixes the profile making the central value the maximum if fill_reference_pixel is True: profile = np.where(profile > central_value, central_value, profile) if maximum_radius is not None: profile = np.where(distance_matrix > maximum_radius + maximum_radius/1e5, 0, profile) return profile Loading
etl/mdl/mdl_execute_radmc_command.py +4 −3 Original line number Diff line number Diff line Loading @@ -181,12 +181,13 @@ def main(grid_tarfile: str, # This is necessary, because the lines_mode is needed both in the lines.inp and radmc3d.inp files # The reason for splitting the main input file from the rest is that some parameters can be changed # independently of the grid for the modeling. The mdl hash should depend on all the mdl parameters, not a subset _override_config = validate_parameter(override_config, default={'grid_lines': {}, 'model': {}}) executed_on = datetime.now() config_stg = load_config_file(os.path.join('stg', 'config', 'config.yml'), override_config=override_config['grid_lines']) override_config=_override_config['grid_lines']) config_lines = config_stg['lines'] config_mdl = load_config_file(os.path.join('mdl', 'config', 'config.yml'), override_config=override_config['model']) override_config=_override_config['model']) write_radmc_main_input_file(config_mdl=config_mdl, config_lines=config_lines, path=os.path.join('mdl', 'radmc_files')) Loading @@ -194,7 +195,7 @@ def main(grid_tarfile: str, with open(os.path.join('mdl', 'radmc3d_postprocessing.sh'), 'w') as outfile: outfile.write('cd mdl/radmc_files\n') options_set = get_command_options(config_mdl) radmc_command = f'radmc3d image {" ".join(options_set)}' radmc_command = f'radmc3d image setthreads 4 {" ".join(options_set)}' outfile.write(radmc_command) engine = get_pg_engine(logger=logger) Loading
etl/stg/config/config.yml +7 −5 Original line number Diff line number Diff line grid: grid_type: regular coordinate_system: cartesian central_density: 1e6 central_density: 1e8 density_unit: "cm^-3" density_powerlaw_idx: 0 density_powerlaw_idx: -1.5 density_value_at_reference: 1e6 maximum_radius: 1 maximum_radius_unit: 'pc' distance_reference: 0.5 distance_reference_unit: 'pc' dust_temperature: 15 Loading @@ -12,7 +14,7 @@ grid: dust_temperature_powerlaw_idx: 0 microturbulence: 1.5 microturbulence_unit: 'km/s' dim1: {"size":1, "size_units": "pc", "shape": 3, "refpix": 1} dim1: {"size":1.2, "size_units": "pc", "shape": 21, "refpix": 10} velocity_field: 'solid' velocity_gradient: 2 velocity_gradient_unit: "km/(s pc)" Loading @@ -20,8 +22,8 @@ grid: lines: species_to_include: ['e-ch3oh'] molecular_abundances: { "e-ch3oh": 1e-8, "p-h2": 0.25, "e-ch3oh": 1e-10, "p-h2": 1, } lines_mode: 'lvg' collision_partners: ['p-h2']
etl/stg/stg_radmc_input_generator.py +4 −3 Original line number Diff line number Diff line Loading @@ -121,7 +121,7 @@ def get_profiles(grid_metadata): (float(grid_metadata['density_value_at_reference']) * u.Unit(grid_metadata['density_unit'])) .to(u.cm ** -3)).value, 'distance_reference': (float(grid_metadata['distance_reference']) * u.Unit( grid_metadata['distance_reference_unit']).to(u.cm)).value grid_metadata['distance_reference_unit'])).to(u.cm).value } except (KeyError, AttributeError): density_ref = { Loading Loading @@ -151,8 +151,8 @@ def get_profiles(grid_metadata): }, 'escprob_lengthscale': { # FIXME: make the unit consistent with the max via indexing 'central_value': (max(grid_metadata['grid_size']) * u.Unit(grid_metadata['grid_size_units'][0])) .to(u.cm).value, 'central_value': min((max(grid_metadata['grid_size']) * u.Unit(grid_metadata['grid_size_units'][0])) .to(u.cm).value, (grid_metadata['maximum_radius'] * u.Unit(grid_metadata['maximum_radius_unit'])).to(u.cm).value), 'power_law_index': 0, 'value_at_reference': None, 'distance_reference': 1.0 Loading Loading @@ -186,6 +186,7 @@ def get_profiles(grid_metadata): distance_matrix=grid_metadata['distance_matrix'], value_at_reference=profiles_mapping[profile]['value_at_reference'], distance_reference=profiles_mapping[profile]['distance_reference'], maximum_radius=grid_metadata['maximum_radius'] * u.Unit(grid_metadata['maximum_radius_unit']).to(u.cm) ) if grid_metadata['velocity_field'] == 'solid': Loading
etl/tests/test_commons.py +11 −1 Original line number Diff line number Diff line Loading @@ -163,6 +163,16 @@ class Test(TestCase): indices=indices) self.assertTrue(np.array_equal(expected_results, distance_matrix)) def test_get_distance_matrix_symmetric(self): grid_metadata = { 'grid_shape': [5, 5, 5], 'physical_px_size': [1 * u.cm, 1 * u.cm, 1 * u.cm] } indices = np.indices(grid_metadata['grid_shape']) - 3 distance_matrix = get_distance_matrix(grid_metadata=grid_metadata, indices=indices) self.assertTrue(np.array_equal(distance_matrix, distance_matrix.T)) def test_get_centered_indices(self): grid_metadata = { 'grid_shape': [5, 3], Loading Loading @@ -232,7 +242,7 @@ class Test(TestCase): 'DB_PORT': 5432, } credentials = get_credentials(logger=self.logger, credentials_filename=os.path.join('tests', 'test_files', 'credentials.yaml'), credentials_filename=os.path.join('test_files', 'credentials.yaml'), set_envs=True) self.assertDictEqual(credentials, expected_results) for key in expected_results: Loading