dbbs-lab / bsb-core

The Brain Scaffold Builder
https://bsb.readthedocs.io
GNU General Public License v3.0
22 stars 16 forks source link

count_ratio on different partitions #885

Closed drodarie closed 1 month ago

drodarie commented 2 months ago
{
    "name": "Test",
    "storage": {
        "engine": "hdf5",
        "root": "test.hdf5"
    },
    "network": {
        "chunk_size": [
            100,
            100,
            100
        ],
        "x": 100,
        "y": 100,
        "z": 300
    },
    "regions": {
        "cerebellar_cortex": {
            "type": "stack",
            "children": [
                "granular_layer",
                "molecular_layer"
            ]
        }
    },
    "partitions": {
        "granular_layer": {
            "thickness": 200
        },
        "molecular_layer": {
            "thickness": 100
        }
    },
    "cell_types": {
        "glomerulus": {
            "spatial": {
                "count": 10,
                "radius": 1.5
            }
        },
        "mossy_fibers": {
            "spatial": {
                "count_ratio": 0.5,
                "radius": 1.5,
                "relative_to": "glomerulus"
            }
        }
    },
    "placement": {
        "granular_layer_innervation": {
            "strategy": "bsb.placement.RandomPlacement",
            "partitions": [
                "granular_layer"
            ],
            "cell_types": [
                "mossy_fibers"
            ]
        },
        "granular_layer_placement": {
            "strategy": "bsb.placement.RandomPlacement",
            "partitions": [
                "molecular_layer"
            ],
            "cell_types": [
                "glomerulus"
            ]
        }
    },
    "connectivity": {}
}

The following configuration will place 10 glomerulus and 0 mossy_fibers because the cells are not in the same partition.

I believe the bug happens because of the function PlacementIndicator.guess on the relative cell. This function returns the number of glomerulus that have been placed in the chunk, based on the function Rhomboid.volume; in this case 0 because the partitions don't overlap. Here is the partial stack:

volume, partition.py:183
<genexpr>, indicator.py:190
_estim_for_chunk, indicator.py:190
guess, indicator.py:91
<genexpr>, indicator.py:102
guess, indicator.py:101
<listcomp>, random.py:27
_fill_system, random.py:20
place, random.py:59
[...]

The ratio of volume measurement should happen during the guess of mossy_fibers and not glomerulus here.