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
41 changes: 41 additions & 0 deletions spine/io/read/hdf5.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions spine/utils/gnn/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading