Skip to content

Commit 0365226

Browse files
committed
lint
1 parent f51758e commit 0365226

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

src/earthkit/meteo/vertical/interpolation.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import dataclasses as dc
2-
from typing import Any, Literal, Sequence
2+
from typing import Any
3+
from typing import Literal
4+
from typing import Sequence
35

46
import numpy as np
57
import xarray as xr
68

7-
89
__all__ = [
910
"TargetCoordinates",
1011
"interpolate_monotonic",
@@ -67,7 +68,9 @@ def interpolate_monotonic(
6768

6869
# Prepare output field field_on_target on target coordinates
6970
field_on_target = _init_field_with_vcoord(
70-
data.broadcast_like(coord), target_coord, np.nan,
71+
data.broadcast_like(coord),
72+
target_coord,
73+
np.nan,
7174
)
7275

7376
# Interpolate
@@ -161,9 +164,7 @@ def interpolate_to_pressure_levels(
161164
# ... supported target units and corresponding conversion factors to Pa
162165
target_p_unit_conversions = dict(Pa=1.0, hPa=100.0)
163166
if target_p_units not in target_p_unit_conversions.keys():
164-
raise ValueError(
165-
f"unsupported value of target_p_units: {target_p_units}"
166-
)
167+
raise ValueError(f"unsupported value of target_p_units: {target_p_units}")
167168
# ... supported range of pressure target values (in Pa)
168169
target_p_min = 1.0
169170
target_p_max = 120000.0
@@ -239,9 +240,7 @@ def interpolate_sleve_to_coord_levels(
239240
# ... find the height field where target is >= t0 on level k and was <= t0
240241
# on level k-1 or where theta is <= th0 on level k
241242
# and was >= th0 on level k-1
242-
ht = h.where(
243-
((coord >= t0) & (tkm1 <= t0)) | ((coord <= t0) & (tkm1 >= t0))
244-
)
243+
ht = h.where(((coord >= t0) & (tkm1 <= t0)) | ((coord <= t0) & (tkm1 >= t0)))
245244
if folding_mode == "undef_fold":
246245
# ... find condition where more than one interval is found, which
247246
# contains the target coordinate value
@@ -325,9 +324,7 @@ def interpolate_sleve_to_theta_levels(
325324
# them in cK for NetCDF (to be checked)
326325
th_tc_unit_conversions = dict(K=1.0, cK=0.01)
327326
if target_t_units not in th_tc_unit_conversions.keys():
328-
raise ValueError(
329-
f"unsupported value of th_tc_units: {target_t_units}"
330-
)
327+
raise ValueError(f"unsupported value of th_tc_units: {target_t_units}")
331328
# ... supported range of tc values (in K)
332329
th_tc_min = 1.0
333330
th_tc_max = 1000.0
@@ -338,8 +335,7 @@ def interpolate_sleve_to_theta_levels(
338335
tc_values = np.array(target_theta) * th_tc_unit_conversions[target_t_units]
339336
if np.any((tc_values < th_tc_min) | (tc_values > th_tc_max)):
340337
raise ValueError(
341-
"target coordinate value "
342-
f"out of range (must be in interval [{th_tc_min}, {th_tc_max}]K)"
338+
"target coordinate value " f"out of range (must be in interval [{th_tc_min}, {th_tc_max}]K)"
343339
)
344340
tc = TargetCoordinates(
345341
type_of_level="theta",

tests/vertical/test_xr_monotonic.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def _make_input_xr(data, coord, target_coord, expected_data, xp=np, device="cpu"
118118
@pytest.mark.parametrize("ds_input,ds_expected,mode", make_input("pressure_s_s_s"))
119119
def test_xr_interpolate_monotonic_s_s_s(ds_input, ds_expected, mode):
120120
from earthkit.meteo.vertical.interpolation import interpolate_monotonic
121+
121122
observed = interpolate_monotonic(ds_input.data, ds_input.z, ds_expected.z, mode)
122123
assert observed == ds_expected
123124

@@ -126,6 +127,7 @@ def test_xr_interpolate_monotonic_s_s_s(ds_input, ds_expected, mode):
126127
@pytest.mark.parametrize("ds_input,ds_expected,mode", make_input("pressure_a_a_s"))
127128
def test_xr_interpolate_monotonic_a_a_s(ds_input, ds_expected, mode):
128129
from earthkit.meteo.vertical.interpolation import interpolate_monotonic
130+
129131
observed = interpolate_monotonic(ds_input.data, ds_input.z, ds_expected.z, mode)
130132
assert observed == ds_expected
131133

@@ -134,6 +136,7 @@ def test_xr_interpolate_monotonic_a_a_s(ds_input, ds_expected, mode):
134136
@pytest.mark.parametrize("ds_input,ds_expected,mode", make_input("pressure_a_s_s"))
135137
def test_xr_interpolate_monotonic_a_s_s(ds_input, ds_expected, mode):
136138
from earthkit.meteo.vertical.interpolation import interpolate_monotonic
139+
137140
observed = interpolate_monotonic(ds_input.data, ds_input.z, ds_expected.z, mode)
138141
assert observed == ds_expected
139142

@@ -142,6 +145,7 @@ def test_xr_interpolate_monotonic_a_s_s(ds_input, ds_expected, mode):
142145
@pytest.mark.parametrize("ds_input,ds_expected,mode", make_input("pressure_a_s_a"))
143146
def test_xr_interpolate_monotonic_a_s_a(ds_input, ds_expected, mode):
144147
from earthkit.meteo.vertical.interpolation import interpolate_monotonic
148+
145149
observed = interpolate_monotonic(ds_input.data, ds_input.z, ds_expected.z, mode)
146150
assert observed == ds_expected
147151

@@ -150,5 +154,6 @@ def test_xr_interpolate_monotonic_a_s_a(ds_input, ds_expected, mode):
150154
@pytest.mark.parametrize("ds_input,ds_expected,mode", make_input("pressure_a_a_a"))
151155
def test_xr_interpolate_monotonic_a_a_a(ds_input, ds_expected, mode):
152156
from earthkit.meteo.vertical.interpolation import interpolate_monotonic
157+
153158
observed = interpolate_monotonic(ds_input.data, ds_input.z, ds_expected.z, mode)
154159
assert observed == ds_expected

tests/vertical/test_xr_theta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import xarray as xr
21
import pytest
2+
import xarray as xr
33

44
from earthkit.meteo import thermo
55
from earthkit.meteo.utils import testing

0 commit comments

Comments
 (0)