Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bad function call in Jupyter tool #36

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions glue_ar/jupyter/export_tool.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from os import getcwd
from os.path import exists
from os.path import exists, splitext
from typing import Dict, Iterable, Tuple

from glue.config import viewer_tool
from glue.core.state_objects import State
from glue.viewers.common.state import LayerState
from glue.viewers.common.tool import Tool
from glue_vispy_viewers.volume.qt.volume_viewer import VispyVolumeViewerMixin

from glue_ar.common.export import export_to_ar
from glue_ar.utils import AR_ICON
from glue_ar.common.export import export_viewer
from glue_ar.common.export_options import ar_layer_export
from glue_ar.utils import AR_ICON, export_label_for_layer, xyz_bounds

import ipyvuetify as v # noqa
from ipywidgets import HBox, Layout # noqa
Expand Down Expand Up @@ -88,5 +93,30 @@ def on_no_click(button, event, data):
self.save_figure(filepath)
self.viewer.output_widget.clear_output()

def _state_dictionary(self,
layers: Iterable[LayerState],
filetype: str) -> Dict[str, Tuple[str, State]]:
state_dict = {}
for layer in layers:
label = export_label_for_layer(layer)
layer_state_cls = type(layer.state)
states = ar_layer_export.export_state_classes(layer_state_cls)
method_names = ar_layer_export.method_names(layer_state_cls, filetype)
method = method_names[0]
state_cls = next(t[1] for t in states if t[0] == method)
state = state_cls()
state_dict[label] = (method, state)

return state_dict

def save_figure(self, filepath):
export_to_ar(self.viewer, filepath, state_dict={}, compression="draco")
bounds = xyz_bounds(self.viewer.state, with_resolution=isinstance(self.viewer, VispyVolumeViewerMixin))
layers = [layer for layer in self.viewer.layers if layer.enabled and layer.state.visible]
filetype = splitext(filepath)[1][1:]
state_dict = self._state_dictionary(layers, filetype)
export_viewer(viewer_state=self.viewer.state,
layer_states=[layer.state for layer in self.viewer.layers
if layer.enabled and layer.state.visible],
bounds=bounds,
state_dictionary=state_dict,
filepath=filepath)