{"metadata":{"kernelspec":{"display_name":".venv","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.12.0"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":91249,"databundleVersionId":11294684,"sourceType":"competition"}],"dockerImageVersionId":30918,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt","metadata":{},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### EDA about aspect ratio\n\nSummary\n\nTomographs with width/height ratio less than 0.9 contain no motors  \nTomographs with width/depth ratio greater than 0.6 contain no motors\n","metadata":{}},{"cell_type":"code","source":"COMP_NAME = \"byu-locating-bacterial-flagellar-motors-2025\"\nCOMP_DIR = f\"/kaggle/input/{COMP_NAME}\"\nLABEL = f\"{COMP_DIR}/train_labels.csv\"\n\nlabel = pd.read_csv(LABEL)\nlabel\n","metadata":{},"outputs":[],"execution_count":null},{"cell_type":"code","source":"label_ = (\n    label.groupby(\"tomo_id\")\n    .agg(\n        {\n            \"Array shape (axis 0)\": \"first\",\n            \"Array shape (axis 1)\": \"first\",\n            \"Array shape (axis 2)\": \"first\",\n            \"Voxel spacing\": \"first\",\n            \"Number of motors\": \"max\",\n        }\n    )\n    .rename(\n        columns={\n            \"Array shape (axis 0)\": \"z\",\n            \"Array shape (axis 1)\": \"y\",\n            \"Array shape (axis 2)\": \"x\",\n        }\n    )\n    .reset_index()\n)\nlabel_[\"y/z\"] = np.round(label_[\"z\"] / label_[\"y\"], 2)\nlabel_[\"x/z\"] = np.round(label_[\"z\"] / label_[\"x\"], 2)\nlabel_[\"x/y\"] = np.round(label_[\"y\"] / label_[\"x\"], 2)\nlabel_","metadata":{},"outputs":[],"execution_count":null},{"cell_type":"code","source":"label_[[\"x/y\", \"x/z\", \"y/z\"]].describe()","metadata":{},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(12, 5))\ncol = \"x/y\"\nplt.hist(\n    label_[label_[\"Number of motors\"] == 0][col],\n    range=(label_[col].min(), label_[col].max()),\n    bins=np.arange(label_[col].min(), label_[col].max(), 0.01),\n    alpha=0.5,\n    label=\"Number of motors = 0\",\n)\n\n\nplt.hist(\n    label_[label_[\"Number of motors\"] >= 1][col],\n    range=(label_[col].min(), label_[col].max()),\n    bins=np.arange(label_[col].min(), label_[col].max(), 0.01),\n    alpha=0.5,\n    label=\"Number of motors >= 1\",\n)\nplt.title(\"distribution of x/y ratio\")\n\nplt.xlabel(\"x/y ratio\")\nplt.ylabel(\"Count\")\nplt.legend()\nplt.tight_layout()\n\n# Tomographs with width/height ratio less than 0.9 contain no motors\n","metadata":{},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(12, 5))\ncol = \"x/z\"\nplt.hist(\n    label_[label_[\"Number of motors\"] == 0][col],\n    range=(label_[col].min(), label_[col].max()),\n    bins=np.arange(label_[col].min(), label_[col].max(), 0.01),\n    alpha=0.5,\n    label=\"Number of motors = 0\",\n)\n\n\nplt.hist(\n    label_[label_[\"Number of motors\"] >= 1][col],\n    range=(label_[col].min(), label_[col].max()),\n    bins=np.arange(label_[col].min(), label_[col].max(), 0.01),\n    alpha=0.5,\n    label=\"Number of motors >= 1\",\n)\nplt.title(\"distribution of x/z ratio\")\n\nplt.xlabel(\"x/z ratio\")\nplt.ylabel(\"Count\")\nplt.legend()\nplt.tight_layout()\n\n# Tomographs with width/depth ratio greater than 0.6 contain no motors","metadata":{},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(12, 5))\ncol = \"y/z\"\n\nplt.hist(\n    label_[label_[\"Number of motors\"] == 0][col],\n    range=(label_[col].min(), label_[col].max()),\n    bins=np.arange(label_[col].min(), label_[col].max(), 0.01),\n    alpha=0.5,\n    label=\"Number of motors = 0\",\n)\n\n\nplt.hist(\n    label_[label_[\"Number of motors\"] >= 1][col],\n    range=(label_[col].min(), label_[col].max()),\n    bins=np.arange(label_[col].min(), label_[col].max(), 0.01),\n    alpha=0.5,\n    label=\"Number of motors >= 1\",\n)\nplt.title(\"distribution of y/z ratio\")\n\nplt.xlabel(\"y/z ratio\")\nplt.ylabel(\"Count\")\nplt.legend()\nplt.tight_layout()\n","metadata":{},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(12, 5))\ncol = \"Voxel spacing\"\n\nplt.hist(\n    label_[label_[\"Number of motors\"] == 0][col],\n    range=(label_[col].min(), label_[col].max()),\n    bins=np.arange(label_[col].min(), label_[col].max(), 0.1),\n    alpha=0.5,\n    label=\"Number of motors = 0\",\n)\n\n\nplt.hist(\n    label_[label_[\"Number of motors\"] >= 1][col],\n    range=(label_[col].min(), label_[col].max()),\n    bins=np.arange(label_[col].min(), label_[col].max(), 0.1),\n    alpha=0.5,\n    label=\"Number of motors >= 1\",\n)\nplt.title(\"distribution of Voxel spacing\")\n\nplt.xlabel(\"Voxel spacing\")\nplt.ylabel(\"Count\")\nplt.legend()\nplt.tight_layout()\n","metadata":{},"outputs":[],"execution_count":null}]}