Skip to content

Commit

Permalink
Fixed padding
Browse files Browse the repository at this point in the history
  • Loading branch information
Hjorthmedh committed Oct 3, 2023
1 parent 8a59e37 commit 658d6a8
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 30 deletions.
20 changes: 19 additions & 1 deletion snudda/analyse/analyse.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from snudda.utils.load import SnuddaLoad
from snudda.utils.snudda_path import snudda_parse_path
from snudda.utils.numpy_encoder import NumpyEncoder

# !!! We need to parallelise the analysis script also!

Expand Down Expand Up @@ -888,7 +889,8 @@ def plot_connection_probability(self,
return_ax=False,
colour="black",
show_plot=None,
save_figure=True):
save_figure=True,
dump_data_to_file=None):

if volume_id is None:
volume_id = self.volume_id
Expand Down Expand Up @@ -952,6 +954,22 @@ def plot_connection_probability(self,
self.connection_probability(pre_id, post_id, num_bins, dist_3d=dist_3d,
connection_type=connection_type)

if dump_data_to_file is not None:
print(f"Updating connection probability data stored in {dump_data_to_file}")

if os.path.isfile(dump_data_to_file):
print(f"Appending connection data to {dump_data_to_file}")
with open(dump_data_to_file, "r") as f:
file_data = json.load(f)
else:
print(f"Creating {dump_data_to_file}")
file_data = dict()

file_data[f"{pre_type},{post_type}"] = (dist.flatten(), p_con.flatten(), count_con.flatten(), count_all.flatten())

with open(dump_data_to_file, "w") as f:
json.dump(file_data, f, indent=4, cls=NumpyEncoder)

# Now let's plot it

# fig = plt.figure()
Expand Down
56 changes: 38 additions & 18 deletions snudda/analyse/analyse_striatum.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ def plot_fslt_scum_dist(self, plot_fs=True, plot_lts=True):
# import pdb
# pdb.set_trace()

dump_connection_data_to_file = os.path.join(sim_dir, "connection_data.json")

nas.plot_synapse_cum_dist_summary(pair_list=[("dSPN", "ChIN"),
("iSPN", "ChIN"),
("LTS", "ChIN")])
Expand All @@ -173,25 +175,29 @@ def plot_fslt_scum_dist(self, plot_fs=True, plot_lts=True):
exp_max_dist=[50e-6, 100e-6],
exp_data=[3 / 47.0, 3 / 66.0],
exp_data_detailed=[(3, 47), (3, 66)],
y_max=y_max_H)
y_max=y_max_H,
dump_data_to_file=dump_connection_data_to_file)
nas.plot_connection_probability("dSPN", "dSPN",
dist_3d=dist3D,
exp_max_dist=[50e-6, 100e-6],
exp_data=[5 / 19.0, 3 / 43.0],
exp_data_detailed=[(5, 19), (3, 43)],
y_max=y_max_H)
y_max=y_max_H,
dump_data_to_file=dump_connection_data_to_file)
nas.plot_connection_probability("iSPN", "dSPN",
dist_3d=dist3D,
exp_max_dist=[50e-6, 100e-6],
exp_data=[13 / 47.0, 10 / 80.0],
exp_data_detailed=[(13, 47), (10, 80)],
y_max=y_max_H)
y_max=y_max_H,
dump_data_to_file=dump_connection_data_to_file)
nas.plot_connection_probability("iSPN", "iSPN",
dist_3d=dist3D,
exp_max_dist=[50e-6, 100e-6],
exp_data=[14 / 39.0, 7 / 31.0],
exp_data_detailed=[(14, 39), (7, 31)],
y_max=y_max_H)
y_max=y_max_H,
dump_data_to_file=dump_connection_data_to_file)

nas.plot_num_synapses_per_pair("dSPN", "dSPN")
nas.plot_num_synapses_per_pair("dSPN", "iSPN")
Expand Down Expand Up @@ -220,14 +226,16 @@ def plot_fslt_scum_dist(self, plot_fs=True, plot_lts=True):
exp_max_dist=[100e-6, 150e-6, 250e-6],
exp_data=[6 / 9.0, 21 / 54.0, 27 / 77.0],
exp_data_detailed=[(6, 9), (21, 54), (27, 77)],
y_max=None)
y_max=None,
dump_data_to_file=dump_connection_data_to_file)

nas.plot_connection_probability("FS", "dSPN",
dist_3d=dist3D,
exp_max_dist=[100e-6, 150e-6, 250e-6],
exp_data=[8 / 9.0, 29 / 48.0, 48 / 90.0],
exp_data_detailed=[(8, 9), (29, 48), (48, 90)],
y_max=None)
y_max=None,
dump_data_to_file=dump_connection_data_to_file)

nas.plot_num_synapses_per_pair("FS", "dSPN")
nas.plot_num_synapses_per_pair("FS", "iSPN")
Expand All @@ -239,7 +247,8 @@ def plot_fslt_scum_dist(self, plot_fs=True, plot_lts=True):
dist_3d=dist3D,
exp_max_dist=[250e-6],
exp_data=[7 / 12.0],
exp_data_detailed=[(7, 12)])
exp_data_detailed=[(7, 12)],
dump_data_to_file=dump_connection_data_to_file)

nas.plot_num_synapses_per_pair("FS", "FS")

Expand All @@ -250,7 +259,8 @@ def plot_fslt_scum_dist(self, plot_fs=True, plot_lts=True):
connection_type="gapjunctions",
exp_max_dist=[200e-6, 250e-6, 250e-6],
exp_data=[6/78.0, 2 / 6.0, 3 / 7.0],
exp_data_detailed=[(6, 78), (2, 6), (3, 7)], )
exp_data_detailed=[(6, 78), (2, 6), (3, 7)],
dump_data_to_file=dump_connection_data_to_file)

nas.plot_num_synapses_per_pair("FS", "FS", connection_type="gapjunctions")

Expand Down Expand Up @@ -280,14 +290,16 @@ def plot_fslt_scum_dist(self, plot_fs=True, plot_lts=True):
exp_max_dist=[250e-6],
exp_data=[2 / 60.0],
exp_data_detailed=[(2, 60)],
x_max=500)
x_max=500,
dump_data_to_file=dump_connection_data_to_file)

nas.plot_connection_probability("LTS", "iSPN",
dist_3d=dist3D,
exp_max_dist=[250e-6],
exp_data=[2 / 60.0],
exp_data_detailed=[(2, 60)],
x_max=500)
x_max=500,
dump_data_to_file=dump_connection_data_to_file)

# Silberberg et al 2013, 2/12 FS-> LTS connected --- distance??
# Voltage deflection... 0.5mV and 0.8mV
Expand All @@ -297,7 +309,8 @@ def plot_fslt_scum_dist(self, plot_fs=True, plot_lts=True):
dist_3d=dist3D,
exp_max_dist=[250e-6],
exp_data=[2.0 / 12],
exp_data_detailed=[(2, 12)])
exp_data_detailed=[(2, 12)],
dump_data_to_file=dump_connection_data_to_file)

nas.plot_num_synapses_per_pair("LTS", "dSPN")
nas.plot_num_synapses_per_pair("LTS", "iSPN")
Expand All @@ -318,22 +331,26 @@ def plot_fslt_scum_dist(self, plot_fs=True, plot_lts=True):
nas.plot_num_synapses_per_pair("ChIN", "LTS")

nas.plot_connection_probability("ChIN", "LTS",
dist_3d=dist3D)
dist_3d=dist3D,
dump_data_to_file=dump_connection_data_to_file)

# Janicova 2015?? --- distance??!
nas.plot_connection_probability("ChIN", "iSPN",
dist_3d=dist3D,
exp_max_dist=[250e-6],
exp_data=[0.05])
exp_data=[0.05],
dump_data_to_file=dump_connection_data_to_file)

nas.plot_connection_probability("ChIN", "dSPN",
dist_3d=dist3D,
exp_max_dist=[250e-6],
exp_data=[0.05])
exp_data=[0.05],
dump_data_to_file=dump_connection_data_to_file)

if True:
nas.plot_connection_probability("LTS", "ChIN",
dist_3d=dist3D)
dist_3d=dist3D,
dump_data_to_file=dump_connection_data_to_file)

# ALSO ADD GAP JUNCTIONS PLOT!!!
# No exp data for this -- Gittis,...,Kreitzer 2010 (p2228) -- 7/12 (and 3/4 reciprocal) -- distance?
Expand Down Expand Up @@ -373,7 +390,8 @@ def plot_fslt_scum_dist(self, plot_fs=True, plot_lts=True):

nas.plot_connection_probability("ChIN", "FS",
dist_3d=dist3D,
y_max=None)
y_max=None,
dump_data_to_file=dump_connection_data_to_file)

# A MS neuron receives 1e4 assymetrical synapses (Kincaid et al 1998),
# and 2500 symmetrical synapses (Ingham et al 1998). Symmetrical synapses
Expand All @@ -394,9 +412,11 @@ def plot_fslt_scum_dist(self, plot_fs=True, plot_lts=True):
# så är 200 MS aktiva, om 75% av ChIN känner av MS input
# (1-p)^200 = 0.25 --> 0.7 %
nas.plot_connection_probability("dSPN", "ChIN",
dist_3d=dist3D)
dist_3d=dist3D,
dump_data_to_file=dump_connection_data_to_file)
nas.plot_connection_probability("iSPN", "ChIN",
dist_3d=dist3D)
dist_3d=dist3D,
dump_data_to_file=dump_connection_data_to_file)

# nas.nearestPreNeighbourDistance("LTS","dSPN")
# nas.nearestPreNeighbourDistance("LTS","iSPN")
Expand Down
23 changes: 12 additions & 11 deletions snudda/place/region_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, filename, d_view=None, role="master",
pickle_version (int) : Which version of pickle to use? (-1 latest)
raytrace_borders (bool) : Raytrace positions in border regions? Slower, but more accurate.
d_min (float) : Closest distance between soma
bin_width (float) : Mesh size
bin_width (float) : Mesh size in meters
logfile_name (str) : Path to logfile
log_file : File pointer to log file
random_seed (int) : Random seed value
Expand Down Expand Up @@ -418,7 +418,7 @@ def load_mesh(self, filename):
self.mesh_vec[ir, :] = row

for ir, row in enumerate(all_faces):
self.mesh_faces[ir,] = row
self.mesh_faces[ir, ] = row

for ir, row in enumerate(all_norm):
self.mesh_norm[ir, :] = row
Expand Down Expand Up @@ -562,7 +562,7 @@ def check_inside(self, coords):

def _voxel_mask_helper(self, x_range):

""" Helper function. """
""" Helper function. Determine if voxels are inner our outer."""

try:

Expand Down Expand Up @@ -825,20 +825,17 @@ def update_padding_mask(self):

if np.sum(self.voxel_mask_border):
# If we do raytracing then the border exists
self.voxel_mask_padding = np.copy(self.voxel_mask_border)

self.voxel_mask_padding = \
scipy.ndimage.binary_dilation(self.voxel_mask_padding,
structure=s,
iterations=n_dist)
dilated_mask = scipy.ndimage.binary_dilation(self.voxel_mask_border,
structure=s,
iterations=n_dist)
else:
# No ray tracing, we need to create a padding region

dilated_mask = scipy.ndimage.binary_dilation(self.voxel_mask_inner,
structure=s,
iterations=n_dist)
self.voxel_mask_padding = \
np.logical_xor(dilated_mask, self.voxel_mask_inner)

self.voxel_mask_padding = np.logical_and(dilated_mask, ~self.voxel_mask_inner)

############################################################################

Expand Down Expand Up @@ -976,6 +973,10 @@ def place_neurons(self, num_cells, neuron_type=None, d_min=None):
self.density_total_n_sample[neuron_type] += 1

try:
# We are sampling the densities, to see how much of the density mass is in
# the current voxel compared to the total density mass in all voxels together
# That should tell us what fraction of all the neurons placed of that type
# should be in this particular voxel
n_expected = (self.density_voxel_sum[neuron_type][vx, vy, vz]
/ self.density_total_sum[neuron_type]
* (self.placed_total[neuron_type] + 1))
Expand Down

0 comments on commit 658d6a8

Please sign in to comment.