Skip to content

Commit

Permalink
Add ginga Spec1dView plugin to view 1dspec files (#1858)
Browse files Browse the repository at this point in the history
- Created 1d spec viewer plugin in Ginga
* New viewer to show 1d Spec Files
* Add hooks to run pypeit_show_1dspec using ginga as the viewer
* Addressed PR comments
  - added docstrings
  - extensions now shown and selected using names
  - Properly handle command line parameters to pypeit_show_1dspec
  - Add "Plot error" checkbox to the Ginga Spec1dView plugin
  - Make title of the plot include the extension name
  - Add autozoom feature when changing extensions or files
  - Handle situation in which OPT or BOX extraction is missing
* Update Ginga requirement to v5.2.0

Co-authored-by: Maile Brilhante <[email protected]>
  • Loading branch information
ejeschke and mailebrilhante authored Nov 13, 2024
1 parent 693d727 commit 6a16f26
Show file tree
Hide file tree
Showing 5 changed files with 564 additions and 4 deletions.
6 changes: 6 additions & 0 deletions pypeit/display/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ def setup_SlitWavelength():
module='ginga_plugins', klass='SlitWavelength',
ptype='global', workspace='right', start=False,
category='PypeIt', menu='SlitWavelength', tab='SlitWavelength')

def setup_Spec1dView():
return Bunch(path=os.path.join(os.path.split(__file__)[0], 'ginga_spec1dview.py'),
module='ginga_spec1dview', klass='Spec1dView',
ptype='local', workspace='right', start=False,
category='PypeIt', menu='Spec1dView', tab='Spec1dView')
27 changes: 26 additions & 1 deletion pypeit/display/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def show_slits(viewer, ch, left, right, slit_ids=None, left_ids=None, right_ids=

_right = right.reshape(-1,1) if right.ndim == 1 else right
nright = _right.shape[1]

nspec = _left.shape[0]
if _right.shape[0] != nspec:
# TODO: Any reason to remove this restriction?
Expand Down Expand Up @@ -667,3 +667,28 @@ def show_scattered_light(image_list, slits=None, wcs_match=True):
if clear:
clear = False


def show_1dspec(filename, ext=0, masked=True, fluxed=False, extraction='OPT'):
"""
Interface to ginga to show a 1dspec and manipulate with Spec1dView plugin.
Parameters
----------
filename : str
spec1d FITS file to show in the viewer
ext : int
extension to show (which spectrum)
"""
viewer = connect_to_ginga(raise_err=True, allow_new=True)
sh = viewer.shell()

chname, plname = "Spec1d", "Spec1dView"
sh.add_channel(chname)
ch = viewer.channel(chname)
# set up the options as passed
kwargs = dict(ext=ext, extraction=extraction, masked=masked, fluxed=fluxed)
sh.call_local_plugin_method(chname, plname, 'set_params', [], kwargs)
# start the plugin
sh.start_local_plugin(chname, plname)
# load the file
sh.load_file(filename, chname=chname)
Loading

0 comments on commit 6a16f26

Please sign in to comment.