Skip to content

Commit c8ce122

Browse files
committed
Merge branch 'rajeeja/fix_issue1393' of https://github.com/UXARRAY/uxarray into rajeeja/fix_issue1393
2 parents 1926b04 + 92c83f0 commit c8ce122

File tree

1 file changed

+13
-26
lines changed

1 file changed

+13
-26
lines changed

uxarray/core/dataarray.py

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -406,37 +406,21 @@ def to_raster(
406406
else:
407407

408408
def _is_default_extent() -> bool:
409-
# Default extents can be (0, 1) or projection limits while autoscale stays on.
409+
# Default extents are indicated by xlim/ylim being (0, 1)
410+
# when autoscale is still on (no extent has been explicitly set)
410411
if not ax.get_autoscale_on():
411412
return False
412-
try:
413-
import cartopy.crs as ccrs
414-
415-
extent = ax.get_extent(ccrs.PlateCarree())
416-
except Exception:
417-
xlim, ylim = ax.get_xlim(), ax.get_ylim()
418-
return np.allclose(xlim, (0.0, 1.0)) and np.allclose(
419-
ylim, (0.0, 1.0)
420-
)
421-
return np.allclose(extent, (-180.0, 180.0, -90.0, 90.0), atol=1.0)
413+
xlim, ylim = ax.get_xlim(), ax.get_ylim()
414+
return np.allclose(xlim, (0.0, 1.0)) and np.allclose(ylim, (0.0, 1.0))
422415

423416
if _is_default_extent():
424417
try:
425418
import cartopy.crs as ccrs
426419

427-
lon_min = self.uxgrid.node_lon.min(skipna=True)
428-
lon_max = self.uxgrid.node_lon.max(skipna=True)
429-
lat_min = self.uxgrid.node_lat.min(skipna=True)
430-
lat_max = self.uxgrid.node_lat.max(skipna=True)
431-
432-
lon_min, lon_max = (
433-
float(lon_min.to_numpy().item()),
434-
float(lon_max.to_numpy().item()),
435-
)
436-
lat_min, lat_max = (
437-
float(lat_min.to_numpy().item()),
438-
float(lat_max.to_numpy().item()),
439-
)
420+
lon_min = float(self.uxgrid.node_lon.min(skipna=True).values)
421+
lon_max = float(self.uxgrid.node_lon.max(skipna=True).values)
422+
lat_min = float(self.uxgrid.node_lat.min(skipna=True).values)
423+
lat_max = float(self.uxgrid.node_lat.max(skipna=True).values)
440424
ax.set_extent(
441425
(lon_min, lon_max, lat_min, lat_max),
442426
crs=ccrs.PlateCarree(),
@@ -447,8 +431,11 @@ def _is_default_extent() -> bool:
447431
"ax.set_extent(...), or ax.set_xlim(...) + ax.set_ylim(...).",
448432
stacklevel=2,
449433
)
450-
except Exception:
451-
pass
434+
except Exception as e:
435+
warn(
436+
f"Failed to auto-set extent from grid bounds: {e}",
437+
stacklevel=2,
438+
)
452439
input_ax_attrs = _RasterAxAttrs.from_ax(ax, pixel_ratio=pixel_ratio)
453440

454441
raster, pixel_mapping_np = _nearest_neighbor_resample(

0 commit comments

Comments
 (0)