satisfy flake8 linter (this is ridiculus)

This commit is contained in:
Bdoner
2023-02-22 10:57:40 +01:00
parent fdbcf92bd6
commit 291ab9263e
4 changed files with 29 additions and 43 deletions
+2 -1
View File
@@ -48,7 +48,8 @@ readings = 10
plt_top10_today = (df_plt_today['Com_Name'].value_counts()[:readings]) plt_top10_today = (df_plt_today['Com_Name'].value_counts()[:readings])
df_plt_top10_today = df_plt_today[df_plt_today.Com_Name.isin(plt_top10_today.index)] df_plt_top10_today = df_plt_today[df_plt_today.Com_Name.isin(plt_top10_today.index)]
if df_plt_top10_today.empty: exit(0) if df_plt_top10_today.empty:
exit(0)
# Set Palette for graphics # Set Palette for graphics
pal = "Greens" pal = "Greens"
+8 -8
View File
@@ -93,7 +93,7 @@ else:
def date_filter(df, start_date, end_date): def date_filter(df, start_date, end_date):
filt = (df2.index >= pd.Timestamp(start_date)) & (df2.index <= pd.Timestamp(end_date + timedelta(days=1))) filt = (df2.index >= pd.Timestamp(start_date)) & (df2.index <= pd.Timestamp(end_date + timedelta(days=1)))
df = df[filt] df = df[filt]
return(df) return (df)
df2 = date_filter(df2, start_date, end_date) df2 = date_filter(df2, start_date, end_date)
@@ -140,7 +140,7 @@ def time_resample(df, resample_time):
else: else:
df_resample = df.resample(resample_time)['Com_Name'].aggregate('unique').explode() df_resample = df.resample(resample_time)['Com_Name'].aggregate('unique').explode()
return(df_resample) return (df_resample)
top_bird = df2['Com_Name'].mode()[0] top_bird = df2['Com_Name'].mode()[0]
@@ -172,10 +172,10 @@ if daily is False:
if resample_time != '1D': if resample_time != '1D':
specie = st.selectbox( specie = st.selectbox(
'Which bird would you like to explore for the dates ' 'Which bird would you like to explore for the dates '
+ str(start_date) + ' to ' + str(end_date) + '?', + str(start_date) + ' to ' + str(end_date) + '?',
species, species,
index=0) index=0)
# filt = df2['Com_Name'] == specie # filt = df2['Com_Name'] == specie
if specie == 'All': if specie == 'All':
@@ -192,7 +192,7 @@ if daily is False:
# '{:.2f}%'.format(max(df2[df2['Com_Name'] == specie]['Confidence']) * 100)) + # '{:.2f}%'.format(max(df2[df2['Com_Name'] == specie]['Confidence']) * 100)) +
# ' ' + ' Median:' + str( # ' ' + ' Median:' + str(
# '{:.2f}%'.format(np.median(df2[df2['Com_Name'] == specie]['Confidence']) * 100)) # '{:.2f}%'.format(np.median(df2[df2['Com_Name'] == specie]['Confidence']) * 100))
) )
) )
fig.layout.annotations[1].update(x=0.7, y=0.25, font_size=15) fig.layout.annotations[1].update(x=0.7, y=0.25, font_size=15)
@@ -252,7 +252,7 @@ if daily is False:
fig = make_subplots( fig = make_subplots(
rows=3, cols=1, rows=3, cols=1,
specs=[[{"type": "polar", "rowspan": 2}], [{"rowspan": 1}], [{"type": "xy", "rowspan": 1}]] specs=[[{"type": "polar", "rowspan": 2}], [{"rowspan": 1}], [{"type": "xy", "rowspan": 1}]]
) )
# Set 360 degrees, 24 hours for polar plot # Set 360 degrees, 24 hours for polar plot
theta = np.linspace(0.0, 360, 24, endpoint=False) theta = np.linspace(0.0, 360, 24, endpoint=False)
+16 -31
View File
@@ -1,18 +1,5 @@
from pathlib import Path
from tzlocal import get_localzone
import datetime
import sqlite3
import requests
import json
import time
import math
import numpy as np import numpy as np
import librosa
import operator
import socket
import threading
import os import os
import sys
import argparse import argparse
import datetime import datetime
@@ -22,7 +9,6 @@ except BaseException:
from tensorflow import lite as tflite from tensorflow import lite as tflite
def loadMetaModel(): def loadMetaModel():
global M_INTERPRETER global M_INTERPRETER
@@ -51,15 +37,16 @@ def loadMetaModel():
print("loaded META model") print("loaded META model")
def predictFilter(lat, lon, week): def predictFilter(lat, lon, week):
global M_INTERPRETER global M_INTERPRETER
# Does interpreter exist? # Does interpreter exist?
try: try:
if M_INTERPRETER == None: if M_INTERPRETER is None:
loadMetaModel() loadMetaModel()
except Exception as e: except Exception:
loadMetaModel() loadMetaModel()
# Prepare mdata as sample # Prepare mdata as sample
@@ -71,6 +58,7 @@ def predictFilter(lat, lon, week):
return M_INTERPRETER.get_tensor(M_OUTPUT_LAYER_INDEX)[0] return M_INTERPRETER.get_tensor(M_OUTPUT_LAYER_INDEX)[0]
def explore(lat, lon, week, threshold): def explore(lat, lon, week, threshold):
# Make filter prediction # Make filter prediction
@@ -87,6 +75,7 @@ def explore(lat, lon, week, threshold):
return l_filter return l_filter
def getSpeciesList(lat, lon, week, threshold=0.05, sort=False): def getSpeciesList(lat, lon, week, threshold=0.05, sort=False):
print('Getting species list for {}/{}, Week {}...'.format(lat, lon, week), end='', flush=True) print('Getting species list for {}/{}, Week {}...'.format(lat, lon, week), end='', flush=True)
@@ -98,7 +87,7 @@ def getSpeciesList(lat, lon, week, threshold=0.05, sort=False):
slist = [] slist = []
for p in pred: for p in pred:
if p[0] >= threshold: if p[0] >= threshold:
slist.append([p[1],p[0]]) slist.append([p[1], p[0]])
return slist return slist
@@ -112,17 +101,14 @@ with open(userDir + '/BirdNET-Pi/scripts/thisrun.txt', 'r') as f:
lon = str(str(str([i for i in this_run if i.startswith('LONGITUDE')]).split('=')[1]).split('\\')[0]) lon = str(str(str([i for i in this_run if i.startswith('LONGITUDE')]).split('=')[1]).split('\\')[0])
weekofyear = datetime.datetime.today().isocalendar()[1] weekofyear = datetime.datetime.today().isocalendar()[1]
if __name__ == '__main__': if __name__ == '__main__':
# Parse arguments # Parse arguments
parser = argparse.ArgumentParser(description='Get list of species for a given location with BirdNET. Sorted by occurrence frequency.') parser = argparse.ArgumentParser(
#parser.add_argument('--o', default='/home/pi/BirdNET-Pi/include_species_list.txt', help='Path to output file or folder. If this is a folder, file will be named \'species_list.txt\'.') description='Get list of species for a given location with BirdNET. Sorted by occurrence frequency.'
#parser.add_argument('--lat', type=float, default=##, help='Recording location latitude. Set -1 to ignore.') )
#parser.add_argument('--lon', type=float, default=##, help='Recording location longitude. Set -1 to ignore.')
#parser.add_argument('--week', type=int, default=dayofweek, help='Week of the year when the recording was made. Values in [1, 48] (4 weeks per month). Set -1 for year-round species list.')
parser.add_argument('--threshold', type=float, default=0.05, help='Occurrence frequency threshold. Defaults to 0.05.') parser.add_argument('--threshold', type=float, default=0.05, help='Occurrence frequency threshold. Defaults to 0.05.')
#parser.add_argument('--sortby', default='freq', help='Sort species by occurrence frequency or alphabetically. Values in [\'freq\', \'alpha\']. Defaults to \'freq\'.')
args = parser.parse_args() args = parser.parse_args()
LOCATION_FILTER_THRESHOLD = args.threshold LOCATION_FILTER_THRESHOLD = args.threshold
@@ -130,10 +116,9 @@ if __name__ == '__main__':
# Get species list # Get species list
species_list = getSpeciesList(lat, lon, weekofyear, LOCATION_FILTER_THRESHOLD, False) species_list = getSpeciesList(lat, lon, weekofyear, LOCATION_FILTER_THRESHOLD, False)
for x in range(len(species_list)): for x in range(len(species_list)):
print(species_list[x][0] + " - "+ str(species_list[x][1])) print(species_list[x][0] + " - " + str(species_list[x][1]))
print("\nThe above species list describes all the species that the model will attempt to detect. If you don't see a species you want detected on this list, decrease your threshold.")
print("\nNOTE: no actual changes to your BirdNET-Pi species list were made by running this command. To set your desired frequency threshold, do it through the BirdNET-Pi web interface (Tools -> Settings -> Model)")
print("\nThe above species list describes all the species that the model will attempt to detect. \
If you don't see a species you want detected on this list, decrease your threshold.")
print("\nNOTE: no actual changes to your BirdNET-Pi species list were made by running this command. \
To set your desired frequency threshold, do it through the BirdNET-Pi web interface (Tools -> Settings -> Model)")
+3 -3
View File
@@ -39,6 +39,6 @@ IDFILE=/home/pi/BirdNET-Pi/IdentifiedSoFar.txt"""
f.write(text) f.write(text)
settings = config_to_settings(filename.name) settings = config_to_settings(filename.name)
assert(settings["APPRISE_NOTIFICATION_TITLE"] == "Bird!") assert (settings["APPRISE_NOTIFICATION_TITLE"] == "Bird!")
assert(settings["FULL_DISK"] == "purge") assert (settings["FULL_DISK"] == "purge")
assert(settings["OVERLAP"] == "0.0") # Yes, it's a string at this point. assert (settings["OVERLAP"] == "0.0") # Yes, it's a string at this point.