Skip to content

Commit 31d6706

Browse files
authored
FIX: Only emit FutureWarning when method is not given (#494)
1 parent e344fe9 commit 31d6706

2 files changed

Lines changed: 68 additions & 16 deletions

File tree

src/fmu/tools/domainconversion/dconvert.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ def depth_convert_cube(
945945
zmin: float | None = None,
946946
zmax: float | None = None,
947947
undefined: float = -999.25,
948-
method: Literal["fft", "linear"] = "linear",
948+
method: Literal["fft", "linear"] | None = None,
949949
) -> xtgeo.Cube:
950950
"""Depth convert a cube (time to depth).
951951
@@ -964,13 +964,15 @@ def depth_convert_cube(
964964
for technical reasons.
965965
966966
"""
967-
warnings.warn(
968-
"Default trace interpolation method will be set to 'fft' in the near "
969-
"future. Explicitely set method='linear' to keep the same results: "
970-
"vm.depth_convert_cube(incube, zinc, zmin, zmax, method='linear').",
971-
category=FutureWarning,
972-
stacklevel=2,
973-
)
967+
if method is None:
968+
warnings.warn(
969+
"Default trace interpolation method will be set to 'fft' in the near "
970+
"future. Explicitly set method='linear' to keep the same results: "
971+
"vm.depth_convert_cube(incube, zinc, zmin, zmax, method='linear').",
972+
category=FutureWarning,
973+
stacklevel=2,
974+
)
975+
method = "linear"
974976

975977
return self._domain_convert_cube(
976978
incube,
@@ -989,7 +991,7 @@ def time_convert_cube(
989991
tmin: float | None = None,
990992
tmax: float | None = None,
991993
undefined: float = -999.25,
992-
method: Literal["fft", "linear"] = "linear",
994+
method: Literal["fft", "linear"] | None = None,
993995
) -> xtgeo.Cube:
994996
"""Time convert a cube (depth to time).
995997
@@ -1008,13 +1010,15 @@ def time_convert_cube(
10081010
reasons.
10091011
10101012
"""
1011-
warnings.warn(
1012-
"Default trace interpolation method will be set to 'fft' in the near "
1013-
"future. Explicitely set method='linear' to keep the same results: "
1014-
"vm.time_convert_cube(incube, tinc, tmin, tmax, method='linear').",
1015-
category=FutureWarning,
1016-
stacklevel=2,
1017-
)
1013+
if method is None:
1014+
warnings.warn(
1015+
"Default trace interpolation method will be set to 'fft' in the near "
1016+
"future. Explicitly set method='linear' to keep the same results: "
1017+
"vm.time_convert_cube(incube, tinc, tmin, tmax, method='linear').",
1018+
category=FutureWarning,
1019+
stacklevel=2,
1020+
)
1021+
method = "linear"
10181022

10191023
return self._domain_convert_cube(
10201024
incube,

tests/domainconversion/test_domainconversion.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import os
3+
import warnings
34
from typing import Any, Literal
45

56
import numpy as np
@@ -210,6 +211,53 @@ def test_generate_simple_velocube(
210211
plot_section(velocube, simplesurfs, title="Avg Velocity cube in T")
211212

212213

214+
def test_depth_convert_cube_warns_only_when_method_is_omitted(
215+
smallcube: xtgeo.Cube,
216+
simplesurfs: tuple[list[xtgeo.RegularSurface], list[xtgeo.RegularSurface]],
217+
) -> None:
218+
"""FutureWarning should only be emitted when method is not explicitly set."""
219+
220+
dc = DomainConversion(*simplesurfs)
221+
222+
with pytest.warns(FutureWarning, match="Default trace interpolation method"):
223+
dc.depth_convert_cube(smallcube, zinc=1.0, zmin=0.0, zmax=100.0)
224+
225+
with warnings.catch_warnings(record=True) as recorded:
226+
dc.depth_convert_cube(
227+
smallcube, zinc=1.0, zmin=0.0, zmax=100.0, method="linear"
228+
)
229+
230+
assert not any(
231+
isinstance(w.message, FutureWarning)
232+
and "Default trace interpolation method" in str(w.message)
233+
for w in recorded
234+
)
235+
236+
237+
def test_time_convert_cube_warns_only_when_method_is_omitted(
238+
smallcube: xtgeo.Cube,
239+
simplesurfs: tuple[list[xtgeo.RegularSurface], list[xtgeo.RegularSurface]],
240+
) -> None:
241+
"""FutureWarning should only be emitted when method is not explicitly set."""
242+
243+
dc = DomainConversion(*simplesurfs)
244+
depthcube = dc.depth_convert_cube(
245+
smallcube, zinc=1.0, zmin=0.0, zmax=100.0, method="linear"
246+
)
247+
248+
with pytest.warns(FutureWarning, match="Default trace interpolation method"):
249+
dc.time_convert_cube(depthcube, tinc=1.0, tmin=0.0, tmax=100.0)
250+
251+
with warnings.catch_warnings(record=True) as recorded:
252+
dc.time_convert_cube(depthcube, tinc=1.0, tmin=0.0, tmax=100.0, method="linear")
253+
254+
assert not any(
255+
isinstance(w.message, FutureWarning)
256+
and "Default trace interpolation method" in str(w.message)
257+
for w in recorded
258+
)
259+
260+
213261
@pytest.mark.parametrize(
214262
"input, expected",
215263
[

0 commit comments

Comments
 (0)