Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nocturnal species list #2

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ firstrun.ini
HUMAN.txt
include_species_list.txt
/nbproject/private/
nocturnal_species_list.txt
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ apprise==1.9.0
paho-mqtt<2.0.0
pytest==7.1.2
scikit-learn
suntime
suntime==1.2.5
inotify
requests
matplotlib
1 change: 1 addition & 0 deletions scripts/backup_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ required=("/home/$BIRDNET_USER/BirdNET-Pi/birdnet.conf"
optional=("/home/$BIRDNET_USER/BirdNET-Pi/apprise.txt"
"/home/$BIRDNET_USER/BirdNET-Pi/scripts/blacklisted_images.txt"
"/home/$BIRDNET_USER/BirdNET-Pi/scripts/disk_check_exclude.txt"
"/home/$BIRDNET_USER/BirdNET-Pi/nocturnal_species_list.txt"
"/home/$BIRDNET_USER/BirdNET-Pi/exclude_species_list.txt"
"/home/$BIRDNET_USER/BirdNET-Pi/include_species_list.txt")

Expand Down
1 change: 1 addition & 0 deletions scripts/clear_all_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ echo "Re-creating necessary directories"
sudo -u ${USER} ln -fs $(dirname $my_dir)/exclude_species_list.txt $my_dir
sudo -u ${USER} ln -fs $(dirname $my_dir)/include_species_list.txt $my_dir
sudo -u ${USER} ln -fs $(dirname $my_dir)/whitelist_species_list.txt $my_dir
sudo -u ${USER} ln -fs $(dirname $my_dir)/nocturnal_species_list.txt $my_dir
sudo -u ${USER} ln -fs $(dirname $my_dir)/homepage/* ${EXTRACTED}
sudo -u ${USER} ln -fs $(dirname $my_dir)/model/labels.txt ${my_dir}
sudo -u ${USER} ln -fs $my_dir ${EXTRACTED}
Expand Down
1 change: 1 addition & 0 deletions scripts/install_services.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ create_necessary_dirs() {
sudo -u ${USER} ln -fs $my_dir/exclude_species_list.txt $my_dir/scripts
sudo -u ${USER} ln -fs $my_dir/include_species_list.txt $my_dir/scripts
sudo -u ${USER} ln -fs $my_dir/whitelist_species_list.txt $my_dir/scripts
sudo -u ${USER} ln -fs $my_dir/nocturnal_species_list.txt $my_dir/scripts
sudo -u ${USER} ln -fs $my_dir/homepage/* ${EXTRACTED}
sudo -u ${USER} ln -fs $my_dir/model/labels.txt ${my_dir}/scripts
sudo -u ${USER} ln -fs $my_dir/scripts ${EXTRACTED}
Expand Down
10 changes: 7 additions & 3 deletions scripts/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import librosa
import numpy as np

from utils.helpers import get_settings, Detection
from utils.helpers import get_settings, Detection, LocationTime

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
os.environ['CUDA_VISIBLE_DEVICES'] = ''
Expand All @@ -22,12 +22,13 @@


userDir = os.path.expanduser('~')
INTERPRETER, M_INTERPRETER, INCLUDE_LIST, EXCLUDE_LIST = (None, None, None, None)
INTERPRETER, M_INTERPRETER, INCLUDE_LIST, EXCLUDE_LIST, NOCTURNAL_LIST = (None, None, None, None, None)
PREDICTED_SPECIES_LIST = []
model, priv_thresh, sf_thresh = (None, None, None)

mdata, mdata_params = (None, None)

lt = LocationTime(get_settings().getfloat('LATITUDE'), get_settings().getfloat('LONGITUDE'))

def loadModel():

Expand Down Expand Up @@ -310,9 +311,10 @@ def load_global_model():


def run_analysis(file):
global INCLUDE_LIST, EXCLUDE_LIST
global INCLUDE_LIST, EXCLUDE_LIST, NOCTURNAL_LIST
INCLUDE_LIST = loadCustomSpeciesList(os.path.expanduser("~/BirdNET-Pi/include_species_list.txt"))
EXCLUDE_LIST = loadCustomSpeciesList(os.path.expanduser("~/BirdNET-Pi/exclude_species_list.txt"))
NOCTURNAL_LIST = loadCustomSpeciesList(os.path.expanduser("~/BirdNET-Pi/nocturnal_species_list.txt"))

conf = get_settings()

Expand All @@ -335,6 +337,8 @@ def run_analysis(file):
log.warning("Excluded as INCLUDE_LIST is active but this species is not in it: %s", entry[0])
elif entry[0] in EXCLUDE_LIST and len(EXCLUDE_LIST) != 0:
log.warning("Excluded as species in EXCLUDE_LIST: %s", entry[0])
elif entry[0] in NOCTURNAL_LIST and len(NOCTURNAL_LIST) != 0 and not lt.is_night(file.file_date):
log.warning("Excluded as species in NOCTURNAL_LIST during daytime: %s", entry[0])
elif entry[0] not in PREDICTED_SPECIES_LIST and len(PREDICTED_SPECIES_LIST) != 0:
log.warning("Excluded as below Species Occurrence Frequency Threshold: %s", entry[0])
else:
Expand Down
11 changes: 11 additions & 0 deletions scripts/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from itertools import chain

from tzlocal import get_localzone
from suntime import Sun

_settings = None

Expand Down Expand Up @@ -107,3 +108,13 @@ def get_wav_files():
open_recs = get_open_files_in_dir(rec_dir)
files = [file for file in files if file not in open_recs]
return files

class LocationTime:
def __init__(self, lat, lon):
self.timezone = get_localzone()
self.sun = Sun(lat, lon)
def is_night(self, compare_time: datetime.datetime):
local_time = compare_time.astimezone(self.timezone)
sunrise_time = self.sun.get_local_sunrise_time(local_time.date())
sunset_time = self.sun.get_local_sunset_time(local_time.date())
return local_time < sunrise_time or local_time > sunset_time