Skip to content

Instantly share code, notes, and snippets.

View mikkohei13's full-sized avatar

Mikko Heikkinen mikkohei13

View GitHub Profile
@mikkohei13
mikkohei13 / process-named-places.py
Created October 13, 2023 11:10
Convert FinBIF named places file (line transects) into geojson
import json
def process_geojson_with_properties(input_filename, output_filename):
# Load the JSON file
with open(input_filename, "r") as file:
data = json.load(file)
# Extract all items under "results"
results = data.get("results", [])
@mikkohei13
mikkohei13 / forecast_species.py
Created August 25, 2023 09:24
Estimate future observation counts based on laji.fi data
import json
from statsmodels.tsa.holtwinters import Holt
# Load the JSON data
with open("pyjamalude-years.json", "r") as file:
data = json.load(file)
'''
Estimate future observation counts based on laji.fi data
@mikkohei13
mikkohei13 / ai-model-comparison-set3.csv
Created July 7, 2023 18:35
Comparison of Naturalis and iNaturalist species recognition models.
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
File unique identifier;Prediction by Naturalis;Probability by Naturalis;True or false by Naturalis;Prediction by iNat;Probability by iNat;True or false by iNat
_test_set_3/(Acanthosomatidae) Elasmucha grisea Parent Bug_8.jpg;Elasmucha grisea;0.894348;1;Elasmucha grisea;0.314679;1
_test_set_3/(Aphrophoridae) Aphrophora alni_3.jpg;Aphrophora alni;1;1;Aphrophora alni;0.410643;1
_test_set_3/(Cercopidae) Cercopis vulnerata_2.jpg;Cercopis vulnerata;1;1;Cercopis vulnerata;0.460223;1
_test_set_3/(Cicadellidae) Adarrus ocellaris_3.jpg;Errastunus ocellaris;0.973848;0;Speudotettix subfusculus;0.303513;0
_test_set_3/(Cicadellidae) Aguriahana stellulata_4.jpg;Aguriahana stellulata;0.999827;1;Aguriahana;0.433531;1
_test_set_3/(Cicadellidae) Arthaldeus pascuellus_4.jpg;Arthaldeus pascuellus;1;1;Graminella nigrifrons;0.347305;0
_test_set_3/(Cicadellidae) Athysanus argentarius_5.jpg;Athysanus argentarius;0.999749;1;Athysanus argentarius;0.491078;1
_test_set_3/(Cicadellidae) Batracomorphus irroratus_5.jpg;Iassus lanio;0.699501
@mikkohei13
mikkohei13 / weekly_species_heatmaps.py
Created June 1, 2023 08:39
Script reads laji.fi data file, and a heatmap of weekly species distribution.
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.preprocessing import MinMaxScaler
rarity_threshold = 100
# Read datafile that has number of observations for each species
df = pd.read_csv('species_rarity.csv', sep='\t')
@mikkohei13
mikkohei13 / weekly_species_charts.py
Created June 1, 2023 08:34
Script reads laji.fi citatable data file, and creates Excel file and a line chart of weekly species distribution.
import pandas as pd
import matplotlib.pyplot as plt
# Load the csv file
df = pd.read_csv('rows_HBF.75704.tsv', sep='\t')
# Remove those without a day of year
df = df.dropna(subset=['Gathering.Conversions.DayOfYearBegin'])
@mikkohei13
mikkohei13 / birdatlas-treevolume.csv
Created February 13, 2023 16:45
Data from Finnish bird atlas: observations with 100 m accuracy compared to tree volume data (gaussian filtered) from Luke. Data CC-BY 4.0.
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 1 column, instead of 13 in line 1.
fid;common_name_finnish;count;unique;min;max;range;sum;mean;median;stddev;minority;majority;q1;q3;iqr
187;tulipäähippiäinen;1;1;255,7875214;255,79;0,00;255,79;255,79;255,79;0,00;255,79;255,7875214;255,79;255,79;0,00
201;puukiipijät;1;1;235,3859253;235,39;0,00;235,39;235,39;235,39;0,00;235,39;235,3859253;235,39;235,39;0,00
222;hömötiainen × lapintiainen;1;1;210,9716034;210,97;0,00;210,97;210,97;210,97;0,00;210,97;210,9716034;210,97;210,97;0,00
175;pikkusieppo;29;29;79,25;303,37;224,11;5629,43;194,12;185,46;64,38;79,25;79,25;148,34;245,10;96,77
180;kanahaukka (alalaji gentilis);1;1;165,2255707;165,23;0,00;165,23;165,23;165,23;0,00;165,23;165,2255707;165,23;165,23;0,00
195;idänuunilintu;13;13;9,39;293,14;283,74;2079,52;159,96;175,33;79,21;9,39;9,39;104,69;209,42;104,73
8;hippiäinen;376;359;0,00;354,92;354,92;54432,47;144,77;142,78;77,85;0,67;0,00;94,62;193,35;98,73
82;peukaloinen;353;347;0,00;357,88;357,88;50821,14;143,97;144,19;76,40;0,02;0,00;90,73;198,19;107,46
69;sirittäjä;190;188;0,00;318,41;318,41;27312,49
@mikkohei13
mikkohei13 / finland_simple_outline.geojson
Created February 11, 2023 22:10
GeoJSON file of the outline of Finland, simplified for very small maps.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mikkohei13
mikkohei13 / minimaps.py
Last active February 12, 2023 09:09
Generates small PNG maps of Finland with a dot at given coordinates.
# Generates small maps of Finland with a dot at given coordinates.
import geopandas as gpd
import matplotlib.pyplot as plt
from pyproj import Proj, transform
# Load a GeoJSON file with outline of Finland into a GeoDataFrame
geojson = gpd.read_file('fin.geojson')
@mikkohei13
mikkohei13 / inat-sound.py
Created February 6, 2023 14:11
Python script to fetch sound files from iNaturalist API
'''
Script to download sound files from iNaturalist.
Mikko Heikkinen / Luomus, 2023-02-06
Requires "requests" library.
input: iNat API URL with parameters
output: files divided into folders by taxon
@mikkohei13
mikkohei13 / crop.py
Created November 23, 2022 12:42
Crop images in a folder
import os
from os import listdir
from PIL import Image
# get the path/directory
source_dir = "images/Carpocoris_fuscispinus"
target_dir = "images/carp_fusc_crop"
limit = 300