@@ -620,15 +620,17 @@ def _clip_if_needed(
620620 """
621621 if transformer is None :
622622 target_bbox = target_gm .xy_bbox
623- buffer_x = 2 * source_gm .x_res
624- buffer_y = 2 * source_gm .y_res
623+ buffer_x = 2 * max ( source_gm .x_res , target_gm . x_res )
624+ buffer_y = 2 * max ( source_gm .y_res , target_gm . y_res )
625625 else :
626626 target_bbox = transformer .transform_bounds (* target_gm .xy_bbox )
627- buffer_x = 2 * (target_bbox [2 ] - target_bbox [0 ]) / target_gm .width
628- buffer_y = 2 * (target_bbox [3 ] - target_bbox [1 ]) / target_gm .height
627+ target_x_res = (target_bbox [2 ] - target_bbox [0 ]) / target_gm .width
628+ target_y_res = (target_bbox [3 ] - target_bbox [1 ]) / target_gm .height
629+ buffer_x = 2 * max (source_gm .x_res , target_x_res )
630+ buffer_y = 2 * max (source_gm .y_res , target_y_res )
629631
630632 overlap = bbox_overlap (source_gm .xy_bbox , target_bbox )
631- if overlap < 1e-5 :
633+ if overlap == 0.0 :
632634 LOG .info (
633635 "Target grid mapping does not overlap with the source grid mapping. "
634636 "Returning empty target dataset."
@@ -647,6 +649,14 @@ def _clip_if_needed(
647649 ]
648650 clipped = clip_dataset_by_bbox (source_ds , bbox )
649651
652+ if any (clipped .sizes [source_gm .xy_dim_names [i ]] < 2 for i in range (2 )):
653+ LOG .warning (
654+ "Clipped dataset contains a spatial dimension with size < 2. "
655+ "Returning empty target dataset."
656+ )
657+ empty_ds = _create_empty_dataset (source_ds , source_gm , target_gm , fill_values )
658+ return empty_ds , target_gm , True
659+
650660 return clipped , GridMapping .from_dataset (clipped ), False
651661
652662
0 commit comments