Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jul 30, 2024
1 parent fb95122 commit 7377b5f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
18 changes: 10 additions & 8 deletions ocf_datapipes/select/select_spatial_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions tests/select/test_select_spatial_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

0 comments on commit 7377b5f

Please sign in to comment.