diff --git a/dist/nt2py-1.5.2-py3-none-any.whl b/dist/nt2py-1.5.2-py3-none-any.whl new file mode 100644 index 0000000..129371c Binary files /dev/null and b/dist/nt2py-1.5.2-py3-none-any.whl differ diff --git a/dist/nt2py-1.5.2.tar.gz b/dist/nt2py-1.5.2.tar.gz new file mode 100644 index 0000000..15209cf Binary files /dev/null and b/dist/nt2py-1.5.2.tar.gz differ diff --git a/nt2/__init__.py b/nt2/__init__.py index c9a797c..62c33fa 100644 --- a/nt2/__init__.py +++ b/nt2/__init__.py @@ -1,4 +1,4 @@ -__version__ = "1.5.1" +__version__ = "1.5.2" import nt2.containers.data as nt2_data diff --git a/nt2/containers/data.py b/nt2/containers/data.py index 0758956..dec97cd 100644 --- a/nt2/containers/data.py +++ b/nt2/containers/data.py @@ -1,6 +1,7 @@ from typing import Callable, Any, Union, Optional, List, Dict import sys +import logging if sys.version_info >= (3, 12): from typing import override @@ -248,7 +249,11 @@ def __init__( self.__coordinate_system = coord_system super(Data, self).__init__(path=path, reader=self.__reader, remap=remap) - self.__diagnostics = Diagnostics(path) + try: + self.__diagnostics = Diagnostics(path) + except Exception as e: + logging.warning(f"Failed to read diagnostics: {e}") + self.__diagnostics = None def makeMovie( self, @@ -314,6 +319,8 @@ def attrs(self) -> Dict[str, Any]: @property def diagnostics(self) -> Union[pd.DataFrame, None]: """pd.DataFrame or None: The diagnostics output if .out file is found, None otherwise.""" + if self.__diagnostics is None: + return None return self.__diagnostics.df def to_str(self) -> str: diff --git a/nt2/containers/diagnostics.py b/nt2/containers/diagnostics.py index a8dff85..98fe33b 100644 --- a/nt2/containers/diagnostics.py +++ b/nt2/containers/diagnostics.py @@ -76,7 +76,7 @@ def to_ns(value: float, unit: str) -> float: data["species_min"][specie[0]] = [] data["species_max"][specie[0]] = [] data["species"][specie[0]].append(int(float(specie[1]))) - if len(specie) == 6: + if len(specie) == 6 and specie[3] != "" and specie[5] != "": data["species_min"][specie[0]].append(int(float(specie[3]))) data["species_max"][specie[0]].append(int(float(specie[5]))) @@ -84,13 +84,11 @@ def to_ns(value: float, unit: str) -> float: assert len(data["species"][key]) == len( data["steps"] ), f"Number of species entries for {key} does not match number of steps" - assert ( - len(data["species_min"][key]) == len(data["steps"]) - or len("species_min") == 0 + assert (len(data["species_min"][key]) == len(data["steps"])) or ( + len(data["species_min"][key]) == 0 ), f"Number of species min entries for {key} does not match number of steps" - assert ( - len(data["species_max"][key]) == len(data["steps"]) - or len("species_max") == 0 + assert (len(data["species_max"][key]) == len(data["steps"])) or ( + len(data["species_max"][key]) == 0 ), f"Number of species max entries for {key} does not match number of steps" self.df = pd.DataFrame(index=data["steps"]) @@ -100,7 +98,11 @@ def to_ns(value: float, unit: str) -> float: self.df[key] = data["substeps"][key] for key in data["species"].keys(): self.df[f"species_{key}"] = data["species"][key] - self.df[f"species_{key}_min"] = data["species_min"][key] - self.df[f"species_{key}_max"] = data["species_max"][key] + if ( + len(data["species_min"][key]) > 0 + and len(data["species_max"][key]) > 0 + ): + self.df[f"species_{key}_min"] = data["species_min"][key] + self.df[f"species_{key}_max"] = data["species_max"][key] del data