birdnet-analyzer 2.1.0__py3-none-any.whl → 2.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. birdnet_analyzer/__init__.py +9 -9
  2. birdnet_analyzer/analyze/__init__.py +19 -19
  3. birdnet_analyzer/analyze/__main__.py +3 -3
  4. birdnet_analyzer/analyze/cli.py +30 -30
  5. birdnet_analyzer/analyze/core.py +268 -246
  6. birdnet_analyzer/analyze/utils.py +700 -694
  7. birdnet_analyzer/audio.py +368 -368
  8. birdnet_analyzer/cli.py +732 -732
  9. birdnet_analyzer/config.py +243 -243
  10. birdnet_analyzer/eBird_taxonomy_codes_2024E.json +13045 -13045
  11. birdnet_analyzer/embeddings/__init__.py +3 -3
  12. birdnet_analyzer/embeddings/__main__.py +3 -3
  13. birdnet_analyzer/embeddings/cli.py +12 -12
  14. birdnet_analyzer/embeddings/core.py +70 -70
  15. birdnet_analyzer/embeddings/utils.py +173 -220
  16. birdnet_analyzer/evaluation/__init__.py +189 -189
  17. birdnet_analyzer/evaluation/__main__.py +3 -3
  18. birdnet_analyzer/evaluation/assessment/metrics.py +388 -388
  19. birdnet_analyzer/evaluation/assessment/performance_assessor.py +364 -364
  20. birdnet_analyzer/evaluation/assessment/plotting.py +378 -378
  21. birdnet_analyzer/evaluation/preprocessing/data_processor.py +631 -631
  22. birdnet_analyzer/evaluation/preprocessing/utils.py +98 -98
  23. birdnet_analyzer/gui/__init__.py +19 -19
  24. birdnet_analyzer/gui/__main__.py +3 -3
  25. birdnet_analyzer/gui/analysis.py +179 -179
  26. birdnet_analyzer/gui/assets/arrow_down.svg +4 -4
  27. birdnet_analyzer/gui/assets/arrow_left.svg +4 -4
  28. birdnet_analyzer/gui/assets/arrow_right.svg +4 -4
  29. birdnet_analyzer/gui/assets/arrow_up.svg +4 -4
  30. birdnet_analyzer/gui/assets/gui.css +36 -36
  31. birdnet_analyzer/gui/assets/gui.js +89 -93
  32. birdnet_analyzer/gui/embeddings.py +638 -638
  33. birdnet_analyzer/gui/evaluation.py +801 -801
  34. birdnet_analyzer/gui/localization.py +75 -75
  35. birdnet_analyzer/gui/multi_file.py +265 -265
  36. birdnet_analyzer/gui/review.py +472 -472
  37. birdnet_analyzer/gui/segments.py +191 -191
  38. birdnet_analyzer/gui/settings.py +149 -149
  39. birdnet_analyzer/gui/single_file.py +264 -264
  40. birdnet_analyzer/gui/species.py +95 -95
  41. birdnet_analyzer/gui/train.py +687 -687
  42. birdnet_analyzer/gui/utils.py +803 -797
  43. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_af.txt +6522 -6522
  44. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_ar.txt +6522 -6522
  45. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_bg.txt +6522 -6522
  46. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_ca.txt +6522 -6522
  47. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_cs.txt +6522 -6522
  48. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_da.txt +6522 -6522
  49. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_de.txt +6522 -6522
  50. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_el.txt +6522 -6522
  51. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_en_uk.txt +6522 -6522
  52. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_es.txt +6522 -6522
  53. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_fi.txt +6522 -6522
  54. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_fr.txt +6522 -6522
  55. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_he.txt +6522 -6522
  56. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_hr.txt +6522 -6522
  57. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_hu.txt +6522 -6522
  58. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_in.txt +6522 -6522
  59. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_is.txt +6522 -6522
  60. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_it.txt +6522 -6522
  61. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_ja.txt +6522 -6522
  62. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_ko.txt +6522 -6522
  63. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_lt.txt +6522 -6522
  64. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_ml.txt +6522 -6522
  65. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_nl.txt +6522 -6522
  66. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_no.txt +6522 -6522
  67. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_pl.txt +6522 -6522
  68. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_pt_BR.txt +6522 -6522
  69. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_pt_PT.txt +6522 -6522
  70. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_ro.txt +6522 -6522
  71. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_ru.txt +6522 -6522
  72. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_sk.txt +6522 -6522
  73. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_sl.txt +6522 -6522
  74. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_sr.txt +6522 -6522
  75. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_sv.txt +6522 -6522
  76. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_th.txt +6522 -6522
  77. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_tr.txt +6522 -6522
  78. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_uk.txt +6522 -6522
  79. birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_zh.txt +6522 -6522
  80. birdnet_analyzer/lang/de.json +342 -341
  81. birdnet_analyzer/lang/en.json +342 -341
  82. birdnet_analyzer/lang/fi.json +342 -341
  83. birdnet_analyzer/lang/fr.json +342 -341
  84. birdnet_analyzer/lang/id.json +342 -341
  85. birdnet_analyzer/lang/pt-br.json +342 -341
  86. birdnet_analyzer/lang/ru.json +342 -341
  87. birdnet_analyzer/lang/se.json +342 -341
  88. birdnet_analyzer/lang/tlh.json +342 -341
  89. birdnet_analyzer/lang/zh_TW.json +342 -341
  90. birdnet_analyzer/model.py +1213 -1212
  91. birdnet_analyzer/search/__init__.py +3 -3
  92. birdnet_analyzer/search/__main__.py +3 -3
  93. birdnet_analyzer/search/cli.py +11 -11
  94. birdnet_analyzer/search/core.py +78 -78
  95. birdnet_analyzer/search/utils.py +104 -107
  96. birdnet_analyzer/segments/__init__.py +3 -3
  97. birdnet_analyzer/segments/__main__.py +3 -3
  98. birdnet_analyzer/segments/cli.py +13 -13
  99. birdnet_analyzer/segments/core.py +81 -81
  100. birdnet_analyzer/segments/utils.py +383 -383
  101. birdnet_analyzer/species/__init__.py +3 -3
  102. birdnet_analyzer/species/__main__.py +3 -3
  103. birdnet_analyzer/species/cli.py +13 -13
  104. birdnet_analyzer/species/core.py +35 -35
  105. birdnet_analyzer/species/utils.py +73 -74
  106. birdnet_analyzer/train/__init__.py +3 -3
  107. birdnet_analyzer/train/__main__.py +3 -3
  108. birdnet_analyzer/train/cli.py +13 -13
  109. birdnet_analyzer/train/core.py +113 -113
  110. birdnet_analyzer/train/utils.py +878 -877
  111. birdnet_analyzer/translate.py +132 -133
  112. birdnet_analyzer/utils.py +425 -425
  113. {birdnet_analyzer-2.1.0.dist-info → birdnet_analyzer-2.1.1.dist-info}/METADATA +147 -146
  114. birdnet_analyzer-2.1.1.dist-info/RECORD +124 -0
  115. {birdnet_analyzer-2.1.0.dist-info → birdnet_analyzer-2.1.1.dist-info}/licenses/LICENSE +18 -18
  116. birdnet_analyzer/playground.py +0 -5
  117. birdnet_analyzer-2.1.0.dist-info/RECORD +0 -125
  118. {birdnet_analyzer-2.1.0.dist-info → birdnet_analyzer-2.1.1.dist-info}/WHEEL +0 -0
  119. {birdnet_analyzer-2.1.0.dist-info → birdnet_analyzer-2.1.1.dist-info}/entry_points.txt +0 -0
  120. {birdnet_analyzer-2.1.0.dist-info → birdnet_analyzer-2.1.1.dist-info}/top_level.txt +0 -0
@@ -1,149 +1,149 @@
1
- import json
2
- import os
3
- import sys
4
- from pathlib import Path
5
-
6
- import birdnet_analyzer.config as cfg
7
- from birdnet_analyzer import utils
8
-
9
- if utils.FROZEN:
10
- # divert stdout & stderr to logs.txt file since we have no console when deployed
11
- userdir = Path.home()
12
-
13
- if sys.platform == "win32":
14
- userdir /= "AppData/Roaming"
15
- elif sys.platform == "linux":
16
- userdir /= ".local/share"
17
- elif sys.platform == "darwin":
18
- userdir /= "Library/Application Support"
19
-
20
- APPDIR = userdir / "BirdNET-Analyzer-GUI"
21
-
22
- APPDIR.mkdir(parents=True, exist_ok=True)
23
-
24
- sys.stderr = sys.stdout = open(str(APPDIR / "logs.txt"), "a") # noqa: SIM115
25
- cfg.ERROR_LOG_FILE = str(APPDIR / os.path.basename(cfg.ERROR_LOG_FILE))
26
- else:
27
- APPDIR = ""
28
-
29
- FALLBACK_LANGUAGE = "en"
30
- SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
31
- GUI_SETTINGS_PATH = os.path.join(APPDIR if utils.FROZEN else os.path.dirname(SCRIPT_DIR), "gui-settings.json")
32
- LANG_DIR = str(Path(SCRIPT_DIR).parent / "lang")
33
- STATE_SETTINGS_PATH = os.path.join(APPDIR if utils.FROZEN else os.path.dirname(SCRIPT_DIR), "state.json")
34
-
35
-
36
- def get_state_dict() -> dict:
37
- """
38
- Retrieves the state dictionary from a JSON file specified by STATE_SETTINGS_PATH.
39
-
40
- If the file does not exist, it creates an empty JSON file and returns an empty dictionary.
41
- If any other exception occurs during file operations, it logs the error and returns an empty dictionary.
42
-
43
- Returns:
44
- dict: The state dictionary loaded from the JSON file, or an empty dictionary if the file does not exist or an error occurs.
45
- """
46
- try:
47
- with open(STATE_SETTINGS_PATH, encoding="utf-8") as f:
48
- return json.load(f)
49
- except FileNotFoundError:
50
- try:
51
- with open(STATE_SETTINGS_PATH, "w", encoding="utf-8") as f:
52
- json.dump({}, f)
53
- return {}
54
- except Exception as e:
55
- utils.write_error_log(e)
56
- return {}
57
-
58
-
59
- def get_state(key: str, default=None):
60
- """
61
- Retrieves the value associated with the given key from the state dictionary.
62
-
63
- Args:
64
- key (str): The key to look up in the state dictionary.
65
- default: The value to return if the key is not found. Defaults to None.
66
-
67
- Returns:
68
- str: The value associated with the key if found, otherwise the default value.
69
- """
70
- return get_state_dict().get(key, default)
71
-
72
-
73
- def set_state(key: str, value: str):
74
- """
75
- Updates the state dictionary with the given key-value pair and writes it to a JSON file.
76
-
77
- Args:
78
- key (str): The key to update in the state dictionary.
79
- value (str): The value to associate with the key in the state dictionary.
80
- """
81
- try:
82
- state = get_state_dict()
83
- state[key] = value
84
-
85
- with open(STATE_SETTINGS_PATH, "w") as f:
86
- json.dump(state, f, indent=4)
87
- except Exception as e:
88
- utils.write_error_log(e)
89
-
90
-
91
- def ensure_settings_file():
92
- """
93
- Ensures that the settings file exists at the specified path. If the file does not exist,
94
- it creates a new settings file with default settings.
95
-
96
- If the file creation fails, the error is logged.
97
- """
98
- if not os.path.exists(GUI_SETTINGS_PATH):
99
- try:
100
- with open(GUI_SETTINGS_PATH, "w") as f:
101
- settings = {"language-id": FALLBACK_LANGUAGE, "theme": "light"}
102
- f.write(json.dumps(settings, indent=4))
103
- except Exception as e:
104
- utils.write_error_log(e)
105
-
106
-
107
- def get_setting(key, default=None):
108
- """
109
- Retrieves the value associated with the given key from the settings file.
110
-
111
- Args:
112
- key (str): The key to look up in the settings file.
113
- default: The value to return if the key is not found. Defaults to None.
114
-
115
- Returns:
116
- str: The value associated with the key if found, otherwise the default value.
117
- """
118
- ensure_settings_file()
119
-
120
- try:
121
- with open(GUI_SETTINGS_PATH, encoding="utf-8") as f:
122
- settings_dict: dict = json.load(f)
123
-
124
- return settings_dict.get(key, default)
125
- except FileNotFoundError:
126
- return default
127
-
128
-
129
- def set_setting(key, value):
130
- ensure_settings_file()
131
- settings_dict = {}
132
-
133
- try:
134
- with open(GUI_SETTINGS_PATH, "r+", encoding="utf-8") as f:
135
- settings_dict = json.load(f)
136
- settings_dict[key] = value
137
- f.seek(0)
138
- json.dump(settings_dict, f, indent=4)
139
- f.truncate()
140
-
141
- except FileNotFoundError:
142
- pass
143
-
144
-
145
- def theme():
146
- options = ("light", "dark")
147
- current_time = get_setting("theme", "light")
148
-
149
- return current_time if current_time in options else "light"
1
+ import json
2
+ import os
3
+ import sys
4
+ from pathlib import Path
5
+
6
+ import birdnet_analyzer.config as cfg
7
+ from birdnet_analyzer import utils
8
+
9
+ if utils.FROZEN:
10
+ # divert stdout & stderr to logs.txt file since we have no console when deployed
11
+ userdir = Path.home()
12
+
13
+ if sys.platform == "win32":
14
+ userdir /= "AppData/Roaming"
15
+ elif sys.platform == "linux":
16
+ userdir /= ".local/share"
17
+ elif sys.platform == "darwin":
18
+ userdir /= "Library/Application Support"
19
+
20
+ APPDIR = userdir / "BirdNET-Analyzer-GUI"
21
+
22
+ APPDIR.mkdir(parents=True, exist_ok=True)
23
+
24
+ sys.stderr = sys.stdout = open(str(APPDIR / "logs.txt"), "a") # noqa: SIM115
25
+ cfg.ERROR_LOG_FILE = str(APPDIR / os.path.basename(cfg.ERROR_LOG_FILE))
26
+ else:
27
+ APPDIR = ""
28
+
29
+ FALLBACK_LANGUAGE = "en"
30
+ SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
31
+ GUI_SETTINGS_PATH = os.path.join(APPDIR if utils.FROZEN else os.path.dirname(SCRIPT_DIR), "gui-settings.json")
32
+ LANG_DIR = str(Path(SCRIPT_DIR).parent / "lang")
33
+ STATE_SETTINGS_PATH = os.path.join(APPDIR if utils.FROZEN else os.path.dirname(SCRIPT_DIR), "state.json")
34
+
35
+
36
+ def get_state_dict() -> dict:
37
+ """
38
+ Retrieves the state dictionary from a JSON file specified by STATE_SETTINGS_PATH.
39
+
40
+ If the file does not exist, it creates an empty JSON file and returns an empty dictionary.
41
+ If any other exception occurs during file operations, it logs the error and returns an empty dictionary.
42
+
43
+ Returns:
44
+ dict: The state dictionary loaded from the JSON file, or an empty dictionary if the file does not exist or an error occurs.
45
+ """
46
+ try:
47
+ with open(STATE_SETTINGS_PATH, encoding="utf-8") as f:
48
+ return json.load(f)
49
+ except FileNotFoundError:
50
+ try:
51
+ with open(STATE_SETTINGS_PATH, "w", encoding="utf-8") as f:
52
+ json.dump({}, f)
53
+ return {}
54
+ except Exception as e:
55
+ utils.write_error_log(e)
56
+ return {}
57
+
58
+
59
+ def get_state(key: str, default=None):
60
+ """
61
+ Retrieves the value associated with the given key from the state dictionary.
62
+
63
+ Args:
64
+ key (str): The key to look up in the state dictionary.
65
+ default: The value to return if the key is not found. Defaults to None.
66
+
67
+ Returns:
68
+ str: The value associated with the key if found, otherwise the default value.
69
+ """
70
+ return get_state_dict().get(key, default)
71
+
72
+
73
+ def set_state(key: str, value: str):
74
+ """
75
+ Updates the state dictionary with the given key-value pair and writes it to a JSON file.
76
+
77
+ Args:
78
+ key (str): The key to update in the state dictionary.
79
+ value (str): The value to associate with the key in the state dictionary.
80
+ """
81
+ try:
82
+ state = get_state_dict()
83
+ state[key] = value
84
+
85
+ with open(STATE_SETTINGS_PATH, "w") as f:
86
+ json.dump(state, f, indent=4)
87
+ except Exception as e:
88
+ utils.write_error_log(e)
89
+
90
+
91
+ def ensure_settings_file():
92
+ """
93
+ Ensures that the settings file exists at the specified path. If the file does not exist,
94
+ it creates a new settings file with default settings.
95
+
96
+ If the file creation fails, the error is logged.
97
+ """
98
+ if not os.path.exists(GUI_SETTINGS_PATH):
99
+ try:
100
+ with open(GUI_SETTINGS_PATH, "w") as f:
101
+ settings = {"language-id": FALLBACK_LANGUAGE, "theme": "light"}
102
+ f.write(json.dumps(settings, indent=4))
103
+ except Exception as e:
104
+ utils.write_error_log(e)
105
+
106
+
107
+ def get_setting(key, default=None):
108
+ """
109
+ Retrieves the value associated with the given key from the settings file.
110
+
111
+ Args:
112
+ key (str): The key to look up in the settings file.
113
+ default: The value to return if the key is not found. Defaults to None.
114
+
115
+ Returns:
116
+ str: The value associated with the key if found, otherwise the default value.
117
+ """
118
+ ensure_settings_file()
119
+
120
+ try:
121
+ with open(GUI_SETTINGS_PATH, encoding="utf-8") as f:
122
+ settings_dict: dict = json.load(f)
123
+
124
+ return settings_dict.get(key, default)
125
+ except FileNotFoundError:
126
+ return default
127
+
128
+
129
+ def set_setting(key, value):
130
+ ensure_settings_file()
131
+ settings_dict = {}
132
+
133
+ try:
134
+ with open(GUI_SETTINGS_PATH, "r+", encoding="utf-8") as f:
135
+ settings_dict = json.load(f)
136
+ settings_dict[key] = value
137
+ f.seek(0)
138
+ json.dump(settings_dict, f, indent=4)
139
+ f.truncate()
140
+
141
+ except FileNotFoundError:
142
+ pass
143
+
144
+
145
+ def theme():
146
+ options = ("light", "dark")
147
+ current_time = get_setting("theme", "light")
148
+
149
+ return current_time if current_time in options else "light"