oceanstream 0.0.0.dev0__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.
- oceanstream/__init__.py +0 -0
- oceanstream/cli/__init__.py +3 -0
- oceanstream/cli/main.py +267 -0
- oceanstream/denoise/__init__.py +2 -0
- oceanstream/denoise/apply_masks.py +49 -0
- oceanstream/denoise/applying_masks_handler.py +173 -0
- oceanstream/denoise/background_noise_remover.py +97 -0
- oceanstream/denoise/create_masks.py +87 -0
- oceanstream/denoise/noise_masks.py +398 -0
- oceanstream/denoise/types.py +73 -0
- oceanstream/echodata/__init__.py +5 -0
- oceanstream/echodata/ensure_time_continuity.py +75 -0
- oceanstream/echodata/mvbs_computation.py +77 -0
- oceanstream/echodata/raw_handler.py +577 -0
- oceanstream/echodata/sv_computation.py +118 -0
- oceanstream/echodata/sv_dataset_extension.py +126 -0
- oceanstream/echodata/sv_interpolation.py +260 -0
- oceanstream/echodata/target_strength_computation.py +109 -0
- oceanstream/exports/__init__.py +2 -0
- oceanstream/exports/csv/csv_export_from_Sv.py +89 -0
- oceanstream/exports/csv/csv_export_from_raw.py +92 -0
- oceanstream/exports/csv/csv_export_nasc.py +135 -0
- oceanstream/exports/frequency_differencing_handler.py +210 -0
- oceanstream/exports/nasc.py +23 -0
- oceanstream/exports/nasc_computation.py +62 -0
- oceanstream/exports/shoals/shoal_detection_handler.py +109 -0
- oceanstream/exports/shoals/shoal_process.py +224 -0
- oceanstream/exports/shoals/shoals_handler.py +35 -0
- oceanstream/plot/__init__.py +2 -0
- oceanstream/plot/echogram.py +542 -0
- oceanstream/process/__init__.py +21 -0
- oceanstream/process/combine_zarr.py +90 -0
- oceanstream/process/file_processor.py +151 -0
- oceanstream/process/folder_processor.py +246 -0
- oceanstream/process/process.py +77 -0
- oceanstream/process/processed_data_io.py +140 -0
- oceanstream/settings/__init__.py +1 -0
- oceanstream/settings/config.py +17 -0
- oceanstream/utils.py +101 -0
- oceanstream-0.0.0.dev0.dist-info/LICENSE +21 -0
- oceanstream-0.0.0.dev0.dist-info/METADATA +214 -0
- oceanstream-0.0.0.dev0.dist-info/RECORD +46 -0
- oceanstream-0.0.0.dev0.dist-info/WHEEL +5 -0
- oceanstream-0.0.0.dev0.dist-info/dependency_links.txt +1 -0
- oceanstream-0.0.0.dev0.dist-info/entry_points.txt +2 -0
- oceanstream-0.0.0.dev0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
"""
|
|
2
|
+
noise_masks.py
|
|
3
|
+
---------------
|
|
4
|
+
Description: Module for computing noise masks from Sv data.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
import pathlib
|
|
9
|
+
from typing import Union
|
|
10
|
+
|
|
11
|
+
import xarray as xr
|
|
12
|
+
from echopype.clean.api import (
|
|
13
|
+
get_attenuation_mask_multichannel,
|
|
14
|
+
get_impulse_noise_mask_multichannel,
|
|
15
|
+
get_transient_noise_mask_multichannel,
|
|
16
|
+
)
|
|
17
|
+
from echopype.mask.api import get_seabed_mask_multichannel
|
|
18
|
+
|
|
19
|
+
from oceanstream.utils import add_metadata_to_mask, attach_masks_to_dataset, dict_to_formatted_list
|
|
20
|
+
|
|
21
|
+
RAPIDKRILL_MASK_PARAMETERS = {
|
|
22
|
+
"transient": {
|
|
23
|
+
"method": "ryan",
|
|
24
|
+
"params": {
|
|
25
|
+
"m": 5,
|
|
26
|
+
"n": 20,
|
|
27
|
+
# "n": 5,
|
|
28
|
+
"thr": 20,
|
|
29
|
+
"excludeabove": 250,
|
|
30
|
+
"dask_chunking": {"ping_time": 100},
|
|
31
|
+
"operation": "mean",
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
"attenuation": {
|
|
35
|
+
"method": "ryan",
|
|
36
|
+
"params": {
|
|
37
|
+
"r0": 180,
|
|
38
|
+
"r1": 280,
|
|
39
|
+
"n": 30,
|
|
40
|
+
"m": None,
|
|
41
|
+
"thr": -6,
|
|
42
|
+
"start": 0,
|
|
43
|
+
"offset": 0,
|
|
44
|
+
"dask_chunking": {"ping_time": 100, "range_sample": 100},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
"impulse": {"method": "ryan", "params": {"thr": 10, "m": 5, "n": 1}},
|
|
48
|
+
"seabed": {
|
|
49
|
+
"method": "ariza",
|
|
50
|
+
"params": {
|
|
51
|
+
"r0": 10,
|
|
52
|
+
"r1": 1000,
|
|
53
|
+
"roff": 0,
|
|
54
|
+
"thr": -40,
|
|
55
|
+
"ec": 1,
|
|
56
|
+
"ek": (1, 3),
|
|
57
|
+
"dc": 10,
|
|
58
|
+
"dk": (3, 7),
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
"false_seabed": {
|
|
62
|
+
"method": "blackwell",
|
|
63
|
+
"params": {
|
|
64
|
+
"theta": None,
|
|
65
|
+
"phi": None,
|
|
66
|
+
"r0": 10,
|
|
67
|
+
"r1": 1000,
|
|
68
|
+
"tSv": -75,
|
|
69
|
+
"ttheta": 702,
|
|
70
|
+
"tphi": 282,
|
|
71
|
+
"wtheta": 28,
|
|
72
|
+
"wphi": 52,
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
OCEANSTREAM_MASK_PARAMETERS = {
|
|
79
|
+
"transient": {
|
|
80
|
+
"method": "fielding",
|
|
81
|
+
"params": {
|
|
82
|
+
"r0": 200,
|
|
83
|
+
"r1": 1000,
|
|
84
|
+
"n": 5,
|
|
85
|
+
"thr": [2, 0],
|
|
86
|
+
"roff": 250,
|
|
87
|
+
"jumps": 5,
|
|
88
|
+
"maxts": -35,
|
|
89
|
+
"start": 0,
|
|
90
|
+
"dask_chunking": {"ping_time": 100, "range_sample": 100},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
"attenuation": {
|
|
94
|
+
"method": "ryan",
|
|
95
|
+
"params": {
|
|
96
|
+
"r0": 180,
|
|
97
|
+
"r1": 280,
|
|
98
|
+
"n": 5,
|
|
99
|
+
"m": None,
|
|
100
|
+
"thr": -5,
|
|
101
|
+
"start": 0,
|
|
102
|
+
"offset": 0,
|
|
103
|
+
"dask_chunking": {"ping_time": 100, "range_sample": 100},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
"impulse": {"method": "ryan", "params": {"thr": 3, "m": 3, "n": 1}},
|
|
107
|
+
"seabed": {
|
|
108
|
+
"method": "ariza",
|
|
109
|
+
"params": {
|
|
110
|
+
"r0": 10,
|
|
111
|
+
"r1": 1000,
|
|
112
|
+
"roff": 0,
|
|
113
|
+
"thr": -35,
|
|
114
|
+
"ec": 15,
|
|
115
|
+
"ek": (1, 3),
|
|
116
|
+
"dc": 150,
|
|
117
|
+
"dk": (1, 3),
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
"false_seabed": {
|
|
121
|
+
"method": "blackwell",
|
|
122
|
+
"params": {
|
|
123
|
+
"theta": None,
|
|
124
|
+
"phi": None,
|
|
125
|
+
"r0": 10,
|
|
126
|
+
"r1": 1000,
|
|
127
|
+
"tSv": -75,
|
|
128
|
+
"ttheta": 702,
|
|
129
|
+
"tphi": 282,
|
|
130
|
+
"wtheta": 28,
|
|
131
|
+
"wphi": 52,
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
OCEANSTREAM_NOISE_MASK_PARAMETERS = {
|
|
137
|
+
k: OCEANSTREAM_MASK_PARAMETERS[k] for k in ["transient", "attenuation", "impulse"]
|
|
138
|
+
}
|
|
139
|
+
OCEANSTREAM_SEABED_MASK_PARAMETERS = {
|
|
140
|
+
k: OCEANSTREAM_MASK_PARAMETERS[k] for k in ["seabed", "false_seabed"]
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
MASK_PARAMETERS = {
|
|
145
|
+
"method": "ryan",
|
|
146
|
+
"params": {"thr": 3, "m": 3, "n": 1},
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def create_transient_mask(
|
|
151
|
+
Sv: Union[xr.Dataset, str, pathlib.Path], parameters: dict, method: str = "ryan"
|
|
152
|
+
):
|
|
153
|
+
"""
|
|
154
|
+
Invokes echopype's get_transient_noise_mask_multichannel
|
|
155
|
+
(see echopype's documentation)
|
|
156
|
+
|
|
157
|
+
Parameters:
|
|
158
|
+
- Sv: xr.Dataset or str or pathlib.Path
|
|
159
|
+
If a Dataset this value contains the Sv data to create a mask for,
|
|
160
|
+
else it specifies the path to a zarr or netcdf file containing
|
|
161
|
+
a Dataset. This input must correspond to a Dataset that has the
|
|
162
|
+
coordinate ``channel`` and variables ``frequency_nominal`` and ``Sv``.
|
|
163
|
+
- method: str with either "ryan" or "fielding" based on
|
|
164
|
+
the preferred method for transient noise mask generation
|
|
165
|
+
- parameters: dict
|
|
166
|
+
Default method parameters
|
|
167
|
+
|
|
168
|
+
Returns:
|
|
169
|
+
- A multichannel mask for transient noise
|
|
170
|
+
|
|
171
|
+
Example:
|
|
172
|
+
>>> create_transient_mask(Sv, parameters, method)
|
|
173
|
+
"""
|
|
174
|
+
mask = get_transient_noise_mask_multichannel(Sv, parameters, method)
|
|
175
|
+
return mask
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def create_impulse_mask(
|
|
179
|
+
Sv: xr.Dataset,
|
|
180
|
+
parameters: dict,
|
|
181
|
+
method: str = "ryan",
|
|
182
|
+
) -> xr.DataArray:
|
|
183
|
+
"""
|
|
184
|
+
Invokes echopype's get_impulse_noise_mask_multichannel
|
|
185
|
+
(see echopype's documentation)
|
|
186
|
+
|
|
187
|
+
Parameters:
|
|
188
|
+
- Sv: xr.Dataset
|
|
189
|
+
Dataset containing the Sv data to create a mask for
|
|
190
|
+
- method: str, optional
|
|
191
|
+
The method (ryan, ryan iterable or wang) used to mask impulse noise. Defaults to 'ryan'.
|
|
192
|
+
- parameters: dict
|
|
193
|
+
Default method parameters
|
|
194
|
+
|
|
195
|
+
Returns:
|
|
196
|
+
- A multichannel mask for impulse noise
|
|
197
|
+
|
|
198
|
+
Example:
|
|
199
|
+
>>> create_impulse_mask(Sv, parameters, method)
|
|
200
|
+
"""
|
|
201
|
+
mask = get_impulse_noise_mask_multichannel(Sv, parameters, method)
|
|
202
|
+
return mask
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def create_attenuation_mask(
|
|
206
|
+
Sv: Union[xr.Dataset, str, pathlib.Path],
|
|
207
|
+
parameters: dict,
|
|
208
|
+
method: str = "ryan",
|
|
209
|
+
) -> xr.DataArray:
|
|
210
|
+
"""
|
|
211
|
+
Invokes echopype's get_attenuation_mask_multichannel
|
|
212
|
+
(see echopype's documentation)
|
|
213
|
+
|
|
214
|
+
Parameters:
|
|
215
|
+
- Sv: xr.Dataset or str or pathlib.Path
|
|
216
|
+
If a Dataset this value contains the Sv data to create a mask for,
|
|
217
|
+
else it specifies the path to a zarr or netcdf file containing
|
|
218
|
+
a Dataset. This input must correspond to a Dataset that has the
|
|
219
|
+
coordinate ``channel`` and variables ``frequency_nominal`` and ``Sv``.
|
|
220
|
+
- method: str with either "ryan" or "ariza" based on the
|
|
221
|
+
preferred method for signal attenuation mask generation
|
|
222
|
+
- parameters: dict
|
|
223
|
+
Default method parameters
|
|
224
|
+
|
|
225
|
+
Returns:
|
|
226
|
+
- A multichannel mask for attenuation noise
|
|
227
|
+
|
|
228
|
+
Example:
|
|
229
|
+
>>> create_attenuation_mask(Sv, parameters, method)
|
|
230
|
+
"""
|
|
231
|
+
mask = get_attenuation_mask_multichannel(Sv, parameters, method)
|
|
232
|
+
return mask
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def create_seabed_mask(Sv, parameters, method):
|
|
236
|
+
"""
|
|
237
|
+
Invokes echopype's get_seabed_mask_multichannel
|
|
238
|
+
(see echopype's documentation for the possible parameters)
|
|
239
|
+
|
|
240
|
+
Parameters:
|
|
241
|
+
- Sv: the dataset we're trying to create a mask for
|
|
242
|
+
- method: str with either "ariza", "experimental", "blackwell_mod",
|
|
243
|
+
"blackwell", "deltaSv", "maxSv" based on the preferred method for seabed mask generation
|
|
244
|
+
- parameters: dict
|
|
245
|
+
Default method parameters
|
|
246
|
+
|
|
247
|
+
Returns:
|
|
248
|
+
- Multichannel mask for seabed detection
|
|
249
|
+
|
|
250
|
+
Example:
|
|
251
|
+
>>> create_seabed_mask(Sv, parameters, method)
|
|
252
|
+
"""
|
|
253
|
+
mask = get_seabed_mask_multichannel(Sv, parameters, method)
|
|
254
|
+
return mask
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def create_mask(source_Sv: xr.Dataset, mask_type="impulse", params=MASK_PARAMETERS):
|
|
258
|
+
"""
|
|
259
|
+
A function that creates a single noise mask for a given dataset
|
|
260
|
+
|
|
261
|
+
Parameters:
|
|
262
|
+
- source_Sv (xarray.Dataset): the dataset to which the masks will be attached.
|
|
263
|
+
- mask type (str): type of mask
|
|
264
|
+
- params (dict): a dictionary of mask parameters containing type and
|
|
265
|
+
|
|
266
|
+
Returns:
|
|
267
|
+
- xarray.DataArray: the required mask
|
|
268
|
+
"""
|
|
269
|
+
mask_map = {
|
|
270
|
+
"transient": create_transient_mask,
|
|
271
|
+
"impulse": create_impulse_mask,
|
|
272
|
+
"attenuation": create_attenuation_mask,
|
|
273
|
+
"seabed": create_seabed_mask,
|
|
274
|
+
"false_seabed": create_seabed_mask,
|
|
275
|
+
}
|
|
276
|
+
method = params["method"]
|
|
277
|
+
parameters = params["params"]
|
|
278
|
+
|
|
279
|
+
mask = mask_map[mask_type](source_Sv, parameters=parameters, method=method)
|
|
280
|
+
mask = add_metadata_to_mask(
|
|
281
|
+
mask,
|
|
282
|
+
metadata={
|
|
283
|
+
"mask_type": mask_type,
|
|
284
|
+
"method": method,
|
|
285
|
+
"parameters": dict_to_formatted_list(parameters),
|
|
286
|
+
},
|
|
287
|
+
)
|
|
288
|
+
return mask
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
def create_multiple_masks(source_Sv: xr.Dataset, params=None):
|
|
292
|
+
"""
|
|
293
|
+
A function that creates multiple noise masks for a given Sv dataset
|
|
294
|
+
|
|
295
|
+
Parameters:
|
|
296
|
+
- source_Sv (xarray.Dataset): the dataset to which the masks will be attached.
|
|
297
|
+
- params (dict): a dict of dictionaries of mask parameters
|
|
298
|
+
|
|
299
|
+
Returns:
|
|
300
|
+
- xarray.Dataset: a dataset with the same dimensions as the original,
|
|
301
|
+
containing the original data and five masks: mask_transient, mask_impulse,
|
|
302
|
+
mask_attenuated, mask_seabed, mask_false_seabed
|
|
303
|
+
|
|
304
|
+
Notes:
|
|
305
|
+
- To effectively utilize the `blackwell` method for seabed detection,
|
|
306
|
+
it's essential that the `source_Sv` dataset includes the `split-beam angle` parameters.
|
|
307
|
+
Specifically, ensure that your input `source_Sv` contains
|
|
308
|
+
both the `angle_alongship` and `angle_athwartship` variables.
|
|
309
|
+
Absence of these variables leads to errors .
|
|
310
|
+
"""
|
|
311
|
+
masks = [create_mask(source_Sv, mask_type=k, params=params[k]) for k in params.keys()]
|
|
312
|
+
Sv_mask = attach_masks_to_dataset(source_Sv, masks)
|
|
313
|
+
return Sv_mask
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
def create_noise_masks_rapidkrill(source_Sv: xr.Dataset, params=RAPIDKRILL_MASK_PARAMETERS):
|
|
317
|
+
"""
|
|
318
|
+
A function that creates noise masks for a given Sv dataset according to
|
|
319
|
+
rapidkrill processing needs
|
|
320
|
+
|
|
321
|
+
Parameters:
|
|
322
|
+
- source_Sv (xarray.Dataset): the dataset to which the masks will be attached.
|
|
323
|
+
|
|
324
|
+
Returns:
|
|
325
|
+
- xarray.Dataset: a dataset with the same dimensions as the original,
|
|
326
|
+
containing the original data and five masks: mask_transient, mask_impulse,
|
|
327
|
+
mask_attenuated, mask_seabed, mask_false_seabed
|
|
328
|
+
|
|
329
|
+
Notes:
|
|
330
|
+
- To effectively utilize the `blackwell` method for seabed detection,
|
|
331
|
+
it's essential that the `source_Sv` dataset includes the `split-beam angle` parameters.
|
|
332
|
+
Specifically, ensure that your input `source_Sv` contains
|
|
333
|
+
both the `angle_alongship` and `angle_athwartship` variables.
|
|
334
|
+
Absence of these variables leads to errors .
|
|
335
|
+
"""
|
|
336
|
+
Sv_mask = create_multiple_masks(source_Sv, params)
|
|
337
|
+
return Sv_mask
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
def create_default_noise_masks_oceanstream(
|
|
341
|
+
source_Sv: xr.Dataset, params=OCEANSTREAM_MASK_PARAMETERS
|
|
342
|
+
):
|
|
343
|
+
"""
|
|
344
|
+
A function that creates noise masks for a given Sv dataset using default methods for oceanstream
|
|
345
|
+
|
|
346
|
+
Parameters:
|
|
347
|
+
- source_Sv (xarray.Dataset): the dataset to which the masks will be attached.
|
|
348
|
+
|
|
349
|
+
Returns:
|
|
350
|
+
- xarray.Dataset: a dataset with the same dimensions as the original,
|
|
351
|
+
containing the original data and five masks: mask_transient, mask_impulse,
|
|
352
|
+
mask_attenuated, mask_false_seabed, mask_seabed
|
|
353
|
+
|
|
354
|
+
Notes:
|
|
355
|
+
- To effectively utilize the `blackwell` or `blackwell_mod` methods for seabed detection,
|
|
356
|
+
it's essential that the `source_Sv` dataset includes the `split-beam angle` parameters.
|
|
357
|
+
Specifically, ensure that your input `source_Sv` contains
|
|
358
|
+
both the `angle_alongship` and `angle_athwartship` variables.
|
|
359
|
+
Absence of these variables leads to errors .
|
|
360
|
+
"""
|
|
361
|
+
Sv_mask = create_multiple_masks(source_Sv, params)
|
|
362
|
+
return Sv_mask
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
def create_seabed_masks_oceanstream(
|
|
366
|
+
source_Sv: xr.Dataset, params=OCEANSTREAM_SEABED_MASK_PARAMETERS
|
|
367
|
+
):
|
|
368
|
+
"""
|
|
369
|
+
A function that creates seabed masks for a given Sv dataset using default methods for oceanstream
|
|
370
|
+
|
|
371
|
+
Parameters:
|
|
372
|
+
- source_Sv (xarray.Dataset): the dataset to which the masks will be attached.
|
|
373
|
+
|
|
374
|
+
Returns:
|
|
375
|
+
- xarray.Dataset: a dataset with the same dimensions as the original,
|
|
376
|
+
containing the original data and five masks: mask_transient, mask_impulse,
|
|
377
|
+
mask_attenuated
|
|
378
|
+
|
|
379
|
+
"""
|
|
380
|
+
Sv_mask = create_multiple_masks(source_Sv, params)
|
|
381
|
+
return Sv_mask
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
def create_noise_masks_oceanstream(source_Sv: xr.Dataset, params=OCEANSTREAM_NOISE_MASK_PARAMETERS):
|
|
385
|
+
"""
|
|
386
|
+
A function that creates noise masks for a given Sv dataset using default methods for oceanstream
|
|
387
|
+
|
|
388
|
+
Parameters:
|
|
389
|
+
- source_Sv (xarray.Dataset): the dataset to which the masks will be attached.
|
|
390
|
+
|
|
391
|
+
Returns:
|
|
392
|
+
- xarray.Dataset: a dataset with the same dimensions as the original,
|
|
393
|
+
containing the original data and five masks: mask_transient, mask_impulse,
|
|
394
|
+
mask_attenuated
|
|
395
|
+
|
|
396
|
+
"""
|
|
397
|
+
Sv_mask = create_multiple_masks(source_Sv, params)
|
|
398
|
+
return Sv_mask
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
from typing import List, Optional, TypedDict, Union
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class TransientParameters(TypedDict, total=False):
|
|
5
|
+
m: int
|
|
6
|
+
n: int
|
|
7
|
+
thr: int
|
|
8
|
+
excludeabove: int
|
|
9
|
+
operation: str
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class AttenuationParameters(TypedDict, total=False):
|
|
13
|
+
r0: Optional[int]
|
|
14
|
+
r1: Optional[int]
|
|
15
|
+
n: int
|
|
16
|
+
m: Optional[int]
|
|
17
|
+
thr: int
|
|
18
|
+
start: int
|
|
19
|
+
offset: int
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ImpulseParameters(TypedDict, total=False):
|
|
23
|
+
thr: int
|
|
24
|
+
m: int
|
|
25
|
+
n: int
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class SeabedEchoParameters(TypedDict, total=False):
|
|
29
|
+
theta: Optional[int]
|
|
30
|
+
phi: Optional[int]
|
|
31
|
+
r0: int
|
|
32
|
+
r1: int
|
|
33
|
+
tSv: int
|
|
34
|
+
ttheta: int
|
|
35
|
+
tphi: int
|
|
36
|
+
wtheta: int
|
|
37
|
+
wphi: int
|
|
38
|
+
rlog: Optional[int]
|
|
39
|
+
tpi: Optional[int]
|
|
40
|
+
freq: Optional[int]
|
|
41
|
+
rank: int
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class SeabedParameters(TypedDict, total=False):
|
|
45
|
+
r0: int
|
|
46
|
+
r1: int
|
|
47
|
+
roff: int
|
|
48
|
+
thr: int
|
|
49
|
+
ec: int
|
|
50
|
+
ek: List[int]
|
|
51
|
+
dc: int
|
|
52
|
+
dk: List[int]
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class MaskConfig(TypedDict):
|
|
56
|
+
enabled: bool
|
|
57
|
+
method: str
|
|
58
|
+
parameters: Union[
|
|
59
|
+
TransientParameters,
|
|
60
|
+
AttenuationParameters,
|
|
61
|
+
ImpulseParameters,
|
|
62
|
+
SeabedEchoParameters,
|
|
63
|
+
SeabedParameters,
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class DenoiseConfig(TypedDict):
|
|
68
|
+
transient: MaskConfig
|
|
69
|
+
attenuation: MaskConfig
|
|
70
|
+
impulse: MaskConfig
|
|
71
|
+
seabed_echo: MaskConfig
|
|
72
|
+
seabed: MaskConfig
|
|
73
|
+
profile: bool
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
from .ensure_time_continuity import check_reversed_time, fix_time_reversions
|
|
2
|
+
from .sv_computation import compute_sv, compute_sv_with_encode_mode
|
|
3
|
+
from .sv_dataset_extension import enrich_sv_dataset
|
|
4
|
+
from .sv_interpolation import interpolate_sv, regrid_dataset
|
|
5
|
+
from .raw_handler import read_file, read_raw_files, convert_raw_files, get_campaign_metadata
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ensure_time_continuity.py
|
|
3
|
+
-----------------------
|
|
4
|
+
Module for ensuring temporal consistency of EK60/EK80-generated netcdf files
|
|
5
|
+
|
|
6
|
+
This module provides functionalities to:
|
|
7
|
+
- Check if a given netcdf file contains time reversals on a specific \
|
|
8
|
+
beam group and time dimension
|
|
9
|
+
- Fix time reversals in a given netcdf file on a specific list of beam groups \
|
|
10
|
+
and time dimensions associated.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import xarray as xr
|
|
14
|
+
from echopype.qc.api import coerce_increasing_time, exist_reversed_time
|
|
15
|
+
|
|
16
|
+
DEFAULT_TIME_DICT = {"Sonar/Beam_group1": "ping_time"}
|
|
17
|
+
DEFAULT_DIMENSION = list(DEFAULT_TIME_DICT.keys())[0]
|
|
18
|
+
DEFAULT_TIME_NAME = DEFAULT_TIME_DICT.get(DEFAULT_DIMENSION)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def check_reversed_time(
|
|
22
|
+
ed: xr.Dataset,
|
|
23
|
+
dimension: str = DEFAULT_DIMENSION,
|
|
24
|
+
time_name: str = DEFAULT_TIME_NAME,
|
|
25
|
+
):
|
|
26
|
+
"""
|
|
27
|
+
Verifies if there are any issues with reversed timestamps in an unprocessed EK60/80 data file
|
|
28
|
+
|
|
29
|
+
Parameters:
|
|
30
|
+
- ds (xr.Dataset): Unprocessed netcdf file to check for time reversals
|
|
31
|
+
- dimension (str): name of the sonar beam group, etc to examine
|
|
32
|
+
- time_name (str): name of the time coordinate to test
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
- has_reversal (bool): True if there are reversals, False otherwise
|
|
36
|
+
|
|
37
|
+
Example:
|
|
38
|
+
>>> check_reversed_time(ed, "Sonar/Beam_group1", "ping_time"})
|
|
39
|
+
Expected Output
|
|
40
|
+
False
|
|
41
|
+
"""
|
|
42
|
+
has_reversal = exist_reversed_time(ds=ed[dimension], time_name=time_name)
|
|
43
|
+
return has_reversal
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def fix_time_reversions(er: xr.Dataset, time_dict=None, win_len: int = 100):
|
|
49
|
+
"""
|
|
50
|
+
Fixes reversed timestamps in an unprocessed EK60/80 data file
|
|
51
|
+
|
|
52
|
+
Parameters:
|
|
53
|
+
- ds (xr.Dataset): Unprocessed netcdf file to check for time reversals
|
|
54
|
+
- time_dict (dict): a dictionary where the keys are various sonar beam
|
|
55
|
+
groups and the values are the time dimension
|
|
56
|
+
- win_len (int): length of the local window before the reversed timestamp
|
|
57
|
+
within which the median pinging interval
|
|
58
|
+
is used to infer the next ping time
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
- ds (xr.Dataset): the input dataset but with specific time coordinates
|
|
62
|
+
coerced to flow forward
|
|
63
|
+
|
|
64
|
+
Example:
|
|
65
|
+
>>> fix_time_reversions(er, {"Sonar/Beam_group1": "ping_time"})
|
|
66
|
+
Expected Output
|
|
67
|
+
a fixed er dataset
|
|
68
|
+
"""
|
|
69
|
+
if time_dict is None:
|
|
70
|
+
time_dict = DEFAULT_TIME_DICT
|
|
71
|
+
for dim, time in time_dict.items():
|
|
72
|
+
if check_reversed_time(er, dim, time):
|
|
73
|
+
coerce_increasing_time(er[dim], time, win_len)
|
|
74
|
+
return er
|
|
75
|
+
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import xarray as xr
|
|
2
|
+
|
|
3
|
+
from typing import Literal, Optional
|
|
4
|
+
from echopype.commongrid.api import compute_MVBS, compute_MVBS_index_binning
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def compute_mvbs(
|
|
8
|
+
ds_Sv: xr.Dataset,
|
|
9
|
+
method: Literal["index_binning", "physical_units"] = "physical_units",
|
|
10
|
+
range_sample_num: Optional[int] = None,
|
|
11
|
+
ping_num: Optional[int] = None,
|
|
12
|
+
range_var: Optional[Literal["echo_range", "depth"]] = None,
|
|
13
|
+
range_bin: Optional[str] = None,
|
|
14
|
+
ping_time_bin: Optional[str] = None,
|
|
15
|
+
) -> xr.Dataset:
|
|
16
|
+
"""
|
|
17
|
+
Wrapper function around echopype's `echopype.commongrid.api.compute_MVBS`
|
|
18
|
+
and `echopype.commongrid.api.compute_MVBS_index_binning`.
|
|
19
|
+
- `echopype.commongrid.api.compute_MVBS`:
|
|
20
|
+
Compute Mean Volume Backscattering Strength (MVBS)
|
|
21
|
+
based on intervals of range (`echo_range`) or depth (`depth`)
|
|
22
|
+
and `ping_time` specified in physical units.
|
|
23
|
+
- `echopype.commongrid.api.compute_MVBS_index_binning`:
|
|
24
|
+
Compute Mean Volume Backscattering Strength (MVBS)
|
|
25
|
+
based on intervals of range sample number(`range_sample_num`)
|
|
26
|
+
and ping number (`ping_num`) specified in index number.
|
|
27
|
+
|
|
28
|
+
Parameters:
|
|
29
|
+
|
|
30
|
+
- ds_Sv : xr.Dataset
|
|
31
|
+
Input dataset containing Sv
|
|
32
|
+
- method : str
|
|
33
|
+
Choose method type. Either "index_binning" or "physical_units"
|
|
34
|
+
- range_sample_num, ping_num
|
|
35
|
+
Parameters for "index_binning" method. Defaults are 100.
|
|
36
|
+
- range_var: {'echo_range', 'depth'}, default 'echo_range'
|
|
37
|
+
Parameter for "physical_units" method.
|
|
38
|
+
The variable to use for range binning.
|
|
39
|
+
Must be one of `echo_range` or `depth`.
|
|
40
|
+
Note that `depth` is only available if the input dataset contains
|
|
41
|
+
`depth` as a data variable.
|
|
42
|
+
- range_bin, ping_time_bin
|
|
43
|
+
Parameters for "physical_units" method. Defaults are "20m", and "20S" respectively.
|
|
44
|
+
|
|
45
|
+
Returns:
|
|
46
|
+
|
|
47
|
+
- A dataset containing bin-averaged Sv.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
methods = {
|
|
51
|
+
"index_binning": compute_MVBS_index_binning,
|
|
52
|
+
"physical_units": compute_MVBS,
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if method == "index_binning":
|
|
56
|
+
if any([range_var, range_bin, ping_time_bin]):
|
|
57
|
+
raise ValueError(
|
|
58
|
+
"For 'index_binning' method, only range_sample_num and ping_num should be provided."
|
|
59
|
+
)
|
|
60
|
+
range_sample_num = range_sample_num if range_sample_num is not None else 100
|
|
61
|
+
ping_num = ping_num if ping_num is not None else 100
|
|
62
|
+
return methods[method](ds_Sv, range_sample_num, ping_num)
|
|
63
|
+
|
|
64
|
+
elif method == "physical_units":
|
|
65
|
+
if any([range_sample_num, ping_num]):
|
|
66
|
+
raise ValueError(
|
|
67
|
+
"For 'physical_units' method, only range_var, range_bin, and ping_time_bin should be provided."
|
|
68
|
+
)
|
|
69
|
+
range_var = range_var if range_var is not None else "echo_range"
|
|
70
|
+
range_bin = range_bin if range_bin is not None else "20m"
|
|
71
|
+
ping_time_bin = ping_time_bin if ping_time_bin is not None else "20S"
|
|
72
|
+
return methods[method](
|
|
73
|
+
ds_Sv, range_var=range_var, range_bin=range_bin, ping_time_bin=ping_time_bin
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
else:
|
|
77
|
+
raise ValueError("Invalid method. Choose either 'index_binning' or 'physical_units'.")
|