From 817c34f7bdaa888ae4e9376ef6a094c5bf4a6cb5 Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Thu, 28 Mar 2024 17:16:37 -0400 Subject: [PATCH] Guess lat/lon columns for viewer if there's only one layer. --- glue_wwt/viewer/data_viewer.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/glue_wwt/viewer/data_viewer.py b/glue_wwt/viewer/data_viewer.py index 30ca01c5..fd2fb6ea 100644 --- a/glue_wwt/viewer/data_viewer.py +++ b/glue_wwt/viewer/data_viewer.py @@ -7,6 +7,7 @@ from glue.core.coordinates import WCSCoordinates from glue.logger import logger from pywwt import ViewerNotAvailableError +from pywwt.layers import guess_lon_lat_columns from .image_layer import WWTImageLayerArtist from .table_layer import WWTTableLayerArtist @@ -127,3 +128,13 @@ def __setgluestate__(cls, rec, context): camera_kwargs["roll"] = roll * u.deg viewer._wwt.center_on_coordinates(SkyCoord(ra, dec, unit=u.deg), **camera_kwargs) return viewer + + def add_data(self, data): + add = super().add_data(data) + if add and len(self.state.layers) == 1: + colnames = [c.label for c in data.components] + lon, lat = guess_lon_lat_columns(colnames) + if lon is not None and lat is not None: + self.state.lon_att = data.id[lon] + self.state.lat_att = data.id[lat] + return add