From 62a2c38afbfddc99903452231372b2d606e4d3e6 Mon Sep 17 00:00:00 2001 From: Bart Schilperoort Date: Sat, 14 Oct 2023 11:51:46 +0200 Subject: [PATCH] Filter out some common warnings. --- src/dtscalibration/datastore.py | 12 +++++++++--- src/dtscalibration/datastore_utils.py | 10 ++++++++-- tests/test_dtscalibration.py | 7 ++++++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/dtscalibration/datastore.py b/src/dtscalibration/datastore.py index 8825edee..dde59c62 100644 --- a/src/dtscalibration/datastore.py +++ b/src/dtscalibration/datastore.py @@ -80,7 +80,13 @@ class DataStore(xr.Dataset): """ def __init__(self, *args, autofill_dim_attrs=True, **kwargs): - super().__init__(*args, **kwargs) + with warnings.catch_warnings(): + # Filter out nanosecond precision warning: no good way to avoid ATM. + warnings.filterwarnings( + "ignore", + message="Converting non-nanosecond precision timedelta values to nanosecond precision.", + ) + super().__init__(*args, **kwargs) # check order of the dimensions of the data_vars # first 'x' (if in initiated DataStore), then 'time', then the rest @@ -2256,8 +2262,8 @@ def average_single_ended( ---------- p_val : array-like, optional Define `p_val`, `p_var`, `p_cov` if you used an external function - for calibration. Has size 2 + `nt`. First value is :math:`\gamma`, - second is :math:`\Delta \\alpha`, others are :math:`C` for each + for calibration. Has size 2 + `nt`. First value is :math:`\\gamma`, + second is :math:`\\Delta \\alpha`, others are :math:`C` for each timestep. If set to False, no uncertainty in the parameters is propagated into the confidence intervals. Similar to the spec sheets of the DTS diff --git a/src/dtscalibration/datastore_utils.py b/src/dtscalibration/datastore_utils.py index 0d54dd31..71726888 100644 --- a/src/dtscalibration/datastore_utils.py +++ b/src/dtscalibration/datastore_utils.py @@ -1,3 +1,4 @@ +import warnings from typing import TYPE_CHECKING from typing import Optional from typing import Union @@ -1146,8 +1147,13 @@ def suggest_cable_shift_double_ended( rast = ds["rast"].data[:nx2] x2 = ds["x"].data[i_shift:] - i_f = np.log(st / ast) - i_b = np.log(rst / rast) + with warnings.catch_warnings(): + # Supress log(x/0) warnings. The data will result in NaNs values. + warnings.filterwarnings( + "ignore", message="invalid value encountered in log" + ) + i_f = np.log(st / ast) + i_b = np.log(rst / rast) att = (i_b - i_f) / 2 # varianble E in article diff --git a/tests/test_dtscalibration.py b/tests/test_dtscalibration.py index b354c584..24f92951 100644 --- a/tests/test_dtscalibration.py +++ b/tests/test_dtscalibration.py @@ -1,4 +1,5 @@ import os +import warnings import numpy as np import pytest @@ -40,7 +41,11 @@ def assert_almost_equal_verbose(actual, desired, verbose=False, **kwargs): """Print the actual precision decimals""" err = np.abs(actual - desired).max() - dec = -np.ceil(np.log10(err)) + + with warnings.catch_warnings(): + # Supress zero division warnings + warnings.filterwarnings("ignore", message="divide by zero encountered in log10") + dec = -np.ceil(np.log10(err)) if not (np.isfinite(dec)): dec = 18.0