File size: 738 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
#!/usr/bin/env python
# coding: utf-8

"""Create a mapping from taxon keys to species names"""

import json
import os
from pathlib import Path

# System packages
import pandas as pd

# 3rd party packages
from dotenv import load_dotenv

# Load secrets and config from optional .env file
load_dotenv()

# Variable definitions
GLOBAL_MODEL_DIR = os.getenv("GLOBAL_MODEL_DIR")
moth_list = pd.read_csv(Path(GLOBAL_MODEL_DIR) / "gbif_moth_checklist_07242024.csv")
map_dict = {}
map_file = Path(GLOBAL_MODEL_DIR) / "categ_to_name_map.json"

# Build the dict
for _, row in moth_list.iterrows():
    map_dict[int(row["acceptedTaxonKey"])] = row["species"]

# Save the dict
with open(map_file, "w") as file:
    json.dump(map_dict, file, indent=2)