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.
26 import json
27 from pathlib import Path
28
29 import neurots
30 from neurots import extract_input
31
32
33 def run(output_dir, data_dir):
34 """Run the example for extracting inputs for synthesis."""
35 # Generate distribution from directory of neurons
36 distr = extract_input.distributions(
37 data_dir / "neurons", feature="path_distances", diameter_model="default"
38 )
39
40 # Save distributions in a json file
41 with open(output_dir / "test_distr.json", "w", encoding="utf-8") as f:
42 json.dump(distr, f, sort_keys=True, indent=2)
43
44 # Generate default parameters for topological synthesis of basal dendrites
45 params = extract_input.parameters(
46 neurite_types=["basal_dendrite"], feature="path_distances", method="tmd"
47 )
48
49 # Save parameters in a json file
50 with open(output_dir / "test_params.json", "w", encoding="utf-8") as f:
51 json.dump(params, f, sort_keys=True, indent=2)
52
53 # Re-load data from saved distributions
54 with open(output_dir / "test_distr.json", "r", encoding="utf-8") as F:
55 distr = json.load(F)
56
57 # Re-load data from saved parameters
58 with open(output_dir / "test_params.json", "r", encoding="utf-8") as F:
59 params = json.load(F)
60
61 # Initialize a neuron
62 N = neurots.NeuronGrower(input_distributions=distr, input_parameters=params)
63
64 # Grow the neuron
65 neuron = N.grow()
66
67 # Export the synthesized cell
68 neuron.write(output_dir / "generated_cell.asc")
69 neuron.write(output_dir / "generated_cell.swc")
70 neuron.write(output_dir / "generated_cell.h5")
71
72
73 if __name__ == "__main__":
74 result_dir = Path("results_extract_synthesis_inputs")
75 result_dir.mkdir(parents=True, exist_ok=True)
76
77 run(result_dir, Path("data"))