From fe358ff83f578ad59423f08199162231d4d99ffc Mon Sep 17 00:00:00 2001 From: Luke Shingles Date: Tue, 9 May 2023 09:56:20 +0100 Subject: [PATCH] Fix classic 3d model read (#68) --- artistools/inputmodel/__init__.py | 2 ++ artistools/inputmodel/inputmodel_misc.py | 15 ++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/artistools/inputmodel/__init__.py b/artistools/inputmodel/__init__.py index 4566a7650..b0c4906ca 100644 --- a/artistools/inputmodel/__init__.py +++ b/artistools/inputmodel/__init__.py @@ -1,7 +1,9 @@ import artistools.inputmodel.botyanski2017 import artistools.inputmodel.describeinputmodel +import artistools.inputmodel.downscale3dgrid import artistools.inputmodel.energyinputfiles import artistools.inputmodel.makeartismodel +import artistools.inputmodel.maketardismodelfromartis import artistools.inputmodel.modelfromhydro import artistools.inputmodel.opacityinputfile import artistools.inputmodel.rprocess_from_trajectory diff --git a/artistools/inputmodel/inputmodel_misc.py b/artistools/inputmodel/inputmodel_misc.py index d32fd2db5..705a7915d 100644 --- a/artistools/inputmodel/inputmodel_misc.py +++ b/artistools/inputmodel/inputmodel_misc.py @@ -109,6 +109,7 @@ def read_modelfile_text( data_line_even = fmodel.readline().split() ncols_line_even = len(data_line_even) + ncols_line_odd = len(fmodel.readline().split()) if columns is None: if modelmeta["dimensions"] == 1: @@ -123,7 +124,7 @@ def read_modelfile_text( "X_Cr48", "X_Ni57", "X_Co57", - ][:ncols_line_even] + ] elif modelmeta["dimensions"] == 2: columns = [ @@ -138,7 +139,7 @@ def read_modelfile_text( "X_Cr48", "X_Ni57", "X_Co57", - ][:ncols_line_even] + ] elif modelmeta["dimensions"] == 3: columns = [ @@ -154,10 +155,15 @@ def read_modelfile_text( "X_Cr48", "X_Ni57", "X_Co57", - ][:ncols_line_even] + ] + # last two abundances are optional + assert columns is not None + assert len(columns) == (ncols_line_even + ncols_line_odd) or len(columns) == ( + ncols_line_even + ncols_line_odd + 2 + ) + columns = columns[: ncols_line_even + ncols_line_odd] assert columns is not None - if ncols_line_even == len(columns): if not printwarningsonly: print(" model file is one line per cell") @@ -167,7 +173,6 @@ def read_modelfile_text( if not printwarningsonly: print(" model file format is two lines per cell") # columns split over two lines - ncols_line_odd = len(fmodel.readline().split()) assert (ncols_line_even + ncols_line_odd) == len(columns) onelinepercellformat = False