From ad1c25b7c9f0edf0dbb85eb6a34fbfd39472ec5d Mon Sep 17 00:00:00 2001 From: Luke Shingles Date: Tue, 19 Apr 2016 13:07:35 +0100 Subject: [PATCH] Detect and preserve absolute paths in configuration --- tardis/io/config_reader.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/tardis/io/config_reader.py b/tardis/io/config_reader.py index 79050d6ec9f..f820097c3b2 100644 --- a/tardis/io/config_reader.py +++ b/tardis/io/config_reader.py @@ -801,8 +801,11 @@ def from_config_dict(cls, config_dict, atom_data=None, test_parser=False, if test_parser: atom_data = None elif 'atom_data' in validated_config_dict.keys(): - atom_data_fname = os.path.join(config_dirname, - validated_config_dict['atom_data']) + if os.path.isabs(validated_config_dict['atom_data']): + atom_data_fname = validated_config_dict['atom_data'] + else: + atom_data_fname = os.path.join(config_dirname, + validated_config_dict['atom_data']) validated_config_dict['atom_data_fname'] = atom_data_fname else: raise ConfigurationError('No atom_data key found in config or command line') @@ -856,10 +859,14 @@ def from_config_dict(cls, config_dict, atom_data=None, test_parser=False, validated_config_dict['supernova']['time_explosion']).cgs elif structure_section['type'] == 'file': + if os.path.isabs(structure_section['type']): + structure_fname = structure_section['type'] + else: + structure_fname = os.path.join(config_dirname, + structure_section['type']) v_inner, v_outer, mean_densities, inner_boundary_index, \ outer_boundary_index = read_density_file( - os.path.join(config_dirname,structure_section['filename']), - structure_section['filetype'], + structure_fname, structure_section['filetype'], validated_config_dict['supernova']['time_explosion'], structure_section['v_inner_boundary'], structure_section['v_outer_boundary']) @@ -899,8 +906,13 @@ def from_config_dict(cls, config_dict, atom_data=None, test_parser=False, abundances.ix[z] = float(abundances_section[element_symbol_string]) elif abundances_section['type'] == 'file': - index, abundances = read_abundances_file(os.path.join(config_dirname, - abundances_section['filename']), + if os.path.isabs(abundances_section['filename']): + abundances_fname = abundances_section['filename'] + else: + abundances_fname = os.path.join(config_dirname, + abundances_section['filename']) + + index, abundances = read_abundances_file(abundances_fname, abundances_section['filetype'], inner_boundary_index, outer_boundary_index) if len(index) != no_of_shells: