Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added dist/nt2py-1.5.2-py3-none-any.whl
Binary file not shown.
Binary file added dist/nt2py-1.5.2.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion nt2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.5.1"
__version__ = "1.5.2"

import nt2.containers.data as nt2_data

Expand Down
9 changes: 8 additions & 1 deletion nt2/containers/data.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
20 changes: 11 additions & 9 deletions nt2/containers/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,19 @@ 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])))

for key in data["species"].keys():
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"])
Expand All @@ -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
Loading