{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":84969,"databundleVersionId":10033515,"sourceType":"competition"}],"dockerImageVersionId":30786,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Introduction\nJust a quick first look at the data.  Open the first tomogram (Experiment TS_6_4) with zarr and plot the 2D images.","metadata":{}},{"cell_type":"code","source":"# Install zarr\n!pip install zarr","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:12:06.056529Z","iopub.execute_input":"2024-11-12T05:12:06.056958Z","iopub.status.idle":"2024-11-12T05:12:26.724163Z","shell.execute_reply.started":"2024-11-12T05:12:06.056916Z","shell.execute_reply":"2024-11-12T05:12:26.722730Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Imports\nimport json\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport zarr","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:12:26.727298Z","iopub.execute_input":"2024-11-12T05:12:26.727878Z","iopub.status.idle":"2024-11-12T05:12:28.333334Z","shell.execute_reply.started":"2024-11-12T05:12:26.727818Z","shell.execute_reply":"2024-11-12T05:12:28.332090Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Load the first zarr.\nz_ts_6_4 = zarr.open('/kaggle/input/czii-cryo-et-object-identification/test/static/ExperimentRuns/TS_6_4/VoxelSpacing10.000/denoised.zarr', mode='r')\nz_ts_6_4_iso = zarr.open('/kaggle/input/czii-cryo-et-object-identification/train/static/ExperimentRuns/TS_6_4/VoxelSpacing10.000/isonetcorrected.zarr', mode='r')\nz_ts_6_4_dcon = zarr.open('/kaggle/input/czii-cryo-et-object-identification/train/static/ExperimentRuns/TS_6_4/VoxelSpacing10.000/ctfdeconvolved.zarr', mode='r')\nz_ts_6_4_wbp = zarr.open('/kaggle/input/czii-cryo-et-object-identification/train/static/ExperimentRuns/TS_6_4/VoxelSpacing10.000/wbp.zarr', mode='r')\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:12:28.334976Z","iopub.execute_input":"2024-11-12T05:12:28.335898Z","iopub.status.idle":"2024-11-12T05:12:28.468494Z","shell.execute_reply.started":"2024-11-12T05:12:28.335841Z","shell.execute_reply":"2024-11-12T05:12:28.467214Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(z_ts_6_4)\nprint(z_ts_6_4[0].shape)\nprint(z_ts_6_4[1].shape)\nprint(z_ts_6_4[2].shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:12:28.471547Z","iopub.execute_input":"2024-11-12T05:12:28.471943Z","iopub.status.idle":"2024-11-12T05:12:28.499294Z","shell.execute_reply.started":"2024-11-12T05:12:28.471904Z","shell.execute_reply":"2024-11-12T05:12:28.497843Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# High Resolution\nPlot the first image at 100 dpi.  Plot all 184 images in a grid after that.","metadata":{}},{"cell_type":"code","source":"fig = plt.figure(figsize=(6.3,6.3))\n_ = plt.imshow(z_ts_6_4[0][0])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:12:28.500976Z","iopub.execute_input":"2024-11-12T05:12:28.501487Z","iopub.status.idle":"2024-11-12T05:12:31.242233Z","shell.execute_reply.started":"2024-11-12T05:12:28.501433Z","shell.execute_reply":"2024-11-12T05:12:31.240989Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Plot the first 25 of...not sure what we're looking at yet.  :)\nfig = plt.figure(figsize=(10,74))\nfor i in range(184):\n    ax = plt.subplot(37, 5, i + 1)\n    plt.xticks([])\n    plt.yticks([])\n    plt.imshow(z_ts_6_4[0][i])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:12:31.243624Z","iopub.execute_input":"2024-11-12T05:12:31.243998Z","iopub.status.idle":"2024-11-12T05:14:14.958365Z","shell.execute_reply.started":"2024-11-12T05:12:31.243959Z","shell.execute_reply":"2024-11-12T05:14:14.956355Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Medium Resolution\nPlot the first image at 100 dpi.  Plot all 92 images in a grid after that.","metadata":{}},{"cell_type":"code","source":"fig = plt.figure(figsize=(3.15,3.15))\n_ = plt.imshow(z_ts_6_4[1][0])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:14:14.960154Z","iopub.execute_input":"2024-11-12T05:14:14.960677Z","iopub.status.idle":"2024-11-12T05:14:15.733862Z","shell.execute_reply.started":"2024-11-12T05:14:14.960567Z","shell.execute_reply":"2024-11-12T05:14:15.732735Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"fig = plt.figure(figsize=(10,38))\nfor i in range(92):\n    ax = plt.subplot(19, 5, i + 1)\n    plt.xticks([])\n    plt.yticks([])\n    plt.imshow(z_ts_6_4[1][i])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:14:15.735789Z","iopub.execute_input":"2024-11-12T05:14:15.736165Z","iopub.status.idle":"2024-11-12T05:14:34.906717Z","shell.execute_reply.started":"2024-11-12T05:14:15.736126Z","shell.execute_reply":"2024-11-12T05:14:34.904971Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Low Resolution\nPlot the first image at 100 dpi.  Plot all 46 images in a grid after that.","metadata":{}},{"cell_type":"code","source":"fig = plt.figure(figsize=(1.58,1.58))\n_ = plt.imshow(z_ts_6_4[2][0])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:14:34.908606Z","iopub.execute_input":"2024-11-12T05:14:34.908982Z","iopub.status.idle":"2024-11-12T05:14:35.216778Z","shell.execute_reply.started":"2024-11-12T05:14:34.908944Z","shell.execute_reply":"2024-11-12T05:14:35.215730Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"fig = plt.figure(figsize=(10,20))\nfor i in range(46):\n    ax = plt.subplot(10, 5, i + 1)\n    plt.xticks([])\n    plt.yticks([])\n    plt.imshow(z_ts_6_4[2][i])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:14:35.221255Z","iopub.execute_input":"2024-11-12T05:14:35.222328Z","iopub.status.idle":"2024-11-12T05:14:40.159066Z","shell.execute_reply.started":"2024-11-12T05:14:35.222267Z","shell.execute_reply":"2024-11-12T05:14:40.157904Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Denoised, IsoNet Corrected, CTF Deconvolved, and Weighted Back Projection\n\nNext plot each of the different image types present in the training directories.  This time just one high resolution image each of the same layer.","metadata":{}},{"cell_type":"code","source":"fig = plt.figure(figsize=(10,10))\nax = plt.subplot(2, 2, 1)\nplt.xticks([])\nplt.yticks([])\nplt.title('Denoised')\nplt.imshow(z_ts_6_4[0][62], cmap='gray')\nax = plt.subplot(2, 2, 2)\nplt.xticks([])\nplt.yticks([])\nplt.title('IsoNet Corrected')\nplt.imshow(z_ts_6_4_iso[0][62], cmap='gray')\nax = plt.subplot(2, 2, 3)\nplt.xticks([])\nplt.yticks([])\nplt.title('CTF Deconvolved')\nplt.imshow(z_ts_6_4_dcon[0][62], cmap='gray')\nax = plt.subplot(2, 2, 4)\nplt.xticks([])\nplt.yticks([])\nplt.title('Weighted Back Projection')\n_ = plt.imshow(z_ts_6_4_wbp[0][62], cmap='gray')\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:14:40.160852Z","iopub.execute_input":"2024-11-12T05:14:40.161321Z","iopub.status.idle":"2024-11-12T05:14:47.600579Z","shell.execute_reply.started":"2024-11-12T05:14:40.161276Z","shell.execute_reply":"2024-11-12T05:14:47.599484Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Ribosome Identification\n\nNow that we can plot the images the next step is to try to identify structures of interest.  Lists of those structures for TS_6_4 are in the train/overlay directory.  We'll start with ribosomes.\n\nFind all of the ribosomes between 600 and 650 in the z-axis, and plot them on slide 62 to see if we get something reasonable.  If we do that suggests the origin is in the upper left in the x and y directions, and in the first image in the z direction.","metadata":{}},{"cell_type":"code","source":"ribosomes_x = []\nribosomes_y = []\nf = open('/kaggle/input/czii-cryo-et-object-identification/train/overlay/ExperimentRuns/TS_6_4/Picks/ribosome.json')\nfor p in json.loads(f.read())['points']:\n    z = float(p['location']['z'])\n    if z >= 600 and z < 650:\n        ribosomes_x.append(float(p['location']['x'])/10)\n        ribosomes_y.append(float(p['location']['y'])/10)\n        print(p['location'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:14:47.602304Z","iopub.execute_input":"2024-11-12T05:14:47.602778Z","iopub.status.idle":"2024-11-12T05:14:47.623921Z","shell.execute_reply.started":"2024-11-12T05:14:47.602726Z","shell.execute_reply":"2024-11-12T05:14:47.622648Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Looking at the plotted images, we seem to have compelling matches.","metadata":{}},{"cell_type":"code","source":"fig = plt.figure(figsize=(10,5))\nax = plt.subplot(1, 2, 1)\nplt.xticks([])\nplt.yticks([])\nplt.imshow(z_ts_6_4[0][62], cmap='gray', vmin=-0.00005, vmax=0.00005)\nax = plt.subplot(1, 2, 2)\nplt.xticks([])\nplt.yticks([])\nplt.imshow(z_ts_6_4[0][62], cmap='gray', vmin=-0.00005, vmax=0.00005)\n_ = plt.scatter(ribosomes_x, ribosomes_y, edgecolor='red', facecolor='none')\n\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:14:47.625505Z","iopub.execute_input":"2024-11-12T05:14:47.625975Z","iopub.status.idle":"2024-11-12T05:14:48.775682Z","shell.execute_reply.started":"2024-11-12T05:14:47.625933Z","shell.execute_reply":"2024-11-12T05:14:48.774484Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Virus Identification\n\nRepeat the same process for viruses except with a different z-value.","metadata":{}},{"cell_type":"code","source":"virus_x = []\nvirus_y = []\nf = open('/kaggle/input/czii-cryo-et-object-identification/train/overlay/ExperimentRuns/TS_6_4/Picks/virus-like-particle.json')\nfor p in json.loads(f.read())['points']:\n    z = float(p['location']['z'])\n    if z >= 670 and z < 700:\n        virus_x.append(float(p['location']['x'])/10)\n        virus_y.append(float(p['location']['y'])/10)\n        print(p['location'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:14:48.777113Z","iopub.execute_input":"2024-11-12T05:14:48.777542Z","iopub.status.idle":"2024-11-12T05:14:48.793606Z","shell.execute_reply.started":"2024-11-12T05:14:48.777501Z","shell.execute_reply":"2024-11-12T05:14:48.792365Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Good matches again.","metadata":{}},{"cell_type":"code","source":"fig = plt.figure(figsize=(10,5))\nax = plt.subplot(1, 2, 1)\nplt.xticks([])\nplt.yticks([])\nplt.imshow(z_ts_6_4[0][68], cmap='gray', vmin=-0.00005, vmax=0.00005)\nax = plt.subplot(1, 2, 2)\nplt.xticks([])\nplt.yticks([])\nplt.imshow(z_ts_6_4[0][68], cmap='gray', vmin=-0.00005, vmax=0.00005)\n_ = plt.scatter(virus_x, virus_y, edgecolor='red', facecolor='none')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:14:48.795181Z","iopub.execute_input":"2024-11-12T05:14:48.795587Z","iopub.status.idle":"2024-11-12T05:14:50.015229Z","shell.execute_reply.started":"2024-11-12T05:14:48.795547Z","shell.execute_reply":"2024-11-12T05:14:50.013946Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Apo-Ferritin Identification","metadata":{}},{"cell_type":"code","source":"apo_ferritin_x = []\napo_ferritin_y = []\nf = open('/kaggle/input/czii-cryo-et-object-identification/train/overlay/ExperimentRuns/TS_6_4/Picks/apo-ferritin.json')\nfor p in json.loads(f.read())['points']:\n    z = float(p['location']['z'])\n    if z >= 400 and z < 450:\n        apo_ferritin_x.append(float(p['location']['x'])/10)\n        apo_ferritin_y.append(float(p['location']['y'])/10)\n        print(p['location'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:14:50.016807Z","iopub.execute_input":"2024-11-12T05:14:50.017273Z","iopub.status.idle":"2024-11-12T05:14:50.031998Z","shell.execute_reply.started":"2024-11-12T05:14:50.017221Z","shell.execute_reply":"2024-11-12T05:14:50.030747Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"fig = plt.figure(figsize=(10,5))\nax = plt.subplot(1, 2, 1)\nplt.xticks([])\nplt.yticks([])\nplt.imshow(z_ts_6_4[0][42], cmap='gray', vmin=-0.00005, vmax=0.00005)\nax = plt.subplot(1, 2, 2)\nplt.xticks([])\nplt.yticks([])\nplt.imshow(z_ts_6_4[0][42], cmap='gray', vmin=-0.00005, vmax=0.00005)\n_ = plt.scatter(apo_ferritin_x, apo_ferritin_y, edgecolor='red', facecolor='none')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:14:50.033393Z","iopub.execute_input":"2024-11-12T05:14:50.033813Z","iopub.status.idle":"2024-11-12T05:14:51.237302Z","shell.execute_reply.started":"2024-11-12T05:14:50.033768Z","shell.execute_reply":"2024-11-12T05:14:51.236149Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Beta-Galactosidase Identification","metadata":{}},{"cell_type":"code","source":"beta_galactosidase_x = []\nbeta_galactosidase_y = []\nf = open('/kaggle/input/czii-cryo-et-object-identification/train/overlay/ExperimentRuns/TS_6_4/Picks/beta-galactosidase.json')\nfor p in json.loads(f.read())['points']:\n    z = float(p['location']['z'])\n    if z >= 450 and z < 500:\n        beta_galactosidase_x.append(float(p['location']['x'])/10)\n        beta_galactosidase_y.append(float(p['location']['y'])/10)\n        print(p['location'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:14:51.238814Z","iopub.execute_input":"2024-11-12T05:14:51.239235Z","iopub.status.idle":"2024-11-12T05:14:51.253970Z","shell.execute_reply.started":"2024-11-12T05:14:51.239188Z","shell.execute_reply":"2024-11-12T05:14:51.252740Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"fig = plt.figure(figsize=(10,5))\nax = plt.subplot(1, 2, 1)\nplt.xticks([])\nplt.yticks([])\nplt.imshow(z_ts_6_4[0][47], cmap='gray', vmin=-0.00005, vmax=0.00005)\nax = plt.subplot(1, 2, 2)\nplt.xticks([])\nplt.yticks([])\nplt.imshow(z_ts_6_4[0][47], cmap='gray', vmin=-0.00005, vmax=0.00005)\n_ = plt.scatter(beta_galactosidase_x, beta_galactosidase_y, edgecolor='red', facecolor='none')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:14:51.255592Z","iopub.execute_input":"2024-11-12T05:14:51.256091Z","iopub.status.idle":"2024-11-12T05:14:52.452283Z","shell.execute_reply.started":"2024-11-12T05:14:51.256037Z","shell.execute_reply":"2024-11-12T05:14:52.450781Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Thyroglobulin Identification","metadata":{}},{"cell_type":"code","source":"thyroglobulin_x = []\nthyroglobulin_y = []\nf = open('/kaggle/input/czii-cryo-et-object-identification/train/overlay/ExperimentRuns/TS_6_4/Picks/thyroglobulin.json')\nfor p in json.loads(f.read())['points']:\n    z = float(p['location']['z'])\n    if z >= 550 and z < 600:\n        thyroglobulin_x.append(float(p['location']['x'])/10)\n        thyroglobulin_y.append(float(p['location']['y'])/10)\n        print(p['location'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:14:52.453840Z","iopub.execute_input":"2024-11-12T05:14:52.454270Z","iopub.status.idle":"2024-11-12T05:14:52.469536Z","shell.execute_reply.started":"2024-11-12T05:14:52.454221Z","shell.execute_reply":"2024-11-12T05:14:52.468182Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"fig = plt.figure(figsize=(10,5))\nax = plt.subplot(1, 2, 1)\nplt.xticks([])\nplt.yticks([])\nplt.imshow(z_ts_6_4[0][57], cmap='gray', vmin=-0.00005, vmax=0.00005)\nax = plt.subplot(1, 2, 2)\nplt.xticks([])\nplt.yticks([])\nplt.imshow(z_ts_6_4[0][57], cmap='gray', vmin=-0.00005, vmax=0.00005)\n_ = plt.scatter(thyroglobulin_x, thyroglobulin_y, edgecolor='red', facecolor='none')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:14:52.470919Z","iopub.execute_input":"2024-11-12T05:14:52.471309Z","iopub.status.idle":"2024-11-12T05:14:53.700056Z","shell.execute_reply.started":"2024-11-12T05:14:52.471270Z","shell.execute_reply":"2024-11-12T05:14:53.698887Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Ribosome Close-Up\n\nThe following are zoomed in images of a ribosome from three perspectives, straight on, from the right side (front is to the left) and from the top (front is to the bottom.)  Somewhat unexpected is the difference in image quality from the sides and top.","metadata":{}},{"cell_type":"code","source":"# {'x': 5106.838, 'y': 4835.263, 'z': 619.225}\nfig = plt.figure(figsize=(10,2.5))\nax = plt.subplot(1, 4, 1)\nplt.xticks([])\nplt.yticks([])\nplt.title('Original')\nplt.imshow(z_ts_6_4[0][61], cmap='gray', vmin=-0.00005, vmax=0.00005)\n_ = plt.scatter([5106.838/10], [4835.263/10], edgecolor='red', facecolor='none')\nax = plt.subplot(1, 4, 2)\nplt.xticks([])\nplt.yticks([])\nplt.title('Straight On')\nplt.imshow(z_ts_6_4[0][61, 461:505, 488:532], cmap='gray')\nax = plt.subplot(1, 4, 3)\nplt.xticks([])\nplt.yticks([])\nplt.title('Side View')\nplt.imshow(np.transpose(z_ts_6_4[0], axes=(2,1,0))[510, 461:505, 39:83], cmap='gray')\nax = plt.subplot(1, 4, 4)\nplt.xticks([])\nplt.yticks([])\nplt.title('Top View')\n_ = plt.imshow(np.transpose(z_ts_6_4[0], axes=(1,0,2))[483, 39:83, 488:532], cmap='gray')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:14:53.701598Z","iopub.execute_input":"2024-11-12T05:14:53.701982Z","iopub.status.idle":"2024-11-12T05:14:56.001824Z","shell.execute_reply.started":"2024-11-12T05:14:53.701942Z","shell.execute_reply":"2024-11-12T05:14:56.000626Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Virus Close-Up\n\nSame for virus, although I don't believe this captures the full virus.  In the images above, there is an elongated structure protruding down an to the left.","metadata":{}},{"cell_type":"code","source":"# {'x': 5580.108, 'y': 1240.86, 'z': 692.222}\nfig = plt.figure(figsize=(10,2.5))\nax = plt.subplot(1, 4, 1)\nplt.xticks([])\nplt.yticks([])\nplt.title('Original')\nplt.imshow(z_ts_6_4[0][69], cmap='gray', vmin=-0.00005, vmax=0.00005)\n_ = plt.scatter([5580.108/10], [1240.86/10], edgecolor='red', facecolor='none')\nax = plt.subplot(1, 4, 2)\nplt.xticks([])\nplt.yticks([])\nplt.title('Straight On')\nplt.imshow(z_ts_6_4[0][69, 102:146, 536:580], cmap='gray')\nax = plt.subplot(1, 4, 3)\nplt.xticks([])\nplt.yticks([])\nplt.title('Side View')\nplt.imshow(np.transpose(z_ts_6_4[0], axes=(2,1,0))[558, 102:146, 47:91], cmap='gray')\nax = plt.subplot(1, 4, 4)\nplt.xticks([])\nplt.yticks([])\nplt.title('Top View')\n_ = plt.imshow(np.transpose(z_ts_6_4[0], axes=(1,0,2))[124, 47:91, 536:580], cmap='gray')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:14:56.003367Z","iopub.execute_input":"2024-11-12T05:14:56.003798Z","iopub.status.idle":"2024-11-12T05:14:58.103175Z","shell.execute_reply.started":"2024-11-12T05:14:56.003755Z","shell.execute_reply":"2024-11-12T05:14:58.101625Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Apo-Ferritin Close-Up\n\nHere the particle is difficult to discerne from the side and top.","metadata":{}},{"cell_type":"code","source":"# {'x': 1019.831, 'y': 1859.831, 'z': 400.424}\nfig = plt.figure(figsize=(10,2.5))\nax = plt.subplot(1, 4, 1)\nplt.xticks([])\nplt.yticks([])\nplt.title('Original')\nplt.imshow(z_ts_6_4[0][40], cmap='gray', vmin=-0.00005, vmax=0.00005)\n_ = plt.scatter([1019.831/10], [1859.831/10], edgecolor='red', facecolor='none')\nax = plt.subplot(1, 4, 2)\nplt.xticks([])\nplt.yticks([])\nplt.title('Straight On')\nplt.imshow(z_ts_6_4[0][40, 163:207, 79:123], cmap='gray')\nax = plt.subplot(1, 4, 3)\nplt.xticks([])\nplt.yticks([])\nplt.title('Side View')\nplt.imshow(np.transpose(z_ts_6_4[0], axes=(2,1,0))[101, 163:207, 18:62], cmap='gray')\nax = plt.subplot(1, 4, 4)\nplt.xticks([])\nplt.yticks([])\nplt.title('Top View')\n_ = plt.imshow(np.transpose(z_ts_6_4[0], axes=(1,0,2))[185, 18:62, 79:123], cmap='gray')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:14:58.105922Z","iopub.execute_input":"2024-11-12T05:14:58.106626Z","iopub.status.idle":"2024-11-12T05:15:00.305768Z","shell.execute_reply.started":"2024-11-12T05:14:58.106552Z","shell.execute_reply":"2024-11-12T05:15:00.304571Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Beta-Galactosidase Close-Up\n\nSame for beta-galactosidase.","metadata":{}},{"cell_type":"code","source":"# {'x': 804.615, 'y': 1977.846, 'z': 489.385}\nfig = plt.figure(figsize=(10,2.5))\nax = plt.subplot(1, 4, 1)\nplt.xticks([])\nplt.yticks([])\nplt.title('Original')\nplt.imshow(z_ts_6_4[0][48], cmap='gray', vmin=-0.00005, vmax=0.00005)\n_ = plt.scatter([804.615/10], [1977.846/10], edgecolor='red', facecolor='none')\nax = plt.subplot(1, 4, 2)\nplt.xticks([])\nplt.yticks([])\nplt.title('Straight On')\nplt.imshow(z_ts_6_4[0][48, 175:219, 58:102], cmap='gray')\nax = plt.subplot(1, 4, 3)\nplt.xticks([])\nplt.yticks([])\nplt.title('Side View')\nplt.imshow(np.transpose(z_ts_6_4[0], axes=(2,1,0))[80, 175:219, 26:70], cmap='gray')\nax = plt.subplot(1, 4, 4)\nplt.xticks([])\nplt.yticks([])\nplt.title('Top View')\n_ = plt.imshow(np.transpose(z_ts_6_4[0], axes=(1,0,2))[197, 26:70, 58:102], cmap='gray')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:15:00.307441Z","iopub.execute_input":"2024-11-12T05:15:00.307952Z","iopub.status.idle":"2024-11-12T05:15:02.434706Z","shell.execute_reply.started":"2024-11-12T05:15:00.307899Z","shell.execute_reply":"2024-11-12T05:15:02.433515Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Thyroglobulin Close-Up\n\nSame for thyroglobulin.","metadata":{}},{"cell_type":"code","source":"# {'x': 1242.919, 'y': 1464.644, 'z': 581.353}\nfig = plt.figure(figsize=(10,2.5))\nax = plt.subplot(1, 4, 1)\nplt.xticks([])\nplt.yticks([])\nplt.title('Original')\nplt.imshow(z_ts_6_4[0][58], cmap='gray', vmin=-0.00005, vmax=0.00005)\n_ = plt.scatter([1242.919/10], [1464.644/10], edgecolor='red', facecolor='none')\nax = plt.subplot(1, 4, 2)\nplt.xticks([])\nplt.yticks([])\nplt.title('Straight On')\nplt.imshow(z_ts_6_4[0][58, 124:168, 102:146], cmap='gray')\nax = plt.subplot(1, 4, 3)\nplt.xticks([])\nplt.yticks([])\nplt.title('Side View')\nplt.imshow(np.transpose(z_ts_6_4[0], axes=(2,1,0))[124, 175:219, 36:80], cmap='gray')\nax = plt.subplot(1, 4, 4)\nplt.xticks([])\nplt.yticks([])\nplt.title('Top View')\n_ = plt.imshow(np.transpose(z_ts_6_4[0], axes=(1,0,2))[146, 36:80, 102:146], cmap='gray')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:15:02.436228Z","iopub.execute_input":"2024-11-12T05:15:02.436813Z","iopub.status.idle":"2024-11-12T05:15:04.849839Z","shell.execute_reply.started":"2024-11-12T05:15:02.436769Z","shell.execute_reply":"2024-11-12T05:15:04.848514Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Low Res from the Side\n\nHere is the low resolution version plotted from the rigth side moving from the far side to the near side.  The point of doing this is to get a look at the overall image quality from the side.","metadata":{}},{"cell_type":"code","source":"fig = plt.figure(figsize=(10,64))\nfor i in range(158):\n    ax = plt.subplot(18, 9, i + 1)\n    plt.xticks([])\n    plt.yticks([])\n    plt.imshow(np.transpose(z_ts_6_4[2], axes=(2,1,0))[i])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:15:04.851349Z","iopub.execute_input":"2024-11-12T05:15:04.852187Z","iopub.status.idle":"2024-11-12T05:15:21.050780Z","shell.execute_reply.started":"2024-11-12T05:15:04.852141Z","shell.execute_reply":"2024-11-12T05:15:21.048747Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Low Res from the Top\nSame idea from the top.  Images proceed from top to bottom of the volume.","metadata":{}},{"cell_type":"code","source":"fig = plt.figure(figsize=(10,64))\nfor i in range(158):\n    ax = plt.subplot(53, 3, i + 1)\n    plt.xticks([])\n    plt.yticks([])\n    plt.imshow(np.transpose(z_ts_6_4[2], axes=(1,0,2))[i])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:15:21.056653Z","iopub.execute_input":"2024-11-12T05:15:21.057086Z","iopub.status.idle":"2024-11-12T05:15:37.014263Z","shell.execute_reply.started":"2024-11-12T05:15:21.057041Z","shell.execute_reply":"2024-11-12T05:15:37.012137Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Deformation along the Z-axis\n\nReturning to the ribosome, the same views are displayed with the side and top views elongated along the z-axis.  A red circle is displayed to indicate the 150 unit radius around the central point.  The images pretty clearly show that the ribosome does not stay within the radius.\n\n## Straight On","metadata":{}},{"cell_type":"code","source":"# {'x': 5106.838, 'y': 4835.263, 'z': 619.225}\nplt.xticks([])\nplt.yticks([])\ncircle = plt.Circle((22,22), radius=15, facecolor='none', edgecolor='r')\nplt.gca().add_patch(circle)\n_ = plt.imshow(z_ts_6_4[0][61, 461:505, 488:532], cmap='gray')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:44:58.101643Z","iopub.execute_input":"2024-11-12T05:44:58.102090Z","iopub.status.idle":"2024-11-12T05:44:58.339527Z","shell.execute_reply.started":"2024-11-12T05:44:58.102048Z","shell.execute_reply":"2024-11-12T05:44:58.337717Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Side View","metadata":{}},{"cell_type":"code","source":"from matplotlib.patches import Circle\nplt.xticks([])\nplt.yticks([])\ncircle = plt.Circle((37,22), radius=15, facecolor='none', edgecolor='r')\nplt.gca().add_patch(circle)\n_ = plt.imshow(np.transpose(z_ts_6_4[0], axes=(2,1,0))[510, 461:505, 24:98], cmap='gray')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:36:07.801562Z","iopub.execute_input":"2024-11-12T05:36:07.802139Z","iopub.status.idle":"2024-11-12T05:36:08.594589Z","shell.execute_reply.started":"2024-11-12T05:36:07.802092Z","shell.execute_reply":"2024-11-12T05:36:08.592857Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Top View","metadata":{}},{"cell_type":"code","source":"fig = plt.figure(figsize=(5,6))\nplt.xticks([])\nplt.yticks([])\ncircle = plt.Circle((22,37), radius=15, facecolor='none', edgecolor='r')\nplt.gca().add_patch(circle)\n_ = plt.imshow(np.transpose(z_ts_6_4[0], axes=(1,0,2))[483, 24:98, 488:532], cmap='gray')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T05:47:41.067401Z","iopub.execute_input":"2024-11-12T05:47:41.067862Z","iopub.status.idle":"2024-11-12T05:47:42.255218Z","shell.execute_reply.started":"2024-11-12T05:47:41.067819Z","shell.execute_reply":"2024-11-12T05:47:42.253613Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Conclusion\n\nThe mapping between the x, y, and z coordinates so far appears quite straightforward.  For the highest resolution images 10 units per pixel in all 3 directions with the origin in the first image in the upper left had corner seems to work.  The wikipedia article on cryoET suggests the sample is twisted when generating the images, but so far that hasn't seemed to create any complications here.  That said it might be worth identifying structures in \"worst-case\" locations to confirm that we didn't just get lucky. **Note:** The mapping has been confirmed in the notebook comments.\n\n**Update:** The elongation along the z-axis was missed the first time around.  This could have implications for contest ML algorithms.  See discussion here: [https://www.kaggle.com/competitions/czii-cryo-et-object-identification/discussion/545742](https://www.kaggle.com/competitions/czii-cryo-et-object-identification/discussion/545742)","metadata":{}}]}