Skip to content
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
5 changes: 0 additions & 5 deletions echopype/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
from .echodata.api import open_converted
from .echodata.combine import combine_echodata
from .utils.io import init_ep_dir
from .utils.log import verbose

# Turn off verbosity for echopype
verbose(override=False)

init_ep_dir()

Expand All @@ -25,5 +21,4 @@
"open_converted",
"open_raw",
"utils",
"verbose",
]
11 changes: 6 additions & 5 deletions echopype/calibrate/api.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import warnings

import numpy as np
import xarray as xr

from ..core import SONAR_MODELS
from ..echodata import EchoData
from ..echodata.simrad import check_input_args_combination, retrieve_correct_beam_group
from ..utils.log import _init_logger
from ..utils.prov import echopype_prov_attrs, source_files_vars
from .calibrate_azfp import CalibrateAZFP
from .calibrate_ek import CalibrateEK60, CalibrateEK80
Expand All @@ -19,8 +20,6 @@
"EA640": CalibrateEK80,
}

logger = _init_logger(__name__)


def _compute_cal(
cal_type,
Expand All @@ -44,14 +43,16 @@ def _compute_cal(
check_input_args_combination(waveform_mode=waveform_mode, encode_mode=encode_mode)
elif echodata.sonar_model in ("EK60", "AZFP", "AZFP6"):
if waveform_mode is not None and waveform_mode != "CW":
logger.warning(
warnings.warn(
"This sonar model transmits only narrowband signals (waveform_mode='CW'). "
"Calibration will be in CW mode",
category=UserWarning,
)
if encode_mode is not None and encode_mode != "power":
logger.warning(
warnings.warn(
"This sonar model only record data as power or power/angle samples "
"(encode_mode='power'). Calibration will be done on the power samples.",
category=UserWarning,
)

# Check that assume_single_filter_time is correctly passed in.
Expand Down
10 changes: 5 additions & 5 deletions echopype/calibrate/calibrate_azfp.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import warnings

import numpy as np
import xarray
from scipy.interpolate import LinearNDInterpolator

from ..echodata import EchoData
from ..utils.log import _init_logger
from .cal_params import get_cal_params_AZFP
from .calibrate_ek import CalibrateBase
from .env_params import get_env_params_AZFP
from .range import compute_range_AZFP

logger = _init_logger(__name__)

# Common Sv_offset values for frequency > 38 kHz
SV_OFFSET_HF = {
150: 1.4,
Expand Down Expand Up @@ -153,9 +152,10 @@ def compute_Sv_offset(self):
try:
Sv_offset.append(_calc_azfp_Sv_offset(freq, pulse_len * 1e6))
except ValueError:
logger.warning(
warnings.warn(
f"The Sv for {freq}Hz and pulse length {pulse_len}us "
"is uncalibrated (Sv_offset=0.0)"
"is uncalibrated (Sv_offset=0.0)",
category=UserWarning,
)
Sv_offset.append(0.0)

Expand Down
14 changes: 7 additions & 7 deletions echopype/calibrate/calibrate_base.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import abc
import warnings

from ..echodata import EchoData
from ..utils.log import _init_logger
from .ecs import ECSParser

logger = _init_logger(__name__)


class CalibrateBase(abc.ABC):
"""Class to handle calibration for all sonar models."""
Expand All @@ -19,9 +17,10 @@ def __init__(self, echodata: EchoData, env_params=None, cal_params=None, ecs_fil
# Set ECS to overwrite user-provided dict
if self.ecs_file is not None:
if env_params is not None or cal_params is not None:
logger.warning(
warnings.warn(
"The ECS file takes precedence when it is provided. "
"Parameter values provided in 'env_params' and 'cal_params' will not be used!"
"Parameter values provided in 'env_params' and 'cal_params' will not be used!",
category=UserWarning,
)

# Parse ECS file to a dict
Expand Down Expand Up @@ -118,11 +117,12 @@ def _check_echodata_backscatter_size(self):

# Raise Warning if above 2.0
if total_gb > 2.0:
logger.warning(
warnings.warn(
"The Echodata backscatter variables are large and can cause memory issues. "
"Consider modifying the workflow that uses compute_Sv as below: "
"Prior to `compute_Sv` run `echodata.chunk(CHUNK_DICTIONARY) "
"and after `compute_Sv` run `ds_Sv.to_zarr(ZARR_STORE, compute=True)`. "
"This will ensure that the computation is lazily evaluated, "
"with the results stored directly in a Zarr store on disk, rather then in memory."
"with the results stored directly in a Zarr store on disk, rather then in memory.",
category=ResourceWarning,
)
16 changes: 7 additions & 9 deletions echopype/calibrate/calibrate_ek.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import warnings
from typing import Dict

import numpy as np
import xarray as xr

from ..echodata import EchoData
from ..echodata.simrad import retrieve_correct_beam_group
from ..utils.log import _init_logger
from .cal_params import _get_interp_da, get_cal_params_EK
from .calibrate_base import CalibrateBase
from .ecs import conform_channel_order, ecs_ds2dict, ecs_ev2ep
Expand All @@ -19,8 +19,6 @@
from .env_params import get_env_params_EK
from .range import compute_range_EK, range_mod_TVG_EK

logger = _init_logger(__name__)


def _slice_beam_vend(beam, vend, slice_dict):
beam = beam.sel(
Expand Down Expand Up @@ -126,10 +124,10 @@
ping_time=beam["ping_time"],
)
except Exception as e:
logger.warning(
warnings.warn(

Check warning on line 127 in echopype/calibrate/calibrate_ek.py

View workflow job for this annotation

GitHub Actions / integration--3.13--ubuntu-latest

Could not compute tau_effective from transmit signal in power encoding mode; falling back to transmit_duration_nominal. Error: KeyError('receiver_sampling_frequency')

Check warning on line 127 in echopype/calibrate/calibrate_ek.py

View workflow job for this annotation

GitHub Actions / integration--3.13--ubuntu-latest

Could not compute tau_effective from transmit signal in power encoding mode; falling back to transmit_duration_nominal. Error: KeyError('receiver_sampling_frequency')

Check warning on line 127 in echopype/calibrate/calibrate_ek.py

View workflow job for this annotation

GitHub Actions / integration--3.13--ubuntu-latest

Could not compute tau_effective from transmit signal in power encoding mode; falling back to transmit_duration_nominal. Error: KeyError('receiver_sampling_frequency')

Check warning on line 127 in echopype/calibrate/calibrate_ek.py

View workflow job for this annotation

GitHub Actions / integration--3.13--ubuntu-latest

Could not compute tau_effective from transmit signal in power encoding mode; falling back to transmit_duration_nominal. Error: KeyError('receiver_sampling_frequency')

Check warning on line 127 in echopype/calibrate/calibrate_ek.py

View workflow job for this annotation

GitHub Actions / integration--3.13--ubuntu-latest

Could not compute tau_effective from transmit signal in power encoding mode; falling back to transmit_duration_nominal. Error: KeyError('receiver_sampling_frequency')
"Could not compute tau_effective from transmit signal in power encoding mode; "
"falling back to transmit_duration_nominal. Error: %s",
repr(e),
f"falling back to transmit_duration_nominal. Error: {e!r}",
category=RuntimeWarning,
)
tau_effective = beam["transmit_duration_nominal"].isel(ping_time=0)

Expand Down Expand Up @@ -593,11 +591,11 @@
ping_time=self.beam["ping_time"],
)
except Exception as e:
logger.warning(
warnings.warn(
"Could not compute tau_effective "
"from transmit signal in complex encoding mode; "
"falling back to transmit_duration_nominal. Error: %s",
repr(e),
f"falling back to transmit_duration_nominal. Error: {e!r}",
category=RuntimeWarning,
)
tau_effective = self.beam["transmit_duration_nominal"].isel(ping_time=0)
# Use pulse_duration in place of tau_effective for GPT channels
Expand Down
5 changes: 0 additions & 5 deletions echopype/calibrate/ecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
import numpy as np
import xarray as xr

from ..utils.log import _init_logger

logger = _init_logger(__name__)


# String matcher for parser
SEPARATOR = re.compile(r"#=+#\n")
STATUS_CRUDE = re.compile(r"#\s*(?P<status>(.+))\s*#\n") # noqa
Expand Down
9 changes: 4 additions & 5 deletions echopype/clean/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
Functions for reducing variabilities in backscatter data.
"""

import warnings
from functools import partial

import numpy as np
import xarray as xr

from ..commongrid.utils import _parse_x_bin
from ..utils.compute import _lin2log, _log2lin
from ..utils.log import _init_logger
from ..utils.prov import add_processing_level, echopype_prov_attrs, insert_input_processing_level
from .transient_noise.transient_fielding import transient_noise_fielding
from .transient_noise.transient_matecho import transient_noise_matecho
Expand All @@ -24,8 +24,6 @@
pool_Sv,
)

logger = _init_logger(__name__)


def mask_transient_noise(
ds_Sv: xr.Dataset,
Expand Down Expand Up @@ -137,10 +135,11 @@ def mask_transient_noise(
elif func == "nanmedian":
# Warn when `func=nanmedian` since the sorting overhead makes it incredibly slow compared to
# other non-sorting aggregations like `nanmean`.
logger.warning(
warnings.warn(
"`func=nanmedian` is an incredibly slow operation due to the overhead sorting. "
"We plan to add the Fielding Transient Noise Filter in the future"
"described here: https://github.com/OSOceanAcoustics/echopype/issues/1352"
"described here: https://github.com/OSOceanAcoustics/echopype/issues/1352",
category=ResourceWarning,
)
func = np.nanmedian

Expand Down
3 changes: 0 additions & 3 deletions echopype/commongrid/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Functions for enhancing the spatial and temporal coherence of data.
"""

import logging
import warnings
from typing import Literal

Expand All @@ -29,8 +28,6 @@
ping_time_bin_parsing_and_conversion,
)

logger = logging.getLogger(__name__)


@add_processing_level("L3*")
def compute_MVBS(
Expand Down
11 changes: 5 additions & 6 deletions echopype/commongrid/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
import re
import warnings
from typing import Literal, Optional, Tuple, Union

import numpy as np
Expand All @@ -11,8 +11,6 @@
from ..consolidate.api import POSITION_VARIABLES
from ..utils.compute import _lin2log, _log2lin

logger = logging.getLogger(__name__)


def compute_raw_MVBS(
ds_Sv: xr.Dataset,
Expand Down Expand Up @@ -585,7 +583,7 @@ def _groupby_x_along_channels(

# Set correct range_var just in case
if x_var == "distance_nmi" and range_var != "depth":
logger.warning("x_var is 'distance_nmi', setting range_var to 'depth'")
warnings.warn("x_var is 'distance_nmi', setting range_var to 'depth'", category=UserWarning)
range_var = "depth"

# average should be done in linear domain
Expand All @@ -603,8 +601,9 @@ def _groupby_x_along_channels(
)
for array_name, array in named_arrays.items():
if np.isnan(array).any():
logging.warning(
f"The ```{array_name}``` coordinate array contain NaNs. {aggregation_msg}"
warnings.warn(
f"The ```{array_name}``` coordinate array contain NaNs. {aggregation_msg}",
category=UserWarning,
)

# Use the first dimension as the grouping dimension for generality
Expand Down
14 changes: 7 additions & 7 deletions echopype/consolidate/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
import pathlib
import sys
import warnings
from numbers import Number
from pathlib import Path
from typing import Optional, Union
Expand All @@ -14,7 +15,6 @@
from ..echodata.simrad import retrieve_correct_beam_group
from ..utils.align import align_to_ping_time
from ..utils.io import get_file_format, open_source
from ..utils.log import _init_logger
from ..utils.prov import add_processing_level
from .ek_depth_utils import (
ek_use_beam_angles,
Expand All @@ -24,8 +24,6 @@
from .loc_utils import check_and_drop_loc_time_dim_duplicates, check_loc_vars_validity, sel_nmea
from .split_beam_angle import get_angle_complex_samples, get_angle_power_samples

logger = _init_logger(__name__)

POSITION_VARIABLES = ["latitude", "longitude"]


Expand Down Expand Up @@ -137,13 +135,15 @@ def add_depth(

# Log warnings when group variables are not used
if depth_offset is not None and use_platform_vertical_offsets:
logger.warning(
warnings.warn(
"When `depth_offset` is specified, platform vertical offset "
"variables will not be used."
"variables will not be used.",
category=UserWarning,
)
if tilt is not None and (use_beam_angles or use_platform_angles):
logger.warning(
"When `tilt` is specified, beam/platform angle variables will " "not be used."
warnings.warn(
"When `tilt` is specified, beam/platform angle variables will " "not be used.",
category=UserWarning,
)

if echodata:
Expand Down
22 changes: 13 additions & 9 deletions echopype/consolidate/ek_depth_utils.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import warnings

import numpy as np
import xarray as xr
from scipy.spatial.transform import Rotation as R

from ..utils.align import align_to_ping_time
from ..utils.log import _init_logger

logger = _init_logger(__name__)


def _check_and_log_nans(
echodata_group: xr.Dataset, group_name: str, variable_names: list[str]
) -> None:
"""
Checks for NaNs in Echodata group variables and raises logger warning.
Checks for NaNs in Echodata group variables and raises UserWarning.
"""
# Iterate through group variable names
for variable_name in variable_names:
# Extract group and check if it contains any NaNs
group_var = echodata_group[variable_name]
# Log warning if the group variable contains any NaNs
if np.any(np.isnan(group_var.values)):
logger.warning(
warnings.warn(
f"The Echodata `{group_name}` group `{variable_name}` variable array contains "
"NaNs. This will result in NaNs in the final `depth` array. Consider filling the "
"NaNs and calling `.add_depth(...)` again."
"NaNs and calling `.add_depth(...)` again.",
category=UserWarning,
)


Expand Down Expand Up @@ -98,14 +98,18 @@ def ek_use_beam_angles(beam_ds: xr.Dataset) -> xr.DataArray:
# Warn if any nonzero vector is not normalized
tolerance = 1e-8
if ((norm > tolerance) & (np.abs(norm - 1) > tolerance)).any():
logger.warning(
warnings.warn(
"Beam direction vector was not normalized; applying normalization. "
"By definition, it should have been normalized."
"By definition, it should have been normalized.",
category=UserWarning,
)

# Warn if any channel has a (nearly) zero vector
if (norm < tolerance).any():
logger.warning("Some beam direction vectors are zero. Outputting NaN for those channels.")
warnings.warn(
"Some beam direction vectors are zero. Outputting NaN for those channels.",
category=UserWarning,
)

# For channels with near-zero norm, we return NaN. Otherwise, we return the normalized
# z component.
Expand Down
Loading
Loading