Skip to content

Commit

Permalink
Filter out some common warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
BSchilperoort committed Oct 14, 2023
1 parent 7dd73e6 commit 62a2c38
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/dtscalibration/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions src/dtscalibration/datastore_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from typing import TYPE_CHECKING
from typing import Optional
from typing import Union
Expand Down Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion tests/test_dtscalibration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import warnings

import numpy as np
import pytest
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 62a2c38

Please sign in to comment.