Skip to content

Commit

Permalink
Merge pull request #1125 from djhoese/bugfix-crop-epsg
Browse files Browse the repository at this point in the history
Fix Scene.crop using PROJ definition to create target area definition
  • Loading branch information
mraspaud committed Mar 30, 2020
2 parents 8853aac + c2e5075 commit 6457707
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion satpy/scene.py
Expand Up @@ -468,9 +468,10 @@ def _slice_area_from_bbox(self, src_area, dst_area, ll_bbox=None,
'crop_area', 'crop_area', 'crop_latlong',
{'proj': 'latlong'}, 100, 100, ll_bbox)
elif xy_bbox is not None:
crs = src_area.crs if hasattr(src_area, 'crs') else src_area.proj_dict
dst_area = AreaDefinition(
'crop_area', 'crop_area', 'crop_xy',
src_area.proj_dict, src_area.x_size, src_area.y_size,
crs, src_area.x_size, src_area.y_size,
xy_bbox)
x_slice, y_slice = src_area.get_area_slices(dst_area)
return src_area[y_slice, x_slice], y_slice, x_slice
Expand Down
29 changes: 29 additions & 0 deletions satpy/tests/test_scene.py
Expand Up @@ -457,6 +457,35 @@ def test_crop(self):
self.assertTupleEqual(new_scn1['3'].shape, (36, 70))
self.assertTupleEqual(new_scn1['4'].shape, (18, 35))

def test_crop_epsg_crs(self):
"""Test the crop method when source area uses an EPSG code."""
from satpy import Scene
from xarray import DataArray
from pyresample.geometry import AreaDefinition
import numpy as np
try:
from pyproj import CRS # noqa
except ImportError:
self.skipTest("Test requires pyproj 2.0+")

scene1 = Scene()
area_extent = (699960.0, 5390220.0, 809760.0, 5500020.0)
x_size = 3712
y_size = 3712
area_def = AreaDefinition(
'test', 'test', 'test',
"EPSG:32630",
x_size,
y_size,
area_extent,
)
scene1["1"] = DataArray(np.zeros((y_size, x_size)), dims=('y', 'x'),
attrs={'area': area_def})
# by x/y bbox
new_scn1 = scene1.crop(xy_bbox=(719695.7781587119, 5427887.407618969, 725068.1609052602, 5433708.364368956))
self.assertIn('1', new_scn1)
self.assertTupleEqual(new_scn1['1'].shape, (198, 182))

def test_crop_rgb(self):
"""Test the crop method on multi-dimensional data."""
from satpy import Scene
Expand Down

0 comments on commit 6457707

Please sign in to comment.