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
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ repos:
- id: no-commit-to-branch

- repo: https://github.com/psf/black
rev: 21.12b0
rev: 22.1.0
hooks:
- id: black
pass_filenames: false
Expand All @@ -50,14 +50,14 @@ repos:
args: [--filter-files]

- repo: https://github.com/asottile/blacken-docs
rev: v1.12.0
rev: v1.12.1
hooks:
- id: blacken-docs
types: [file, rst]
additional_dependencies: [black==21.6b0]

- repo: https://github.com/aio-libs/sort-all
rev: v1.1.0
rev: v1.2.0
hooks:
- id: sort-all
types: [file, python]
4 changes: 2 additions & 2 deletions benchmarks/benchmarks/generate_data/um_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ def add_field(level_: int, time_step_: int) -> None:
six_rec = 20 / 3
three_rec = six_rec / 2

new_field.blev = level_1 ** 2 * six_rec - six_rec
new_field.blev = level_1**2 * six_rec - six_rec
new_field.brsvd1 = (
level_1 ** 2 * six_rec + (six_rec * level_1) - three_rec
level_1**2 * six_rec + (six_rec * level_1) - three_rec
)

brsvd2_simulated = np.linspace(0.995, 0, len_z)
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/benchmarks/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def setup(self):
# Should generate 10 distinct contours, regardless of dim size.
dim_size = int(ARTIFICIAL_DIM_SIZE / 5)
repeat_number = int(dim_size / 10)
repeat_range = range(int((dim_size ** 2) / repeat_number))
repeat_range = range(int((dim_size**2) / repeat_number))
data = np.repeat(repeat_range, repeat_number)
data = data.reshape((dim_size,) * 2)

Expand Down
4 changes: 2 additions & 2 deletions docs/gallery_code/meteorology/plot_wind_barbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def main():

# To illustrate the full range of barbs, scale the wind speed up to pretend
# that a storm is passing over
magnitude = (uwind ** 2 + vwind ** 2) ** 0.5
magnitude = (uwind**2 + vwind**2) ** 0.5
magnitude.convert_units("knot")
max_speed = magnitude.collapsed(
("latitude", "longitude"), iris.analysis.MAX
Expand All @@ -41,7 +41,7 @@ def main():
vwind = vwind / max_speed * max_desired

# Create a cube containing the wind speed
windspeed = (uwind ** 2 + vwind ** 2) ** 0.5
windspeed = (uwind**2 + vwind**2) ** 0.5
windspeed.rename("windspeed")
windspeed.convert_units("knot")

Expand Down
2 changes: 1 addition & 1 deletion docs/gallery_code/meteorology/plot_wind_speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def main():
vwind = iris.load_cube(infile, "y_wind")

# Create a cube containing the wind speed.
windspeed = (uwind ** 2 + vwind ** 2) ** 0.5
windspeed = (uwind**2 + vwind**2) ** 0.5
windspeed.rename("windspeed")

# Plot the wind speed as a contour plot.
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/analysis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,7 @@ def _lazy_rms(array, axis, **kwargs):
# all. Thus trying to use this aggregator with weights will currently
# raise an error in dask due to the unexpected keyword `weights`,
# rather than silently returning the wrong answer.
return da.sqrt(da.mean(array ** 2, axis=axis, **kwargs))
return da.sqrt(da.mean(array**2, axis=axis, **kwargs))


@_build_dask_mdtol_function
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/analysis/_grid_angles.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def _angle(p, q, r):
mid_lons = np.deg2rad(q[0])

pr = _3d_xyz_from_latlon(r[0], r[1]) - _3d_xyz_from_latlon(p[0], p[1])
pr_norm = np.sqrt(np.sum(pr ** 2, axis=0))
pr_norm = np.sqrt(np.sum(pr**2, axis=0))
pr_top = pr[1] * np.cos(mid_lons) - pr[0] * np.sin(mid_lons)

index = pr_norm == 0
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/analysis/_scipy_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def compute_interp_weights(self, xi, method=None):
xi_shape, method, indices, norm_distances, out_of_bounds = prepared

# Allocate arrays for describing the sparse matrix.
n_src_values_per_result_value = 2 ** ndim
n_src_values_per_result_value = 2**ndim
n_result_values = len(indices[0])
n_non_zero = n_result_values * n_src_values_per_result_value
weights = np.ones(n_non_zero, dtype=norm_distances[0].dtype)
Expand Down
12 changes: 4 additions & 8 deletions lib/iris/analysis/calculus.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,14 +629,10 @@ def curl(i_cube, j_cube, k_cube=None):
# (d/dtheta (i_cube * sin(lat)) - d_j_cube_dphi)
# phi_cmpt = 1/r * ( d/dr (r * j_cube) - d_k_cube_dtheta)
# theta_cmpt = 1/r * ( 1/cos(lat) * d_k_cube_dphi - d/dr (r * i_cube)
if (
y_coord.name()
not in [
"latitude",
"grid_latitude",
]
or x_coord.name() not in ["longitude", "grid_longitude"]
):
if y_coord.name() not in [
"latitude",
"grid_latitude",
] or x_coord.name() not in ["longitude", "grid_longitude"]:
raise ValueError(
"Expecting latitude as the y coord and "
"longitude as the x coord for spherical curl."
Expand Down
6 changes: 3 additions & 3 deletions lib/iris/analysis/cartography.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def _quadrant_area(radian_lat_bounds, radian_lon_bounds, radius_of_earth):
raise ValueError("Bounds must be [n,2] array")

# fill in a new array of areas
radius_sqr = radius_of_earth ** 2
radius_sqr = radius_of_earth**2
radian_lat_64 = radian_lat_bounds.astype(np.float64)
radian_lon_64 = radian_lon_bounds.astype(np.float64)

Expand Down Expand Up @@ -1010,8 +1010,8 @@ def _transform_distance_vectors_tolerance_mask(
# Squared magnitudes should be equal to one within acceptable tolerance.
# A value of atol=2e-3 is used, which corresponds to a change in magnitude
# of approximately 0.1%.
sqmag_1_0 = u_one_t ** 2 + v_zero_t ** 2
sqmag_0_1 = u_zero_t ** 2 + v_one_t ** 2
sqmag_1_0 = u_one_t**2 + v_zero_t**2
sqmag_0_1 = u_zero_t**2 + v_one_t**2
mask = np.logical_not(
np.logical_and(
np.isclose(sqmag_1_0, ones, atol=2e-3),
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/analysis/maths.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ def power(data, out=None):
return _math_op_common(
cube,
power,
cube.units ** exponent,
cube.units**exponent,
new_dtype=new_dtype,
in_place=in_place,
)
Expand Down
4 changes: 2 additions & 2 deletions lib/iris/analysis/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ def _ones_like(cube):
covar = (s1 * s2).collapsed(
corr_coords, iris.analysis.SUM, weights=weights_1, mdtol=mdtol
)
var_1 = (s1 ** 2).collapsed(
var_1 = (s1**2).collapsed(
corr_coords, iris.analysis.SUM, weights=weights_1
)
var_2 = (s2 ** 2).collapsed(
var_2 = (s2**2).collapsed(
corr_coords, iris.analysis.SUM, weights=weights_2
)

Expand Down
4 changes: 2 additions & 2 deletions lib/iris/fileformats/netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2738,9 +2738,9 @@ def _create_cf_data_variable(
cmin, cmax = _co_realise_lazy_arrays([cmin, cmax])
n = dtype.itemsize * 8
if masked:
scale_factor = (cmax - cmin) / (2 ** n - 2)
scale_factor = (cmax - cmin) / (2**n - 2)
else:
scale_factor = (cmax - cmin) / (2 ** n - 1)
scale_factor = (cmax - cmin) / (2**n - 1)
if dtype.kind == "u":
add_offset = cmin
elif dtype.kind == "i":
Expand Down
4 changes: 2 additions & 2 deletions lib/iris/fileformats/pp.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ def _calculate_str_value_from_value(self):

def _calculate_value_from_str_value(self):
self._value = np.sum(
[10 ** i * val for i, val in enumerate(self._strvalue)]
[10**i * val for i, val in enumerate(self._strvalue)]
)

def __len__(self):
Expand All @@ -418,7 +418,7 @@ def __getitem__(self, key):
# if the key returns a list of values, then combine them together
# to an integer
if isinstance(val, list):
val = sum([10 ** i * val for i, val in enumerate(val)])
val = sum([10**i * val for i, val in enumerate(val)])

return val

Expand Down
6 changes: 3 additions & 3 deletions lib/iris/tests/integration/test_netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def setUp(self):
levels.units = "centimeters"
levels.positive = "down"
levels.axis = "Z"
levels[:] = np.linspace(0, 10 ** 5, 3)
levels[:] = np.linspace(0, 10**5, 3)

volcello.id = "volcello"
volcello.out_name = "volcello"
Expand Down Expand Up @@ -507,9 +507,9 @@ def _get_scale_factor_add_offset(cube, datatype):
else:
masked = False
if masked:
scale_factor = (cmax - cmin) / (2 ** n - 2)
scale_factor = (cmax - cmin) / (2**n - 2)
else:
scale_factor = (cmax - cmin) / (2 ** n - 1)
scale_factor = (cmax - cmin) / (2**n - 1)
if dt.kind == "u":
add_offset = cmin
elif dt.kind == "i":
Expand Down
38 changes: 19 additions & 19 deletions lib/iris/tests/test_basic_maths.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def test_apply_ufunc(self):
np.square,
a,
new_name="squared temperature",
new_unit=a.units ** 2,
new_unit=a.units**2,
in_place=False,
)
self.assertCMLApproxData(a, ("analysis", "apply_ufunc_original.cml"))
Expand All @@ -259,14 +259,14 @@ def test_apply_ufunc(self):
np.square,
a,
new_name="squared temperature",
new_unit=a.units ** 2,
new_unit=a.units**2,
in_place=True,
)
self.assertCMLApproxData(b, ("analysis", "apply_ufunc.cml"))
self.assertCMLApproxData(a, ("analysis", "apply_ufunc.cml"))

def vec_mag(u, v):
return math.sqrt(u ** 2 + v ** 2)
return math.sqrt(u**2 + v**2)

c = a.copy() + 2

Expand Down Expand Up @@ -295,7 +295,7 @@ def test_apply_ufunc_fail(self):
def test_ifunc(self):
a = self.cube

my_ifunc = iris.analysis.maths.IFunc(np.square, lambda a: a.units ** 2)
my_ifunc = iris.analysis.maths.IFunc(np.square, lambda a: a.units**2)
b = my_ifunc(a, new_name="squared temperature", in_place=False)

self.assertCMLApproxData(a, ("analysis", "apply_ifunc_original.cml"))
Expand All @@ -307,7 +307,7 @@ def test_ifunc(self):
self.assertCMLApproxData(a, ("analysis", "apply_ifunc.cml"))

def vec_mag(u, v):
return math.sqrt(u ** 2 + v ** 2)
return math.sqrt(u**2 + v**2)

c = a.copy() + 2

Expand Down Expand Up @@ -347,7 +347,7 @@ def test_ifunc_init_fail(self):
def test_ifunc_call_fail(self):
a = self.cube

my_ifunc = iris.analysis.maths.IFunc(np.square, lambda a: a.units ** 2)
my_ifunc = iris.analysis.maths.IFunc(np.square, lambda a: a.units**2)

# should now NOT fail because giving 2 arguments to an ifunc that
# expects only one will now ignore the surplus argument and raise
Expand All @@ -367,7 +367,7 @@ def test_ifunc_call_fail(self):
my_ifunc(a)

my_ifunc = iris.analysis.maths.IFunc(
lambda a: (a, a ** 2.0), lambda cube: cf_units.Unit("1")
lambda a: (a, a**2.0), lambda cube: cf_units.Unit("1")
)

# should fail because data function returns a tuple
Expand Down Expand Up @@ -553,9 +553,9 @@ def test_square_root(self):
a.data = abs(a.data)
a.units **= 2

e = a ** 0.5
e = a**0.5

self.assertArrayAllClose(e.data, a.data ** 0.5)
self.assertArrayAllClose(e.data, a.data**0.5)
self.assertCML(e, ("analysis", "sqrt.cml"), checksum=False)
self.assertRaises(ValueError, iris.analysis.maths.exponentiate, a, 0.3)

Expand Down Expand Up @@ -585,26 +585,26 @@ def test_apply_ufunc(self):
np.square,
a,
new_name="more_thingness",
new_unit=a.units ** 2,
new_unit=a.units**2,
in_place=False,
)

ans = a.data ** 2
ans = a.data**2

self.assertArrayEqual(b.data, ans)
self.assertEqual(b.name(), "more_thingness")
self.assertEqual(b.units, cf_units.Unit("m^2"))

def vec_mag(u, v):
return math.sqrt(u ** 2 + v ** 2)
return math.sqrt(u**2 + v**2)

c = a.copy() + 2

vec_mag_ufunc = np.frompyfunc(vec_mag, 2, 1)
b = iris.analysis.maths.apply_ufunc(vec_mag_ufunc, a, c)

ans = a.data ** 2 + c.data ** 2
b2 = b ** 2
ans = a.data**2 + c.data**2
b2 = b**2

self.assertArrayAlmostEqual(b2.data, ans)

Expand All @@ -617,17 +617,17 @@ def test_ifunc(self):
a = self.cube
a.units = cf_units.Unit("meters")

my_ifunc = iris.analysis.maths.IFunc(np.square, lambda x: x.units ** 2)
my_ifunc = iris.analysis.maths.IFunc(np.square, lambda x: x.units**2)
b = my_ifunc(a, new_name="more_thingness", in_place=False)

ans = a.data ** 2
ans = a.data**2

self.assertArrayEqual(b.data, ans)
self.assertEqual(b.name(), "more_thingness")
self.assertEqual(b.units, cf_units.Unit("m^2"))

def vec_mag(u, v):
return math.sqrt(u ** 2 + v ** 2)
return math.sqrt(u**2 + v**2)

c = a.copy() + 2

Expand All @@ -637,12 +637,12 @@ def vec_mag(u, v):
)
b = my_ifunc(a, c)

ans = (a.data ** 2 + c.data ** 2) ** 0.5
ans = (a.data**2 + c.data**2) ** 0.5

self.assertArrayAlmostEqual(b.data, ans)

def vec_mag_data_func(u_data, v_data):
return np.sqrt(u_data ** 2 + v_data ** 2)
return np.sqrt(u_data**2 + v_data**2)

vec_mag_ifunc = iris.analysis.maths.IFunc(
vec_mag_data_func, lambda a, b: (a + b).units
Expand Down
8 changes: 4 additions & 4 deletions lib/iris/tests/unit/analysis/cartography/test_rotate_winds.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ def test_orig_coords(self):
def test_magnitude_preservation(self):
u, v = self._uv_cubes_limited_extent()
ut, vt = rotate_winds(u, v, iris.coord_systems.OSGB())
orig_sq_mag = u.data ** 2 + v.data ** 2
res_sq_mag = ut.data ** 2 + vt.data ** 2
orig_sq_mag = u.data**2 + v.data**2
res_sq_mag = ut.data**2 + vt.data**2
self.assertArrayAllClose(orig_sq_mag, res_sq_mag, rtol=5e-4)

def test_data_values(self):
Expand Down Expand Up @@ -437,9 +437,9 @@ def test_rotated_to_osgb(self):
self.assertArrayEqual(expected_mask, vt.data.mask)

# Check unmasked values have sufficiently small error in mag.
expected_mag = np.sqrt(u.data ** 2 + v.data ** 2)
expected_mag = np.sqrt(u.data**2 + v.data**2)
# Use underlying data to ignore mask in calculation.
res_mag = np.sqrt(ut.data.data ** 2 + vt.data.data ** 2)
res_mag = np.sqrt(ut.data.data**2 + vt.data.data**2)
# Calculate percentage error (note there are no zero magnitudes
# so we can divide safely).
anom = 100.0 * np.abs(res_mag - expected_mag) / expected_mag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def setUp(self):
self.xs, self.ys = np.meshgrid(self.x.points, self.y.points)

def transformation(x, y):
return x + y ** 2
return x + y**2

# Construct a function which adds dimensions to the 2D data array
# so that we can test higher dimensional functionality.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_vectorise_call(self):
# The reason we use numpy.vectorize is to support multi-dimensional
# coordinate points.
def fn(coord, v):
return v ** 2
return v**2

with mock.patch(
"numpy.vectorize", return_value=self.vectorised
Expand Down
Loading