Explorar el Código

current state: code is finished for representation

arefks hace 3 meses
padre
commit
e8e54e0207
Se han modificado 42 ficheros con 3830 adiciones y 19 borrados
  1. 1843 0
      code/.ipynb_checkpoints/Big_data_mouse_practical_2020_answer-checkpoint.ipynb
  2. 1748 0
      code/Big_data_mouse_practical_2020_answer.ipynb
  3. 103 0
      code/mouse_connectivity/manifest.json
  4. 19 19
      code/overlayPlot.py
  5. 109 0
      code/overlayPlot3D.py
  6. BIN
      input/12_wks_coronal_100141780_100um_projection_density.nii.gz
  7. BIN
      input/12_wks_coronal_100141780_50um_projection_density.nii.gz
  8. BIN
      input/C57BL6_mouse_fiber.nii.gz
  9. BIN
      input/SSp_bfd5_Primary_somatosensory_area_barrel_field_layer_5.nii.gz
  10. BIN
      input/average_template_100_from_website.nii.gz
  11. BIN
      input/average_template_50_from_website.nii.gz
  12. BIN
      input/del/1-s2.0-S1053811923001453-gr1.jpg
  13. BIN
      input/del/12_wks_coronal_100141780_100um_projection_density.nii.gz
  14. 0 0
      input/del/12_wks_coronal_100141780_100um_projection_density.nrrd
  15. BIN
      input/del/12_wks_coronal_100141780_50um_projection_density.nrrd
  16. BIN
      input/del/ABtempate_adj_reg.nii.gz
  17. BIN
      input/del/ABtempate_reg.nii.gz
  18. BIN
      input/del/ABtemplate100_adjusted.nii.gz
  19. 0 0
      input/del/ABtemplate_Website.nii.gz
  20. BIN
      input/del/ABtemplate_Website_registered.nii.gz
  21. BIN
      input/del/ABtemplate_adjusted.nii.gz
  22. BIN
      input/del/ABtemplate_test.nii.gz
  23. 4 0
      input/del/AffineTraicing.txt
  24. BIN
      input/del/C57BL6_mouse.fib.image.jpg
  25. 4 0
      input/del/affine4tracing
  26. BIN
      input/del/average_template_100.nii.gz
  27. BIN
      input/del/average_template_100.nrrd
  28. BIN
      input/del/average_template_100_adjusted.nii.gz
  29. BIN
      input/del/average_template_50.nrrd
  30. BIN
      input/del/average_template_50_Niklas.nii.gz
  31. BIN
      input/fiber_registered.nii.gz
  32. BIN
      output/Nifti_Trakte/CC_Mop_dilated_denstitymask.nii.gz.nii
  33. BIN
      output/Nifti_Trakte_registered/CC_Mop_desnitymask_50um.nii.gz
  34. BIN
      output/figures/Figure 2024-01-26 114119.png
  35. BIN
      output/figures/Figure 2024-01-26 114922.png
  36. BIN
      output/figures/Figure 2024-01-26 115238.png
  37. BIN
      output/figures/Figure 2024-01-26 115310.png
  38. BIN
      output/figures/Figure 2024-01-26 115426.png
  39. BIN
      output/figures/Figure 2024-01-26 132643.png
  40. BIN
      output/figures/Figure 2024-01-26 143629.png
  41. BIN
      output/figures/Figure 2024-01-26 153529.png
  42. BIN
      output/figures/Figure 2024-01-26 153824.png

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 1843 - 0
code/.ipynb_checkpoints/Big_data_mouse_practical_2020_answer-checkpoint.ipynb


La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 1748 - 0
code/Big_data_mouse_practical_2020_answer.ipynb


+ 103 - 0
code/mouse_connectivity/manifest.json

@@ -0,0 +1,103 @@
+{
+  "manifest": [
+    {
+      "type": "manifest_version",
+      "value": 1.3
+    },
+    {
+      "key": "BASEDIR",
+      "type": "dir",
+      "spec": "."
+    },
+    {
+      "key": "STRUCTURE_TREE",
+      "type": "file",
+      "spec": "structures.json",
+      "parent_key": "BASEDIR"
+    },
+    {
+      "key": "REFERENCE_SPACE_VERSION",
+      "type": "dir",
+      "spec": "%s",
+      "parent_key": "BASEDIR"
+    },
+    {
+      "key": "ANNOTATION",
+      "type": "file",
+      "spec": "annotation_%d.nrrd",
+      "parent_key": "REFERENCE_SPACE_VERSION"
+    },
+    {
+      "key": "TEMPLATE",
+      "type": "file",
+      "spec": "average_template_%d.nrrd",
+      "parent_key": "BASEDIR"
+    },
+    {
+      "key": "STRUCTURE_MASK",
+      "type": "file",
+      "spec": "structure_masks/resolution_%d/structure_%d.nrrd",
+      "parent_key": "REFERENCE_SPACE_VERSION"
+    },
+    {
+      "key": "STRUCTURE_MESH",
+      "type": "file",
+      "spec": "structure_meshes/structure_%d.obj",
+      "parent_key": "REFERENCE_SPACE_VERSION"
+    },
+    {
+      "key": "EXPERIMENTS",
+      "type": "file",
+      "spec": "experiments.json",
+      "parent_key": "BASEDIR"
+    },
+    {
+      "key": "STRUCTURE_UNIONIZES",
+      "type": "file",
+      "spec": "experiment_%d/structure_unionizes.csv",
+      "parent_key": "BASEDIR"
+    },
+    {
+      "key": "INJECTION_DENSITY",
+      "type": "file",
+      "spec": "experiment_%d/injection_density_%d.nrrd",
+      "parent_key": "BASEDIR"
+    },
+    {
+      "key": "INJECTION_FRACTION",
+      "type": "file",
+      "spec": "experiment_%d/injection_fraction_%d.nrrd",
+      "parent_key": "BASEDIR"
+    },
+    {
+      "key": "DATA_MASK",
+      "type": "file",
+      "spec": "experiment_%d/data_mask_%d.nrrd",
+      "parent_key": "BASEDIR"
+    },
+    {
+      "key": "PROJECTION_DENSITY",
+      "type": "file",
+      "spec": "experiment_%d/projection_density_%d.nrrd",
+      "parent_key": "BASEDIR"
+    },
+    {
+      "key": "DEFORMATION_FIELD_HEADER",
+      "type": "file",
+      "spec": "experiment_%d/dfmfld.mhd",
+      "parent_key": "BASEDIR"
+    },
+    {
+      "key": "DEFORMATION_FIELD_VOXELS",
+      "type": "file",
+      "spec": "experiment_%d/dfmfld.raw",
+      "parent_key": "BASEDIR"
+    },
+    {
+      "key": "ALIGNMENT3D",
+      "type": "file",
+      "spec": "experiment_%d/alignment3d.json",
+      "parent_key": "BASEDIR"
+    }
+  ]
+}

+ 19 - 19
code/overlayPlot.py

@@ -1,11 +1,12 @@
 import nibabel as nib
 import numpy as np
 import matplotlib.pyplot as plt
+from scipy.ndimage import rotate
 
 # Define the file paths
 templateFilePath = r"C:\Users\aswen\Desktop\Code\2024_Ruthe_SND\input\average_template_50_from_website.nii.gz"
 densityFilePath = r"C:\Users\aswen\Desktop\Code\2024_Ruthe_SND\input\12_wks_coronal_100141780_50um_projection_density.nii.gz"
-maskFilePath = r"C:\Users\aswen\Desktop\Code\2024_Ruthe_SND\output\Nifti_Trakte_registered\CC_Mop_dilated_registered.nii.gz"
+maskFilePath = r"C:\Users\aswen\Desktop\Code\2024_Ruthe_SND\output\Nifti_Trakte_registered\CC_Mop_desnitymask_50um.nii.gz"
 
 # Load the NIfTI files
 templateNifti = nib.load(templateFilePath)
@@ -15,13 +16,6 @@ maskNifti = nib.load(maskFilePath)
 # Ensure that both images have the same data type (e.g., cast density to the data type of template)
 densityNifti = nib.Nifti1Image(densityNifti.get_fdata().astype(templateNifti.get_fdata().dtype), densityNifti.affine)
 
-# Load the mask data and normalize it to [0, 1]
-maskData = maskNifti.get_fdata()
-maskData = (maskData - np.min(maskData)) / (np.max(maskData) - np.min(maskData))
-
-# Define the color for the mask overlay (e.g., blue)
-mask_color = np.array([0, 0, 1])  # Blue
-
 # Customize the figure DPI
 dpi = 400
 
@@ -29,10 +23,10 @@ dpi = 400
 num_slices_dim0, num_slices_dim1, num_slices_dim2 = templateNifti.shape
 
 # Set the slice step for display (every tenth slice)
-slice_step = 2
+slice_step = 10
 
 # Choose the dimension for iteration (0, 1, or 2)
-iteration_dimension = 0  # Change this value to select the dimension
+iteration_dimension = 1  # Change this value to select the dimension
 
 # Calculate the number of rows and columns for the grid based on the selected dimension
 if iteration_dimension == 0:
@@ -55,6 +49,12 @@ for ax_row in axs:
     for ax in ax_row:
         ax.axis('off')
 
+# Load the mask and perform necessary flips
+mask_data = np.squeeze(maskNifti.get_fdata())
+# Swap the mask over the x and y axes
+mask_data = mask_data.swapaxes(0, 2)
+mask_data = np.flip(mask_data, axis=0)
+
 # Loop through and display every nth slice as subplots along the selected dimension
 for i, sliceIdx in enumerate(range(0, num_slices, slice_step)):
     row = i // grid_size
@@ -64,27 +64,27 @@ for i, sliceIdx in enumerate(range(0, num_slices, slice_step)):
     if iteration_dimension == 0:
         templateSlice = np.squeeze(templateNifti.get_fdata()[sliceIdx, :, :]).astype(np.uint16)
         densitySlice = np.squeeze(densityNifti.get_fdata()[sliceIdx, :, :]).astype(np.double)
-        maskSlice = np.squeeze(maskData[sliceIdx, :, :])
+        maskSlice = np.squeeze(mask_data[sliceIdx, :, :])
     elif iteration_dimension == 1:
         templateSlice = np.squeeze(templateNifti.get_fdata()[:, sliceIdx, :]).astype(np.uint16)
         densitySlice = np.squeeze(densityNifti.get_fdata()[:, sliceIdx, :]).astype(np.double)
-        maskSlice = np.squeeze(maskData[:, sliceIdx, :])
+        maskSlice = np.squeeze(mask_data[:, sliceIdx, :])
     else:
         templateSlice = np.squeeze(templateNifti.get_fdata()[:, :, sliceIdx]).astype(np.uint16)
         densitySlice = np.squeeze(densityNifti.get_fdata()[:, :, sliceIdx]).astype(np.double)
-        maskSlice = np.squeeze(maskData[:, :, sliceIdx])
+        maskSlice = np.squeeze(mask_data[:, :, sliceIdx])
 
     # Normalize the templateSlice to [0, 1] for visualization
     templateSlice = (templateSlice - np.min(templateSlice)) / (np.max(templateSlice) - np.min(templateSlice))
 
-    # Overlay the density onto the template slice
-    overlayedImage = templateSlice + densitySlice
-
-    # Apply the mask color to the mask region
-    overlayedImage[np.where(maskSlice > 0.5)] = mask_color
+    # Overlay the density and mask onto the template slice
+    overlayedImage = templateSlice + densitySlice + maskSlice
 
     # Display the overlaid image in the corresponding subplot
-    axs[row, col].imshow(overlayedImage, cmap='gray')
+    axs[row, col].imshow(templateSlice, cmap='gray')
+    axs[row, col].imshow(densitySlice, cmap='hot', alpha=0.3)
+    axs[row, col].imshow(maskSlice, cmap='cool', alpha=0.3)  # Apply "hot" colormap to the mask
+  # Apply "cool" colormap to the mask
 
 # Remove empty subplots if necessary
 for i in range(num_slices // slice_step, grid_size * grid_size):

+ 109 - 0
code/overlayPlot3D.py

@@ -0,0 +1,109 @@
+import nibabel as nib
+import numpy as np
+import matplotlib.pyplot as plt
+from scipy.ndimage import rotate
+
+# Define the file paths
+templateFilePath = r"C:\Users\aswen\Desktop\Code\2024_Ruthe_SND\input\average_template_50_from_website.nii.gz"
+densityFilePath = r"C:\Users\aswen\Desktop\Code\2024_Ruthe_SND\input\12_wks_coronal_100141780_50um_projection_density.nii.gz"
+maskFilePath = r"C:\Users\aswen\Desktop\Code\2024_Ruthe_SND\output\Nifti_Trakte_registered\CC_Mop_dilated_registered.nii.gz"
+tractFilePath = r"C:\Users\aswen\Desktop\Code\2024_Ruthe_SND\input\fiber_registered.nii.gz"
+
+# Load the NIfTI files
+templateNifti = nib.load(templateFilePath)
+densityNifti = nib.load(densityFilePath)
+maskNifti = nib.load(maskFilePath)
+tractNifti = nib.load(tractFilePath)
+
+# Ensure that both images have the same data type (e.g., cast density to the data type of template)
+densityNifti = nib.Nifti1Image(densityNifti.get_fdata().astype(templateNifti.get_fdata().dtype), densityNifti.affine)
+
+# Customize the figure DPI
+dpi = 400
+
+# Get the number of slices along each dimension
+num_slices_dim0, num_slices_dim1, num_slices_dim2 = templateNifti.shape
+
+# Set the slice step for display (every tenth slice)
+slice_step = 10
+
+# Choose the dimension for iteration (0, 1, or 2)
+iteration_dimension = 0  # Change this value to select the dimension
+
+# Calculate the number of rows and columns for the grid based on the selected dimension
+if iteration_dimension == 0:
+    num_slices = num_slices_dim0
+elif iteration_dimension == 1:
+    num_slices = num_slices_dim1
+else:
+    num_slices = num_slices_dim2
+
+grid_size = int(np.sqrt(num_slices // slice_step))
+if grid_size * grid_size < num_slices // slice_step:
+    grid_size += 1
+
+cm = 1/2.54
+# Adjust the figure size to be larger
+fig, axs = plt.subplots(grid_size, grid_size, figsize=(20, 20), dpi=dpi)
+
+# Hide axis numbers
+for ax_row in axs:
+    for ax in ax_row:
+        ax.axis('off')
+
+# Load the mask and perform necessary flips
+mask_data = np.squeeze(maskNifti.get_fdata())
+# Swap the mask over the x and y axes
+mask_data = mask_data.swapaxes(0, 2)
+mask_data = np.flip(mask_data, axis=0)
+
+# Load the tract data and perform necessary flips
+tract_data0 = np.squeeze(tractNifti.get_fdata())
+tract_data = tract_data0[:,:,:,1]
+# Swap the tract over the x and y axes
+tract_data = tract_data.swapaxes(0, 2)
+tract_data = np.flip(tract_data, axis=0)
+
+# Loop through and display every nth slice as subplots along the selected dimension
+for i, sliceIdx in enumerate(range(0, num_slices, slice_step)):
+    row = i // grid_size
+    col = i % grid_size
+
+    # Extract the desired slice from the template, density, mask, and tract based on the selected dimension
+    if iteration_dimension == 0:
+        templateSlice = np.squeeze(templateNifti.get_fdata()[sliceIdx, :, :]).astype(np.uint16)
+        densitySlice = np.squeeze(densityNifti.get_fdata()[sliceIdx, :, :]).astype(np.double)
+        maskSlice = np.squeeze(mask_data[sliceIdx, :, :])
+        tractSlice = np.squeeze(tract_data[sliceIdx, :, :])
+    elif iteration_dimension == 1:
+        templateSlice = np.squeeze(templateNifti.get_fdata()[:, sliceIdx, :]).astype(np.uint16)
+        densitySlice = np.squeeze(densityNifti.get_fdata()[:, sliceIdx, :]).astype(np.double)
+        maskSlice = np.squeeze(mask_data[:, sliceIdx, :])
+        tractSlice = np.squeeze(tract_data[:, sliceIdx, :])
+    else:
+        templateSlice = np.squeeze(templateNifti.get_fdata()[:, :, sliceIdx]).astype(np.uint16)
+        densitySlice = np.squeeze(densityNifti.get_fdata()[:, :, sliceIdx]).astype(np.double)
+        maskSlice = np.squeeze(mask_data[:, :, sliceIdx])
+        tractSlice = np.squeeze(tract_data[:, :, sliceIdx])
+
+    # Normalize the templateSlice to [0, 1] for visualization
+    templateSlice = (templateSlice - np.min(templateSlice)) / (np.max(templateSlice) - np.min(templateSlice))
+
+    # Overlay the density, mask, and tract onto the template slice
+    overlayedImage = templateSlice + densitySlice + maskSlice + tractSlice
+
+    # Display the overlaid image in the corresponding subplot
+    #axs[row, col].imshow(templateSlice, cmap='gray')
+    #axs[row, col].imshow(densitySlice, cmap='hot', alpha=0.3)
+    #axs[row, col].imshow(maskSlice, cmap='YlGn', alpha=0.20, vmin=0.9, vmax=1)  # Apply "hot" colormap to the mask
+    axs[row, col].imshow(tractSlice, cmap='gray', alpha=1)  # Apply "Blues" colormap to the tract
+
+# Remove empty subplots if necessary
+for i in range(num_slices // slice_step, grid_size * grid_size):
+    fig.delaxes(axs.flatten()[i])
+
+# Adjust spacing between subplots
+plt.tight_layout()
+
+# Show the plot
+plt.show()

BIN
input/12_wks_coronal_100141780_100um_projection_density.nii.gz


BIN
input/12_wks_coronal_100141780_50um_projection_density.nii.gz


BIN
input/C57BL6_mouse_fiber.nii.gz


BIN
input/SSp_bfd5_Primary_somatosensory_area_barrel_field_layer_5.nii.gz


BIN
input/average_template_100_from_website.nii.gz


BIN
input/average_template_50_from_website.nii.gz


BIN
input/del/1-s2.0-S1053811923001453-gr1.jpg


BIN
input/del/12_wks_coronal_100141780_100um_projection_density.nii.gz


input/12_wks_coronal_100141780_100um_projection_density.nrrd → input/del/12_wks_coronal_100141780_100um_projection_density.nrrd


BIN
input/del/12_wks_coronal_100141780_50um_projection_density.nrrd


BIN
input/del/ABtempate_adj_reg.nii.gz


BIN
input/del/ABtempate_reg.nii.gz


BIN
input/del/ABtemplate100_adjusted.nii.gz


input/ABtemplate_Website.nii.gz → input/del/ABtemplate_Website.nii.gz


BIN
input/del/ABtemplate_Website_registered.nii.gz


BIN
input/del/ABtemplate_adjusted.nii.gz


BIN
input/del/ABtemplate_test.nii.gz


+ 4 - 0
input/del/AffineTraicing.txt

@@ -0,0 +1,4 @@
+0.04167841 0.08808794 -0.02362752 -6.387238
+-0.06238003 0.04099635 -0.03338426 2.982297
+-0.01895299 0.04575063 0.1045295 -5.975962
+0 0 0 1

BIN
input/del/C57BL6_mouse.fib.image.jpg


+ 4 - 0
input/del/affine4tracing

@@ -0,0 +1,4 @@
+4.964144 -12.625 -2.685628 50.82305
+5.568674 1.860485 4.831832 43.57913
+-5.458191 -6.029406 6.024457 36.90547
+0 0 0 1

BIN
input/del/average_template_100.nii.gz


BIN
input/del/average_template_100.nrrd


BIN
input/del/average_template_100_adjusted.nii.gz


BIN
input/del/average_template_50.nrrd


BIN
input/del/average_template_50_Niklas.nii.gz


BIN
input/fiber_registered.nii.gz


BIN
output/Nifti_Trakte/CC_Mop_dilated_denstitymask.nii.gz.nii


BIN
output/Nifti_Trakte_registered/CC_Mop_desnitymask_50um.nii.gz


BIN
output/figures/Figure 2024-01-26 114119.png


BIN
output/figures/Figure 2024-01-26 114922.png


BIN
output/figures/Figure 2024-01-26 115238.png


BIN
output/figures/Figure 2024-01-26 115310.png


BIN
output/figures/Figure 2024-01-26 115426.png


BIN
output/figures/Figure 2024-01-26 132643.png


BIN
output/figures/Figure 2024-01-26 143629.png


BIN
output/figures/Figure 2024-01-26 153529.png


BIN
output/figures/Figure 2024-01-26 153824.png