From 1f4671d7e4a2d18b9f8ed4ebcdef7559e4629c7e Mon Sep 17 00:00:00 2001 From: Marc Williamson Date: Wed, 7 Aug 2019 14:27:42 +0200 Subject: [PATCH 1/3] Replaced 'w' with 'dilution_factor' in csvy model --- tardis/model/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tardis/model/base.py b/tardis/model/base.py index acc2a9cdef6..802dec4e774 100644 --- a/tardis/model/base.py +++ b/tardis/model/base.py @@ -562,8 +562,8 @@ def from_csvy(cls, config): dilution_factor = None if hasattr(csvy_model_data, 'columns'): - if 'w' in csvy_model_data.columns: - dilution_factor = csvy_model_data['w'].iloc[0:].to_numpy() + if 'dilution_factor' in csvy_model_data.columns: + dilution_factor = csvy_model_data['dilution_factor'].iloc[0:].to_numpy() elif config.plasma.initial_t_rad > 0 * u.K: t_radiative = np.ones(no_of_shells) * config.plasma.initial_t_rad From 80d026480310f4462448ced48b3e6ffaff178a40 Mon Sep 17 00:00:00 2001 From: Marc Williamson Date: Wed, 7 Aug 2019 15:23:21 +0200 Subject: [PATCH 2/3] Added Warning for unsupported CSVY columns --- tardis/model/base.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tardis/model/base.py b/tardis/model/base.py index 802dec4e774..7474eb818d7 100644 --- a/tardis/model/base.py +++ b/tardis/model/base.py @@ -14,6 +14,7 @@ from tardis.io.util import HDFWriterMixin from tardis.io.decay import IsotopeAbundances from tardis.model.density import HomologousDensity +from pyne import nucname logger = logging.getLogger(__name__) @@ -498,6 +499,9 @@ def from_csvy(cls, config): Radial1DModel """ + CSVY_SUPPORTED_COLUMNS = ['velocity', 'density', 't_rad', 'dilution_factor'] + + if os.path.isabs(config.csvy_model): csvy_model_fname = config.csvy_model else: @@ -510,6 +514,14 @@ def from_csvy(cls, config): csvy_model_config = Configuration(validate_dict(csvy_model_config, schemapath=csvy_schema_file)) + abund_names = [name for name in csvy_model_data.columns if nucname.iselement(name) or nucname.isnuclide(name)] + unsupported_columns = [name for name in csvy_model_data.columns + if not (name in abund_names) and not (name in CSVY_SUPPORTED_COLUMNS)] + + if len(unsupported_columns) > 0: + logger.warning("The following columns are specified in the csvy" + "model file, but are IGNORED by TARDIS: %s"%(str(unsupported_columns))) + time_explosion = config.supernova.time_explosion.cgs electron_densities = None From c77b4e4b7cd92fb0a6d319cb82745d441f7b13f2 Mon Sep 17 00:00:00 2001 From: Marc Williamson Date: Wed, 7 Aug 2019 18:41:25 +0200 Subject: [PATCH 3/3] Changed supported column checks to use Sets --- tardis/model/base.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tardis/model/base.py b/tardis/model/base.py index 7474eb818d7..dd7e9a32d80 100644 --- a/tardis/model/base.py +++ b/tardis/model/base.py @@ -499,7 +499,7 @@ def from_csvy(cls, config): Radial1DModel """ - CSVY_SUPPORTED_COLUMNS = ['velocity', 'density', 't_rad', 'dilution_factor'] + CSVY_SUPPORTED_COLUMNS = {'velocity', 'density', 't_rad', 'dilution_factor'} if os.path.isabs(config.csvy_model): @@ -511,16 +511,22 @@ def from_csvy(cls, config): base_dir = os.path.abspath(os.path.dirname(__file__)) schema_dir = os.path.join(base_dir, '..', 'io', 'schemas') csvy_schema_file = os.path.join(schema_dir, 'csvy_model.yml') - csvy_model_config = Configuration(validate_dict(csvy_model_config, + csvy_model_config = Configuration(validate_dict(csvy_model_config, schemapath=csvy_schema_file)) - abund_names = [name for name in csvy_model_data.columns if nucname.iselement(name) or nucname.isnuclide(name)] - unsupported_columns = [name for name in csvy_model_data.columns - if not (name in abund_names) and not (name in CSVY_SUPPORTED_COLUMNS)] - - if len(unsupported_columns) > 0: - logger.warning("The following columns are specified in the csvy" - "model file, but are IGNORED by TARDIS: %s"%(str(unsupported_columns))) + if hasattr(csvy_model_data, 'columns'): + abund_names = set([name for name in csvy_model_data.columns + if nucname.iselement(name) or nucname.isnuclide(name)]) + unsupported_columns = set(csvy_model_data.columns) - abund_names - CSVY_SUPPORTED_COLUMNS + + field_names = set([field['name'] for field in csvy_model_config.datatype.fields]) + assert set(csvy_model_data.columns) - field_names == set(),\ + 'CSVY columns exist without field descriptions' + assert field_names - set(csvy_model_data.columns) == set(),\ + 'CSVY field descriptions exist without corresponding csv data' + if unsupported_columns != set(): + logger.warning("The following columns are specified in the csvy" + "model file, but are IGNORED by TARDIS: %s"%(str(unsupported_columns))) time_explosion = config.supernova.time_explosion.cgs