Note
Go to the end to download the full example code.
Synthesize a single neuron with global directionΒΆ
This example shows how to synthesize a single cell with different y directions
14 import json
15 from pathlib import Path
16
17 import numpy as np
18 from morph_tool.transform import rotate
19
20 import neurots
21
22
23 def run(output_dir, data_dir):
24 """Run the example for generating a single cell."""
25 np.random.seed(42)
26 with open(data_dir / "bio_params.json", encoding="utf-8") as p_file:
27 params = json.load(p_file)
28 # use trunk angle with y_direction awareness
29 params["basal_dendrite"]["orientation"] = {
30 "mode": "pia_constraint",
31 "values": {"form": "step", "params": [1.5, 0.25]},
32 }
33 params["apical_dendrite"]["orientation"] = {
34 "mode": "normal_pia_constraint",
35 "values": {"direction": {"mean": [0.0], "std": [0.0]}},
36 }
37
38 # Initialize a neuron
39 N = neurots.NeuronGrower(
40 input_distributions=data_dir / "bio_distr.json",
41 input_parameters=params,
42 )
43
44 # Grow the neuron
45 neuron = N.grow()
46
47 # Export the synthesized cell
48 neuron.write(output_dir / "generated_cell_orig.asc")
49
50 np.random.seed(42)
51
52 # Initialize a neuron
53 N = neurots.NeuronGrower(
54 input_distributions=data_dir / "bio_distr.json",
55 input_parameters=params,
56 # context={"y_direction": [0.0, 1.0, 0.0]},
57 )
58
59 # Grow the neuron
60 neuron = N.grow()
61
62 # Export the synthesized cell
63 neuron.write(output_dir / "generated_cell_y.asc")
64
65 np.random.seed(42)
66
67 # Initialize a neuron
68 N = neurots.NeuronGrower(
69 input_distributions=data_dir / "bio_distr.json",
70 input_parameters=params,
71 context={"y_direction": [1.0, 0.0, 0.0]},
72 )
73
74 # Grow the neuron
75 neuron = N.grow()
76
77 # Export the synthesized cell
78 neuron.write(output_dir / "generated_cell_x.asc")
79
80 # the rotated neuron should be the same as original one
81
82 rotate(neuron, [[0, -1, 0], [1, 0, 0], [0, 0, 1]])
83 neuron.write(output_dir / "generated_cell_x_rot.asc")
84
85
86 if __name__ == "__main__":
87 result_dir = Path("results_single_neuron")
88 result_dir.mkdir(parents=True, exist_ok=True)
89
90 run(result_dir, Path("data"))