mbari-pbp 0.3.0__tar.gz
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.
- mbari_pbp-0.3.0/PKG-INFO +87 -0
- mbari_pbp-0.3.0/README.md +59 -0
- mbari_pbp-0.3.0/pbp/__init__.py +49 -0
- mbari_pbp-0.3.0/pbp/file_helper.py +523 -0
- mbari_pbp-0.3.0/pbp/json_generator/__init__.py +0 -0
- mbari_pbp-0.3.0/pbp/json_generator/corrector.py +259 -0
- mbari_pbp-0.3.0/pbp/json_generator/gen_abstract.py +65 -0
- mbari_pbp-0.3.0/pbp/json_generator/gen_iclisten.py +223 -0
- mbari_pbp-0.3.0/pbp/json_generator/gen_nrs.py +212 -0
- mbari_pbp-0.3.0/pbp/json_generator/gen_soundtrap.py +211 -0
- mbari_pbp-0.3.0/pbp/json_generator/metadata_extractor.py +250 -0
- mbari_pbp-0.3.0/pbp/json_generator/utils.py +13 -0
- mbari_pbp-0.3.0/pbp/json_support.py +137 -0
- mbari_pbp-0.3.0/pbp/logging_helper.py +85 -0
- mbari_pbp-0.3.0/pbp/main.py +80 -0
- mbari_pbp-0.3.0/pbp/main_args.py +189 -0
- mbari_pbp-0.3.0/pbp/main_cloud.py +205 -0
- mbari_pbp-0.3.0/pbp/main_json_generator.py +71 -0
- mbari_pbp-0.3.0/pbp/main_json_generator_args.py +87 -0
- mbari_pbp-0.3.0/pbp/metadata.py +77 -0
- mbari_pbp-0.3.0/pbp/misc_helper.py +65 -0
- mbari_pbp-0.3.0/pbp/plot.py +105 -0
- mbari_pbp-0.3.0/pbp/plot_const.py +12 -0
- mbari_pbp-0.3.0/pbp/plotting.py +157 -0
- mbari_pbp-0.3.0/pbp/process_helper.py +314 -0
- mbari_pbp-0.3.0/pbp/pypam_support.py +291 -0
- mbari_pbp-0.3.0/pyproject.toml +61 -0
mbari_pbp-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: mbari-pbp
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: PyPAM based Processing
|
|
5
|
+
License: MIT
|
|
6
|
+
Author: Carlos Rueda
|
|
7
|
+
Author-email: carueda@mbari.org
|
|
8
|
+
Requires-Python: >=3.9,<3.12.0
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Requires-Dist: Pyarrow (==15.0.0)
|
|
15
|
+
Requires-Dist: boto3 (==1.34.47)
|
|
16
|
+
Requires-Dist: dataclasses-json (==0.6.4)
|
|
17
|
+
Requires-Dist: google-cloud-storage (==2.14.0)
|
|
18
|
+
Requires-Dist: h5netcdf (==1.3.0)
|
|
19
|
+
Requires-Dist: lifewatch-pypam (==0.3.0)
|
|
20
|
+
Requires-Dist: marshmallow (==3.20.2)
|
|
21
|
+
Requires-Dist: progressbar2 (==3.53.1)
|
|
22
|
+
Requires-Dist: pvlib (==0.10.3)
|
|
23
|
+
Requires-Dist: python-dateutil (==2.8.2)
|
|
24
|
+
Requires-Dist: pyyaml (==6.0.1)
|
|
25
|
+
Requires-Dist: soundfile (==0.12.1)
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# PyPAM based data processing
|
|
29
|
+
|
|
30
|
+
This package uses [PyPAM](https://github.com/lifewatch/pypam/)
|
|
31
|
+
to generate _hybrid millidecade band spectra_ for soundscape data.
|
|
32
|
+
|
|
33
|
+
**Status**: Functional version, including support for S3-based cloud based processing.
|
|
34
|
+
|
|
35
|
+
- [x] JSON generation of timekeeping
|
|
36
|
+
- [x] Timekeeping based on given JSON indicating start and duration of every available (recognized) sound file
|
|
37
|
+
- [x] Audio file processing
|
|
38
|
+
- [x] Frequency and psd array output
|
|
39
|
+
- [x] Concatenation of processed 1-minute segments for daily product
|
|
40
|
+
- [x] Calibration with given sensitivity file (NetCDF)
|
|
41
|
+
- [x] Calibration with given flat sensitivity value
|
|
42
|
+
- [x] Data products
|
|
43
|
+
- [x] NetCDF with metadata
|
|
44
|
+
- [x] CSV (optional)
|
|
45
|
+
- [x] Summary plot (optional)
|
|
46
|
+
- [x] Cloud processing (inputs downloaded from, and generated products uploaded to S3)
|
|
47
|
+
|
|
48
|
+
TODO more details
|
|
49
|
+
|
|
50
|
+
## Setup
|
|
51
|
+
|
|
52
|
+
### Create and activate virtual environment
|
|
53
|
+
|
|
54
|
+
python3.9 -m venv virtenv
|
|
55
|
+
source virtenv/bin/activate
|
|
56
|
+
|
|
57
|
+
### Install dependencies
|
|
58
|
+
|
|
59
|
+
pip3 install -r requirements.txt
|
|
60
|
+
|
|
61
|
+
### Programs
|
|
62
|
+
|
|
63
|
+
- `src/main.py` - Main CLI program, run `python src/main.py --help` for usage.
|
|
64
|
+
|
|
65
|
+
- `src/main_cloud.py` - Main program for cloud based processing.
|
|
66
|
+
All parameters passed via environment variables, see source file.
|
|
67
|
+
|
|
68
|
+
- `src/plot.py` - Plotting program: `python src/plot.py --help`.
|
|
69
|
+
|
|
70
|
+
- `src/main_json_generator.py` - Main CLI program to generate JSONS with audio metadata, run `python src/main_json_gen.py --help` for usage.
|
|
71
|
+
|
|
72
|
+
## Refs
|
|
73
|
+
|
|
74
|
+
- PyPAM - Python tool for Passive Acoustic Monitoring –
|
|
75
|
+
<https://doi.org/10.5281/zenodo.6044593>
|
|
76
|
+
- Computation of single-sided mean-square sound pressure spectral density with 1 Hz resolution follows
|
|
77
|
+
ISO 18405 3.1.3.13 (International Standard ISO 18405:2017(E), Underwater Acoustics – Terminology. Geneva: ISO)
|
|
78
|
+
– https://www.iso.org/standard/62406.html
|
|
79
|
+
- Hybrid millidecade spectra: A practical format for exchange of long-term ambient sound data –
|
|
80
|
+
<https://asa.scitation.org/doi/10.1121/10.0003324>
|
|
81
|
+
- Erratum: Hybrid millidecade spectra –
|
|
82
|
+
<https://asa.scitation.org/doi/10.1121/10.0005818>
|
|
83
|
+
|
|
84
|
+
## Development
|
|
85
|
+
|
|
86
|
+
See [DEVEL.md](DEVEL.md) for details.
|
|
87
|
+
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# PyPAM based data processing
|
|
2
|
+
|
|
3
|
+
This package uses [PyPAM](https://github.com/lifewatch/pypam/)
|
|
4
|
+
to generate _hybrid millidecade band spectra_ for soundscape data.
|
|
5
|
+
|
|
6
|
+
**Status**: Functional version, including support for S3-based cloud based processing.
|
|
7
|
+
|
|
8
|
+
- [x] JSON generation of timekeeping
|
|
9
|
+
- [x] Timekeeping based on given JSON indicating start and duration of every available (recognized) sound file
|
|
10
|
+
- [x] Audio file processing
|
|
11
|
+
- [x] Frequency and psd array output
|
|
12
|
+
- [x] Concatenation of processed 1-minute segments for daily product
|
|
13
|
+
- [x] Calibration with given sensitivity file (NetCDF)
|
|
14
|
+
- [x] Calibration with given flat sensitivity value
|
|
15
|
+
- [x] Data products
|
|
16
|
+
- [x] NetCDF with metadata
|
|
17
|
+
- [x] CSV (optional)
|
|
18
|
+
- [x] Summary plot (optional)
|
|
19
|
+
- [x] Cloud processing (inputs downloaded from, and generated products uploaded to S3)
|
|
20
|
+
|
|
21
|
+
TODO more details
|
|
22
|
+
|
|
23
|
+
## Setup
|
|
24
|
+
|
|
25
|
+
### Create and activate virtual environment
|
|
26
|
+
|
|
27
|
+
python3.9 -m venv virtenv
|
|
28
|
+
source virtenv/bin/activate
|
|
29
|
+
|
|
30
|
+
### Install dependencies
|
|
31
|
+
|
|
32
|
+
pip3 install -r requirements.txt
|
|
33
|
+
|
|
34
|
+
### Programs
|
|
35
|
+
|
|
36
|
+
- `src/main.py` - Main CLI program, run `python src/main.py --help` for usage.
|
|
37
|
+
|
|
38
|
+
- `src/main_cloud.py` - Main program for cloud based processing.
|
|
39
|
+
All parameters passed via environment variables, see source file.
|
|
40
|
+
|
|
41
|
+
- `src/plot.py` - Plotting program: `python src/plot.py --help`.
|
|
42
|
+
|
|
43
|
+
- `src/main_json_generator.py` - Main CLI program to generate JSONS with audio metadata, run `python src/main_json_gen.py --help` for usage.
|
|
44
|
+
|
|
45
|
+
## Refs
|
|
46
|
+
|
|
47
|
+
- PyPAM - Python tool for Passive Acoustic Monitoring –
|
|
48
|
+
<https://doi.org/10.5281/zenodo.6044593>
|
|
49
|
+
- Computation of single-sided mean-square sound pressure spectral density with 1 Hz resolution follows
|
|
50
|
+
ISO 18405 3.1.3.13 (International Standard ISO 18405:2017(E), Underwater Acoustics – Terminology. Geneva: ISO)
|
|
51
|
+
– https://www.iso.org/standard/62406.html
|
|
52
|
+
- Hybrid millidecade spectra: A practical format for exchange of long-term ambient sound data –
|
|
53
|
+
<https://asa.scitation.org/doi/10.1121/10.0003324>
|
|
54
|
+
- Erratum: Hybrid millidecade spectra –
|
|
55
|
+
<https://asa.scitation.org/doi/10.1121/10.0005818>
|
|
56
|
+
|
|
57
|
+
## Development
|
|
58
|
+
|
|
59
|
+
See [DEVEL.md](DEVEL.md) for details.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
import xarray as xr
|
|
4
|
+
|
|
5
|
+
from pbp.logging_helper import PbpLogger
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def save_dataset_to_netcdf(logger: PbpLogger, ds: xr.Dataset, filename: str) -> bool:
|
|
9
|
+
logger.info(f" - saving dataset to: {filename}")
|
|
10
|
+
try:
|
|
11
|
+
ds.to_netcdf(
|
|
12
|
+
filename,
|
|
13
|
+
engine="h5netcdf",
|
|
14
|
+
encoding={
|
|
15
|
+
"effort": {"_FillValue": None},
|
|
16
|
+
"frequency": {"_FillValue": None},
|
|
17
|
+
"sensitivity": {"_FillValue": None},
|
|
18
|
+
},
|
|
19
|
+
)
|
|
20
|
+
return True
|
|
21
|
+
except Exception as e: # pylint: disable=broad-exception-caught
|
|
22
|
+
error = f"Unable to save {filename}: {e}"
|
|
23
|
+
logger.error(error)
|
|
24
|
+
print(error)
|
|
25
|
+
return False
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def save_dataset_to_csv(logger: PbpLogger, ds: xr.Dataset, filename: str):
|
|
29
|
+
logger.info(f" - saving dataset to: {filename}")
|
|
30
|
+
try:
|
|
31
|
+
ds.to_pandas().to_csv(filename, float_format="%.1f")
|
|
32
|
+
except Exception as e: # pylint: disable=broad-exception-caught
|
|
33
|
+
logger.error(f"Unable to save {filename}: {e}")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def get_cpus_to_use(num_cpus: int) -> int:
|
|
37
|
+
cpu_count: int = os.cpu_count() or 1
|
|
38
|
+
if num_cpus <= 0 or num_cpus > cpu_count:
|
|
39
|
+
num_cpus = cpu_count
|
|
40
|
+
return num_cpus
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class PBPException(Exception):
|
|
44
|
+
"""
|
|
45
|
+
Placeholder for a more specific exception.
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
def __init__(self, msg: str):
|
|
49
|
+
super().__init__(f"PBPException({msg})")
|