diff --git a/spine/io/read/hdf5.py b/spine/io/read/hdf5.py index eb39f349..5f496ad5 100644 --- a/spine/io/read/hdf5.py +++ b/spine/io/read/hdf5.py @@ -1,6 +1,7 @@ """Contains a reader class dedicated to loading data from HDF5 files.""" import h5py +import yaml import numpy as np from dataclasses import fields @@ -123,6 +124,46 @@ def __init__(self, file_keys, limit_num_files=None, max_print_files=10, self.build_classes = build_classes self.skip_unknown_attrs = skip_unknown_attrs + # Process the configuration used to produce the HDF5 file + self.cfg = self.process_cfg() + + # Process the SPINE version used to produced the HDF5 file + self.version = self.process_version() + + def process_cfg(self): + """Fetches the SPINE configuration used to produce the HDF5 file. + + Returns + ------- + dict + Configuration dictionary + """ + # Fetch the string-form configuration + with h5py.File(self.file_paths[0], 'r') as in_file: + cfg_str = in_file['info'].attrs['cfg'] + + # Attempt to parse it (need try for now for SPINE versions < v0.4.0) + try: + cfg = yaml.safe_load(cfg_str) + except: + return None + + return cfg + + def process_version(self): + """Returns the SPINE release version used to produce the HDF5 file. + + Returns + ------- + str + SPINE release tag + """ + # Fetch the string-form configuration + with h5py.File(self.file_paths[0], 'r') as in_file: + version = in_file['info'].attrs['version'] + + return version + def get(self, idx): """Returns a specific entry in the file. diff --git a/spine/utils/gnn/cluster.py b/spine/utils/gnn/cluster.py index 08de61a5..2d958470 100644 --- a/spine/utils/gnn/cluster.py +++ b/spine/utils/gnn/cluster.py @@ -1016,10 +1016,10 @@ def cluster_direction(voxels: nb.float64[:,:], # Get the eigenvalues, compute relative transverse spread w, _ = np.linalg.eigh(covk) labels[i] = np.sqrt(w[2] / (w[0] + w[1])) \ - if (w[0] + w[1]) / w[2] > 1e-9 else 0. + if (w[0] + w[1]) / w[2] > 1e-6 else 0. # If the value is the same as the previous, choose this one - if dist_mat[i] == dist_mat[i-1]: + if labels[i] == labels[i-1]: labels[i-1] = -1. # Increment mean and matrix