Created
November 24, 2023 12:04
-
-
Save mikkohei13/514051935eaa808e1080cc181da5d927 to your computer and use it in GitHub Desktop.
Find spatial outliers from FinBIF simple data format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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') | |
# Extracting latitude and longitude | |
latitude = bird_data['WGS84 N'] | |
longitude = bird_data['WGS84 E'] | |
# Calculating mean and standard deviation | |
mean_latitude = np.mean(latitude) | |
std_latitude = np.std(latitude) | |
mean_longitude = np.mean(longitude) | |
std_longitude = np.std(longitude) | |
# Defining a threshold for outliers (e.g., 2 standard deviations from the mean) | |
threshold = 2 | |
min_lat, max_lat = mean_latitude - threshold * std_latitude, mean_latitude + threshold * std_latitude | |
min_lon, max_lon = mean_longitude - threshold * std_longitude, mean_longitude + threshold * std_longitude | |
# Identifying outliers | |
outliers = bird_data[(latitude < min_lat) | (latitude > max_lat) | (longitude < min_lon) | (longitude > max_lon)] | |
# Print or export the outliers | |
print(outliers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment