Challenge reshaping 1D density ISH data into 3D

Hi – I’m having a challenge reshaping the 1D density ISH data into 3D for Developing Mouse Brain.

Here’s an example (in python) for the Lgals1 gene for Dev Mouse Brain – p28:

  1. Download the p28 density data from the API using this call:
  2. Save into a numpy array called ‘density_1d’. The array has a length of 158,629 (which corresponds to the 1D version of the 73x41x53 3D voxel space.
  3. Reshape into 3D via this code: density_3d = np.reshape(density_1d, (73, 41, 53))

Attached are visualizations of the 1D array and the 3D reshaped array:

The 3D visualization should look much more like a brain, but it looks like noise, suggesting that the reshape/transformation failed. Can you help suggest how to properly reshape into 3D?

Thanks for any help you can give!

Also, I’m curious why the 1D array doesn’t have any data above voxel 80,000? I found that the density files for all of the 2,000 genes in p28 developing mouse brain had no data above voxel 110,000. Does it have to do with the shape of the brain?


I like to leverage SimpleITK to read/write volumetric images and to convert them to a numpy array.
Note that numpy array the dimension are flipped so for this volume you will get an array of (53,41,73)

Some notebook code snippet that might be useful

import SimpleITK as sitk
%matplotlib inline
import matplotlib.pyplot as plt

volume = sitk.ReadImage( ‘density.mhd’)
array = sitk.GetArrayFromImage( volume )

Note the reference volume (below) typically covers larger area of the brain than a typical sagittal dataset.
This is why you will get a lot of voxels that has no data (value = -1)

Lydia – this is fantastic! This all works and makes sense. Thank you.