{ "cells": [ { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The autoreload extension is already loaded. To reload it, use:\n", " %reload_ext autoreload\n", "Found 32 sessions\n" ] } ], "source": [ "%load_ext autoreload\n", "%autoreload 2\n", "\n", "import csv\n", "from py.Dataset import Dataset\n", "from py.Session import Session, MotionImage, LapseImage\n", "from datetime import datetime\n", "\n", "DIR = '/home/AMMOD_data/camera_traps/BayerWald/Vielkadaver-Projekt/'\n", "\n", "ds = Dataset(DIR)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "def parse_datetime(datetime_str: str) -> datetime:\n", " return datetime.strptime(datetime_str[:-5], \"%Y-%m-%dT%H:%M:%S\")\n", "\n", "assert parse_datetime(\"2021-05-28T09:55:24+0100\") == datetime(2021, 5, 28, 9, 55, 24)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Header: ['observationID', 'deploymentID', 'sequenceID', 'mediaID', 'timestamp', 'observationType', 'cameraSetup', 'taxonID', 'scientificName', 'count', 'countNew', 'lifeStage', 'sex', 'behaviour', 'individualID', 'classificationMethod', 'classifiedBy', 'classificationTimestamp', 'classificationConfidence', 'comments', '_id']\n", "Trying to create session VIELAAS_Spring_Session03-VIELAAS_Beaver_03...\n", "There are no sessions matching this name: []\n", "Trying to create session VIELAAS_Spring_Session03-VIELAAS_Ermine_03...\n", "There are no sessions matching this name: []\n", "Trying to create session VIELAAS_Spring_Session03-VIELAAS_Fox_03...\n", "Session 'Fox_03' at folder: /home/AMMOD_data/camera_traps/BayerWald/Vielkadaver-Projekt/VIELAAS_Spring_Session03-VIELAAS_Fox_03\n", "Loaded scans.\n", "Generating motion map...\n", "Trying to create session VIELAAS_Spring_Session03-VIELAAS_Rat_03...\n", "There are no sessions matching this name: []\n", "Successfully found 3695 images\n", "Skipped 138 images because session was not found\n", "For 0 session dates less images were found than specified (inconsistency)\n", "For 6 session dates more images were found than specified (ambiguous)\n" ] } ], "source": [ "with open(\"Kadaverbilder_leer.csv\", newline=\"\") as csvfile:\n", " reader = csv.reader(csvfile, delimiter=\";\")\n", " header = next(reader)\n", " print(\"Header: \", header)\n", " session_col = header.index(\"deploymentID\")\n", " datetime_col = header.index(\"timestamp\")\n", " session_name: str = None\n", " session: Session = None\n", " successful = 0\n", " skipped = 0\n", " less_found = 0\n", " ambiguous = 0\n", " results = []\n", " last_date = None\n", " last_date_occurences = 0\n", " for row in reader:\n", " # print(row)\n", " # open session if not already opened\n", " if session_name != row[session_col]:\n", " session_name = row[session_col]\n", " print(f\"Trying to create session {session_name}...\")\n", " try:\n", " session = ds.create_session(session_name)\n", " except ValueError as e:\n", " print(e)\n", " session = None\n", " if session is None:\n", " skipped += 1\n", " else:\n", " # get datetime\n", " date = parse_datetime(row[datetime_col])\n", " if date == last_date:\n", " last_date_occurences += 1\n", " else:\n", " # look for images\n", " images = session.get_motion_images_from_date(last_date)\n", "\n", " if len(images) < last_date_occurences:\n", " less_images += last_date_occurences\n", " elif len(images) > last_date_occurences:\n", " ambiguous += last_date_occurences\n", " else:\n", " for image in images:\n", " results.append([session.name, image.filename])\n", " successful += last_date_occurences\n", "\n", " last_date = date\n", " last_date_occurences = 1\n", "print(f\"Successfully found {successful} images\")\n", "print(f\"Skipped {skipped} images because session was not found\")\n", "print(f\"For {not_found} session dates less images were found than specified (inconsistency)\")\n", "print(f\"For {ambiguous} session dates more images were found than specified (ambiguous)\")\n" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "np.save(\"test_images.npy\", results)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "interpreter": { "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6" }, "kernelspec": { "display_name": "Python 3.6.9 64-bit", "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.6.9" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }