File size: 3,804 Bytes
d6c6696 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# System packages\n",
"import sys\n",
"import os\n",
"\n",
"# 3rd party packages\n",
"import pandas as pd\n",
"import dotenv\n",
"import json\n",
"\n",
"# Our main package (coming soon!)\n",
"# import ami_ml\n",
"\n",
"# Local development packages not yet in the main package\n",
"sys.path.append(\"./\")\n",
"\n",
"# Auto reload your development packages\n",
"%load_ext autoreload\n",
"%autoreload 2\n",
"\n",
"# Load secrets and config from optional .env file\n",
"dotenv.load_dotenv()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"No. of accepted moth species: 46983\n",
"No. of unique genera: 9413\n",
"No. of unique families: 124\n"
]
}
],
"source": [
"# Read the global moth checklist\n",
"moth_checklist_df = pd.read_csv(os.getenv(\"GLOBAL_MOTH_CHECKLIST\"))\n",
"\n",
"# Get statistics regarding accepted moth species\n",
"accepted_moths = moth_checklist_df[moth_checklist_df[\"taxonomicStatus\"] == \"ACCEPTED\"]\n",
"num_genus = set(accepted_moths[\"genus\"])\n",
"num_family = set(accepted_moths[\"family\"])\n",
"print(f\"No. of accepted moth species: {accepted_moths.shape[0]}\")\n",
"print(f\"No. of unique genera: {len(num_genus)}\")\n",
"print(f\"No. of unique families: {len(num_family)}\")\n"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
"# Save the accepted taxon keys to json file\n",
"unique_accepted_keys = list(accepted_moths[\"acceptedTaxonKey\"])\n",
"file_path = os.getenv(\"ACCEPTED_KEY_LIST\")\n",
"with open(file_path, \"w\") as file:\n",
" json.dump(unique_accepted_keys, file)"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
"# Test the json file read\n",
"with open(os.getenv(\"ACCEPTED_KEY_LIST\")) as f:\n",
" keys_list = json.load(f)\n",
" keys_list = [int(x) for x in keys_list]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Calculate the total occurrences for all accepted taxon keys, with a cap of 1000"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The total occurrences with a cap of thousand images is 3898528.\n"
]
}
],
"source": [
"num_occ = list(accepted_moths[\"numberOfOccurrences\"])\n",
"num_occ_limit = [] \n",
"for count in num_occ:\n",
" if count <= 1000: num_occ_limit.append(count)\n",
" else: num_occ_limit.append(1000)\n",
"\n",
"print(f\"The total occurrences with a cap of thousand images is {sum(num_occ_limit)}.\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|