Skip to content

Commit 2f5eb7c

Browse files
Merge pull request #79 from francois-drielsma/develop
Final %-level bug fix in direction estimator
2 parents 22a6b84 + 7918476 commit 2f5eb7c

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

spine/io/read/hdf5.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Contains a reader class dedicated to loading data from HDF5 files."""
22

33
import h5py
4+
import yaml
45
import numpy as np
56
from dataclasses import fields
67

@@ -123,6 +124,46 @@ def __init__(self, file_keys, limit_num_files=None, max_print_files=10,
123124
self.build_classes = build_classes
124125
self.skip_unknown_attrs = skip_unknown_attrs
125126

127+
# Process the configuration used to produce the HDF5 file
128+
self.cfg = self.process_cfg()
129+
130+
# Process the SPINE version used to produced the HDF5 file
131+
self.version = self.process_version()
132+
133+
def process_cfg(self):
134+
"""Fetches the SPINE configuration used to produce the HDF5 file.
135+
136+
Returns
137+
-------
138+
dict
139+
Configuration dictionary
140+
"""
141+
# Fetch the string-form configuration
142+
with h5py.File(self.file_paths[0], 'r') as in_file:
143+
cfg_str = in_file['info'].attrs['cfg']
144+
145+
# Attempt to parse it (need try for now for SPINE versions < v0.4.0)
146+
try:
147+
cfg = yaml.safe_load(cfg_str)
148+
except:
149+
return None
150+
151+
return cfg
152+
153+
def process_version(self):
154+
"""Returns the SPINE release version used to produce the HDF5 file.
155+
156+
Returns
157+
-------
158+
str
159+
SPINE release tag
160+
"""
161+
# Fetch the string-form configuration
162+
with h5py.File(self.file_paths[0], 'r') as in_file:
163+
version = in_file['info'].attrs['version']
164+
165+
return version
166+
126167
def get(self, idx):
127168
"""Returns a specific entry in the file.
128169

spine/utils/gnn/cluster.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,10 +1016,10 @@ def cluster_direction(voxels: nb.float64[:,:],
10161016
# Get the eigenvalues, compute relative transverse spread
10171017
w, _ = np.linalg.eigh(covk)
10181018
labels[i] = np.sqrt(w[2] / (w[0] + w[1])) \
1019-
if (w[0] + w[1]) / w[2] > 1e-9 else 0.
1019+
if (w[0] + w[1]) / w[2] > 1e-6 else 0.
10201020

10211021
# If the value is the same as the previous, choose this one
1022-
if dist_mat[i] == dist_mat[i-1]:
1022+
if labels[i] == labels[i-1]:
10231023
labels[i-1] = -1.
10241024

10251025
# Increment mean and matrix

0 commit comments

Comments
 (0)