Skip to content

Commit

Permalink
defer to_script functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Aug 7, 2024
1 parent 8ae0c5b commit 78357a0
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,6 @@ def smooth(self, add_data=True):
spec : `~specutils.Spectrum1D`
The smoothed spectrum or data cube
"""
plugin_state = self.user_api.to_dict()
plugin_script = self.user_api.to_script(as_string=False)

if self.mode_selected == 'Spatial':
if self.config != 'cubeviz':
raise NotImplementedError("spatial smoothing only supported for Cubeviz")
Expand All @@ -174,12 +171,6 @@ def smooth(self, add_data=True):
else:
results = self.spectral_smooth()

if '_jdaviz_history' not in results.meta.keys():
results.meta['_jdaviz_history'] = []
results.meta['_jdaviz_script'] = []
results.meta['_jdaviz_history'] += [plugin_state]
results.meta['_jdaviz_script'] += plugin_script + ['plg.smooth()']

if add_data:
# add data to the collection/viewer
self.add_results.add_results_from_plugin(results)
Expand Down
7 changes: 0 additions & 7 deletions jdaviz/core/template_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3392,13 +3392,6 @@ def __init__(self, plugin, items, selected,
# initialize items from original viewers
self._on_data_changed()

def to_script(self, as_string=False):
script = [f"{self.app.config}.load_data({self.selected_obj}, data_label='{self.selected})'"]
script += [f"plg.selected = '{self.selected}'"]
if as_string:
return "\n".join(script)
return script

@property
def default_data_cls(self):
if self.app.config == 'imviz':
Expand Down
18 changes: 0 additions & 18 deletions jdaviz/core/user_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,24 +141,6 @@ def __repr__(self):
super().__setattr__('_deprecation_msg', None)
return f'<{self._obj._registry_label} API>'

def to_script(self, as_string=True):
def _value_as_str(v):
if isinstance(v, str):
return f"'{v}'"
return v
script = [f"plg = {self._obj.app.config}.plugins['{self._obj._registry_label}']"]
for k, v in self.to_dict().items():
if hasattr(getattr(self, k), "to_script"):
script += getattr(self, k).to_script(as_string=False)
elif isinstance(v, dict):
# TODO: make recursive
script += [f"plg.{k}.{kk} = {_value_as_str(vv)}" for kk, vv in v.items()]
else:
script += [f"plg.{k} = {_value_as_str(v)}"]
if as_string:
return "\n".join(script)
return script


class ViewerUserApi(UserApiWrapper):
"""
Expand Down

0 comments on commit 78357a0

Please sign in to comment.