From 7377b5f31e57c65ac8388032bf4695db2e9196ab Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 30 Jul 2024 16:36:49 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- ocf_datapipes/select/select_spatial_slice.py | 18 ++++++++++-------- tests/select/test_select_spatial_slice.py | 12 ++++++++---- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/ocf_datapipes/select/select_spatial_slice.py b/ocf_datapipes/select/select_spatial_slice.py index b29bc45e..df511f44 100644 --- a/ocf_datapipes/select/select_spatial_slice.py +++ b/ocf_datapipes/select/select_spatial_slice.py @@ -117,17 +117,19 @@ def _get_idx_of_pixel_closest_to_poi_geostationary( """ xr_coords, xr_x_dim, xr_y_dim = spatial_coord_type(xr_data) if center_coordinate.coordinate_system == "osgb": - x, y = osgb_to_geostationary_area_coords(x=center_coordinate.x, - y=center_coordinate.y, - xr_data=xr_data) + x, y = osgb_to_geostationary_area_coords( + x=center_coordinate.x, y=center_coordinate.y, xr_data=xr_data + ) elif center_coordinate.coordinate_system == "lon_lat": - x, y = lon_lat_to_geostationary_area_coords(x=center_coordinate.x, - y=center_coordinate.y, - xr_data=xr_data) + x, y = lon_lat_to_geostationary_area_coords( + x=center_coordinate.x, y=center_coordinate.y, xr_data=xr_data + ) else: - raise NotImplementedError(f"Only 'osgb' and 'lon_lat' location coordinates are \ + raise NotImplementedError( + f"Only 'osgb' and 'lon_lat' location coordinates are \ supported in conversion to geostationary \ - - not '{center_coordinate.coordinate_system}'") + - not '{center_coordinate.coordinate_system}'" + ) center_geostationary = Location(x=x, y=y, coordinate_system="geostationary") # Check that the requested point lies within the data diff --git a/tests/select/test_select_spatial_slice.py b/tests/select/test_select_spatial_slice.py index 0d408fe1..4e24a58e 100644 --- a/tests/select/test_select_spatial_slice.py +++ b/tests/select/test_select_spatial_slice.py @@ -161,6 +161,7 @@ def test_select_spatial_slice_meters_icon_global(passiv_datapipe, icon_global_da assert len(data.longitude) == 49 assert len(data.latitude) == 49 + def test_get_idx_of_pixel_closest_to_poi_geostationary_lon_lat_location(): # Create dummy data x = np.arange(5000000, -5000000, -5000) @@ -175,12 +176,15 @@ def test_get_idx_of_pixel_closest_to_poi_geostationary_lon_lat_location(): y_geostationary=(["y_geostationary"], y), ), ) - xr_data.attrs["area"] = 'msg_seviri_iodc_3km:\n description: MSG SEVIRI Indian Ocean Data Coverage service area definition with\n 3 km resolution\n projection:\n proj: geos\n lon_0: 41.5\n h: 35785831\n x_0: 0\n y_0: 0\n a: 6378169\n rf: 295.488065897014\n no_defs: null\n type: crs\n shape:\n height: 3712\n width: 3712\n area_extent:\n lower_left_xy: [5000000, 5000000]\n upper_right_xy: [-5000000, -5000000]\n units: m\n' - + xr_data.attrs["area"] = ( + "msg_seviri_iodc_3km:\n description: MSG SEVIRI Indian Ocean Data Coverage service area definition with\n 3 km resolution\n projection:\n proj: geos\n lon_0: 41.5\n h: 35785831\n x_0: 0\n y_0: 0\n a: 6378169\n rf: 295.488065897014\n no_defs: null\n type: crs\n shape:\n height: 3712\n width: 3712\n area_extent:\n lower_left_xy: [5000000, 5000000]\n upper_right_xy: [-5000000, -5000000]\n units: m\n" + ) center = Location(x=77.1, y=28.6, coordinate_system="lon_lat") - location_center_idx = _get_idx_of_pixel_closest_to_poi_geostationary(xr_data=xr_data, center_coordinate=center) + location_center_idx = _get_idx_of_pixel_closest_to_poi_geostationary( + xr_data=xr_data, center_coordinate=center + ) - assert location_center_idx.coordinate_system == 'idx' + assert location_center_idx.coordinate_system == "idx" assert location_center_idx.x == 2000