Skip to content

Instantly share code, notes, and snippets.

@mikkohei13
mikkohei13 / fin_ykj.geojson
Created February 10, 2024 09:53
Simplified borders of Finland as EPSG:2393 (KKJ / Finland Uniform Coordinate System, YKJ yhtenäiskoordinaatisto) in GeoJSON polygon format.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mikkohei13
mikkohei13 / finland_ykj_squares.tsv
Created February 9, 2024 22:47
EPSG:2393 (KKJ / Finland Uniform Coordinate System) 10*10 km square centerpoint coordinates with rainbow colors
6615000 3125000 #ff0000
6635000 3185000 #ff0000
6635000 3195000 #ff0000
6635000 3205000 #ff0100
6635000 3215000 #ff0100
6635000 3225000 #ff0100
6635000 3235000 #ff0200
6635000 3245000 #ff0200
6635000 3255000 #ff0300
6635000 3265000 #ff0300
@mikkohei13
mikkohei13 / ykj_svg_map.py
Last active February 10, 2024 16:47
Reads EPSG:2393 (KKJ / Finland Uniform Coordinate System) coordinates with optional color and draws them as dots on a SVG map.
# Reads EPSG:2393 (KKJ / Finland Uniform Coordinate System) coordinates with optional color and draws them as dots on a SVG map.
# Depends on:
# GeoJSON data from https://gist.github.com/mikkohei13/0acf09633a1635b5363d47c5603fd789
# Sample data from https://gist.github.com/mikkohei13/d03316b75393a1718be5232986e0e2eb
import re
import json
def extract_polygons_from_geojson(file_path):
@mikkohei13
mikkohei13 / oma_riista_conversions.py
Last active February 1, 2024 13:41
Script to convert CSV tabular file to FinBIF data bank format
"""
Script to make conversions to a CSV tabular file containing bird species observations (occurrence records)
Data format sample (mock data):
ID;pvm;aika;laji;lkm;ykj_p;ykj_i;pesimävarmuusindeksi
2021_A;01.02.2021;07:50;teeri;2;7100000;3390000;2
2021_B;01.05.2021;09:18;heinäsorsa;12;6900000;3410000;2
2021_C;13.02.2021;09:37;riekko;NaN;7100000;3470000;3
2021_D;02.02.2021;07:16;fasaani;NA;6710000;3410000;2
2021_E;11.04.2021;09:06;riekko;4;7580000;3360000;2
@mikkohei13
mikkohei13 / atlas-tiira.py
Last active January 22, 2024 18:49
Tool to compare data from bird atlas and Tiira, to see which species & observations are missing breeding index.
'''
Tool to compare observations from Tiira to atlas data, to see which observations could increase breeding indices.
MIT License
'''
# Source data - Tiira export saved as UTF-8 CSV file
tiira_filename = "./import/tiira.csv"
# Atlas square to compare to
atlas_square = "667:337"
@mikkohei13
mikkohei13 / convert.py
Created December 29, 2023 11:16
Convert Luke atlas dataset to FinBIF Data Bank format
'''
Converts "Luken aineistokooste 4. lintuatlakseen" tsv file into FinBIF Data Bank secondary data format.
Mikko Heikkinen 2023-12-29
'''
import pandas as pd
# Load the file into a Pandas dataframe using tab as the delimiter. Keep "NA" as a value.
file_path = 'luke_atlasdata.txt'
@mikkohei13
mikkohei13 / spatial_outliers.py
Created November 24, 2023 12:04
Find spatial outliers from FinBIF simple data format
# Made wth ChatGPT / GPT-4
# Finds spatial ouliers by clcularing SD of locations
# Input: FinBIF data of a single species in simple data format
import pandas as pd
import numpy as np
# Load the data (Replace 'file_path' with your actual file path)
file_path = 'your_data_file.csv' # Change this to your file path
bird_data = pd.read_csv(file_path, sep='\t')
@mikkohei13
mikkohei13 / temporal_outliers.py
Created November 23, 2023 21:13
Find temporal outliers in FinBIF simple datafile
# Made with ChatGPT GPT-4 2023-11-23
# Finds temporal outliers from a simple occurrence data file of a single species from FinBIF, with headers in English.
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from shapely.geometry import Point
import geopandas as gpd
# Load the data
@mikkohei13
mikkohei13 / citations.py
Created November 16, 2023 14:41
Fetch article citation counts based on DOI's from opencitations.net API
# Made with ChatGPT/GPT-4
import requests
import pandas as pd
import time
import csv
def fetch_citation_count(doi):
"""
Function to fetch the citation count for a given DOI using the OpenCitations API.
@mikkohei13
mikkohei13 / convert.py
Created October 24, 2023 11:02
Convert eBird GBIF simple archive to multiple DwC files for FinBIF ETL import
import pandas as pd
import numpy as np
import re
# Mikko Heikkinen 2020, 2022, 2023
# Defines which columns to use. Order is not significant.
usecols = [
'gbifID',