Skip to content

Commit 02bd36c

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 6abfd99 commit 02bd36c

File tree

13 files changed

+108
-110
lines changed

13 files changed

+108
-110
lines changed

.github/ci/min_deps_check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def main() -> None:
193193
print("\nErrors:")
194194
print("-------")
195195
for i, e in enumerate(errors):
196-
print(f"{i+1}. {e}")
196+
print(f"{i + 1}. {e}")
197197
sys.exit(1)
198198

199199

docs/examples/example_dask_chunk_OCMs.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -377,13 +377,13 @@ def test_swash(mode, chunk_mode):
377377
if chunk_mode not in [
378378
"failsafe",
379379
]:
380-
assert len(fieldset.U.grid._load_chunk) == len(
381-
fieldset.V.grid._load_chunk
382-
), f"U {fieldset.U.grid.chunk_info} vs V {fieldset.V.grid.chunk_info}"
380+
assert len(fieldset.U.grid._load_chunk) == len(fieldset.V.grid._load_chunk), (
381+
f"U {fieldset.U.grid.chunk_info} vs V {fieldset.V.grid.chunk_info}"
382+
)
383383
if chunk_mode not in ["failsafe", "auto"]:
384-
assert len(fieldset.U.grid._load_chunk) == len(
385-
fieldset.W.grid._load_chunk
386-
), f"U {fieldset.U.grid.chunk_info} vs W {fieldset.W.grid.chunk_info}"
384+
assert len(fieldset.U.grid._load_chunk) == len(fieldset.W.grid._load_chunk), (
385+
f"U {fieldset.U.grid.chunk_info} vs W {fieldset.W.grid.chunk_info}"
386+
)
387387
if chunk_mode is False:
388388
assert len(fieldset.U.grid._load_chunk) == 1
389389
else:

docs/examples/tutorial_NestedFields.ipynb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,13 @@
235235
"pset = parcels.ParticleSet(fieldset, pclass=SampleParticle, lon=[1000], lat=[500])\n",
236236
"pset.execute(SampleNestedFieldIndex, runtime=1)\n",
237237
"print(\n",
238-
" f\"Particle ({pset[0].lon:g}, {pset[0].lat:g}) \"\n",
239-
" f\"interpolates Field #{int(pset[0].f)}\"\n",
238+
" f\"Particle ({pset[0].lon:g}, {pset[0].lat:g}) interpolates Field #{int(pset[0].f)}\"\n",
240239
")\n",
241240
"\n",
242241
"pset[0].lon = 10000\n",
243242
"pset.execute(SampleNestedFieldIndex, runtime=1)\n",
244243
"print(\n",
245-
" f\"Particle ({pset[0].lon:g}, {pset[0].lat:g}) \"\n",
246-
" f\"interpolates Field #{int(pset[0].f)}\"\n",
244+
" f\"Particle ({pset[0].lon:g}, {pset[0].lat:g}) interpolates Field #{int(pset[0].f)}\"\n",
247245
")"
248246
]
249247
}

docs/examples/tutorial_nemo_3D.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
"print(\n",
156156
" f\"Level[{int(depth_level)}] depth is: \"\n",
157157
" f\"[{fieldset.W.grid.depth[depth_level]:g} \"\n",
158-
" f\"{fieldset.W.grid.depth[depth_level+1]:g}]\"\n",
158+
" f\"{fieldset.W.grid.depth[depth_level + 1]:g}]\"\n",
159159
")\n",
160160
"\n",
161161
"plt.pcolormesh(\n",

docs/examples/tutorial_peninsula_AvsCgrid.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@
272272
" # Set the same limits for all subplots\n",
273273
" ax.set_xlim([fieldset.U.lon.min(), fieldset.U.lon.max()])\n",
274274
" ax.set_ylim([0, 23e3])\n",
275-
" m2km = lambda x, _: f\"{x/1000:.1f}\"\n",
275+
" m2km = lambda x, _: f\"{x / 1000:.1f}\"\n",
276276
" ax.xaxis.set_major_formatter(m2km)\n",
277277
" ax.yaxis.set_major_formatter(m2km)\n",
278278
" ax.set_xlabel(\"x [km]\")\n",
@@ -347,7 +347,7 @@
347347
"ax.set_ylim([0, 23e3])\n",
348348
"ax.set_ylabel(\"y [km]\")\n",
349349
"ax.set_xlabel(\"x [km]\")\n",
350-
"m2km = lambda x, _: f\"{x/1000:.1f}\"\n",
350+
"m2km = lambda x, _: f\"{x / 1000:.1f}\"\n",
351351
"ax.xaxis.set_major_formatter(m2km)\n",
352352
"ax.yaxis.set_major_formatter(m2km)\n",
353353
"\n",

parcels/compilation/codegenerator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ def visit_FieldEvalNode(self, node):
832832
# Get Cs_w values directly from fieldset (since they are 1D in vertical only)
833833
Cs_w = [float(self.fieldset.Cs_w.data[0][zi][0][0]) for zi in range(self.fieldset.Cs_w.data.shape[1])]
834834
statements_croco = [
835-
c.Statement(f"float cs_w[] = {*Cs_w, }".replace("(", "{").replace(")", "}")),
835+
c.Statement(f"float cs_w[] = {(*Cs_w,)}".replace("(", "{").replace(")", "}")),
836836
c.Statement(
837837
f"{node.var} = croco_from_z_to_sigma(time, {args[1]}, {args[2]}, {args[3]}, U, H, Zeta, &particles->ti[pnum*ngrid], &particles->zi[pnum*ngrid], &particles->yi[pnum*ngrid], &particles->xi[pnum*ngrid], hc, &cs_w)"
838838
),
@@ -861,7 +861,7 @@ def visit_VectorFieldEvalNode(self, node):
861861
# Get Cs_w values directly from fieldset (since they are 1D in vertical only)
862862
Cs_w = [float(self.fieldset.Cs_w.data[0][zi][0][0]) for zi in range(self.fieldset.Cs_w.data.shape[1])]
863863
statements_croco = [
864-
c.Statement(f"float cs_w[] = {*Cs_w, }".replace("(", "{").replace(")", "}")),
864+
c.Statement(f"float cs_w[] = {(*Cs_w,)}".replace("(", "{").replace(")", "}")),
865865
c.Statement(
866866
f"{node.var4} = croco_from_z_to_sigma(time, {args[1]}, {args[2]}, {args[3]}, U, H, Zeta, &particles->ti[pnum*ngrid], &particles->zi[pnum*ngrid], &particles->yi[pnum*ngrid], &particles->xi[pnum*ngrid], hc, &cs_w)"
867867
),

parcels/field.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,9 @@ def __init__(
334334
self.grid.depth_field = kwargs.pop("depth_field", None)
335335

336336
if self.grid.depth_field == "not_yet_set":
337-
assert (
338-
self.grid._z4d
339-
), "Providing the depth dimensions from another field data is only available for 4d S grids"
337+
assert self.grid._z4d, (
338+
"Providing the depth dimensions from another field data is only available for 4d S grids"
339+
)
340340

341341
# data_full_zdim is the vertical dimension of the complete field data, ignoring the indices.
342342
# (data_full_zdim = grid.zdim if no indices are used, for A- and C-grids and for some B-grids). It is used for the B-grid,
@@ -572,20 +572,20 @@ def from_netcdf(
572572
# Ensure the timestamps array is compatible with the user-provided datafiles.
573573
if timestamps is not None:
574574
if isinstance(filenames, list):
575-
assert len(filenames) == len(
576-
timestamps
577-
), "Outer dimension of timestamps should correspond to number of files."
575+
assert len(filenames) == len(timestamps), (
576+
"Outer dimension of timestamps should correspond to number of files."
577+
)
578578
elif isinstance(filenames, dict):
579579
for k in filenames.keys():
580580
if k not in ["lat", "lon", "depth", "time"]:
581581
if isinstance(filenames[k], list):
582-
assert len(filenames[k]) == len(
583-
timestamps
584-
), "Outer dimension of timestamps should correspond to number of files."
582+
assert len(filenames[k]) == len(timestamps), (
583+
"Outer dimension of timestamps should correspond to number of files."
584+
)
585585
else:
586-
assert (
587-
len(timestamps) == 1
588-
), "Outer dimension of timestamps should correspond to number of files."
586+
assert len(timestamps) == 1, (
587+
"Outer dimension of timestamps should correspond to number of files."
588+
)
589589
for t in timestamps:
590590
assert isinstance(t, (list, np.ndarray)), "timestamps should be a list for each file"
591591

@@ -597,13 +597,13 @@ def from_netcdf(
597597
if isinstance(variable, str): # for backward compatibility with Parcels < 2.0.0
598598
variable = (variable, variable)
599599
elif isinstance(variable, dict):
600-
assert (
601-
len(variable) == 1
602-
), "Field.from_netcdf() supports only one variable at a time. Use FieldSet.from_netcdf() for multiple variables."
600+
assert len(variable) == 1, (
601+
"Field.from_netcdf() supports only one variable at a time. Use FieldSet.from_netcdf() for multiple variables."
602+
)
603603
variable = tuple(variable.items())[0]
604-
assert (
605-
len(variable) == 2
606-
), "The variable tuple must have length 2. Use FieldSet.from_netcdf() for multiple variables"
604+
assert len(variable) == 2, (
605+
"The variable tuple must have length 2. Use FieldSet.from_netcdf() for multiple variables"
606+
)
607607

608608
data_filenames = cls._get_dim_filenames(filenames, "data")
609609
lonlat_filename = cls._get_dim_filenames(filenames, "lon")
@@ -2136,21 +2136,21 @@ def __init__(self, name: str, F, V=None, W=None):
21362136
if isinstance(F[0], VectorField):
21372137
vector_type = F[0].vector_type
21382138
for Fi in F:
2139-
assert isinstance(Fi, Field) or (
2140-
isinstance(Fi, VectorField) and Fi.vector_type == vector_type
2141-
), "Components of a NestedField must be Field or VectorField"
2139+
assert isinstance(Fi, Field) or (isinstance(Fi, VectorField) and Fi.vector_type == vector_type), (
2140+
"Components of a NestedField must be Field or VectorField"
2141+
)
21422142
self.append(Fi)
21432143
elif W is None:
21442144
for i, Fi, Vi in zip(range(len(F)), F, V, strict=True):
2145-
assert isinstance(Fi, Field) and isinstance(
2146-
Vi, Field
2147-
), "F, and V components of a NestedField must be Field"
2145+
assert isinstance(Fi, Field) and isinstance(Vi, Field), (
2146+
"F, and V components of a NestedField must be Field"
2147+
)
21482148
self.append(VectorField(f"{name}_{i}", Fi, Vi))
21492149
else:
21502150
for i, Fi, Vi, Wi in zip(range(len(F)), F, V, W, strict=True):
2151-
assert (
2152-
isinstance(Fi, Field) and isinstance(Vi, Field) and isinstance(Wi, Field)
2153-
), "F, V and W components of a NestedField must be Field"
2151+
assert isinstance(Fi, Field) and isinstance(Vi, Field) and isinstance(Wi, Field), (
2152+
"F, V and W components of a NestedField must be Field"
2153+
)
21542154
self.append(VectorField(f"{name}_{i}", Fi, Vi, Wi))
21552155
self.name = name
21562156

parcels/fieldset.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,9 @@ def check_velocityfields(U, V, W):
313313
g._check_zonal_periodic()
314314
if len(g.time) == 1:
315315
continue
316-
assert isinstance(
317-
g.time_origin.time_origin, type(self.time_origin.time_origin)
318-
), "time origins of different grids must be have the same type"
316+
assert isinstance(g.time_origin.time_origin, type(self.time_origin.time_origin)), (
317+
"time origins of different grids must be have the same type"
318+
)
319319
g.time = g.time + self.time_origin.reltime(g.time_origin)
320320
if g.defer_load:
321321
g.time_full = g.time_full + self.time_origin.reltime(g.time_origin)

parcels/grid.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ def __init__(
6464
if not lat.dtype == np.float32:
6565
lat = lat.astype(np.float32)
6666
if not time.dtype == np.float64:
67-
assert isinstance(
68-
time[0], (np.integer, np.floating, float, int)
69-
), "Time vector must be an array of int or floats"
67+
assert isinstance(time[0], (np.integer, np.floating, float, int)), (
68+
"Time vector must be an array of int or floats"
69+
)
7070
time = time.astype(np.float64)
7171

7272
self._lon = lon
@@ -627,22 +627,22 @@ def __init__(
627627
self._z4d = 1 if len(self.depth.shape) == 4 else 0
628628
if self._z4d:
629629
# self.depth.shape[0] is 0 for S grids loaded from netcdf file
630-
assert (
631-
self.tdim == self.depth.shape[0] or self.depth.shape[0] == 0
632-
), "depth dimension has the wrong format. It should be [tdim, zdim, ydim, xdim]"
633-
assert (
634-
self.xdim == self.depth.shape[-1] or self.depth.shape[-1] == 0
635-
), "depth dimension has the wrong format. It should be [tdim, zdim, ydim, xdim]"
636-
assert (
637-
self.ydim == self.depth.shape[-2] or self.depth.shape[-2] == 0
638-
), "depth dimension has the wrong format. It should be [tdim, zdim, ydim, xdim]"
630+
assert self.tdim == self.depth.shape[0] or self.depth.shape[0] == 0, (
631+
"depth dimension has the wrong format. It should be [tdim, zdim, ydim, xdim]"
632+
)
633+
assert self.xdim == self.depth.shape[-1] or self.depth.shape[-1] == 0, (
634+
"depth dimension has the wrong format. It should be [tdim, zdim, ydim, xdim]"
635+
)
636+
assert self.ydim == self.depth.shape[-2] or self.depth.shape[-2] == 0, (
637+
"depth dimension has the wrong format. It should be [tdim, zdim, ydim, xdim]"
638+
)
639639
else:
640-
assert (
641-
self.xdim == self.depth.shape[-1]
642-
), "depth dimension has the wrong format. It should be [zdim, ydim, xdim]"
643-
assert (
644-
self.ydim == self.depth.shape[-2]
645-
), "depth dimension has the wrong format. It should be [zdim, ydim, xdim]"
640+
assert self.xdim == self.depth.shape[-1], (
641+
"depth dimension has the wrong format. It should be [zdim, ydim, xdim]"
642+
)
643+
assert self.ydim == self.depth.shape[-2], (
644+
"depth dimension has the wrong format. It should be [zdim, ydim, xdim]"
645+
)
646646
if not self.depth.dtype == np.float32:
647647
self._depth = self.depth.astype(np.float32)
648648
if self._lat_flipped:
@@ -799,22 +799,22 @@ def __init__(
799799
self._z4d = 1 if len(self.depth.shape) == 4 else 0
800800
if self._z4d:
801801
# self.depth.shape[0] is 0 for S grids loaded from netcdf file
802-
assert (
803-
self.tdim == self.depth.shape[0] or self.depth.shape[0] == 0
804-
), "depth dimension has the wrong format. It should be [tdim, zdim, ydim, xdim]"
805-
assert (
806-
self.xdim == self.depth.shape[-1] or self.depth.shape[-1] == 0
807-
), "depth dimension has the wrong format. It should be [tdim, zdim, ydim, xdim]"
808-
assert (
809-
self.ydim == self.depth.shape[-2] or self.depth.shape[-2] == 0
810-
), "depth dimension has the wrong format. It should be [tdim, zdim, ydim, xdim]"
802+
assert self.tdim == self.depth.shape[0] or self.depth.shape[0] == 0, (
803+
"depth dimension has the wrong format. It should be [tdim, zdim, ydim, xdim]"
804+
)
805+
assert self.xdim == self.depth.shape[-1] or self.depth.shape[-1] == 0, (
806+
"depth dimension has the wrong format. It should be [tdim, zdim, ydim, xdim]"
807+
)
808+
assert self.ydim == self.depth.shape[-2] or self.depth.shape[-2] == 0, (
809+
"depth dimension has the wrong format. It should be [tdim, zdim, ydim, xdim]"
810+
)
811811
else:
812-
assert (
813-
self.xdim == self.depth.shape[-1]
814-
), "depth dimension has the wrong format. It should be [zdim, ydim, xdim]"
815-
assert (
816-
self.ydim == self.depth.shape[-2]
817-
), "depth dimension has the wrong format. It should be [zdim, ydim, xdim]"
812+
assert self.xdim == self.depth.shape[-1], (
813+
"depth dimension has the wrong format. It should be [zdim, ydim, xdim]"
814+
)
815+
assert self.ydim == self.depth.shape[-2], (
816+
"depth dimension has the wrong format. It should be [zdim, ydim, xdim]"
817+
)
818818
if not self.depth.dtype == np.float32:
819819
self._depth = self.depth.astype(np.float32)
820820

parcels/interaction/interactionkernel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ def __init__(
8383

8484
numkernelargs = self.check_kernel_signature_on_version()
8585

86-
assert numkernelargs[0] == 5 and numkernelargs.count(numkernelargs[0]) == len(
87-
numkernelargs
88-
), "Interactionkernels take exactly 5 arguments: particle, fieldset, time, neighbors, mutator"
86+
assert numkernelargs[0] == 5 and numkernelargs.count(numkernelargs[0]) == len(numkernelargs), (
87+
"Interactionkernels take exactly 5 arguments: particle, fieldset, time, neighbors, mutator"
88+
)
8989

9090
# At this time, JIT mode is not supported for InteractionKernels,
9191
# so there is no need for any further "processing" of pyfunc's.

0 commit comments

Comments
 (0)