def setUp(self):
     self.morphology = Morphology(
         basic_nodes(),
         node_id_cb=lambda node: node["id"],
         parent_id_cb=lambda node: node["parent_id"],
     )
     self.data = Data(self.morphology, relative_soma_depth=0.25)
 def test_select_features_only(self):
     run = (FeatureExtractionRun(Data(
         self.morphology, a=2,
         b=4)).select_marks([self.amark, self.bmark
                             ]).select_features([self.foo, self.baz],
                                                only_marks={self.bmark}))
     self.assertEqual(set(run.selected_features), set())
    def test_extract(self):
        run = FeatureExtractionRun(Data(self.morphology, a=2, b=4))
        run.selected_features = [self.foo]
        run.extract()

        self.assertEqual(run.results["foo"], True)
        self.assertEqual(len(run.results), 1)
    def test_normalized_depth_histograms_across_layers(self):

        _data = Data(self.morphology,
                     reference_layer_depths=self.reference_depths,
                     layered_point_depths=self.point_depths)

        obtained = layer.normalized_depth_histogram(_data, bin_size=10)

        expected = {
            "1":
            layer.LayerHistogram(counts=np.array(
                [0, 0, 0, 0, 1, 0, 1, 0, 1, 0]),
                                 bin_edges=np.arange(0, 110, 10)),
            "2":
            layer.LayerHistogram(counts=np.array(
                [1, 0, 0, 0, 0, 0, 0, 1, 0, 1]),
                                 bin_edges=np.arange(100, 210, 10)),
            "wm":
            layer.LayerHistogram(counts=np.array(
                [0, 1, 0, 0, 1, 0, 0, 0, 0, 0]),
                                 bin_edges=np.arange(200, 310, 10))
        }

        self.assertEqual(set(expected.keys()), set(obtained.keys()))
        for key, obt in obtained.items():
            expt = expected[key]
            print(key, expt.counts, obt.counts)
            assert np.allclose(expt.counts, obt.counts)
            assert np.allclose(expt.bin_edges, obt.bin_edges)
Пример #5
0
def setup_data(
    reconstruction: Dict[str, Any], 
    global_parameters: Dict[str, Any]
) -> Tuple[str, Data]:
    """ Construct a Data for extracting features from a single reconstruction.

    Parameters
    ----------
    reconstruction : The reconstruction to be setup. Must specify an swc_path
    global_parameters : any cross-reconstruction feature parameters

    Returns 
    -------
    identifier : a label for this reconstruction
    data suitable for feature extraction

    """

    parameters: Dict[str, Any] = {}
    identifier = reconstruction.get("identifier", reconstruction.get("swc_path"))
    swc_path = reconstruction.pop("swc_path")
    morphology = morphology_from_swc(swc_path)

    parameters.update(hydrate_parameters(global_parameters))
    parameters.update(hydrate_parameters(reconstruction))

    return identifier, Data(morphology, **parameters)
 def setUp(self):
     # 180 deg at soma
     # axon - 90 deg local, 60 deg remote
     # basal - 90 deg local, 90 deg remote
     self.morphology = (
         MorphologyBuilder()
             .root(0, 0, 0)
                 .axon(0, 0, 1)
                     .axon(0, 1, 2)
                         .axon(0, 1, 1 + np.sqrt(3)).up(2)
                     .axon(0, -1, 2)
                         .axon(0, -1, 1 + np.sqrt(3)).up(3)
                 .basal_dendrite(0, 0, -1)
                     .basal_dendrite(0, 1, -2).up()
                     .basal_dendrite(0, -1, -2)
             .build()
     )
     nodes = self.morphology.nodes()
     for node in nodes:
         print(node)
     self.data = Data(self.morphology)
     self.local_specialized = specialize(
         bf.mean_bifurcation_angle_local,
         {AxonSpec, ApicalDendriteSpec, BasalDendriteSpec}
     )
     self.remote_specialized = specialize(
         bf.mean_bifurcation_angle_remote,
         {AxonSpec, ApicalDendriteSpec, BasalDendriteSpec}
     )
    def setUp(self):
        # morphology with 3/4 axons below soma in z
        self.morphology = Morphology(
            [
                {
                    "id": 0,
                    "parent_id": -1,
                    "type": SOMA,
                    "x": 0,
                    "y": 0,
                    "z": 100,
                    "radius": 5
                },
                {
                    "id": 1,
                    "parent_id": 0,
                    "type": AXON,
                    "x": 0,
                    "y": 0,
                    "z": 110,
                    "radius": 1
                },
                {
                    "id": 2,
                    "parent_id": 1,
                    "type": AXON,
                    "x": 0,
                    "y": 0,
                    "z": 90,
                    "radius": 1
                },
                {
                    "id": 3,
                    "parent_id": 2,
                    "type": AXON,
                    "x": 0,
                    "y": 0,
                    "z": 80,
                    "radius": 1
                },
                {
                    "id": 4,
                    "parent_id": 3,
                    "type": AXON,
                    "x": 0,
                    "y": 0,
                    "z": 70,
                    "radius": 1
                },
            ],
            node_id_cb=lambda node: node["id"],
            parent_id_cb=lambda node: node["parent_id"],
        )

        self.data = Data(self.morphology)
    def test_earth_movers_distance(self):

        _data = Data(self.morphology,
                     reference_layer_depths=self.reference_depths,
                     layered_point_depths=self.point_depths)

        obtained = layer.earth_movers_distance(_data, [AXON],
                                               [APICAL_DENDRITE])

        self.assertEqual(set(obtained.keys()), {"2"})
        self.assertEqual(obtained["2"].result, 17)
class TestDefault(unittest.TestCase):

    fe = FeatureExtractor()

    for feature in default_features:
        fe.register_features([feature])

    data = Data(test_morphology_large())
    feature_extraction_run = fe.extract(data)
    results = feature_extraction_run.results

    pass
    def setUp(self):

        # Create an axon that branches once,
        # and a basal dendrite that has a bifurcation and a trifurcation
        self.morphology = (MorphologyBuilder(
        ).root().axon().axon().axon().axon().up().axon().up(4).basal_dendrite(
        ).basal_dendrite().basal_dendrite().up().basal_dendrite(
        ).basal_dendrite().up().basal_dendrite().up().basal_dendrite().build())

        self.data = Data(self.morphology)

        self.num_nodes = specialize(ic.num_nodes, NEURITE_SPECIALIZATIONS)
        self.num_tips = specialize(ic.num_tips, NEURITE_SPECIALIZATIONS)
        self.num_branches = specialize(ic.num_branches,
                                       NEURITE_SPECIALIZATIONS)
        self.mean_fragmentation = specialize(ic.mean_fragmentation,
                                             NEURITE_SPECIALIZATIONS)
        self.max_branch_order = specialize(ic.max_branch_order,
                                           NEURITE_SPECIALIZATIONS)
Пример #11
0
 def test_additional_data(self):
     obt = Data(self.morphology, a=1, b=2)
     self.assertEqual(obt.a, 1)
     self.assertEqual(obt.b, 2)
     self.assertEqual(len(obt.morphology.nodes()), 4)
    def setUp(self):

        # Create an axon that extends positively,
        # and a basal dendrite that extends negatively
        self.one_dim_neuron = Morphology(
            [
                {
                    "id": 0,
                    "parent_id": -1,
                    "type": SOMA,
                    "x": 0,
                    "y": 100,
                    "z": 0,
                    "radius": 10
                },
                # Axon node [100, 125, 150, 175, 200]
                {
                    "id": 1,
                    "parent_id": 0,
                    "type": AXON,
                    "x": 0,
                    "y": 100,
                    "z": 0,
                    "radius": 3
                },
                {
                    "id": 2,
                    "parent_id": 1,
                    "type": AXON,
                    "x": 0,
                    "y": 125,
                    "z": 0,
                    "radius": 3
                },
                {
                    "id": 3,
                    "parent_id": 2,
                    "type": AXON,
                    "x": 0,
                    "y": 150,
                    "z": 0,
                    "radius": 3
                },
                {
                    "id": 4,
                    "parent_id": 3,
                    "type": AXON,
                    "x": 0,
                    "y": 175,
                    "z": 0,
                    "radius": 3
                },
                {
                    "id": 5,
                    "parent_id": 4,
                    "type": AXON,
                    "x": 0,
                    "y": 200,
                    "z": 0,
                    "radius": 3
                },
                # Basal node [100, 75, 50]
                {
                    "id": 11,
                    "parent_id": 0,
                    "type": BASAL_DENDRITE,
                    "x": 0,
                    "y": 100,
                    "z": 0,
                    "radius": 3
                },
                {
                    "id": 12,
                    "parent_id": 11,
                    "type": BASAL_DENDRITE,
                    "x": 0,
                    "y": 75,
                    "z": 0,
                    "radius": 3
                },
                {
                    "id": 13,
                    "parent_id": 12,
                    "type": BASAL_DENDRITE,
                    "x": 0,
                    "y": 50,
                    "z": 0,
                    "radius": 3
                },
            ],
            node_id_cb=lambda node: node["id"],
            parent_id_cb=lambda node: node["parent_id"],
        )

        self.one_dim_neuron_data = Data(self.one_dim_neuron)

        self.dimension_features = nested_specialize(
            di.dimension,
            [COORD_TYPE_SPECIALIZATIONS, NEURITE_SPECIALIZATIONS])
    def setUp(self):

        self.one_dim_neuron = Morphology([
                {
                    "id": 0,
                    "parent_id": -1,
                    "type": SOMA,
                    "x": 0,
                    "y": 0,
                    "z": 100,
                    "radius": 1
                },
                {
                    "id": 1,
                    "parent_id": 0,
                    "type": AXON,
                    "x": 0,
                    "y": 0,
                    "z": 101,
                    "radius": 1
                },
                {
                    "id": 2,
                    "parent_id": 0,
                    "type": APICAL_DENDRITE,
                    "x": 0,
                    "y": 0,
                    "z": 102,
                    "radius": 1
                },
                { # bifurcates and is within 120
                    "id": 3,
                    "parent_id": 1,
                    "type": AXON,
                    "x": 0,
                    "y": 0,
                    "z": 110,
                    "radius": 1
                },                
                { # This is the farthest node from the root
                    "id": 4,
                    "parent_id": 3,
                    "type": AXON,
                    "x": 0,
                    "y": 0,
                    "z": 140,
                    "radius": 1 
                },                
                { # bifurcates, and is beyond 120
                    "id": 5,
                    "parent_id": 3,
                    "type": AXON,
                    "x": 0,
                    "y": 0,
                    "z": 130,
                    "radius": 1 
                },                
                {
                    "id": 6,
                    "parent_id": 5,
                    "type": AXON,
                    "x": 0,
                    "y": 0,
                    "z": 135,
                    "radius": 1 
                },       
                {
                    "id": 7,
                    "parent_id": 5,
                    "type": AXON,
                    "x": 0,
                    "y": 0,
                    "z": 136,
                    "radius": 1 
                },     
                { # bifurcates and is beyond 120
                    "id": 8,
                    "parent_id": 2,
                    "type": APICAL_DENDRITE,
                    "x": 0,
                    "y": 0,
                    "z": 125,
                    "radius": 1 
                },
                {
                    "id": 9,
                    "parent_id": 8,
                    "type": APICAL_DENDRITE,
                    "x": 0,
                    "y": 0,
                    "z": 126,
                    "radius": 1 
                },
                {
                    "id": 10,
                    "parent_id": 8,
                    "type": APICAL_DENDRITE,
                    "x": 0,
                    "y": 0,
                    "z": 127,
                    "radius": 1 
                },
            ],
            node_id_cb=lambda node: node["id"],
            parent_id_cb=lambda node: node["parent_id"],
        )

        self.one_dim_neuron_data = Data(self.one_dim_neuron)

        self.neurite_features = specialize(
            bf.num_outer_bifurcations,
            {AxonSpec, ApicalDendriteSpec, BasalDendriteSpec}
        )
Пример #14
0
    def test_get_morphology(self):
        aa = get_morphology(Data(self.morphology))
        bb = get_morphology(self.morphology)

        self.assertEqual(aa.__class__.__name__, "Morphology")
        self.assertEqual(bb.__class__.__name__, "Morphology")
    def test_select_marks(self):
        run = (FeatureExtractionRun(Data(
            self.morphology, a=2, b=4)).select_marks([self.amark, self.bmark]))

        self.assertEqual(run.selected_marks, {self.amark})
Пример #16
0
 def test_hash(self):
     dat = Data(self.morphology)
     self.assertEqual({dat}, {dat})
Пример #17
0
    def setUp(self):

        # Create an Axon that extends y 100 to 120
        # and Basal Dendrite that extends y 100 to 110 and 100 to 80
        # So that 3/4 axon nodes overlap, 1/4 are above basal
        # and that 3/6 basal are below, and 3/6 overlap
        self.one_dim_neuron = Morphology(
            [
                {
                    "id": 0,
                    "parent_id": -1,
                    "type": SOMA,
                    "x": 0,
                    "y": 100,
                    "z": 0,
                    "radius": 10
                },
                # Axon y 100 to 150
                {
                    "id": 1,
                    "parent_id": 0,
                    "type": AXON,
                    "x": 0,
                    "y": 101,
                    "z": 0,
                    "radius": 3
                },
                {
                    "id": 2,
                    "parent_id": 1,
                    "type": AXON,
                    "x": 0,
                    "y": 102,
                    "z": 0,
                    "radius": 3
                },
                {
                    "id": 3,
                    "parent_id": 2,
                    "type": AXON,
                    "x": 0,
                    "y": 110,
                    "z": 0,
                    "radius": 3
                },
                {
                    "id": 4,
                    "parent_id": 3,
                    "type": AXON,
                    "x": 0,
                    "y": 120,
                    "z": 0,
                    "radius": 3
                },
                {
                    "id": 11,
                    "parent_id": 0,
                    "type": BASAL_DENDRITE,
                    "x": 0,
                    "y": 101,
                    "z": 0,
                    "radius": 3
                },
                {
                    "id": 12,
                    "parent_id": 11,
                    "type": BASAL_DENDRITE,
                    "x": 0,
                    "y": 102,
                    "z": 0,
                    "radius": 3
                },
                {
                    "id": 13,
                    "parent_id": 12,
                    "type": BASAL_DENDRITE,
                    "x": 0,
                    "y": 110,
                    "z": 0,
                    "radius": 3
                },
                # Basal Dendrite y 100 to 80
                {
                    "id": 14,
                    "parent_id": 12,
                    "type": BASAL_DENDRITE,
                    "x": 0,
                    "y": 99,
                    "z": 0,
                    "radius": 3
                },
                {
                    "id": 15,
                    "parent_id": 14,
                    "type": BASAL_DENDRITE,
                    "x": 0,
                    "y": 90,
                    "z": 0,
                    "radius": 3
                },
                {
                    "id": 16,
                    "parent_id": 15,
                    "type": BASAL_DENDRITE,
                    "x": 0,
                    "y": 80,
                    "z": 0,
                    "radius": 3
                },
            ],
            node_id_cb=lambda node: node["id"],
            parent_id_cb=lambda node: node["parent_id"],
        )

        self.one_dim_neuron_data = Data(self.one_dim_neuron)

        self.overlap_features = nested_specialize(
            ol.overlap,
            [
                NEURITE_SPECIALIZATIONS,  #.remove(AllNeuriteSpec),
                NEURITE_COMPARISON_SPECIALIZATIONS
            ]  #.remove(AllNeuriteCompareSpec)]
        )