Note
Go to the end to download the full example code.
Extract inputs for synthesisΒΆ
This example shows how to extract the inputs required for synthesis from a set of existing morphologies.
15 import json
16 from pathlib import Path
17
18 import neurots
19 from neurots import extract_input
20
21
22 def run(output_dir, data_dir):
23 """Run the example for extracting inputs for synthesis."""
24 # Generate distribution from directory of neurons
25 distr = extract_input.distributions(
26 data_dir / "neurons", feature="path_distances", diameter_model="default"
27 )
28
29 # Save distributions in a json file
30 with open(output_dir / "test_distr.json", "w", encoding="utf-8") as f:
31 json.dump(distr, f, sort_keys=True, indent=2)
32
33 # Generate default parameters for topological synthesis of basal dendrites
34 params = extract_input.parameters(
35 neurite_types=["basal_dendrite"], feature="path_distances", method="tmd"
36 )
37
38 # Save parameters in a json file
39 with open(output_dir / "test_params.json", "w", encoding="utf-8") as f:
40 json.dump(params, f, sort_keys=True, indent=2)
41
42 # Re-load data from saved distributions
43 with open(output_dir / "test_distr.json", "r", encoding="utf-8") as F:
44 distr = json.load(F)
45
46 # Re-load data from saved parameters
47 with open(output_dir / "test_params.json", "r", encoding="utf-8") as F:
48 params = json.load(F)
49
50 # Initialize a neuron
51 N = neurots.NeuronGrower(input_distributions=distr, input_parameters=params)
52
53 # Grow the neuron
54 neuron = N.grow()
55
56 # Export the synthesized cell
57 neuron.write(output_dir / "generated_cell.asc")
58 neuron.write(output_dir / "generated_cell.swc")
59 neuron.write(output_dir / "generated_cell.h5")
60
61
62 if __name__ == "__main__":
63 result_dir = Path("results_extract_synthesis_inputs")
64 result_dir.mkdir(parents=True, exist_ok=True)
65
66 run(result_dir, Path("data"))