{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.12.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":112509,"databundleVersionId":14254895,"sourceType":"competition"},{"sourceId":14405409,"sourceType":"datasetVersion","datasetId":9200408},{"sourceId":14491100,"sourceType":"datasetVersion","datasetId":9255474},{"sourceId":14492651,"sourceType":"datasetVersion","datasetId":9256398}],"dockerImageVersionId":31234,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2026-01-14T01:45:57.549634Z","iopub.execute_input":"2026-01-14T01:45:57.549893Z","iopub.status.idle":"2026-01-14T01:45:58.390155Z","shell.execute_reply.started":"2026-01-14T01:45:57.549867Z","shell.execute_reply":"2026-01-14T01:45:58.389124Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Copy data and executables to writable space","metadata":{}},{"cell_type":"code","source":"import os\nimport stat\nimport shutil\n\n# Define the source and destination paths\n### To process TEST Images copy executable\nsource_path = '/kaggle/input/biomass-prediction-executables/csiro_dataset_executables/joined_hog_test'\ndestination_path = '/kaggle/working/joined_hog_test'\n# Copy the file to the working directory\nshutil.copy(source_path, destination_path)\n# Grant executable privileges using os.chmod\nos.chmod(destination_path, stat.S_IEXEC)\n### Shared libraries\nshutil.copy('/kaggle/input/biomass-prediction-executables/csiro_dataset_executables/librgsl.so', '/kaggle/working/librgsl.so')\nshutil.copy('/kaggle/input/biomass-prediction-executables/csiro_dataset_executables/libgsl_sys.so', '/kaggle/working/libgsl_sys.so')\n### To predict values copy executable\nshutil.copy('/kaggle/input/biomass-prediction-executables/csiro_dataset_executables/csiro_biomass_prediction', '/kaggle/working/csiro_biomass_prediction') \nos.chmod('/kaggle/working/csiro_biomass_prediction', stat.S_IEXEC)\nshutil.copy('/kaggle/input/iy-debug/IY_Debug/diabetes_regression','/kaggle/working/diabetes_regression')\nos.chmod('/kaggle/working/diabetes_regression', stat.S_IEXEC)\n### To edit test images CSV file copy \"sd\" - like Linux \"sed\"\nshutil.copy('/kaggle/input/biomass-prediction-executables/csiro_dataset_executables/sd','/kaggle/working/sd')\nos.chmod('/kaggle/working/sd', stat.S_IEXEC)\n### Copy TEST images to edit and produce features\nsource_dir = '/kaggle/input/csiro-biomass/test'\ndestination_dir = '/kaggle/working/test'\n\ntry:\n    shutil.copytree(source_dir, destination_dir)\n    print(f\"Directory '{source_dir}' successfully copied to '{destination_dir}'\")\nexcept FileExistsError:\n    print(f\"Error: Destination directory '{destination_dir}' already exists.\")\nexcept OSError as e:\n    print(f\"Error: {e}\")\n### Copy CSV features for every target\n#/kaggle/input/csiro-train-dataset/data/data_Dry_Total_g.csv\nsource_dir = '/kaggle/input/csiro-train-dataset/data'\ndestination_dir = '/kaggle/working/data'\n\ntry:\n    shutil.copytree(source_dir, destination_dir)\n    print(f\"Directory '{source_dir}' successfully copied to '{destination_dir}'\")\nexcept FileExistsError:\n    print(f\"Error: Destination directory '{destination_dir}' already exists.\")\nexcept OSError as e:\n    print(f\"Error: {e}\")\n### List Result of copying\nprint(os.listdir('/kaggle/working'))\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-14T01:45:58.391399Z","iopub.execute_input":"2026-01-14T01:45:58.392124Z","iopub.status.idle":"2026-01-14T01:45:58.412135Z","shell.execute_reply.started":"2026-01-14T01:45:58.392081Z","shell.execute_reply":"2026-01-14T01:45:58.410667Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Process TEST Images","metadata":{}},{"cell_type":"code","source":"import subprocess\n\nbinary_path = \"/kaggle/working/joined_hog_test\"\n\ntry:\n    result = subprocess.run(\n        [binary_path],          # Command and arguments\n        capture_output=True,      # Capture stdout and stderr\n        text=True,                # Decode output as strings (instead of bytes)\n        check=True                # Raise CalledProcessError if command fails (non-zero exit code)\n    )\n    print(\"STDOUT:\", result.stdout)\n    print(\"STDERR:\", result.stderr)\nexcept subprocess.CalledProcessError as e:\n    print(f\"Command failed with return code {e.returncode}\")\n    print(\"Error output:\", e.stderr)\n\n### Check result CSV File\n!ls /kaggle/working\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-14T01:45:58.412962Z","iopub.status.idle":"2026-01-14T01:45:58.413297Z","shell.execute_reply.started":"2026-01-14T01:45:58.413135Z","shell.execute_reply":"2026-01-14T01:45:58.413153Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"### Get TEST IDs\n### Remove IDs from TEST Images features CSV\n\nimport duckdb\ncon = duckdb.connect(database=':memory:', read_only=False)\ncon.execute(\"CREATE TABLE test AS FROM read_csv('test_joined_hog.csv', delim = ',', header = true)\");\nresult = con.execute(\"SELECT * FROM test;\").fetchdf()\nheaders = result.columns.tolist()\n#print(headers)\nids = con.execute(\"SELECT file_name FROM test;\").fetchdf()\nprint(ids)\nids.to_csv('test_ids.csv', index=False, header=False)\n\n\n!cp test_joined_hog.csv test_joined_hog_no_id.csv \n!ls\n!/kaggle/working/sd 'file_name,' '' test_joined_hog_no_id.csv\n!/kaggle/working/sd 'ID(\\d)*\\.jpg,' '' test_joined_hog_no_id.csv\n\nimport os\nprint(os.listdir(\"/kaggle/working/\"))\n\"\"\"\n### Check If Executable Exists\nfrom pathlib import Path\n\nfile_path = Path(\"/kaggle/working/csiro_biomass_prediction\")\n\nif file_path.is_file():\n    print(f\"The file '{file_path}' exists.\")\nelse:\n    print(f\"The file '{file_path}' does not exist.\")\n\n### Check If Binary can be Executed\nif os.access(file_path, os.X_OK):\n    print(f\"'{file_path}' is executable by the current user.\")\nelse:\n    print(f\"'{file_path}' is not executable by the current user or does not exist.\")\n\n!/kaggle/working/csiro_biomass_prediction\n\n\"\"\"\n\"\"\"\nimport subprocess\n\nbinary_path = \"/kaggle/working/csiro_biomass_prediction\"\n\ntry:\n    result = subprocess.run(\n        [binary_path],          # Command and arguments\n        capture_output=True,      # Capture stdout and stderr\n        text=True,                # Decode output as strings (instead of bytes)\n        check=True                # Raise CalledProcessError if command fails (non-zero exit code)\n    )\n    print(\"STDOUT:\", result.stdout)\n    print(\"STDERR:\", result.stderr)\nexcept subprocess.CalledProcessError as e:\n    print(f\"Command failed with return code {e.returncode}\")\n    print(\"Error output:\", e.stderr)\n\"\"\"\n!/kaggle/working/diabetes_regression\n!ls /kaggle/working","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-14T01:45:58.414785Z","iopub.status.idle":"2026-01-14T01:45:58.415110Z","shell.execute_reply.started":"2026-01-14T01:45:58.414961Z","shell.execute_reply":"2026-01-14T01:45:58.414980Z"}},"outputs":[],"execution_count":null}]}