Skip to content

Commit

Permalink
fix for the biophysical node validation (#67)
Browse files Browse the repository at this point in the history
* fix for the biophysical node validation
  • Loading branch information
tomdele committed Jun 25, 2020
1 parent 5a54917 commit 717f2b8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
17 changes: 15 additions & 2 deletions bluepysnap/circuit_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import click
from pathlib2 import Path
import h5py
import six

from bluepysnap.config import Config

Expand Down Expand Up @@ -248,6 +249,18 @@ def _check_rotations():
return errors


def _is_biophysical(group):
"""Check if a group contains biophysical nodes."""
if group['model_type'][0] == 'biophysical':
return True
if "@library/model_type" in group:
model_type_int = group['model_type'][0]
model_type = group["@library/model_type"][model_type_int]
if six.ensure_str(model_type) == 'biophysical':
return True
return False


def _check_nodes_group(group, config):
"""Validates nodes group in nodes population.
Expand All @@ -264,7 +277,7 @@ def _check_nodes_group(group, config):
return [fatal('Group {} of {} misses required fields: {}'
.format(_get_group_name(group, parents=1), group.file.filename,
missing_fields))]
elif 'biophysical' in group['model_type'][:]:
elif _is_biophysical(group):
return _check_bio_nodes_group(group, config)
return []

Expand Down Expand Up @@ -430,7 +443,7 @@ def _check_edge_population_data(population, groups, nodes):
'Cannot be read via bluepysnap or libsonata'.
format(population_name, population.file.filename)))

children_object_names = set(population.keys())
children_object_names = set(population)
group_datasets = ["edge_group_id", "edge_group_index"]
required_datasets = ['edge_type_id', 'source_node_id', 'target_node_id']
if len(groups) > 1:
Expand Down
20 changes: 18 additions & 2 deletions tests/test_circuit_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
except ImportError:
from pathlib2 import Path
import h5py
from six import u as unicode

import six
import bluepysnap.circuit_validation as test_module
from bluepysnap.circuit_validation import Error, BbpError
import numpy as np

from utils import setup_tempdir, TEST_DATA_DIR

Expand Down Expand Up @@ -50,7 +52,7 @@ def _edit_config(config_path):
yield config
finally:
with config_path.open('w') as f:
f.write(unicode(json.dumps(config)))
f.write(six.u(json.dumps(config)))


def test_error_comparison():
Expand Down Expand Up @@ -207,6 +209,20 @@ def test_no_required_bio_node_group_datasets():
.format(nodes_file, required_datasets))]


def test_ok_bio_model_type_in_library():
with _copy_circuit() as (circuit_copy_path, config_copy_path):
nodes_file = circuit_copy_path / 'nodes.h5'
with h5py.File(nodes_file, 'r+') as h5f:
data = h5f['nodes/default/0/model_type'][:]
del h5f['nodes/default/0/model_type']
h5f.create_dataset('nodes/default/0/model_type', data=np.zeros_like(data, dtype=int))
dt = h5py.special_dtype(vlen=six.text_type)
h5f.create_dataset('nodes/default/0/@library/model_type',
data=np.array(["biophysical", ], dtype=object), dtype=dt)
errors = test_module.validate(str(config_copy_path))
assert errors == []


def test_no_rotation_bio_node_group_datasets():
angle_datasets = ['rotation_angle_xaxis', 'rotation_angle_yaxis', 'rotation_angle_zaxis']
with _copy_circuit() as (circuit_copy_path, config_copy_path):
Expand Down

0 comments on commit 717f2b8

Please sign in to comment.