From 143f2c21f266299b49f5c7adac3338e70cbd8ffa Mon Sep 17 00:00:00 2001 From: BartJongbloets Date: Mon, 20 Jan 2020 17:57:13 -0800 Subject: [PATCH 1/2] Added section in tmd.io.load_neuron to remove structural annotations that are not declared in TYPE_DCT. This prevents breakage of load_neuron when data contains undeclared structural annotations (eg. contours, spines). These undeclared structural annotations have not the same origin points as the soma, basal, apical, or axon (TYPE_DCT). During csr_matrix generation the annotations require to be connected with soma, therefore those undeclared annotations often break the loading of data. To block annoying error messages an verbose argument is added to suppress printing of the messages. --- tmd/io/io.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tmd/io/io.py b/tmd/io/io.py index b260679..01e098b 100644 --- a/tmd/io/io.py +++ b/tmd/io/io.py @@ -46,7 +46,7 @@ def make_tree(data): def load_neuron(input_file, line_delimiter='\n', soma_type=None, - tree_types=None, remove_duplicates=True): + tree_types=None, remove_duplicates=True, verbose=True): ''' Io method to load an swc or h5 file into a Neuron object. TODO: Check if tree is connected to soma, otherwise do @@ -79,6 +79,20 @@ def load_neuron(input_file, line_delimiter='\n', soma_type=None, except IndexError: raise LoadNeuronError('Soma points not in the expected format') + # Remove structural annotations other than defined in TYPE_DICT + # Presence of those annotations impede loading of data when generating + # csr_matrix. + in_type_dct = _np.zeros((len(data), len(TYPE_DCT))).astype(bool) + for ind, TYPE in enumerate(TYPE_DCT.values()): + in_type_dct[:, ind] = data[:, 1] == int(TYPE) + in_type_dct = _np.sum(in_type_dct, axis=1).astype(bool) + if verbose and len(data) > _np.sum(in_type_dct): + raise LoadNeuronError('Loaded neuron data contains structural ' + 'annotations that are ignored in current TMD ' + ' package. Processed data only contains: %s' + % str(TYPE_DCT)) + data = data[in_type_dct, :] + # Extract soma information from swc soma = Soma.Soma(x=_np.transpose(data)[SWC_DCT['x']][soma_ids], y=_np.transpose(data)[SWC_DCT['y']][soma_ids], From dd52ed72764cace9efcd2348085e50e2701fd889 Mon Sep 17 00:00:00 2001 From: BartJongbloets Date: Mon, 20 Jan 2020 18:07:56 -0800 Subject: [PATCH 2/2] CHanged LoadNeuronError to a printed warning to allow the data to be processed. Otherwise in case of LoadNeuronError the loading is stopped. --- tmd/io/io.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmd/io/io.py b/tmd/io/io.py index 01e098b..a2c67e4 100644 --- a/tmd/io/io.py +++ b/tmd/io/io.py @@ -87,7 +87,7 @@ def load_neuron(input_file, line_delimiter='\n', soma_type=None, in_type_dct[:, ind] = data[:, 1] == int(TYPE) in_type_dct = _np.sum(in_type_dct, axis=1).astype(bool) if verbose and len(data) > _np.sum(in_type_dct): - raise LoadNeuronError('Loaded neuron data contains structural ' + print('LoadNeuronWarning: Loaded neuron data contains structural ' 'annotations that are ignored in current TMD ' ' package. Processed data only contains: %s' % str(TYPE_DCT))