{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":91249,"databundleVersionId":11294684,"sourceType":"competition"}],"dockerImageVersionId":30918,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport matplotlib.image as mpimg\nimport pandas as pd\nimport matplotlib.patches as patches\nimport numpy as np\nimport math\n\nlabels_df = pd.read_csv('/kaggle/input/byu-locating-bacterial-flagellar-motors-2025/train_labels.csv', index_col=0)\nlabels_df = labels_df[labels_df['Motor axis 0'] > 0] # filtering out only cells with motors\n\nlabels_df['file_name'] = '/kaggle/input/byu-locating-bacterial-flagellar-motors-2025/train/' + \\\n                        labels_df['tomo_id'] + '/slice_' + \\\n                        labels_df['Motor axis 0'].astype(int).astype(str).str.zfill(4) + '.jpg'\n\nnum_images = 450\nimages_per_row = 8\n\nnum_rows = math.ceil(num_images / images_per_row)\nfig, axes = plt.subplots(num_rows, images_per_row, figsize=(12, 1.5 * num_rows))\naxes = axes.flatten() if num_rows > 1 else [axes] if num_images == 1 else axes\n\nfor i, (idx, row) in enumerate(labels_df[:num_images].iterrows()):\n    if i < len(axes):\n        path = row['file_name']\n        x_coord = row['Motor axis 2']\n        y_coord = row['Motor axis 1']\n\n        img = mpimg.imread(path)\n        axes[i].imshow(img)\n\n        circle = patches.Circle((x_coord, y_coord), radius=40, \n                               edgecolor='red', facecolor='none', linewidth=1)\n        axes[i].add_patch(circle)\n        \n        #axes[i].set_title(f\"{row['tomo_id']}\\nSlice {int(row['Motor axis 0'])}\", fontsize=8) \n\n        axes[i].set_xticks([])\n        axes[i].set_yticks([])\n\nfor j in range(i+1, len(axes)):\n    axes[j].axis('off')\n\nplt.tight_layout()\nplt.savefig('motor_locations_grid.png', dpi=50, bbox_inches='tight')\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-20T11:06:30.950961Z","iopub.execute_input":"2025-03-20T11:06:30.951324Z","iopub.status.idle":"2025-03-20T11:06:43.424468Z","shell.execute_reply.started":"2025-03-20T11:06:30.951298Z","shell.execute_reply":"2025-03-20T11:06:43.423134Z"}},"outputs":[],"execution_count":null}]}