holoviz / hvplot

A high-level plotting API for pandas, dask, xarray, and networkx built on HoloViews
https://hvplot.holoviz.org
BSD 3-Clause "New" or "Revised" License
1.07k stars 104 forks source link

Automatically or manually toggle to automatically use lon_lat_to_easting_northing #1375

Open ahuang11 opened 1 month ago

ahuang11 commented 1 month ago

Sometimes, I don't want to use geoviews because it's extra dependency and import (and sometimes it breaks):

import hvplot.xarray
import xarray as xr
import holoviews as hv
from holoviews.util.transform import lon_lat_to_easting_northing

ds = xr.tutorial.load_dataset("air_temperature").isel(time=slice(0, 100))
ds["easting"], ds["northing"] = lon_lat_to_easting_northing(ds["lon"], ds["lat"])
ds = ds.swap_dims({"lon": "easting", "lat": "northing"})
hv.element.tiles.CartoDark() * ds.hvplot("easting", "northing")
image

I'm wondering whether there should be a kwarg to transform so the above can be simplified down to

import hvplot.xarray
import xarray as xr

ds = xr.tutorial.load_dataset("air_temperature").isel(time=slice(0, 100))
ds.hvplot("lon", "lat", tiles=True, to_easting_northing=True)  # or some other kwarg

Or, if it detects the x is between -180, 360 and y is between -90, 90 without any crs/projection kwargs, automatically convert to easting/northing?

import hvplot.xarray
import xarray as xr

ds = xr.tutorial.load_dataset("air_temperature").isel(time=slice(0, 100))
# automatic detection
ds.hvplot("lon", "lat", tiles=True)
jbednar commented 1 month ago

I'd be ok with assuming lat,lon inputs with geo=True and projecting them using our own internal functions from HoloViews without having to bring in geoviews/cartopy/proj for that one common case. I would not be ok with checking the ranges and automatically converting; at best that could be a warning (maybe people really do want to look at some tiny area of the earth, or vice versa!).

ahuang11 commented 1 month ago

Okay I think a warning is probably good, because without it, the data is centered around 0 and that can be confusing.

image