Skip to content

Commit ec85c09

Browse files
committed
style(repo): Ruff fix
1 parent e7704b1 commit ec85c09

File tree

14 files changed

+84
-84
lines changed

14 files changed

+84
-84
lines changed

src/nwp_consumer/internal/entities/coordinates.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,15 @@ def from_pandas(
213213
f"Cannot create {cls.__class__.__name__} instance from pandas indexes "
214214
"as required keys 'init_time', 'step', and 'variable' are not all present. "
215215
f"Got: '{list(pd_indexes.keys())}'",
216-
)
216+
),
217217
)
218218
if not all(len(pd_indexes[key].to_list()) > 0 for key in ["init_time", "step", "variable"]):
219219
return Failure(
220220
ValueError(
221221
f"Cannot create {cls.__class__.__name__} instance from pandas indexes "
222222
"as the 'init_time', 'step', and 'variable' dimensions must have "
223223
"at least one coordinate value.",
224-
)
224+
),
225225
)
226226
input_parameter_set: set[str] = set(pd_indexes["variable"].to_list())
227227
known_parameter_set: set[str] = {str(p) for p in Parameter}
@@ -233,7 +233,7 @@ def from_pandas(
233233
f"'{list(input_parameter_set.difference(known_parameter_set))}'. "
234234
"Ensure the parameter names match the names of the standard parameter set "
235235
"defined by the `entities.Parameter` Enum.",
236-
)
236+
),
237237
)
238238
if not all(key in [f.name for f in dataclasses.fields(cls)] for key in pd_indexes):
239239
unknown_keys: list[str] = list(
@@ -243,7 +243,7 @@ def from_pandas(
243243
KeyError(
244244
f"Cannot create {cls.__class__.__name__} instance from pandas indexes "
245245
f"as unknown index/dimension keys were encountered: {unknown_keys}.",
246-
)
246+
),
247247
)
248248
if (
249249
"latitude" in pd_indexes
@@ -255,7 +255,7 @@ def from_pandas(
255255
"as the latitude values are not in descending order. "
256256
"Latitude coordinates should run from 90 -> -90. "
257257
"Modify the coordinate in the source data to be in descending order.",
258-
)
258+
),
259259
)
260260
if (
261261
"longitude" in pd_indexes
@@ -267,7 +267,7 @@ def from_pandas(
267267
"as the longitude values are not in ascending order. "
268268
"Longitude coordinates should run from -180 -> 180. "
269269
"Modify the coordinate in the source data to be in ascending order.",
270-
)
270+
),
271271
)
272272
if (
273273
"y_osgb" in pd_indexes
@@ -278,7 +278,7 @@ def from_pandas(
278278
"Cannot create NWPDimensionCoordinateMap instance from pandas indexes "
279279
"as the y_osgb values are not in descending order. "
280280
"Modify the coordinate in the source data to be in descending order.",
281-
)
281+
),
282282
)
283283
if (
284284
"x_osgb" in pd_indexes
@@ -289,7 +289,7 @@ def from_pandas(
289289
"Cannot create NWPDimensionCoordinateMap instance from pandas indexes "
290290
"as the x_osgb values are not in ascending order. "
291291
"Modify the coordinate in the source data to be in ascending order.",
292-
)
292+
),
293293
)
294294
if (
295295
"y_laea" in pd_indexes
@@ -300,7 +300,7 @@ def from_pandas(
300300
"Cannot create NWPDimensionCoordinateMap instance from pandas indexes "
301301
"as the y_laea values are not in descending order. "
302302
"Modify the coordinate in the source data to be in descending order.",
303-
)
303+
),
304304
)
305305
if (
306306
"x_laea" in pd_indexes
@@ -311,7 +311,7 @@ def from_pandas(
311311
"Cannot create NWPDimensionCoordinateMap instance from pandas indexes "
312312
"as the x_laea values are not in ascending order. "
313313
"Modify the coordinate in the source data to be in ascending order.",
314-
)
314+
),
315315
)
316316

317317
# Convert the pandas Index objects to lists of the appropriate types
@@ -346,7 +346,7 @@ def from_pandas(
346346

347347
@classmethod
348348
def from_xarray(
349-
cls, xarray_obj: xr.DataArray | xr.Dataset
349+
cls, xarray_obj: xr.DataArray | xr.Dataset,
350350
) -> ResultE["NWPDimensionCoordinateMap"]:
351351
"""Create a new NWPDimensionCoordinateMap from an XArray DataArray or Dataset object."""
352352
return cls.from_pandas(xarray_obj.coords.indexes) # type: ignore
@@ -566,7 +566,7 @@ def as_zeroed_dataarray(self, name: str, chunks: dict[str, int]) -> xr.DataArray
566566
(
567567
f"nwp-consumer {__version__} at ",
568568
f"{dt.datetime.now(tz=dt.UTC).strftime('%Y-%m-%d %H:%M')}",
569-
)
569+
),
570570
),
571571
"variables": json.dumps(
572572
{
@@ -575,7 +575,7 @@ def as_zeroed_dataarray(self, name: str, chunks: dict[str, int]) -> xr.DataArray
575575
"units": p.metadata().units,
576576
}
577577
for p in self.variable
578-
}
578+
},
579579
),
580580
"coord_system": json.dumps(self.coord_system),
581581
}
@@ -614,7 +614,7 @@ def crop(
614614
"Cannot crop coordinates to a region as latitude and/or longitude "
615615
"dimension coordinates are not present in the map. "
616616
f"Dimensions: '{self.dims}'.",
617-
)
617+
),
618618
)
619619

620620
if not (-90 <= south < north <= 90 and -180 <= west < east <= 180):
@@ -625,7 +625,7 @@ def crop(
625625
" and both must sit between 90 and -90 degrees; "
626626
f"East ({east}) greater than West ({west}) "
627627
" and both must sit between 180 and -180 degrees.",
628-
)
628+
),
629629
)
630630

631631
if (
@@ -639,7 +639,7 @@ def crop(
639639
"Cannot crop coordinates to a region outside the bounds of the map. "
640640
f"Crop region '{north, west, south, east}' not in "
641641
f"map bounds '{self.nwse()}'.",
642-
)
642+
),
643643
)
644644

645645
# Determine the indices of the region in the latitude and longitude lists
@@ -652,7 +652,7 @@ def crop(
652652
self,
653653
latitude=[self.latitude[i] for i in lat_indices],
654654
longitude=[self.longitude[i] for i in lon_indices],
655-
)
655+
),
656656
)
657657

658658
def nwse(self) -> tuple[float, float, float, float]:

src/nwp_consumer/internal/entities/modelmetadata.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def __str__(self) -> str:
8787
else f"\t\t{dim}: {vals[:3]} ... {vals[-3:]}"
8888
for dim, vals in self.expected_coordinates.__dict__.items()
8989
),
90-
)
90+
),
9191
)
9292
return pretty
9393

@@ -111,7 +111,7 @@ def with_region(self, region: str) -> "ModelMetadata":
111111
self,
112112
name=f"{self.name}_uk",
113113
expected_coordinates=coords,
114-
)
114+
),
115115
)
116116
.unwrap()
117117
)
@@ -129,7 +129,7 @@ def with_region(self, region: str) -> "ModelMetadata":
129129
self,
130130
name=f"{self.name}_uk",
131131
expected_coordinates=coords,
132-
)
132+
),
133133
)
134134
.unwrap()
135135
)
@@ -146,7 +146,7 @@ def with_region(self, region: str) -> "ModelMetadata":
146146
self,
147147
name=f"{self.name}_india",
148148
expected_coordinates=coords,
149-
)
149+
),
150150
)
151151
.unwrap()
152152
)
@@ -163,7 +163,7 @@ def with_region(self, region: str) -> "ModelMetadata":
163163
self,
164164
name=f"{self.name}_west-europe",
165165
expected_coordinates=coords,
166-
)
166+
),
167167
)
168168
.unwrap()
169169
)
@@ -180,7 +180,7 @@ def with_region(self, region: str) -> "ModelMetadata":
180180
self,
181181
name=f"{self.name}_nl",
182182
expected_coordinates=coords,
183-
)
183+
),
184184
)
185185
.unwrap()
186186
)
@@ -366,7 +366,7 @@ class Models:
366366
np.arange(45, 135, 0.234),
367367
np.arange(135, 225, 0.234),
368368
np.arange(225, 315, 0.234),
369-
]
369+
],
370370
)
371371
],
372372
# TODO: Change to -180 -> 180

src/nwp_consumer/internal/entities/notification.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __str__(self) -> str:
3939
f"Store created: {self.filename} ({self.size_mb} MB) in ",
4040
f"{self.performance.duration_seconds} secs ",
4141
f"(using {self.performance.memory_mb} MB RAM)",
42-
)
42+
),
4343
)
4444

4545

src/nwp_consumer/internal/entities/repometadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,6 @@ def __str__(self) -> str:
103103
"\n".join(f"\t\t{var}" for var in self.required_env),
104104
"\n\tOptional:",
105105
"\n".join(f"\t\t{var}={val}" for var, val in self.optional_env.items()),
106-
)
106+
),
107107
)
108108
return pretty

src/nwp_consumer/internal/entities/tensorstore.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def initialize_empty_store(
151151
f"Unable to create Directory Store at dir '{zarrdir}'. "
152152
"Ensure ZARRDIR environment variable is specified correctly. "
153153
f"Error context: {e}",
154-
)
154+
),
155155
)
156156

157157
# Write the coordinates to a skeleton Zarr store
@@ -183,7 +183,7 @@ def initialize_empty_store(
183183
f"Existing store at '{path}' is for a different model. "
184184
"Delete the existing store or move it to a new location, "
185185
"or choose a new location for the new store via ZARRDIR.",
186-
)
186+
),
187187
)
188188
log.info(f"Using existing store at '{path}'")
189189
return Success(
@@ -355,7 +355,7 @@ def _calc_null_percentage(data: np.typing.NDArray[np.float32]) -> float:
355355
"Store does not have expected spatial dimensions. "
356356
"Expected: ['latitude', 'longitude'], ['x_osgb', 'y_osgb'], ['x_laea', 'y_laea']. "
357357
f"Got: {store_da.dims}.",
358-
)
358+
),
359359
)
360360

361361
result = xr.apply_ufunc(
@@ -405,7 +405,7 @@ def validate_store(self) -> ResultE[None]:
405405
ValueError(
406406
"Store contains NaN values. "
407407
"Check the source data for missing values and reprocess the data.",
408-
)
408+
),
409409
)
410410

411411
# TODO: Use consistency checks instead
@@ -457,7 +457,7 @@ def delete_store(self) -> ResultE[None]:
457457
f"Unable to delete S3 store at path '{self.path}'."
458458
"Ensure AWS credentials are correct and discoverable by botocore. "
459459
f"Error context: {e}",
460-
)
460+
),
461461
)
462462
else:
463463
try:
@@ -466,7 +466,7 @@ def delete_store(self) -> ResultE[None]:
466466
return Failure(
467467
OSError(
468468
f"Unable to delete store at path '{self.path}'. " f"Error context: {e}",
469-
)
469+
),
470470
)
471471
log.info("Deleted zarr store at '%s'", self.path)
472472
return Success(None)
@@ -493,7 +493,7 @@ def scan_parameter_values(self, p: Parameter) -> ResultE[ParameterScanResult]:
493493
"parameters defined in `entities.parameters` if desired, or "
494494
"add the parameter to the entities parameters if it is new. "
495495
f"Store parameters: {[p.name for p in self.coordinate_map.variable]}.",
496-
)
496+
),
497497
)
498498
store_da: xr.DataArray = xr.open_dataarray(self.path, engine="zarr")
499499

@@ -554,7 +554,7 @@ def missing_times(self) -> ResultE[list[dt.datetime]]:
554554
OSError(
555555
"Cannot determine missing times in store due to "
556556
f"error reading '{self.path}': {e}",
557-
)
557+
),
558558
)
559559
missing_times: list[dt.datetime] = []
560560
for it in store_da.coords["init_time"].values:
@@ -569,7 +569,7 @@ def missing_times(self) -> ResultE[list[dt.datetime]]:
569569
if len(missing_times) > 0:
570570
log.debug(
571571
f"NaNs in init times '{missing_times}' suggest they are missing, "
572-
f"will redownload"
572+
f"will redownload",
573573
)
574574
return Success(missing_times)
575575

@@ -592,7 +592,7 @@ def _create_zarrstore_s3(s3_folder: str, filename: str) -> ResultE[tuple[Mutable
592592
return Failure(
593593
ValueError(
594594
"S3 folder path must start with 's3://'. " f"Got: {s3_folder}",
595-
)
595+
),
596596
)
597597
log.debug("Attempting AWS connection using credential discovery")
598598
try:
@@ -613,7 +613,7 @@ def _create_zarrstore_s3(s3_folder: str, filename: str) -> ResultE[tuple[Mutable
613613
"Ensure ZARRDIR environment variable is specified correctly, "
614614
"and AWS credentials are discoverable by botocore. "
615615
f"Error context: {e}",
616-
)
616+
),
617617
)
618618
return Success((store, path))
619619

src/nwp_consumer/internal/entities/test_coordinates.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,15 @@ class TestCase:
143143
"2021-01-01T00:00:00Z",
144144
"2021-01-01T03:00:00Z",
145145
"2021-01-01T06:00:00Z",
146-
]
146+
],
147147
),
148148
"step": pd.Index([hour * 60 * 60 * 1000000000 for hour in range(12)]),
149149
"variable": pd.Index(
150150
[
151151
Parameter.CLOUD_COVER_HIGH.value,
152152
Parameter.TEMPERATURE_SL.value,
153153
Parameter.TOTAL_PRECIPITATION_RATE_GL.value,
154-
]
154+
],
155155
),
156156
"latitude": pd.Index([62.0, 61.0, 60.0]),
157157
"longitude": pd.Index([10.0, 11.0, 12.0]),
@@ -166,7 +166,7 @@ class TestCase:
166166
self.assertListEqual(list(result.keys()), list(t.expected_indexes.keys()))
167167
for key in result:
168168
self.assertListEqual(
169-
result[key].values.tolist(), t.expected_indexes[key].values.tolist()
169+
result[key].values.tolist(), t.expected_indexes[key].values.tolist(),
170170
)
171171

172172
def test_from_pandas(self) -> None:

src/nwp_consumer/internal/ports/repositories.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def authenticate(cls) -> ResultE["RawRepository"]:
5050

5151
@abc.abstractmethod
5252
def fetch_init_data(
53-
self, it: dt.datetime
53+
self, it: dt.datetime,
5454
) -> Iterator[Callable[..., ResultE[list[xr.DataArray]]]]:
5555
"""Fetch raw data files for an init time as xarray datasets.
5656

0 commit comments

Comments
 (0)