id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
51
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
26,200
ejeschke/ginga
ginga/rv/Control.py
GingaShell.get_plugin_spec
def get_plugin_spec(self, name): """Get the specification attributes for plugin with name `name`.""" l_name = name.lower() for spec in self.plugins: name = spec.get('name', spec.get('klass', spec.module)) if name.lower() == l_name: return spec raise KeyError(name)
python
def get_plugin_spec(self, name): l_name = name.lower() for spec in self.plugins: name = spec.get('name', spec.get('klass', spec.module)) if name.lower() == l_name: return spec raise KeyError(name)
[ "def", "get_plugin_spec", "(", "self", ",", "name", ")", ":", "l_name", "=", "name", ".", "lower", "(", ")", "for", "spec", "in", "self", ".", "plugins", ":", "name", "=", "spec", ".", "get", "(", "'name'", ",", "spec", ".", "get", "(", "'klass'", ...
Get the specification attributes for plugin with name `name`.
[ "Get", "the", "specification", "attributes", "for", "plugin", "with", "name", "name", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L397-L404
26,201
ejeschke/ginga
ginga/rv/Control.py
GingaShell.help_text
def help_text(self, name, text, text_kind='plain', trim_pfx=0): """ Provide help text for the user. This method will convert the text as necessary with docutils and display it in the WBrowser plugin, if available. If the plugin is not available and the text is type 'rst' then the text will be displayed in a plain text widget. Parameters ---------- name : str Category of help to show. text : str The text to show. Should be plain, HTML or RST text text_kind : str (optional) One of 'plain', 'html', 'rst'. Default is 'plain'. trim_pfx : int (optional) Number of spaces to trim off the beginning of each line of text. """ if trim_pfx > 0: # caller wants to trim some space off the front # of each line text = toolbox.trim_prefix(text, trim_pfx) if text_kind == 'rst': # try to convert RST to HTML using docutils try: overrides = {'input_encoding': 'ascii', 'output_encoding': 'utf-8'} text_html = publish_string(text, writer_name='html', settings_overrides=overrides) # docutils produces 'bytes' output, but webkit needs # a utf-8 string text = text_html.decode('utf-8') text_kind = 'html' except Exception as e: self.logger.error("Error converting help text to HTML: %s" % ( str(e))) # revert to showing RST as plain text else: raise ValueError( "I don't know how to display text of kind '%s'" % (text_kind)) if text_kind == 'html': self.help(text=text, text_kind='html') else: self.show_help_text(name, text)
python
def help_text(self, name, text, text_kind='plain', trim_pfx=0): if trim_pfx > 0: # caller wants to trim some space off the front # of each line text = toolbox.trim_prefix(text, trim_pfx) if text_kind == 'rst': # try to convert RST to HTML using docutils try: overrides = {'input_encoding': 'ascii', 'output_encoding': 'utf-8'} text_html = publish_string(text, writer_name='html', settings_overrides=overrides) # docutils produces 'bytes' output, but webkit needs # a utf-8 string text = text_html.decode('utf-8') text_kind = 'html' except Exception as e: self.logger.error("Error converting help text to HTML: %s" % ( str(e))) # revert to showing RST as plain text else: raise ValueError( "I don't know how to display text of kind '%s'" % (text_kind)) if text_kind == 'html': self.help(text=text, text_kind='html') else: self.show_help_text(name, text)
[ "def", "help_text", "(", "self", ",", "name", ",", "text", ",", "text_kind", "=", "'plain'", ",", "trim_pfx", "=", "0", ")", ":", "if", "trim_pfx", ">", "0", ":", "# caller wants to trim some space off the front", "# of each line", "text", "=", "toolbox", ".",...
Provide help text for the user. This method will convert the text as necessary with docutils and display it in the WBrowser plugin, if available. If the plugin is not available and the text is type 'rst' then the text will be displayed in a plain text widget. Parameters ---------- name : str Category of help to show. text : str The text to show. Should be plain, HTML or RST text text_kind : str (optional) One of 'plain', 'html', 'rst'. Default is 'plain'. trim_pfx : int (optional) Number of spaces to trim off the beginning of each line of text.
[ "Provide", "help", "text", "for", "the", "user", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L455-L510
26,202
ejeschke/ginga
ginga/rv/Control.py
GingaShell.load_file
def load_file(self, filepath, chname=None, wait=True, create_channel=True, display_image=True, image_loader=None): """Load a file and display it. Parameters ---------- filepath : str The path of the file to load (must reference a local file). chname : str, optional The name of the channel in which to display the image. wait : bool, optional If `True`, then wait for the file to be displayed before returning (synchronous behavior). create_channel : bool, optional Create channel. display_image : bool, optional If not `False`, then will load the image. image_loader : func, optional A special image loader, if provided. Returns ------- image The image object that was loaded. """ if not chname: channel = self.get_current_channel() else: if not self.has_channel(chname) and create_channel: self.gui_call(self.add_channel, chname) channel = self.get_channel(chname) chname = channel.name if image_loader is None: image_loader = self.load_image cache_dir = self.settings.get('download_folder', self.tmpdir) info = iohelper.get_fileinfo(filepath, cache_dir=cache_dir) # check that file is locally accessible if not info.ondisk: errmsg = "File must be locally loadable: %s" % (filepath) self.gui_do(self.show_error, errmsg) return filepath = info.filepath kwargs = {} idx = None if info.numhdu is not None: kwargs['idx'] = info.numhdu try: image = image_loader(filepath, **kwargs) except Exception as e: errmsg = "Failed to load '%s': %s" % (filepath, str(e)) self.gui_do(self.show_error, errmsg) return future = Future.Future() future.freeze(image_loader, filepath, **kwargs) # Save a future for this image to reload it later if we # have to remove it from memory image.set(loader=image_loader, image_future=future) if image.get('path', None) is None: image.set(path=filepath) # Assign a name to the image if the loader did not. name = image.get('name', None) if name is None: name = iohelper.name_image_from_path(filepath, idx=idx) image.set(name=name) if display_image: # Display image. If the wait parameter is False then don't wait # for the image to load into the viewer if wait: self.gui_call(self.add_image, name, image, chname=chname) else: self.gui_do(self.add_image, name, image, chname=chname) else: self.gui_do(self.bulk_add_image, name, image, chname) # Return the image return image
python
def load_file(self, filepath, chname=None, wait=True, create_channel=True, display_image=True, image_loader=None): if not chname: channel = self.get_current_channel() else: if not self.has_channel(chname) and create_channel: self.gui_call(self.add_channel, chname) channel = self.get_channel(chname) chname = channel.name if image_loader is None: image_loader = self.load_image cache_dir = self.settings.get('download_folder', self.tmpdir) info = iohelper.get_fileinfo(filepath, cache_dir=cache_dir) # check that file is locally accessible if not info.ondisk: errmsg = "File must be locally loadable: %s" % (filepath) self.gui_do(self.show_error, errmsg) return filepath = info.filepath kwargs = {} idx = None if info.numhdu is not None: kwargs['idx'] = info.numhdu try: image = image_loader(filepath, **kwargs) except Exception as e: errmsg = "Failed to load '%s': %s" % (filepath, str(e)) self.gui_do(self.show_error, errmsg) return future = Future.Future() future.freeze(image_loader, filepath, **kwargs) # Save a future for this image to reload it later if we # have to remove it from memory image.set(loader=image_loader, image_future=future) if image.get('path', None) is None: image.set(path=filepath) # Assign a name to the image if the loader did not. name = image.get('name', None) if name is None: name = iohelper.name_image_from_path(filepath, idx=idx) image.set(name=name) if display_image: # Display image. If the wait parameter is False then don't wait # for the image to load into the viewer if wait: self.gui_call(self.add_image, name, image, chname=chname) else: self.gui_do(self.add_image, name, image, chname=chname) else: self.gui_do(self.bulk_add_image, name, image, chname) # Return the image return image
[ "def", "load_file", "(", "self", ",", "filepath", ",", "chname", "=", "None", ",", "wait", "=", "True", ",", "create_channel", "=", "True", ",", "display_image", "=", "True", ",", "image_loader", "=", "None", ")", ":", "if", "not", "chname", ":", "chan...
Load a file and display it. Parameters ---------- filepath : str The path of the file to load (must reference a local file). chname : str, optional The name of the channel in which to display the image. wait : bool, optional If `True`, then wait for the file to be displayed before returning (synchronous behavior). create_channel : bool, optional Create channel. display_image : bool, optional If not `False`, then will load the image. image_loader : func, optional A special image loader, if provided. Returns ------- image The image object that was loaded.
[ "Load", "a", "file", "and", "display", "it", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L615-L710
26,203
ejeschke/ginga
ginga/rv/Control.py
GingaShell.add_download
def add_download(self, info, future): """ Hand off a download to the Downloads plugin, if it is present. Parameters ---------- info : `~ginga.misc.Bunch.Bunch` A bunch of information about the URI as returned by `ginga.util.iohelper.get_fileinfo()` future : `~ginga.misc.Future.Future` A future that represents the future computation to be performed after downloading the file. Resolving the future will trigger the computation. """ if self.gpmon.has_plugin('Downloads'): obj = self.gpmon.get_plugin('Downloads') self.gui_do(obj.add_download, info, future) else: self.show_error("Please activate the 'Downloads' plugin to" " enable download functionality")
python
def add_download(self, info, future): if self.gpmon.has_plugin('Downloads'): obj = self.gpmon.get_plugin('Downloads') self.gui_do(obj.add_download, info, future) else: self.show_error("Please activate the 'Downloads' plugin to" " enable download functionality")
[ "def", "add_download", "(", "self", ",", "info", ",", "future", ")", ":", "if", "self", ".", "gpmon", ".", "has_plugin", "(", "'Downloads'", ")", ":", "obj", "=", "self", ".", "gpmon", ".", "get_plugin", "(", "'Downloads'", ")", "self", ".", "gui_do", ...
Hand off a download to the Downloads plugin, if it is present. Parameters ---------- info : `~ginga.misc.Bunch.Bunch` A bunch of information about the URI as returned by `ginga.util.iohelper.get_fileinfo()` future : `~ginga.misc.Future.Future` A future that represents the future computation to be performed after downloading the file. Resolving the future will trigger the computation.
[ "Hand", "off", "a", "download", "to", "the", "Downloads", "plugin", "if", "it", "is", "present", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L712-L732
26,204
ejeschke/ginga
ginga/rv/Control.py
GingaShell.open_file_cont
def open_file_cont(self, pathspec, loader_cont_fn): """Open a file and do some action on it. Parameters ---------- pathspec : str The path of the file to load (can be a URI, but must reference a local file). loader_cont_fn : func (data_obj) -> None A continuation consisting of a function of one argument that does something with the data_obj created by the loader """ info = iohelper.get_fileinfo(pathspec) filepath = info.filepath if not os.path.exists(filepath): errmsg = "File does not appear to exist: '%s'" % (filepath) self.gui_do(self.show_error, errmsg) return try: typ, subtyp = iohelper.guess_filetype(filepath) except Exception as e: self.logger.warning("error determining file type: %s; " "assuming 'image/fits'" % (str(e))) # Can't determine file type: assume and attempt FITS typ, subtyp = 'image', 'fits' mimetype = "%s/%s" % (typ, subtyp) try: opener_class = loader.get_opener(mimetype) except KeyError: # TODO: here pop up a dialog asking which loader to use errmsg = "No registered opener for: '%s'" % (mimetype) self.gui_do(self.show_error, errmsg) return # kwd args to pass to opener kwargs = dict() inherit_prihdr = self.settings.get('inherit_primary_header', False) kwargs['inherit_primary_header'] = inherit_prihdr # open the file and load the items named by the index opener = opener_class(self.logger) try: with opener.open_file(filepath) as io_f: io_f.load_idx_cont(info.idx, loader_cont_fn, **kwargs) except Exception as e: errmsg = "Error opening '%s': %s" % (filepath, str(e)) try: (type, value, tb) = sys.exc_info() tb_str = "\n".join(traceback.format_tb(tb)) except Exception as e: tb_str = "Traceback information unavailable." self.gui_do(self.show_error, errmsg + '\n' + tb_str)
python
def open_file_cont(self, pathspec, loader_cont_fn): info = iohelper.get_fileinfo(pathspec) filepath = info.filepath if not os.path.exists(filepath): errmsg = "File does not appear to exist: '%s'" % (filepath) self.gui_do(self.show_error, errmsg) return try: typ, subtyp = iohelper.guess_filetype(filepath) except Exception as e: self.logger.warning("error determining file type: %s; " "assuming 'image/fits'" % (str(e))) # Can't determine file type: assume and attempt FITS typ, subtyp = 'image', 'fits' mimetype = "%s/%s" % (typ, subtyp) try: opener_class = loader.get_opener(mimetype) except KeyError: # TODO: here pop up a dialog asking which loader to use errmsg = "No registered opener for: '%s'" % (mimetype) self.gui_do(self.show_error, errmsg) return # kwd args to pass to opener kwargs = dict() inherit_prihdr = self.settings.get('inherit_primary_header', False) kwargs['inherit_primary_header'] = inherit_prihdr # open the file and load the items named by the index opener = opener_class(self.logger) try: with opener.open_file(filepath) as io_f: io_f.load_idx_cont(info.idx, loader_cont_fn, **kwargs) except Exception as e: errmsg = "Error opening '%s': %s" % (filepath, str(e)) try: (type, value, tb) = sys.exc_info() tb_str = "\n".join(traceback.format_tb(tb)) except Exception as e: tb_str = "Traceback information unavailable." self.gui_do(self.show_error, errmsg + '\n' + tb_str)
[ "def", "open_file_cont", "(", "self", ",", "pathspec", ",", "loader_cont_fn", ")", ":", "info", "=", "iohelper", ".", "get_fileinfo", "(", "pathspec", ")", "filepath", "=", "info", ".", "filepath", "if", "not", "os", ".", "path", ".", "exists", "(", "fil...
Open a file and do some action on it. Parameters ---------- pathspec : str The path of the file to load (can be a URI, but must reference a local file). loader_cont_fn : func (data_obj) -> None A continuation consisting of a function of one argument that does something with the data_obj created by the loader
[ "Open", "a", "file", "and", "do", "some", "action", "on", "it", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L772-L833
26,205
ejeschke/ginga
ginga/rv/Control.py
GingaShell.open_uris
def open_uris(self, uris, chname=None, bulk_add=False): """Open a set of URIs. Parameters ---------- uris : list of str The URIs of the files to load chname: str, optional (defaults to channel with focus) The name of the channel in which to load the items bulk_add : bool, optional (defaults to False) If True, then all the data items are loaded into the channel without disturbing the current item there. If False, then the first item loaded will be displayed and the rest of the items will be loaded as bulk. """ if len(uris) == 0: return if chname is None: channel = self.get_channel_info() if channel is None: # No active channel to load these into return chname = channel.name channel = self.get_channel_on_demand(chname) def show_dataobj_bulk(data_obj): self.gui_do(channel.add_image, data_obj, bulk_add=True) def load_file_bulk(filepath): self.nongui_do(self.open_file_cont, filepath, show_dataobj_bulk) def show_dataobj(data_obj): self.gui_do(channel.add_image, data_obj, bulk_add=False) def load_file(filepath): self.nongui_do(self.open_file_cont, filepath, show_dataobj) # determine whether first file is loaded as a bulk load if bulk_add: self.open_uri_cont(uris[0], load_file_bulk) else: self.open_uri_cont(uris[0], load_file) self.update_pending() for uri in uris[1:]: # rest of files are all loaded using bulk load self.open_uri_cont(uri, load_file_bulk) self.update_pending()
python
def open_uris(self, uris, chname=None, bulk_add=False): if len(uris) == 0: return if chname is None: channel = self.get_channel_info() if channel is None: # No active channel to load these into return chname = channel.name channel = self.get_channel_on_demand(chname) def show_dataobj_bulk(data_obj): self.gui_do(channel.add_image, data_obj, bulk_add=True) def load_file_bulk(filepath): self.nongui_do(self.open_file_cont, filepath, show_dataobj_bulk) def show_dataobj(data_obj): self.gui_do(channel.add_image, data_obj, bulk_add=False) def load_file(filepath): self.nongui_do(self.open_file_cont, filepath, show_dataobj) # determine whether first file is loaded as a bulk load if bulk_add: self.open_uri_cont(uris[0], load_file_bulk) else: self.open_uri_cont(uris[0], load_file) self.update_pending() for uri in uris[1:]: # rest of files are all loaded using bulk load self.open_uri_cont(uri, load_file_bulk) self.update_pending()
[ "def", "open_uris", "(", "self", ",", "uris", ",", "chname", "=", "None", ",", "bulk_add", "=", "False", ")", ":", "if", "len", "(", "uris", ")", "==", "0", ":", "return", "if", "chname", "is", "None", ":", "channel", "=", "self", ".", "get_channel...
Open a set of URIs. Parameters ---------- uris : list of str The URIs of the files to load chname: str, optional (defaults to channel with focus) The name of the channel in which to load the items bulk_add : bool, optional (defaults to False) If True, then all the data items are loaded into the channel without disturbing the current item there. If False, then the first item loaded will be displayed and the rest of the items will be loaded as bulk.
[ "Open", "a", "set", "of", "URIs", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L835-L886
26,206
ejeschke/ginga
ginga/rv/Control.py
GingaShell.zoom_in
def zoom_in(self): """Zoom the view in one zoom step. """ viewer = self.getfocus_viewer() if hasattr(viewer, 'zoom_in'): viewer.zoom_in() return True
python
def zoom_in(self): viewer = self.getfocus_viewer() if hasattr(viewer, 'zoom_in'): viewer.zoom_in() return True
[ "def", "zoom_in", "(", "self", ")", ":", "viewer", "=", "self", ".", "getfocus_viewer", "(", ")", "if", "hasattr", "(", "viewer", ",", "'zoom_in'", ")", ":", "viewer", ".", "zoom_in", "(", ")", "return", "True" ]
Zoom the view in one zoom step.
[ "Zoom", "the", "view", "in", "one", "zoom", "step", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L923-L929
26,207
ejeschke/ginga
ginga/rv/Control.py
GingaShell.zoom_out
def zoom_out(self): """Zoom the view out one zoom step. """ viewer = self.getfocus_viewer() if hasattr(viewer, 'zoom_out'): viewer.zoom_out() return True
python
def zoom_out(self): viewer = self.getfocus_viewer() if hasattr(viewer, 'zoom_out'): viewer.zoom_out() return True
[ "def", "zoom_out", "(", "self", ")", ":", "viewer", "=", "self", ".", "getfocus_viewer", "(", ")", "if", "hasattr", "(", "viewer", ",", "'zoom_out'", ")", ":", "viewer", ".", "zoom_out", "(", ")", "return", "True" ]
Zoom the view out one zoom step.
[ "Zoom", "the", "view", "out", "one", "zoom", "step", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L931-L937
26,208
ejeschke/ginga
ginga/rv/Control.py
GingaShell.zoom_fit
def zoom_fit(self): """Zoom the view to fit the image entirely in the window. """ viewer = self.getfocus_viewer() if hasattr(viewer, 'zoom_fit'): viewer.zoom_fit() return True
python
def zoom_fit(self): viewer = self.getfocus_viewer() if hasattr(viewer, 'zoom_fit'): viewer.zoom_fit() return True
[ "def", "zoom_fit", "(", "self", ")", ":", "viewer", "=", "self", ".", "getfocus_viewer", "(", ")", "if", "hasattr", "(", "viewer", ",", "'zoom_fit'", ")", ":", "viewer", ".", "zoom_fit", "(", ")", "return", "True" ]
Zoom the view to fit the image entirely in the window.
[ "Zoom", "the", "view", "to", "fit", "the", "image", "entirely", "in", "the", "window", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L947-L953
26,209
ejeschke/ginga
ginga/rv/Control.py
GingaShell.prev_img_ws
def prev_img_ws(self, ws, loop=True): """Go to the previous image in the focused channel in the workspace. """ channel = self.get_active_channel_ws(ws) if channel is None: return channel.prev_image() return True
python
def prev_img_ws(self, ws, loop=True): channel = self.get_active_channel_ws(ws) if channel is None: return channel.prev_image() return True
[ "def", "prev_img_ws", "(", "self", ",", "ws", ",", "loop", "=", "True", ")", ":", "channel", "=", "self", ".", "get_active_channel_ws", "(", "ws", ")", "if", "channel", "is", "None", ":", "return", "channel", ".", "prev_image", "(", ")", "return", "Tru...
Go to the previous image in the focused channel in the workspace.
[ "Go", "to", "the", "previous", "image", "in", "the", "focused", "channel", "in", "the", "workspace", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L962-L969
26,210
ejeschke/ginga
ginga/rv/Control.py
GingaShell.next_img_ws
def next_img_ws(self, ws, loop=True): """Go to the next image in the focused channel in the workspace. """ channel = self.get_active_channel_ws(ws) if channel is None: return channel.next_image() return True
python
def next_img_ws(self, ws, loop=True): channel = self.get_active_channel_ws(ws) if channel is None: return channel.next_image() return True
[ "def", "next_img_ws", "(", "self", ",", "ws", ",", "loop", "=", "True", ")", ":", "channel", "=", "self", ".", "get_active_channel_ws", "(", "ws", ")", "if", "channel", "is", "None", ":", "return", "channel", ".", "next_image", "(", ")", "return", "Tru...
Go to the next image in the focused channel in the workspace.
[ "Go", "to", "the", "next", "image", "in", "the", "focused", "channel", "in", "the", "workspace", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L971-L978
26,211
ejeschke/ginga
ginga/rv/Control.py
GingaShell.prev_img
def prev_img(self, loop=True): """Go to the previous image in the channel. """ channel = self.get_current_channel() if channel is None: self.show_error("Please create a channel.", raisetab=True) return channel.prev_image() return True
python
def prev_img(self, loop=True): channel = self.get_current_channel() if channel is None: self.show_error("Please create a channel.", raisetab=True) return channel.prev_image() return True
[ "def", "prev_img", "(", "self", ",", "loop", "=", "True", ")", ":", "channel", "=", "self", ".", "get_current_channel", "(", ")", "if", "channel", "is", "None", ":", "self", ".", "show_error", "(", "\"Please create a channel.\"", ",", "raisetab", "=", "Tru...
Go to the previous image in the channel.
[ "Go", "to", "the", "previous", "image", "in", "the", "channel", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L980-L988
26,212
ejeschke/ginga
ginga/rv/Control.py
GingaShell.next_img
def next_img(self, loop=True): """Go to the next image in the channel. """ channel = self.get_current_channel() if channel is None: self.show_error("Please create a channel.", raisetab=True) return channel.next_image() return True
python
def next_img(self, loop=True): channel = self.get_current_channel() if channel is None: self.show_error("Please create a channel.", raisetab=True) return channel.next_image() return True
[ "def", "next_img", "(", "self", ",", "loop", "=", "True", ")", ":", "channel", "=", "self", ".", "get_current_channel", "(", ")", "if", "channel", "is", "None", ":", "self", ".", "show_error", "(", "\"Please create a channel.\"", ",", "raisetab", "=", "Tru...
Go to the next image in the channel.
[ "Go", "to", "the", "next", "image", "in", "the", "channel", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L990-L998
26,213
ejeschke/ginga
ginga/rv/Control.py
GingaShell.close_plugins
def close_plugins(self, channel): """Close all plugins associated with the channel.""" opmon = channel.opmon for key in opmon.get_active(): obj = opmon.get_plugin(key) try: self.gui_call(obj.close) except Exception as e: self.logger.error( "Failed to continue operation: %s" % (str(e)))
python
def close_plugins(self, channel): opmon = channel.opmon for key in opmon.get_active(): obj = opmon.get_plugin(key) try: self.gui_call(obj.close) except Exception as e: self.logger.error( "Failed to continue operation: %s" % (str(e)))
[ "def", "close_plugins", "(", "self", ",", "channel", ")", ":", "opmon", "=", "channel", ".", "opmon", "for", "key", "in", "opmon", ".", "get_active", "(", ")", ":", "obj", "=", "opmon", ".", "get_plugin", "(", "key", ")", "try", ":", "self", ".", "...
Close all plugins associated with the channel.
[ "Close", "all", "plugins", "associated", "with", "the", "channel", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L1227-L1237
26,214
ejeschke/ginga
ginga/rv/Control.py
GingaShell.add_channel
def add_channel(self, chname, workspace=None, num_images=None, settings=None, settings_template=None, settings_share=None, share_keylist=None): """Create a new Ginga channel. Parameters ---------- chname : str The name of the channel to create. workspace : str or None The name of the workspace in which to create the channel num_images : int or None The cache size for the number of images to keep in memory settings : `~ginga.misc.Settings.SettingGroup` or `None` Viewer preferences. If not given, one will be created. settings_template : `~ginga.misc.Settings.SettingGroup` or `None` Viewer preferences template settings_share : `~ginga.misc.Settings.SettingGroup` or `None` Viewer preferences instance to share with newly created settings share_keylist : list of str List of names of settings that should be shared Returns ------- channel : `~ginga.misc.Bunch.Bunch` The channel info bunch. """ with self.lock: if self.has_channel(chname): return self.get_channel(chname) if chname in self.ds.get_tabnames(None): raise ValueError("Tab name already in use: '%s'" % (chname)) name = chname if settings is None: settings = self.prefs.create_category('channel_' + name) try: settings.load(onError='raise') except Exception as e: self.logger.warning("no saved preferences found for channel " "'%s': %s" % (name, str(e))) # copy template settings to new channel if settings_template is not None: osettings = settings_template osettings.copy_settings(settings) else: try: # use channel_Image as a template if one was not # provided osettings = self.prefs.get_settings('channel_Image') self.logger.debug("Copying settings from 'Image' to " "'%s'" % (name)) osettings.copy_settings(settings) except KeyError: pass if (share_keylist is not None) and (settings_share is not None): # caller wants us to share settings with another viewer settings_share.share_settings(settings, keylist=share_keylist) # Make sure these preferences are at least defined if num_images is None: num_images = settings.get('numImages', self.settings.get('numImages', 1)) settings.set_defaults(switchnew=True, numImages=num_images, raisenew=True, genthumb=True, focus_indicator=False, preload_images=False, sort_order='loadtime') self.logger.debug("Adding channel '%s'" % (chname)) channel = Channel(chname, self, datasrc=None, settings=settings) bnch = self.add_viewer(chname, settings, workspace=workspace) # for debugging bnch.image_viewer.set_name('channel:%s' % (chname)) opmon = self.get_plugin_manager(self.logger, self, self.ds, self.mm) channel.widget = bnch.widget channel.container = bnch.container channel.workspace = bnch.workspace channel.connect_viewer(bnch.image_viewer) channel.viewer = bnch.image_viewer # older name, should eventually be deprecated channel.fitsimage = bnch.image_viewer channel.opmon = opmon name = chname.lower() self.channel[name] = channel # Update the channels control self.channel_names.append(chname) self.channel_names.sort() if len(self.channel_names) == 1: self.cur_channel = channel # Prepare local plugins for this channel for spec in self.get_plugins(): opname = spec.get('klass', spec.get('module')) if spec.get('ptype', 'global') == 'local': opmon.load_plugin(opname, spec, chinfo=channel) self.make_gui_callback('add-channel', channel) return channel
python
def add_channel(self, chname, workspace=None, num_images=None, settings=None, settings_template=None, settings_share=None, share_keylist=None): with self.lock: if self.has_channel(chname): return self.get_channel(chname) if chname in self.ds.get_tabnames(None): raise ValueError("Tab name already in use: '%s'" % (chname)) name = chname if settings is None: settings = self.prefs.create_category('channel_' + name) try: settings.load(onError='raise') except Exception as e: self.logger.warning("no saved preferences found for channel " "'%s': %s" % (name, str(e))) # copy template settings to new channel if settings_template is not None: osettings = settings_template osettings.copy_settings(settings) else: try: # use channel_Image as a template if one was not # provided osettings = self.prefs.get_settings('channel_Image') self.logger.debug("Copying settings from 'Image' to " "'%s'" % (name)) osettings.copy_settings(settings) except KeyError: pass if (share_keylist is not None) and (settings_share is not None): # caller wants us to share settings with another viewer settings_share.share_settings(settings, keylist=share_keylist) # Make sure these preferences are at least defined if num_images is None: num_images = settings.get('numImages', self.settings.get('numImages', 1)) settings.set_defaults(switchnew=True, numImages=num_images, raisenew=True, genthumb=True, focus_indicator=False, preload_images=False, sort_order='loadtime') self.logger.debug("Adding channel '%s'" % (chname)) channel = Channel(chname, self, datasrc=None, settings=settings) bnch = self.add_viewer(chname, settings, workspace=workspace) # for debugging bnch.image_viewer.set_name('channel:%s' % (chname)) opmon = self.get_plugin_manager(self.logger, self, self.ds, self.mm) channel.widget = bnch.widget channel.container = bnch.container channel.workspace = bnch.workspace channel.connect_viewer(bnch.image_viewer) channel.viewer = bnch.image_viewer # older name, should eventually be deprecated channel.fitsimage = bnch.image_viewer channel.opmon = opmon name = chname.lower() self.channel[name] = channel # Update the channels control self.channel_names.append(chname) self.channel_names.sort() if len(self.channel_names) == 1: self.cur_channel = channel # Prepare local plugins for this channel for spec in self.get_plugins(): opname = spec.get('klass', spec.get('module')) if spec.get('ptype', 'global') == 'local': opmon.load_plugin(opname, spec, chinfo=channel) self.make_gui_callback('add-channel', channel) return channel
[ "def", "add_channel", "(", "self", ",", "chname", ",", "workspace", "=", "None", ",", "num_images", "=", "None", ",", "settings", "=", "None", ",", "settings_template", "=", "None", ",", "settings_share", "=", "None", ",", "share_keylist", "=", "None", ")"...
Create a new Ginga channel. Parameters ---------- chname : str The name of the channel to create. workspace : str or None The name of the workspace in which to create the channel num_images : int or None The cache size for the number of images to keep in memory settings : `~ginga.misc.Settings.SettingGroup` or `None` Viewer preferences. If not given, one will be created. settings_template : `~ginga.misc.Settings.SettingGroup` or `None` Viewer preferences template settings_share : `~ginga.misc.Settings.SettingGroup` or `None` Viewer preferences instance to share with newly created settings share_keylist : list of str List of names of settings that should be shared Returns ------- channel : `~ginga.misc.Bunch.Bunch` The channel info bunch.
[ "Create", "a", "new", "Ginga", "channel", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L1344-L1462
26,215
ejeschke/ginga
ginga/rv/Control.py
GingaShell.delete_channel
def delete_channel(self, chname): """Delete a given channel from viewer.""" name = chname.lower() if len(self.channel_names) < 1: self.logger.error('Delete channel={0} failed. ' 'No channels left.'.format(chname)) return with self.lock: channel = self.channel[name] # Close local plugins open on this channel self.close_plugins(channel) try: idx = self.channel_names.index(chname) except ValueError: idx = 0 # Update the channels control self.channel_names.remove(channel.name) self.channel_names.sort() self.ds.remove_tab(chname) del self.channel[name] self.prefs.remove_settings('channel_' + chname) # pick new channel num_channels = len(self.channel_names) if num_channels > 0: if idx >= num_channels: idx = num_channels - 1 self.change_channel(self.channel_names[idx]) else: self.cur_channel = None self.make_gui_callback('delete-channel', channel)
python
def delete_channel(self, chname): name = chname.lower() if len(self.channel_names) < 1: self.logger.error('Delete channel={0} failed. ' 'No channels left.'.format(chname)) return with self.lock: channel = self.channel[name] # Close local plugins open on this channel self.close_plugins(channel) try: idx = self.channel_names.index(chname) except ValueError: idx = 0 # Update the channels control self.channel_names.remove(channel.name) self.channel_names.sort() self.ds.remove_tab(chname) del self.channel[name] self.prefs.remove_settings('channel_' + chname) # pick new channel num_channels = len(self.channel_names) if num_channels > 0: if idx >= num_channels: idx = num_channels - 1 self.change_channel(self.channel_names[idx]) else: self.cur_channel = None self.make_gui_callback('delete-channel', channel)
[ "def", "delete_channel", "(", "self", ",", "chname", ")", ":", "name", "=", "chname", ".", "lower", "(", ")", "if", "len", "(", "self", ".", "channel_names", ")", "<", "1", ":", "self", ".", "logger", ".", "error", "(", "'Delete channel={0} failed. '", ...
Delete a given channel from viewer.
[ "Delete", "a", "given", "channel", "from", "viewer", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L1464-L1501
26,216
ejeschke/ginga
ginga/rv/Control.py
GingaShell.add_menu
def add_menu(self, name): """Add a menu with name `name` to the global menu bar. Returns a menu widget. """ if self.menubar is None: raise ValueError("No menu bar configured") return self.menubar.add_name(name)
python
def add_menu(self, name): if self.menubar is None: raise ValueError("No menu bar configured") return self.menubar.add_name(name)
[ "def", "add_menu", "(", "self", ",", "name", ")", ":", "if", "self", ".", "menubar", "is", "None", ":", "raise", "ValueError", "(", "\"No menu bar configured\"", ")", "return", "self", ".", "menubar", ".", "add_name", "(", "name", ")" ]
Add a menu with name `name` to the global menu bar. Returns a menu widget.
[ "Add", "a", "menu", "with", "name", "name", "to", "the", "global", "menu", "bar", ".", "Returns", "a", "menu", "widget", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L1750-L1756
26,217
ejeschke/ginga
ginga/rv/Control.py
GingaShell.get_menu
def get_menu(self, name): """Get the menu with name `name` from the global menu bar. Returns a menu widget. """ if self.menubar is None: raise ValueError("No menu bar configured") return self.menubar.get_menu(name)
python
def get_menu(self, name): if self.menubar is None: raise ValueError("No menu bar configured") return self.menubar.get_menu(name)
[ "def", "get_menu", "(", "self", ",", "name", ")", ":", "if", "self", ".", "menubar", "is", "None", ":", "raise", "ValueError", "(", "\"No menu bar configured\"", ")", "return", "self", ".", "menubar", ".", "get_menu", "(", "name", ")" ]
Get the menu with name `name` from the global menu bar. Returns a menu widget.
[ "Get", "the", "menu", "with", "name", "name", "from", "the", "global", "menu", "bar", ".", "Returns", "a", "menu", "widget", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L1758-L1764
26,218
ejeschke/ginga
ginga/rv/Control.py
GingaShell.register_viewer
def register_viewer(self, vclass): """Register a channel viewer with the reference viewer. `vclass` is the class of the viewer. """ self.viewer_db[vclass.vname] = Bunch.Bunch(vname=vclass.vname, vclass=vclass, vtypes=vclass.vtypes)
python
def register_viewer(self, vclass): self.viewer_db[vclass.vname] = Bunch.Bunch(vname=vclass.vname, vclass=vclass, vtypes=vclass.vtypes)
[ "def", "register_viewer", "(", "self", ",", "vclass", ")", ":", "self", ".", "viewer_db", "[", "vclass", ".", "vname", "]", "=", "Bunch", ".", "Bunch", "(", "vname", "=", "vclass", ".", "vname", ",", "vclass", "=", "vclass", ",", "vtypes", "=", "vcla...
Register a channel viewer with the reference viewer. `vclass` is the class of the viewer.
[ "Register", "a", "channel", "viewer", "with", "the", "reference", "viewer", ".", "vclass", "is", "the", "class", "of", "the", "viewer", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L1848-L1854
26,219
ejeschke/ginga
ginga/rv/Control.py
GingaShell.get_viewer_names
def get_viewer_names(self, dataobj): """Returns a list of viewer names that are registered that can view `dataobj`. """ res = [] for bnch in self.viewer_db.values(): for vtype in bnch.vtypes: if isinstance(dataobj, vtype): res.append(bnch.vname) return res
python
def get_viewer_names(self, dataobj): res = [] for bnch in self.viewer_db.values(): for vtype in bnch.vtypes: if isinstance(dataobj, vtype): res.append(bnch.vname) return res
[ "def", "get_viewer_names", "(", "self", ",", "dataobj", ")", ":", "res", "=", "[", "]", "for", "bnch", "in", "self", ".", "viewer_db", ".", "values", "(", ")", ":", "for", "vtype", "in", "bnch", ".", "vtypes", ":", "if", "isinstance", "(", "dataobj",...
Returns a list of viewer names that are registered that can view `dataobj`.
[ "Returns", "a", "list", "of", "viewer", "names", "that", "are", "registered", "that", "can", "view", "dataobj", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L1856-L1865
26,220
ejeschke/ginga
ginga/rv/Control.py
GingaShell.make_viewer
def make_viewer(self, vname, channel): """Make a viewer whose type name is `vname` and add it to `channel`. """ if vname not in self.viewer_db: raise ValueError("I don't know how to build a '%s' viewer" % ( vname)) stk_w = channel.widget bnch = self.viewer_db[vname] viewer = bnch.vclass(logger=self.logger, settings=channel.settings) stk_w.add_widget(viewer.get_widget(), title=vname) # let the GUI respond to this widget addition self.update_pending() # let the channel object do any necessary initialization channel.connect_viewer(viewer) # finally, let the viewer do any viewer-side initialization viewer.initialize_channel(self, channel)
python
def make_viewer(self, vname, channel): if vname not in self.viewer_db: raise ValueError("I don't know how to build a '%s' viewer" % ( vname)) stk_w = channel.widget bnch = self.viewer_db[vname] viewer = bnch.vclass(logger=self.logger, settings=channel.settings) stk_w.add_widget(viewer.get_widget(), title=vname) # let the GUI respond to this widget addition self.update_pending() # let the channel object do any necessary initialization channel.connect_viewer(viewer) # finally, let the viewer do any viewer-side initialization viewer.initialize_channel(self, channel)
[ "def", "make_viewer", "(", "self", ",", "vname", ",", "channel", ")", ":", "if", "vname", "not", "in", "self", ".", "viewer_db", ":", "raise", "ValueError", "(", "\"I don't know how to build a '%s' viewer\"", "%", "(", "vname", ")", ")", "stk_w", "=", "chann...
Make a viewer whose type name is `vname` and add it to `channel`.
[ "Make", "a", "viewer", "whose", "type", "name", "is", "vname", "and", "add", "it", "to", "channel", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L1867-L1889
26,221
ejeschke/ginga
ginga/rv/Control.py
GingaShell.collapse_pane
def collapse_pane(self, side): """ Toggle collapsing the left or right panes. """ # TODO: this is too tied to one configuration, need to figure # out how to generalize this hsplit = self.w['hpnl'] sizes = hsplit.get_sizes() lsize, msize, rsize = sizes if self._lsize is None: self._lsize, self._rsize = lsize, rsize self.logger.debug("left=%d mid=%d right=%d" % ( lsize, msize, rsize)) if side == 'right': if rsize < 10: # restore pane rsize = self._rsize msize -= rsize else: # minimize pane self._rsize = rsize msize += rsize rsize = 0 elif side == 'left': if lsize < 10: # restore pane lsize = self._lsize msize -= lsize else: # minimize pane self._lsize = lsize msize += lsize lsize = 0 hsplit.set_sizes([lsize, msize, rsize])
python
def collapse_pane(self, side): # TODO: this is too tied to one configuration, need to figure # out how to generalize this hsplit = self.w['hpnl'] sizes = hsplit.get_sizes() lsize, msize, rsize = sizes if self._lsize is None: self._lsize, self._rsize = lsize, rsize self.logger.debug("left=%d mid=%d right=%d" % ( lsize, msize, rsize)) if side == 'right': if rsize < 10: # restore pane rsize = self._rsize msize -= rsize else: # minimize pane self._rsize = rsize msize += rsize rsize = 0 elif side == 'left': if lsize < 10: # restore pane lsize = self._lsize msize -= lsize else: # minimize pane self._lsize = lsize msize += lsize lsize = 0 hsplit.set_sizes([lsize, msize, rsize])
[ "def", "collapse_pane", "(", "self", ",", "side", ")", ":", "# TODO: this is too tied to one configuration, need to figure", "# out how to generalize this", "hsplit", "=", "self", ".", "w", "[", "'hpnl'", "]", "sizes", "=", "hsplit", ".", "get_sizes", "(", ")", "lsi...
Toggle collapsing the left or right panes.
[ "Toggle", "collapsing", "the", "left", "or", "right", "panes", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L2214-L2247
26,222
ejeschke/ginga
ginga/rv/Control.py
GingaShell.quit
def quit(self, *args): """Quit the application. """ self.logger.info("Attempting to shut down the application...") if self.layout_file is not None: self.error_wrap(self.ds.write_layout_conf, self.layout_file) self.stop() self.w.root = None while len(self.ds.toplevels) > 0: w = self.ds.toplevels.pop() w.delete()
python
def quit(self, *args): self.logger.info("Attempting to shut down the application...") if self.layout_file is not None: self.error_wrap(self.ds.write_layout_conf, self.layout_file) self.stop() self.w.root = None while len(self.ds.toplevels) > 0: w = self.ds.toplevels.pop() w.delete()
[ "def", "quit", "(", "self", ",", "*", "args", ")", ":", "self", ".", "logger", ".", "info", "(", "\"Attempting to shut down the application...\"", ")", "if", "self", ".", "layout_file", "is", "not", "None", ":", "self", ".", "error_wrap", "(", "self", ".",...
Quit the application.
[ "Quit", "the", "application", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L2266-L2278
26,223
ejeschke/ginga
ginga/rv/Control.py
GingaShell.showxy
def showxy(self, viewer, data_x, data_y): """Called by the mouse-tracking callback to handle reporting of cursor position to various plugins that subscribe to the 'field-info' callback. """ # This is an optimization to get around slow coordinate # transformation by astropy and possibly other WCS packages, # which causes delay for other mouse tracking events, e.g. # the zoom plugin. # We only update the under cursor information every period # defined by (self.cursor_interval) sec. # # If the refresh interval has expired then update the info; # otherwise (re)set the timer until the end of the interval. cur_time = time.time() elapsed = cur_time - self._cursor_last_update if elapsed > self.cursor_interval: # cancel timer self._cursor_task.clear() self.gui_do_oneshot('field-info', self._showxy, viewer, data_x, data_y) else: # store needed data into the timer data area self._cursor_task.data.setvals(viewer=viewer, data_x=data_x, data_y=data_y) # calculate delta until end of refresh interval period = self.cursor_interval - elapsed # set timer conditionally (only if it hasn't yet been set) self._cursor_task.cond_set(period) return True
python
def showxy(self, viewer, data_x, data_y): # This is an optimization to get around slow coordinate # transformation by astropy and possibly other WCS packages, # which causes delay for other mouse tracking events, e.g. # the zoom plugin. # We only update the under cursor information every period # defined by (self.cursor_interval) sec. # # If the refresh interval has expired then update the info; # otherwise (re)set the timer until the end of the interval. cur_time = time.time() elapsed = cur_time - self._cursor_last_update if elapsed > self.cursor_interval: # cancel timer self._cursor_task.clear() self.gui_do_oneshot('field-info', self._showxy, viewer, data_x, data_y) else: # store needed data into the timer data area self._cursor_task.data.setvals(viewer=viewer, data_x=data_x, data_y=data_y) # calculate delta until end of refresh interval period = self.cursor_interval - elapsed # set timer conditionally (only if it hasn't yet been set) self._cursor_task.cond_set(period) return True
[ "def", "showxy", "(", "self", ",", "viewer", ",", "data_x", ",", "data_y", ")", ":", "# This is an optimization to get around slow coordinate", "# transformation by astropy and possibly other WCS packages,", "# which causes delay for other mouse tracking events, e.g.", "# the zoom plug...
Called by the mouse-tracking callback to handle reporting of cursor position to various plugins that subscribe to the 'field-info' callback.
[ "Called", "by", "the", "mouse", "-", "tracking", "callback", "to", "handle", "reporting", "of", "cursor", "position", "to", "various", "plugins", "that", "subscribe", "to", "the", "field", "-", "info", "callback", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L2539-L2568
26,224
ejeschke/ginga
ginga/rv/Control.py
GingaShell._cursor_timer_cb
def _cursor_timer_cb(self, timer): """Callback when the cursor timer expires. """ data = timer.data self.gui_do_oneshot('field-info', self._showxy, data.viewer, data.data_x, data.data_y)
python
def _cursor_timer_cb(self, timer): data = timer.data self.gui_do_oneshot('field-info', self._showxy, data.viewer, data.data_x, data.data_y)
[ "def", "_cursor_timer_cb", "(", "self", ",", "timer", ")", ":", "data", "=", "timer", ".", "data", "self", ".", "gui_do_oneshot", "(", "'field-info'", ",", "self", ".", "_showxy", ",", "data", ".", "viewer", ",", "data", ".", "data_x", ",", "data", "."...
Callback when the cursor timer expires.
[ "Callback", "when", "the", "cursor", "timer", "expires", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L2570-L2575
26,225
ejeschke/ginga
ginga/rv/Control.py
GingaShell._showxy
def _showxy(self, viewer, data_x, data_y): """Update the info from the last position recorded under the cursor. """ self._cursor_last_update = time.time() try: image = viewer.get_image() if (image is None) or not isinstance(image, BaseImage.BaseImage): # No compatible image loaded for this channel return settings = viewer.get_settings() info = image.info_xy(data_x, data_y, settings) # Are we reporting in data or FITS coordinates? off = self.settings.get('pixel_coords_offset', 0.0) info.x += off info.y += off except Exception as e: self.logger.warning( "Can't get info under the cursor: %s" % (str(e))) return # TODO: can this be made more efficient? chname = self.get_channel_name(viewer) channel = self.get_channel(chname) self.make_callback('field-info', channel, info) self.update_pending() return True
python
def _showxy(self, viewer, data_x, data_y): self._cursor_last_update = time.time() try: image = viewer.get_image() if (image is None) or not isinstance(image, BaseImage.BaseImage): # No compatible image loaded for this channel return settings = viewer.get_settings() info = image.info_xy(data_x, data_y, settings) # Are we reporting in data or FITS coordinates? off = self.settings.get('pixel_coords_offset', 0.0) info.x += off info.y += off except Exception as e: self.logger.warning( "Can't get info under the cursor: %s" % (str(e))) return # TODO: can this be made more efficient? chname = self.get_channel_name(viewer) channel = self.get_channel(chname) self.make_callback('field-info', channel, info) self.update_pending() return True
[ "def", "_showxy", "(", "self", ",", "viewer", ",", "data_x", ",", "data_y", ")", ":", "self", ".", "_cursor_last_update", "=", "time", ".", "time", "(", ")", "try", ":", "image", "=", "viewer", ".", "get_image", "(", ")", "if", "(", "image", "is", ...
Update the info from the last position recorded under the cursor.
[ "Update", "the", "info", "from", "the", "last", "position", "recorded", "under", "the", "cursor", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L2577-L2607
26,226
ejeschke/ginga
ginga/rv/Control.py
GingaShell.motion_cb
def motion_cb(self, viewer, button, data_x, data_y): """Motion event in the channel viewer window. Show the pointing information under the cursor. """ self.showxy(viewer, data_x, data_y) return True
python
def motion_cb(self, viewer, button, data_x, data_y): self.showxy(viewer, data_x, data_y) return True
[ "def", "motion_cb", "(", "self", ",", "viewer", ",", "button", ",", "data_x", ",", "data_y", ")", ":", "self", ".", "showxy", "(", "viewer", ",", "data_x", ",", "data_y", ")", "return", "True" ]
Motion event in the channel viewer window. Show the pointing information under the cursor.
[ "Motion", "event", "in", "the", "channel", "viewer", "window", ".", "Show", "the", "pointing", "information", "under", "the", "cursor", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L2609-L2614
26,227
ejeschke/ginga
ginga/rv/Control.py
GingaShell.keypress
def keypress(self, viewer, event, data_x, data_y): """Key press event in a channel window.""" keyname = event.key chname = self.get_channel_name(viewer) self.logger.debug("key press (%s) in channel %s" % ( keyname, chname)) # TODO: keyboard accelerators to raise tabs need to be integrated into # the desktop object if keyname == 'Z': self.ds.raise_tab('Zoom') ## elif keyname == 'T': ## self.ds.raise_tab('Thumbs') elif keyname == 'I': self.ds.raise_tab('Info') elif keyname == 'H': self.ds.raise_tab('Header') elif keyname == 'C': self.ds.raise_tab('Contents') elif keyname == 'D': self.ds.raise_tab('Dialogs') elif keyname == 'F': self.build_fullscreen() elif keyname == 'f': self.toggle_fullscreen() elif keyname == 'm': self.maximize() elif keyname == '<': self.collapse_pane('left') elif keyname == '>': self.collapse_pane('right') elif keyname == 'n': self.next_channel() elif keyname == 'J': self.cycle_workspace_type() elif keyname == 'k': self.add_channel_auto() elif keyname == 'K': self.remove_channel_auto() elif keyname == 'f1': self.show_channel_names() ## elif keyname == 'escape': ## self.reset_viewer() elif keyname in ('up',): self.prev_img() elif keyname in ('down',): self.next_img() elif keyname in ('left',): self.prev_channel() elif keyname in ('right',): self.next_channel() return True
python
def keypress(self, viewer, event, data_x, data_y): keyname = event.key chname = self.get_channel_name(viewer) self.logger.debug("key press (%s) in channel %s" % ( keyname, chname)) # TODO: keyboard accelerators to raise tabs need to be integrated into # the desktop object if keyname == 'Z': self.ds.raise_tab('Zoom') ## elif keyname == 'T': ## self.ds.raise_tab('Thumbs') elif keyname == 'I': self.ds.raise_tab('Info') elif keyname == 'H': self.ds.raise_tab('Header') elif keyname == 'C': self.ds.raise_tab('Contents') elif keyname == 'D': self.ds.raise_tab('Dialogs') elif keyname == 'F': self.build_fullscreen() elif keyname == 'f': self.toggle_fullscreen() elif keyname == 'm': self.maximize() elif keyname == '<': self.collapse_pane('left') elif keyname == '>': self.collapse_pane('right') elif keyname == 'n': self.next_channel() elif keyname == 'J': self.cycle_workspace_type() elif keyname == 'k': self.add_channel_auto() elif keyname == 'K': self.remove_channel_auto() elif keyname == 'f1': self.show_channel_names() ## elif keyname == 'escape': ## self.reset_viewer() elif keyname in ('up',): self.prev_img() elif keyname in ('down',): self.next_img() elif keyname in ('left',): self.prev_channel() elif keyname in ('right',): self.next_channel() return True
[ "def", "keypress", "(", "self", ",", "viewer", ",", "event", ",", "data_x", ",", "data_y", ")", ":", "keyname", "=", "event", ".", "key", "chname", "=", "self", ".", "get_channel_name", "(", "viewer", ")", "self", ".", "logger", ".", "debug", "(", "\...
Key press event in a channel window.
[ "Key", "press", "event", "in", "a", "channel", "window", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L2616-L2666
26,228
ejeschke/ginga
ginga/rv/Control.py
GingaShell.show_channel_names
def show_channel_names(self): """Show each channel's name in its image viewer. Useful in 'grid' or 'stack' workspace type to identify which window is which. """ for name in self.get_channel_names(): channel = self.get_channel(name) channel.fitsimage.onscreen_message(name, delay=2.5)
python
def show_channel_names(self): for name in self.get_channel_names(): channel = self.get_channel(name) channel.fitsimage.onscreen_message(name, delay=2.5)
[ "def", "show_channel_names", "(", "self", ")", ":", "for", "name", "in", "self", ".", "get_channel_names", "(", ")", ":", "channel", "=", "self", ".", "get_channel", "(", "name", ")", "channel", ".", "fitsimage", ".", "onscreen_message", "(", "name", ",", ...
Show each channel's name in its image viewer. Useful in 'grid' or 'stack' workspace type to identify which window is which.
[ "Show", "each", "channel", "s", "name", "in", "its", "image", "viewer", ".", "Useful", "in", "grid", "or", "stack", "workspace", "type", "to", "identify", "which", "window", "is", "which", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/Control.py#L2703-L2710
26,229
ejeschke/ginga
ginga/rv/plugins/TVMark.py
TVMark._short_color_list
def _short_color_list(self): """Color list is too long. Discard variations with numbers.""" return [c for c in colors.get_colors() if not re.search(r'\d', c)]
python
def _short_color_list(self): return [c for c in colors.get_colors() if not re.search(r'\d', c)]
[ "def", "_short_color_list", "(", "self", ")", ":", "return", "[", "c", "for", "c", "in", "colors", ".", "get_colors", "(", ")", "if", "not", "re", ".", "search", "(", "r'\\d'", ",", "c", ")", "]" ]
Color list is too long. Discard variations with numbers.
[ "Color", "list", "is", "too", "long", ".", "Discard", "variations", "with", "numbers", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/TVMark.py#L165-L167
26,230
ejeschke/ginga
ginga/rv/plugins/TVMark.py
TVMark._get_markobj
def _get_markobj(self, x, y, marktype, marksize, markcolor, markwidth): """Generate canvas object for given mark parameters.""" if marktype == 'circle': obj = self.dc.Circle( x=x, y=y, radius=marksize, color=markcolor, linewidth=markwidth) elif marktype in ('cross', 'plus'): obj = self.dc.Point( x=x, y=y, radius=marksize, color=markcolor, linewidth=markwidth, style=marktype) elif marktype == 'box': obj = self.dc.Box( x=x, y=y, xradius=marksize, yradius=marksize, color=markcolor, linewidth=markwidth) else: # point, marksize obj = self.dc.Box( x=x, y=y, xradius=1, yradius=1, color=markcolor, linewidth=markwidth, fill=True, fillcolor=markcolor) return obj
python
def _get_markobj(self, x, y, marktype, marksize, markcolor, markwidth): if marktype == 'circle': obj = self.dc.Circle( x=x, y=y, radius=marksize, color=markcolor, linewidth=markwidth) elif marktype in ('cross', 'plus'): obj = self.dc.Point( x=x, y=y, radius=marksize, color=markcolor, linewidth=markwidth, style=marktype) elif marktype == 'box': obj = self.dc.Box( x=x, y=y, xradius=marksize, yradius=marksize, color=markcolor, linewidth=markwidth) else: # point, marksize obj = self.dc.Box( x=x, y=y, xradius=1, yradius=1, color=markcolor, linewidth=markwidth, fill=True, fillcolor=markcolor) return obj
[ "def", "_get_markobj", "(", "self", ",", "x", ",", "y", ",", "marktype", ",", "marksize", ",", "markcolor", ",", "markwidth", ")", ":", "if", "marktype", "==", "'circle'", ":", "obj", "=", "self", ".", "dc", ".", "Circle", "(", "x", "=", "x", ",", ...
Generate canvas object for given mark parameters.
[ "Generate", "canvas", "object", "for", "given", "mark", "parameters", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/TVMark.py#L393-L411
26,231
ejeschke/ginga
ginga/rv/plugins/TVMark.py
TVMark.clear_marking
def clear_marking(self): """Clear marking from image. This does not clear loaded coordinates from memory.""" if self.marktag: try: self.canvas.delete_object_by_tag(self.marktag, redraw=False) except Exception: pass if self.markhltag: try: self.canvas.delete_object_by_tag(self.markhltag, redraw=False) except Exception: pass self.treeview.clear() # Clear table too self.w.nshown.set_text('0') self.fitsimage.redraw()
python
def clear_marking(self): if self.marktag: try: self.canvas.delete_object_by_tag(self.marktag, redraw=False) except Exception: pass if self.markhltag: try: self.canvas.delete_object_by_tag(self.markhltag, redraw=False) except Exception: pass self.treeview.clear() # Clear table too self.w.nshown.set_text('0') self.fitsimage.redraw()
[ "def", "clear_marking", "(", "self", ")", ":", "if", "self", ".", "marktag", ":", "try", ":", "self", ".", "canvas", ".", "delete_object_by_tag", "(", "self", ".", "marktag", ",", "redraw", "=", "False", ")", "except", "Exception", ":", "pass", "if", "...
Clear marking from image. This does not clear loaded coordinates from memory.
[ "Clear", "marking", "from", "image", ".", "This", "does", "not", "clear", "loaded", "coordinates", "from", "memory", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/TVMark.py#L413-L430
26,232
ejeschke/ginga
ginga/rv/plugins/TVMark.py
TVMark.load_file
def load_file(self, filename): """Load coordinates file. Results are appended to previously loaded coordinates. This can be used to load one file per color. """ if not os.path.isfile(filename): return self.logger.info('Loading coordinates from {0}'.format(filename)) if filename.endswith('.fits'): fmt = 'fits' else: # Assume ASCII fmt = 'ascii' try: tab = Table.read(filename, format=fmt) except Exception as e: self.logger.error('{0}: {1}'.format(e.__class__.__name__, str(e))) return if self.use_radec: colname0 = self.settings.get('ra_colname', 'ra') colname1 = self.settings.get('dec_colname', 'dec') else: colname0 = self.settings.get('x_colname', 'x') colname1 = self.settings.get('y_colname', 'y') try: col_0 = tab[colname0] col_1 = tab[colname1] except Exception as e: self.logger.error('{0}: {1}'.format(e.__class__.__name__, str(e))) return nrows = len(col_0) dummy_col = [None] * nrows try: oldrows = int(self.w.ntotal.get_text()) except ValueError: oldrows = 0 self.w.ntotal.set_text(str(oldrows + nrows)) if self.use_radec: ra = self._convert_radec(col_0) dec = self._convert_radec(col_1) x = y = dummy_col else: ra = dec = dummy_col # X and Y always 0-indexed internally x = col_0.data - self.pixelstart y = col_1.data - self.pixelstart args = [ra, dec, x, y] # Load extra columns for colname in self.extra_columns: try: col = tab[colname].data except Exception as e: self.logger.error( '{0}: {1}'.format(e.__class__.__name__, str(e))) col = dummy_col args.append(col) # Use list to preserve order. Does not handle duplicates. key = (self.marktype, self.marksize, self.markcolor) self.coords_dict[key] += list(zip(*args)) self.redo()
python
def load_file(self, filename): if not os.path.isfile(filename): return self.logger.info('Loading coordinates from {0}'.format(filename)) if filename.endswith('.fits'): fmt = 'fits' else: # Assume ASCII fmt = 'ascii' try: tab = Table.read(filename, format=fmt) except Exception as e: self.logger.error('{0}: {1}'.format(e.__class__.__name__, str(e))) return if self.use_radec: colname0 = self.settings.get('ra_colname', 'ra') colname1 = self.settings.get('dec_colname', 'dec') else: colname0 = self.settings.get('x_colname', 'x') colname1 = self.settings.get('y_colname', 'y') try: col_0 = tab[colname0] col_1 = tab[colname1] except Exception as e: self.logger.error('{0}: {1}'.format(e.__class__.__name__, str(e))) return nrows = len(col_0) dummy_col = [None] * nrows try: oldrows = int(self.w.ntotal.get_text()) except ValueError: oldrows = 0 self.w.ntotal.set_text(str(oldrows + nrows)) if self.use_radec: ra = self._convert_radec(col_0) dec = self._convert_radec(col_1) x = y = dummy_col else: ra = dec = dummy_col # X and Y always 0-indexed internally x = col_0.data - self.pixelstart y = col_1.data - self.pixelstart args = [ra, dec, x, y] # Load extra columns for colname in self.extra_columns: try: col = tab[colname].data except Exception as e: self.logger.error( '{0}: {1}'.format(e.__class__.__name__, str(e))) col = dummy_col args.append(col) # Use list to preserve order. Does not handle duplicates. key = (self.marktype, self.marksize, self.markcolor) self.coords_dict[key] += list(zip(*args)) self.redo()
[ "def", "load_file", "(", "self", ",", "filename", ")", ":", "if", "not", "os", ".", "path", ".", "isfile", "(", "filename", ")", ":", "return", "self", ".", "logger", ".", "info", "(", "'Loading coordinates from {0}'", ".", "format", "(", "filename", ")"...
Load coordinates file. Results are appended to previously loaded coordinates. This can be used to load one file per color.
[ "Load", "coordinates", "file", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/TVMark.py#L439-L514
26,233
ejeschke/ginga
ginga/rv/plugins/TVMark.py
TVMark._convert_radec
def _convert_radec(self, val): """Convert RA or DEC table column to degrees and extract data. Assume already in degrees if cannot convert. """ try: ans = val.to('deg') except Exception as e: self.logger.error('Cannot convert, assume already in degrees') ans = val.data else: ans = ans.value return ans
python
def _convert_radec(self, val): try: ans = val.to('deg') except Exception as e: self.logger.error('Cannot convert, assume already in degrees') ans = val.data else: ans = ans.value return ans
[ "def", "_convert_radec", "(", "self", ",", "val", ")", ":", "try", ":", "ans", "=", "val", ".", "to", "(", "'deg'", ")", "except", "Exception", "as", "e", ":", "self", ".", "logger", ".", "error", "(", "'Cannot convert, assume already in degrees'", ")", ...
Convert RA or DEC table column to degrees and extract data. Assume already in degrees if cannot convert.
[ "Convert", "RA", "or", "DEC", "table", "column", "to", "degrees", "and", "extract", "data", ".", "Assume", "already", "in", "degrees", "if", "cannot", "convert", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/TVMark.py#L526-L539
26,234
ejeschke/ginga
ginga/rv/plugins/TVMark.py
TVMark.hl_table2canvas
def hl_table2canvas(self, w, res_dict): """Highlight marking on canvas when user click on table.""" objlist = [] width = self.markwidth + self._dwidth # Remove existing highlight if self.markhltag: try: self.canvas.delete_object_by_tag(self.markhltag, redraw=False) except Exception: pass # Display highlighted entries only in second table self.treeviewsel.set_tree(res_dict) for kstr, sub_dict in res_dict.items(): s = kstr.split(',') marktype = s[0] marksize = float(s[1]) markcolor = s[2] for bnch in sub_dict.values(): obj = self._get_markobj(bnch.X - self.pixelstart, bnch.Y - self.pixelstart, marktype, marksize, markcolor, width) objlist.append(obj) nsel = len(objlist) self.w.nselected.set_text(str(nsel)) # Draw on canvas if nsel > 0: self.markhltag = self.canvas.add(self.dc.CompoundObject(*objlist)) self.fitsimage.redraw()
python
def hl_table2canvas(self, w, res_dict): objlist = [] width = self.markwidth + self._dwidth # Remove existing highlight if self.markhltag: try: self.canvas.delete_object_by_tag(self.markhltag, redraw=False) except Exception: pass # Display highlighted entries only in second table self.treeviewsel.set_tree(res_dict) for kstr, sub_dict in res_dict.items(): s = kstr.split(',') marktype = s[0] marksize = float(s[1]) markcolor = s[2] for bnch in sub_dict.values(): obj = self._get_markobj(bnch.X - self.pixelstart, bnch.Y - self.pixelstart, marktype, marksize, markcolor, width) objlist.append(obj) nsel = len(objlist) self.w.nselected.set_text(str(nsel)) # Draw on canvas if nsel > 0: self.markhltag = self.canvas.add(self.dc.CompoundObject(*objlist)) self.fitsimage.redraw()
[ "def", "hl_table2canvas", "(", "self", ",", "w", ",", "res_dict", ")", ":", "objlist", "=", "[", "]", "width", "=", "self", ".", "markwidth", "+", "self", ".", "_dwidth", "# Remove existing highlight", "if", "self", ".", "markhltag", ":", "try", ":", "se...
Highlight marking on canvas when user click on table.
[ "Highlight", "marking", "on", "canvas", "when", "user", "click", "on", "table", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/TVMark.py#L562-L596
26,235
ejeschke/ginga
ginga/rv/plugins/TVMark.py
TVMark.hl_canvas2table_box
def hl_canvas2table_box(self, canvas, tag): """Highlight all markings inside user drawn box on table.""" self.treeview.clear_selection() # Remove existing box cobj = canvas.get_object_by_tag(tag) if cobj.kind != 'rectangle': return canvas.delete_object_by_tag(tag, redraw=False) # Remove existing highlight if self.markhltag: try: canvas.delete_object_by_tag(self.markhltag, redraw=True) except Exception: pass # Nothing to do if no markings are displayed try: obj = canvas.get_object_by_tag(self.marktag) except Exception: return if obj.kind != 'compound': return # Nothing to do if table has no data if (len(self._xarr) == 0 or len(self._yarr) == 0 or len(self._treepaths) == 0): return # Find markings inside box mask = cobj.contains_arr(self._xarr, self._yarr) for hlpath in self._treepaths[mask]: self._highlight_path(hlpath)
python
def hl_canvas2table_box(self, canvas, tag): self.treeview.clear_selection() # Remove existing box cobj = canvas.get_object_by_tag(tag) if cobj.kind != 'rectangle': return canvas.delete_object_by_tag(tag, redraw=False) # Remove existing highlight if self.markhltag: try: canvas.delete_object_by_tag(self.markhltag, redraw=True) except Exception: pass # Nothing to do if no markings are displayed try: obj = canvas.get_object_by_tag(self.marktag) except Exception: return if obj.kind != 'compound': return # Nothing to do if table has no data if (len(self._xarr) == 0 or len(self._yarr) == 0 or len(self._treepaths) == 0): return # Find markings inside box mask = cobj.contains_arr(self._xarr, self._yarr) for hlpath in self._treepaths[mask]: self._highlight_path(hlpath)
[ "def", "hl_canvas2table_box", "(", "self", ",", "canvas", ",", "tag", ")", ":", "self", ".", "treeview", ".", "clear_selection", "(", ")", "# Remove existing box", "cobj", "=", "canvas", ".", "get_object_by_tag", "(", "tag", ")", "if", "cobj", ".", "kind", ...
Highlight all markings inside user drawn box on table.
[ "Highlight", "all", "markings", "inside", "user", "drawn", "box", "on", "table", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/TVMark.py#L598-L633
26,236
ejeschke/ginga
ginga/rv/plugins/TVMark.py
TVMark.hl_canvas2table
def hl_canvas2table(self, canvas, button, data_x, data_y): """Highlight marking on table when user click on canvas.""" self.treeview.clear_selection() # Remove existing highlight if self.markhltag: try: canvas.delete_object_by_tag(self.markhltag, redraw=True) except Exception: pass # Nothing to do if no markings are displayed try: obj = canvas.get_object_by_tag(self.marktag) except Exception: return if obj.kind != 'compound': return # Nothing to do if table has no data if (len(self._xarr) == 0 or len(self._yarr) == 0 or len(self._treepaths) == 0): return sr = 10 # self.settings.get('searchradius', 10) dx = data_x - self._xarr dy = data_y - self._yarr dr = np.sqrt(dx * dx + dy * dy) mask = dr <= sr for hlpath in self._treepaths[mask]: self._highlight_path(hlpath)
python
def hl_canvas2table(self, canvas, button, data_x, data_y): self.treeview.clear_selection() # Remove existing highlight if self.markhltag: try: canvas.delete_object_by_tag(self.markhltag, redraw=True) except Exception: pass # Nothing to do if no markings are displayed try: obj = canvas.get_object_by_tag(self.marktag) except Exception: return if obj.kind != 'compound': return # Nothing to do if table has no data if (len(self._xarr) == 0 or len(self._yarr) == 0 or len(self._treepaths) == 0): return sr = 10 # self.settings.get('searchradius', 10) dx = data_x - self._xarr dy = data_y - self._yarr dr = np.sqrt(dx * dx + dy * dy) mask = dr <= sr for hlpath in self._treepaths[mask]: self._highlight_path(hlpath)
[ "def", "hl_canvas2table", "(", "self", ",", "canvas", ",", "button", ",", "data_x", ",", "data_y", ")", ":", "self", ".", "treeview", ".", "clear_selection", "(", ")", "# Remove existing highlight", "if", "self", ".", "markhltag", ":", "try", ":", "canvas", ...
Highlight marking on table when user click on canvas.
[ "Highlight", "marking", "on", "table", "when", "user", "click", "on", "canvas", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/TVMark.py#L636-L668
26,237
ejeschke/ginga
ginga/rv/plugins/TVMark.py
TVMark._highlight_path
def _highlight_path(self, hlpath): """Highlight an entry in the table and associated marking.""" self.logger.debug('Highlighting {0}'.format(hlpath)) self.treeview.select_path(hlpath) # TODO: Does not work in Qt. This is known issue in Ginga. self.treeview.scroll_to_path(hlpath)
python
def _highlight_path(self, hlpath): self.logger.debug('Highlighting {0}'.format(hlpath)) self.treeview.select_path(hlpath) # TODO: Does not work in Qt. This is known issue in Ginga. self.treeview.scroll_to_path(hlpath)
[ "def", "_highlight_path", "(", "self", ",", "hlpath", ")", ":", "self", ".", "logger", ".", "debug", "(", "'Highlighting {0}'", ".", "format", "(", "hlpath", ")", ")", "self", ".", "treeview", ".", "select_path", "(", "hlpath", ")", "# TODO: Does not work in...
Highlight an entry in the table and associated marking.
[ "Highlight", "an", "entry", "in", "the", "table", "and", "associated", "marking", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/TVMark.py#L670-L676
26,238
ejeschke/ginga
ginga/rv/plugins/TVMark.py
TVMark.set_marktype_cb
def set_marktype_cb(self, w, index): """Set type of marking.""" self.marktype = self._mark_options[index] # Mark size is not used for point if self.marktype != 'point': self.w.mark_size.set_enabled(True) else: self.w.mark_size.set_enabled(False)
python
def set_marktype_cb(self, w, index): self.marktype = self._mark_options[index] # Mark size is not used for point if self.marktype != 'point': self.w.mark_size.set_enabled(True) else: self.w.mark_size.set_enabled(False)
[ "def", "set_marktype_cb", "(", "self", ",", "w", ",", "index", ")", ":", "self", ".", "marktype", "=", "self", ".", "_mark_options", "[", "index", "]", "# Mark size is not used for point", "if", "self", ".", "marktype", "!=", "'point'", ":", "self", ".", "...
Set type of marking.
[ "Set", "type", "of", "marking", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/TVMark.py#L678-L686
26,239
ejeschke/ginga
ginga/rv/plugins/TVMark.py
TVMark.set_markwidth
def set_markwidth(self): """Set width of marking.""" try: sz = int(self.w.mark_width.get_text()) except ValueError: self.logger.error('Cannot set mark width') self.w.mark_width.set_text(str(self.markwidth)) else: self.markwidth = sz
python
def set_markwidth(self): try: sz = int(self.w.mark_width.get_text()) except ValueError: self.logger.error('Cannot set mark width') self.w.mark_width.set_text(str(self.markwidth)) else: self.markwidth = sz
[ "def", "set_markwidth", "(", "self", ")", ":", "try", ":", "sz", "=", "int", "(", "self", ".", "w", ".", "mark_width", ".", "get_text", "(", ")", ")", "except", "ValueError", ":", "self", ".", "logger", ".", "error", "(", "'Cannot set mark width'", ")"...
Set width of marking.
[ "Set", "width", "of", "marking", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/TVMark.py#L702-L710
26,240
ejeschke/ginga
ginga/rv/plugins/Header.py
Header.redo
def redo(self, channel, image): """This is called when image changes.""" self._image = None # Skip cache checking in set_header() info = channel.extdata._header_info self.set_header(info, image)
python
def redo(self, channel, image): self._image = None # Skip cache checking in set_header() info = channel.extdata._header_info self.set_header(info, image)
[ "def", "redo", "(", "self", ",", "channel", ",", "image", ")", ":", "self", ".", "_image", "=", "None", "# Skip cache checking in set_header()", "info", "=", "channel", ".", "extdata", ".", "_header_info", "self", ".", "set_header", "(", "info", ",", "image"...
This is called when image changes.
[ "This", "is", "called", "when", "image", "changes", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/Header.py#L225-L230
26,241
ejeschke/ginga
ginga/rv/plugins/Header.py
Header.blank
def blank(self, channel): """This is called when image is cleared.""" self._image = None info = channel.extdata._header_info info.table.clear()
python
def blank(self, channel): self._image = None info = channel.extdata._header_info info.table.clear()
[ "def", "blank", "(", "self", ",", "channel", ")", ":", "self", ".", "_image", "=", "None", "info", "=", "channel", ".", "extdata", ".", "_header_info", "info", ".", "table", ".", "clear", "(", ")" ]
This is called when image is cleared.
[ "This", "is", "called", "when", "image", "is", "cleared", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/Header.py#L232-L236
26,242
ejeschke/ginga
ginga/examples/gw/clocks.py
Clock.clock_resized_cb
def clock_resized_cb(self, viewer, width, height): """This method is called when an individual clock is resized. It deletes and reconstructs the placement of the text objects in the canvas. """ self.logger.info("resized canvas to %dx%d" % (width, height)) # add text objects to canvas self.canvas.delete_all_objects() Text = self.canvas.get_draw_class('text') x, y = 20, int(height * 0.55) # text object for the time self.time_txt = Text(x, y, text='', color=self.color, font=self.font, fontsize=self.largesize, coord='window') self.canvas.add(self.time_txt, tag='_time', redraw=False) # for supplementary info (date, timezone, etc) self.suppl_txt = Text(x, height - 10, text='', color=self.color, font=self.font, fontsize=self.smallsize, coord='window') self.canvas.add(self.suppl_txt, tag='_suppl', redraw=False) self.canvas.update_canvas(whence=3)
python
def clock_resized_cb(self, viewer, width, height): self.logger.info("resized canvas to %dx%d" % (width, height)) # add text objects to canvas self.canvas.delete_all_objects() Text = self.canvas.get_draw_class('text') x, y = 20, int(height * 0.55) # text object for the time self.time_txt = Text(x, y, text='', color=self.color, font=self.font, fontsize=self.largesize, coord='window') self.canvas.add(self.time_txt, tag='_time', redraw=False) # for supplementary info (date, timezone, etc) self.suppl_txt = Text(x, height - 10, text='', color=self.color, font=self.font, fontsize=self.smallsize, coord='window') self.canvas.add(self.suppl_txt, tag='_suppl', redraw=False) self.canvas.update_canvas(whence=3)
[ "def", "clock_resized_cb", "(", "self", ",", "viewer", ",", "width", ",", "height", ")", ":", "self", ".", "logger", ".", "info", "(", "\"resized canvas to %dx%d\"", "%", "(", "width", ",", "height", ")", ")", "# add text objects to canvas", "self", ".", "ca...
This method is called when an individual clock is resized. It deletes and reconstructs the placement of the text objects in the canvas.
[ "This", "method", "is", "called", "when", "an", "individual", "clock", "is", "resized", ".", "It", "deletes", "and", "reconstructs", "the", "placement", "of", "the", "text", "objects", "in", "the", "canvas", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/examples/gw/clocks.py#L82-L106
26,243
ejeschke/ginga
ginga/examples/gw/clocks.py
Clock.update_clock
def update_clock(self, dt): """This method is called by the ClockApp whenever the timer fires to update the clock. `dt` is a timezone-aware datetime object. """ dt = dt.astimezone(self.tzinfo) fmt = "%H:%M" if self.show_seconds: fmt = "%H:%M:%S" self.time_txt.text = dt.strftime(fmt) suppl_text = "{0} {1}".format(dt.strftime("%Y-%m-%d"), self.timezone) self.suppl_txt.text = suppl_text self.viewer.redraw(whence=3)
python
def update_clock(self, dt): dt = dt.astimezone(self.tzinfo) fmt = "%H:%M" if self.show_seconds: fmt = "%H:%M:%S" self.time_txt.text = dt.strftime(fmt) suppl_text = "{0} {1}".format(dt.strftime("%Y-%m-%d"), self.timezone) self.suppl_txt.text = suppl_text self.viewer.redraw(whence=3)
[ "def", "update_clock", "(", "self", ",", "dt", ")", ":", "dt", "=", "dt", ".", "astimezone", "(", "self", ".", "tzinfo", ")", "fmt", "=", "\"%H:%M\"", "if", "self", ".", "show_seconds", ":", "fmt", "=", "\"%H:%M:%S\"", "self", ".", "time_txt", ".", "...
This method is called by the ClockApp whenever the timer fires to update the clock. `dt` is a timezone-aware datetime object.
[ "This", "method", "is", "called", "by", "the", "ClockApp", "whenever", "the", "timer", "fires", "to", "update", "the", "clock", ".", "dt", "is", "a", "timezone", "-", "aware", "datetime", "object", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/examples/gw/clocks.py#L108-L122
26,244
ejeschke/ginga
ginga/examples/gw/clocks.py
ClockApp.add_clock
def add_clock(self, timezone, color='lightgreen', show_seconds=None): """Add a clock to the grid. `timezone` is a string representing a valid timezone. """ if show_seconds is None: show_seconds = self.options.show_seconds clock = Clock(self.app, self.logger, timezone, color=color, font=self.options.font, show_seconds=show_seconds) clock.widget.cfg_expand(0x7, 0x7) num_clocks = len(self.clocks) cols = self.settings.get('columns') row = num_clocks // cols col = num_clocks % cols self.clocks[timezone] = clock self.grid.add_widget(clock.widget, row, col, stretch=1)
python
def add_clock(self, timezone, color='lightgreen', show_seconds=None): if show_seconds is None: show_seconds = self.options.show_seconds clock = Clock(self.app, self.logger, timezone, color=color, font=self.options.font, show_seconds=show_seconds) clock.widget.cfg_expand(0x7, 0x7) num_clocks = len(self.clocks) cols = self.settings.get('columns') row = num_clocks // cols col = num_clocks % cols self.clocks[timezone] = clock self.grid.add_widget(clock.widget, row, col, stretch=1)
[ "def", "add_clock", "(", "self", ",", "timezone", ",", "color", "=", "'lightgreen'", ",", "show_seconds", "=", "None", ")", ":", "if", "show_seconds", "is", "None", ":", "show_seconds", "=", "self", ".", "options", ".", "show_seconds", "clock", "=", "Clock...
Add a clock to the grid. `timezone` is a string representing a valid timezone.
[ "Add", "a", "clock", "to", "the", "grid", ".", "timezone", "is", "a", "string", "representing", "a", "valid", "timezone", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/examples/gw/clocks.py#L232-L249
26,245
ejeschke/ginga
ginga/examples/gw/clocks.py
ClockApp.timer_cb
def timer_cb(self, timer): """Timer callback. Update all our clocks.""" dt_now = datetime.utcnow().replace(tzinfo=pytz.utc) self.logger.debug("timer fired. utc time is '%s'" % (str(dt_now))) for clock in self.clocks.values(): clock.update_clock(dt_now) # update clocks approx every second timer.start(1.0)
python
def timer_cb(self, timer): dt_now = datetime.utcnow().replace(tzinfo=pytz.utc) self.logger.debug("timer fired. utc time is '%s'" % (str(dt_now))) for clock in self.clocks.values(): clock.update_clock(dt_now) # update clocks approx every second timer.start(1.0)
[ "def", "timer_cb", "(", "self", ",", "timer", ")", ":", "dt_now", "=", "datetime", ".", "utcnow", "(", ")", ".", "replace", "(", "tzinfo", "=", "pytz", ".", "utc", ")", "self", ".", "logger", ".", "debug", "(", "\"timer fired. utc time is '%s'\"", "%", ...
Timer callback. Update all our clocks.
[ "Timer", "callback", ".", "Update", "all", "our", "clocks", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/examples/gw/clocks.py#L251-L260
26,246
ejeschke/ginga
ginga/table/TableView.py
TableViewGw.set_table_cb
def set_table_cb(self, viewer, table): """Display the given table object.""" self.clear() tree_dict = OrderedDict() # Extract data as astropy table a_tab = table.get_data() # Fill masked values, if applicable try: a_tab = a_tab.filled() except Exception: # Just use original table pass # This is to get around table widget not sorting numbers properly i_fmt = '{{0:0{0}d}}'.format(len(str(len(a_tab)))) # Table header with units columns = [('Row', '_DISPLAY_ROW')] for c in a_tab.columns.values(): col_str = '{0:^s}\n{1:^s}'.format(c.name, str(c.unit)) columns.append((col_str, c.name)) self.widget.setup_table(columns, 1, '_DISPLAY_ROW') # Table contents for i, row in enumerate(a_tab, 1): bnch = Bunch.Bunch(zip(row.colnames, row.as_void())) i_str = i_fmt.format(i) bnch['_DISPLAY_ROW'] = i_str tree_dict[i_str] = bnch self.widget.set_tree(tree_dict) # Resize column widths n_rows = len(tree_dict) if n_rows < self.settings.get('max_rows_for_col_resize', 5000): self.widget.set_optimal_column_widths() self.logger.debug('Resized columns for {0} row(s)'.format(n_rows)) tablename = table.get('name', 'NoName') self.logger.debug('Displayed {0}'.format(tablename))
python
def set_table_cb(self, viewer, table): self.clear() tree_dict = OrderedDict() # Extract data as astropy table a_tab = table.get_data() # Fill masked values, if applicable try: a_tab = a_tab.filled() except Exception: # Just use original table pass # This is to get around table widget not sorting numbers properly i_fmt = '{{0:0{0}d}}'.format(len(str(len(a_tab)))) # Table header with units columns = [('Row', '_DISPLAY_ROW')] for c in a_tab.columns.values(): col_str = '{0:^s}\n{1:^s}'.format(c.name, str(c.unit)) columns.append((col_str, c.name)) self.widget.setup_table(columns, 1, '_DISPLAY_ROW') # Table contents for i, row in enumerate(a_tab, 1): bnch = Bunch.Bunch(zip(row.colnames, row.as_void())) i_str = i_fmt.format(i) bnch['_DISPLAY_ROW'] = i_str tree_dict[i_str] = bnch self.widget.set_tree(tree_dict) # Resize column widths n_rows = len(tree_dict) if n_rows < self.settings.get('max_rows_for_col_resize', 5000): self.widget.set_optimal_column_widths() self.logger.debug('Resized columns for {0} row(s)'.format(n_rows)) tablename = table.get('name', 'NoName') self.logger.debug('Displayed {0}'.format(tablename))
[ "def", "set_table_cb", "(", "self", ",", "viewer", ",", "table", ")", ":", "self", ".", "clear", "(", ")", "tree_dict", "=", "OrderedDict", "(", ")", "# Extract data as astropy table", "a_tab", "=", "table", ".", "get_data", "(", ")", "# Fill masked values, if...
Display the given table object.
[ "Display", "the", "given", "table", "object", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/table/TableView.py#L118-L159
26,247
ejeschke/ginga
ginga/rv/plugins/ChangeHistory.py
ChangeHistory.build_gui
def build_gui(self, container): """This method is called when the plugin is invoked. It builds the GUI used by the plugin into the widget layout passed as ``container``. This method could be called several times if the plugin is opened and closed. """ vbox, sw, self.orientation = Widgets.get_oriented_box(container) vbox.set_border_width(4) vbox.set_spacing(2) # create the Treeview always_expand = self.settings.get('always_expand', True) color_alternate = self.settings.get('color_alternate_rows', True) treeview = Widgets.TreeView(auto_expand=always_expand, sortable=True, use_alt_row_color=color_alternate) self.treeview = treeview treeview.setup_table(self.columns, 3, 'MODIFIED') treeview.set_column_width(0, self.settings.get('ts_colwidth', 250)) treeview.add_callback('selected', self.show_more) vbox.add_widget(treeview, stretch=1) fr = Widgets.Frame('Selected History') captions = (('Channel:', 'label', 'chname', 'llabel'), ('Image:', 'label', 'imname', 'llabel'), ('Timestamp:', 'label', 'modified', 'llabel')) w, b = Widgets.build_info(captions) self.w.update(b) b.chname.set_text('') b.chname.set_tooltip('Channel name') b.imname.set_text('') b.imname.set_tooltip('Image name') b.modified.set_text('') b.modified.set_tooltip('Timestamp (UTC)') captions = (('Description:-', 'llabel'), ('descrip', 'textarea')) w2, b = Widgets.build_info(captions) self.w.update(b) b.descrip.set_editable(False) b.descrip.set_wrap(True) b.descrip.set_text('') b.descrip.set_tooltip('Displays selected history entry') vbox2 = Widgets.VBox() vbox2.set_border_width(4) vbox2.add_widget(w) vbox2.add_widget(w2) fr.set_widget(vbox2, stretch=0) vbox.add_widget(fr, stretch=0) container.add_widget(vbox, stretch=1) btns = Widgets.HBox() btns.set_spacing(3) btn = Widgets.Button('Close') btn.add_callback('activated', lambda w: self.close()) btns.add_widget(btn, stretch=0) btn = Widgets.Button("Help") btn.add_callback('activated', lambda w: self.help()) btns.add_widget(btn, stretch=0) btns.add_widget(Widgets.Label(''), stretch=1) container.add_widget(btns, stretch=0) self.gui_up = True
python
def build_gui(self, container): vbox, sw, self.orientation = Widgets.get_oriented_box(container) vbox.set_border_width(4) vbox.set_spacing(2) # create the Treeview always_expand = self.settings.get('always_expand', True) color_alternate = self.settings.get('color_alternate_rows', True) treeview = Widgets.TreeView(auto_expand=always_expand, sortable=True, use_alt_row_color=color_alternate) self.treeview = treeview treeview.setup_table(self.columns, 3, 'MODIFIED') treeview.set_column_width(0, self.settings.get('ts_colwidth', 250)) treeview.add_callback('selected', self.show_more) vbox.add_widget(treeview, stretch=1) fr = Widgets.Frame('Selected History') captions = (('Channel:', 'label', 'chname', 'llabel'), ('Image:', 'label', 'imname', 'llabel'), ('Timestamp:', 'label', 'modified', 'llabel')) w, b = Widgets.build_info(captions) self.w.update(b) b.chname.set_text('') b.chname.set_tooltip('Channel name') b.imname.set_text('') b.imname.set_tooltip('Image name') b.modified.set_text('') b.modified.set_tooltip('Timestamp (UTC)') captions = (('Description:-', 'llabel'), ('descrip', 'textarea')) w2, b = Widgets.build_info(captions) self.w.update(b) b.descrip.set_editable(False) b.descrip.set_wrap(True) b.descrip.set_text('') b.descrip.set_tooltip('Displays selected history entry') vbox2 = Widgets.VBox() vbox2.set_border_width(4) vbox2.add_widget(w) vbox2.add_widget(w2) fr.set_widget(vbox2, stretch=0) vbox.add_widget(fr, stretch=0) container.add_widget(vbox, stretch=1) btns = Widgets.HBox() btns.set_spacing(3) btn = Widgets.Button('Close') btn.add_callback('activated', lambda w: self.close()) btns.add_widget(btn, stretch=0) btn = Widgets.Button("Help") btn.add_callback('activated', lambda w: self.help()) btns.add_widget(btn, stretch=0) btns.add_widget(Widgets.Label(''), stretch=1) container.add_widget(btns, stretch=0) self.gui_up = True
[ "def", "build_gui", "(", "self", ",", "container", ")", ":", "vbox", ",", "sw", ",", "self", ".", "orientation", "=", "Widgets", ".", "get_oriented_box", "(", "container", ")", "vbox", ".", "set_border_width", "(", "4", ")", "vbox", ".", "set_spacing", "...
This method is called when the plugin is invoked. It builds the GUI used by the plugin into the widget layout passed as ``container``. This method could be called several times if the plugin is opened and closed.
[ "This", "method", "is", "called", "when", "the", "plugin", "is", "invoked", ".", "It", "builds", "the", "GUI", "used", "by", "the", "plugin", "into", "the", "widget", "layout", "passed", "as", "container", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/ChangeHistory.py#L75-L149
26,248
ejeschke/ginga
ginga/rv/plugins/ChangeHistory.py
ChangeHistory.redo
def redo(self, channel, image): """Add an entry with image modification info.""" chname = channel.name if image is None: # shouldn't happen, but let's play it safe return imname = image.get('name', 'none') iminfo = channel.get_image_info(imname) timestamp = iminfo.time_modified if timestamp is None: reason = iminfo.get('reason_modified', None) if reason is not None: self.fv.show_error( "{0} invoked 'modified' callback to ChangeHistory with a " "reason but without a timestamp. The plugin invoking the " "callback is no longer be compatible with Ginga. " "Please contact plugin developer to update the plugin " "to use self.fv.update_image_info() like Mosaic " "plugin.".format(imname)) # Image somehow lost its history self.remove_image_info_cb(self.fv, channel, iminfo) return self.add_entry(chname, iminfo)
python
def redo(self, channel, image): chname = channel.name if image is None: # shouldn't happen, but let's play it safe return imname = image.get('name', 'none') iminfo = channel.get_image_info(imname) timestamp = iminfo.time_modified if timestamp is None: reason = iminfo.get('reason_modified', None) if reason is not None: self.fv.show_error( "{0} invoked 'modified' callback to ChangeHistory with a " "reason but without a timestamp. The plugin invoking the " "callback is no longer be compatible with Ginga. " "Please contact plugin developer to update the plugin " "to use self.fv.update_image_info() like Mosaic " "plugin.".format(imname)) # Image somehow lost its history self.remove_image_info_cb(self.fv, channel, iminfo) return self.add_entry(chname, iminfo)
[ "def", "redo", "(", "self", ",", "channel", ",", "image", ")", ":", "chname", "=", "channel", ".", "name", "if", "image", "is", "None", ":", "# shouldn't happen, but let's play it safe", "return", "imname", "=", "image", ".", "get", "(", "'name'", ",", "'n...
Add an entry with image modification info.
[ "Add", "an", "entry", "with", "image", "modification", "info", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/ChangeHistory.py#L181-L207
26,249
ejeschke/ginga
ginga/rv/plugins/ChangeHistory.py
ChangeHistory.remove_image_info_cb
def remove_image_info_cb(self, gshell, channel, iminfo): """Delete entries related to deleted image.""" chname = channel.name if chname not in self.name_dict: return fileDict = self.name_dict[chname] name = iminfo.name if name not in fileDict: return del fileDict[name] self.logger.debug('{0} removed from ChangeHistory'.format(name)) if not self.gui_up: return False self.clear_selected_history() self.recreate_toc()
python
def remove_image_info_cb(self, gshell, channel, iminfo): chname = channel.name if chname not in self.name_dict: return fileDict = self.name_dict[chname] name = iminfo.name if name not in fileDict: return del fileDict[name] self.logger.debug('{0} removed from ChangeHistory'.format(name)) if not self.gui_up: return False self.clear_selected_history() self.recreate_toc()
[ "def", "remove_image_info_cb", "(", "self", ",", "gshell", ",", "channel", ",", "iminfo", ")", ":", "chname", "=", "channel", ".", "name", "if", "chname", "not", "in", "self", ".", "name_dict", ":", "return", "fileDict", "=", "self", ".", "name_dict", "[...
Delete entries related to deleted image.
[ "Delete", "entries", "related", "to", "deleted", "image", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/ChangeHistory.py#L238-L257
26,250
ejeschke/ginga
ginga/rv/plugins/ChangeHistory.py
ChangeHistory.add_image_info_cb
def add_image_info_cb(self, gshell, channel, iminfo): """Add entries related to an added image.""" timestamp = iminfo.time_modified if timestamp is None: # Not an image we are interested in tracking return self.add_entry(channel.name, iminfo)
python
def add_image_info_cb(self, gshell, channel, iminfo): timestamp = iminfo.time_modified if timestamp is None: # Not an image we are interested in tracking return self.add_entry(channel.name, iminfo)
[ "def", "add_image_info_cb", "(", "self", ",", "gshell", ",", "channel", ",", "iminfo", ")", ":", "timestamp", "=", "iminfo", ".", "time_modified", "if", "timestamp", "is", "None", ":", "# Not an image we are interested in tracking", "return", "self", ".", "add_ent...
Add entries related to an added image.
[ "Add", "entries", "related", "to", "an", "added", "image", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/ChangeHistory.py#L259-L267
26,251
ejeschke/ginga
ginga/rv/plugins/Thumbs.py
Thumbs.drag_drop_cb
def drag_drop_cb(self, viewer, urls): """Punt drag-drops to the ginga shell. """ channel = self.fv.get_current_channel() if channel is None: return self.fv.open_uris(urls, chname=channel.name, bulk_add=True) return True
python
def drag_drop_cb(self, viewer, urls): channel = self.fv.get_current_channel() if channel is None: return self.fv.open_uris(urls, chname=channel.name, bulk_add=True) return True
[ "def", "drag_drop_cb", "(", "self", ",", "viewer", ",", "urls", ")", ":", "channel", "=", "self", ".", "fv", ".", "get_current_channel", "(", ")", "if", "channel", "is", "None", ":", "return", "self", ".", "fv", ".", "open_uris", "(", "urls", ",", "c...
Punt drag-drops to the ginga shell.
[ "Punt", "drag", "-", "drops", "to", "the", "ginga", "shell", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/Thumbs.py#L223-L230
26,252
ejeschke/ginga
ginga/rv/plugins/Thumbs.py
Thumbs.update_highlights
def update_highlights(self, old_highlight_set, new_highlight_set): """Unhighlight the thumbnails represented by `old_highlight_set` and highlight the ones represented by new_highlight_set. Both are sets of thumbkeys. """ with self.thmblock: un_hilite_set = old_highlight_set - new_highlight_set re_hilite_set = new_highlight_set - old_highlight_set # highlight new labels that should be bg = self.settings.get('label_bg_color', 'lightgreen') fg = self.settings.get('label_font_color', 'black') # unhighlight thumb labels that should NOT be highlighted any more for thumbkey in un_hilite_set: if thumbkey in self.thumb_dict: namelbl = self.thumb_dict[thumbkey].get('namelbl') namelbl.color = fg for thumbkey in re_hilite_set: if thumbkey in self.thumb_dict: namelbl = self.thumb_dict[thumbkey].get('namelbl') namelbl.color = bg if self.gui_up: self.c_view.redraw(whence=3)
python
def update_highlights(self, old_highlight_set, new_highlight_set): with self.thmblock: un_hilite_set = old_highlight_set - new_highlight_set re_hilite_set = new_highlight_set - old_highlight_set # highlight new labels that should be bg = self.settings.get('label_bg_color', 'lightgreen') fg = self.settings.get('label_font_color', 'black') # unhighlight thumb labels that should NOT be highlighted any more for thumbkey in un_hilite_set: if thumbkey in self.thumb_dict: namelbl = self.thumb_dict[thumbkey].get('namelbl') namelbl.color = fg for thumbkey in re_hilite_set: if thumbkey in self.thumb_dict: namelbl = self.thumb_dict[thumbkey].get('namelbl') namelbl.color = bg if self.gui_up: self.c_view.redraw(whence=3)
[ "def", "update_highlights", "(", "self", ",", "old_highlight_set", ",", "new_highlight_set", ")", ":", "with", "self", ".", "thmblock", ":", "un_hilite_set", "=", "old_highlight_set", "-", "new_highlight_set", "re_hilite_set", "=", "new_highlight_set", "-", "old_highl...
Unhighlight the thumbnails represented by `old_highlight_set` and highlight the ones represented by new_highlight_set. Both are sets of thumbkeys.
[ "Unhighlight", "the", "thumbnails", "represented", "by", "old_highlight_set", "and", "highlight", "the", "ones", "represented", "by", "new_highlight_set", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/Thumbs.py#L483-L510
26,253
ejeschke/ginga
ginga/rv/plugins/Thumbs.py
Thumbs.have_thumbnail
def have_thumbnail(self, fitsimage, image): """Returns True if we already have a thumbnail version of this image cached, False otherwise. """ chname = self.fv.get_channel_name(fitsimage) # Look up our version of the thumb idx = image.get('idx', None) path = image.get('path', None) if path is not None: path = os.path.abspath(path) name = iohelper.name_image_from_path(path, idx=idx) else: name = 'NoName' # get image name name = image.get('name', name) thumbkey = self.get_thumb_key(chname, name, path) with self.thmblock: return thumbkey in self.thumb_dict
python
def have_thumbnail(self, fitsimage, image): chname = self.fv.get_channel_name(fitsimage) # Look up our version of the thumb idx = image.get('idx', None) path = image.get('path', None) if path is not None: path = os.path.abspath(path) name = iohelper.name_image_from_path(path, idx=idx) else: name = 'NoName' # get image name name = image.get('name', name) thumbkey = self.get_thumb_key(chname, name, path) with self.thmblock: return thumbkey in self.thumb_dict
[ "def", "have_thumbnail", "(", "self", ",", "fitsimage", ",", "image", ")", ":", "chname", "=", "self", ".", "fv", ".", "get_channel_name", "(", "fitsimage", ")", "# Look up our version of the thumb", "idx", "=", "image", ".", "get", "(", "'idx'", ",", "None"...
Returns True if we already have a thumbnail version of this image cached, False otherwise.
[ "Returns", "True", "if", "we", "already", "have", "a", "thumbnail", "version", "of", "this", "image", "cached", "False", "otherwise", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/Thumbs.py#L546-L566
26,254
ejeschke/ginga
ginga/rv/plugins/Thumbs.py
Thumbs.auto_scroll
def auto_scroll(self, thumbkey): """Scroll the window to the thumb.""" if not self.gui_up: return # force scroll to bottom of thumbs, if checkbox is set scrollp = self.w.auto_scroll.get_state() if not scrollp: return bnch = self.thumb_dict[thumbkey] # override X parameter because we only want to scroll vertically pan_x, pan_y = self.c_view.get_pan() self.c_view.panset_xy(pan_x, bnch.image.y)
python
def auto_scroll(self, thumbkey): if not self.gui_up: return # force scroll to bottom of thumbs, if checkbox is set scrollp = self.w.auto_scroll.get_state() if not scrollp: return bnch = self.thumb_dict[thumbkey] # override X parameter because we only want to scroll vertically pan_x, pan_y = self.c_view.get_pan() self.c_view.panset_xy(pan_x, bnch.image.y)
[ "def", "auto_scroll", "(", "self", ",", "thumbkey", ")", ":", "if", "not", "self", ".", "gui_up", ":", "return", "# force scroll to bottom of thumbs, if checkbox is set", "scrollp", "=", "self", ".", "w", ".", "auto_scroll", ".", "get_state", "(", ")", "if", "...
Scroll the window to the thumb.
[ "Scroll", "the", "window", "to", "the", "thumb", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/Thumbs.py#L1011-L1024
26,255
ejeschke/ginga
ginga/rv/plugins/Thumbs.py
Thumbs.clear_widget
def clear_widget(self): """ Clears the thumbnail display widget of all thumbnails, but does not remove them from the thumb_dict or thumb_list. """ if not self.gui_up: return canvas = self.c_view.get_canvas() canvas.delete_all_objects() self.c_view.redraw(whence=0)
python
def clear_widget(self): if not self.gui_up: return canvas = self.c_view.get_canvas() canvas.delete_all_objects() self.c_view.redraw(whence=0)
[ "def", "clear_widget", "(", "self", ")", ":", "if", "not", "self", ".", "gui_up", ":", "return", "canvas", "=", "self", ".", "c_view", ".", "get_canvas", "(", ")", "canvas", ".", "delete_all_objects", "(", ")", "self", ".", "c_view", ".", "redraw", "("...
Clears the thumbnail display widget of all thumbnails, but does not remove them from the thumb_dict or thumb_list.
[ "Clears", "the", "thumbnail", "display", "widget", "of", "all", "thumbnails", "but", "does", "not", "remove", "them", "from", "the", "thumb_dict", "or", "thumb_list", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/Thumbs.py#L1026-L1035
26,256
ejeschke/ginga
ginga/AstroImage.py
AstroImage.load_nddata
def load_nddata(self, ndd, naxispath=None): """Load from an astropy.nddata.NDData object. """ self.clear_metadata() # Make a header based on any NDData metadata ahdr = self.get_header() ahdr.update(ndd.meta) self.setup_data(ndd.data, naxispath=naxispath) if ndd.wcs is None: # no wcs in ndd obj--let's try to make one from the header self.wcs = wcsmod.WCS(logger=self.logger) self.wcs.load_header(ahdr) else: # already have a valid wcs in the ndd object # we assume it needs an astropy compatible wcs wcsinfo = wcsmod.get_wcs_class('astropy') self.wcs = wcsinfo.wrapper_class(logger=self.logger) self.wcs.load_nddata(ndd)
python
def load_nddata(self, ndd, naxispath=None): self.clear_metadata() # Make a header based on any NDData metadata ahdr = self.get_header() ahdr.update(ndd.meta) self.setup_data(ndd.data, naxispath=naxispath) if ndd.wcs is None: # no wcs in ndd obj--let's try to make one from the header self.wcs = wcsmod.WCS(logger=self.logger) self.wcs.load_header(ahdr) else: # already have a valid wcs in the ndd object # we assume it needs an astropy compatible wcs wcsinfo = wcsmod.get_wcs_class('astropy') self.wcs = wcsinfo.wrapper_class(logger=self.logger) self.wcs.load_nddata(ndd)
[ "def", "load_nddata", "(", "self", ",", "ndd", ",", "naxispath", "=", "None", ")", ":", "self", ".", "clear_metadata", "(", ")", "# Make a header based on any NDData metadata", "ahdr", "=", "self", ".", "get_header", "(", ")", "ahdr", ".", "update", "(", "nd...
Load from an astropy.nddata.NDData object.
[ "Load", "from", "an", "astropy", ".", "nddata", ".", "NDData", "object", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/AstroImage.py#L146-L166
26,257
ejeschke/ginga
ginga/AstroImage.py
AstroImage.set_naxispath
def set_naxispath(self, naxispath): """Choose a slice out of multidimensional data. """ revnaxis = list(naxispath) revnaxis.reverse() # construct slice view and extract it view = tuple(revnaxis + [slice(None), slice(None)]) data = self.get_mddata()[view] if len(data.shape) != 2: raise ImageError( "naxispath does not lead to a 2D slice: {}".format(naxispath)) self.naxispath = naxispath self.revnaxis = revnaxis self.set_data(data)
python
def set_naxispath(self, naxispath): revnaxis = list(naxispath) revnaxis.reverse() # construct slice view and extract it view = tuple(revnaxis + [slice(None), slice(None)]) data = self.get_mddata()[view] if len(data.shape) != 2: raise ImageError( "naxispath does not lead to a 2D slice: {}".format(naxispath)) self.naxispath = naxispath self.revnaxis = revnaxis self.set_data(data)
[ "def", "set_naxispath", "(", "self", ",", "naxispath", ")", ":", "revnaxis", "=", "list", "(", "naxispath", ")", "revnaxis", ".", "reverse", "(", ")", "# construct slice view and extract it", "view", "=", "tuple", "(", "revnaxis", "+", "[", "slice", "(", "No...
Choose a slice out of multidimensional data.
[ "Choose", "a", "slice", "out", "of", "multidimensional", "data", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/AstroImage.py#L214-L231
26,258
ejeschke/ginga
ginga/AstroImage.py
AstroImage.get_keyword
def get_keyword(self, kwd, *args): """Get an item from the fits header, if any.""" try: kwds = self.get_header() return kwds[kwd] except KeyError: # return a default if there is one if len(args) > 0: return args[0] raise KeyError(kwd)
python
def get_keyword(self, kwd, *args): try: kwds = self.get_header() return kwds[kwd] except KeyError: # return a default if there is one if len(args) > 0: return args[0] raise KeyError(kwd)
[ "def", "get_keyword", "(", "self", ",", "kwd", ",", "*", "args", ")", ":", "try", ":", "kwds", "=", "self", ".", "get_header", "(", ")", "return", "kwds", "[", "kwd", "]", "except", "KeyError", ":", "# return a default if there is one", "if", "len", "(",...
Get an item from the fits header, if any.
[ "Get", "an", "item", "from", "the", "fits", "header", "if", "any", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/AstroImage.py#L276-L285
26,259
ejeschke/ginga
ginga/AstroImage.py
AstroImage.as_nddata
def as_nddata(self, nddata_class=None): "Return a version of ourself as an astropy.nddata.NDData object" if nddata_class is None: from astropy.nddata import NDData nddata_class = NDData # transfer header, preserving ordering ahdr = self.get_header() header = OrderedDict(ahdr.items()) data = self.get_mddata() wcs = None if hasattr(self, 'wcs') and self.wcs is not None: # for now, assume self.wcs wraps an astropy wcs object wcs = self.wcs.wcs ndd = nddata_class(data, wcs=wcs, meta=header) return ndd
python
def as_nddata(self, nddata_class=None): "Return a version of ourself as an astropy.nddata.NDData object" if nddata_class is None: from astropy.nddata import NDData nddata_class = NDData # transfer header, preserving ordering ahdr = self.get_header() header = OrderedDict(ahdr.items()) data = self.get_mddata() wcs = None if hasattr(self, 'wcs') and self.wcs is not None: # for now, assume self.wcs wraps an astropy wcs object wcs = self.wcs.wcs ndd = nddata_class(data, wcs=wcs, meta=header) return ndd
[ "def", "as_nddata", "(", "self", ",", "nddata_class", "=", "None", ")", ":", "if", "nddata_class", "is", "None", ":", "from", "astropy", ".", "nddata", "import", "NDData", "nddata_class", "=", "NDData", "# transfer header, preserving ordering", "ahdr", "=", "sel...
Return a version of ourself as an astropy.nddata.NDData object
[ "Return", "a", "version", "of", "ourself", "as", "an", "astropy", ".", "nddata", ".", "NDData", "object" ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/AstroImage.py#L347-L364
26,260
ejeschke/ginga
ginga/AstroImage.py
AstroImage.as_hdu
def as_hdu(self): "Return a version of ourself as an astropy.io.fits.PrimaryHDU object" from astropy.io import fits # transfer header, preserving ordering ahdr = self.get_header() header = fits.Header(ahdr.items()) data = self.get_mddata() hdu = fits.PrimaryHDU(data=data, header=header) return hdu
python
def as_hdu(self): "Return a version of ourself as an astropy.io.fits.PrimaryHDU object" from astropy.io import fits # transfer header, preserving ordering ahdr = self.get_header() header = fits.Header(ahdr.items()) data = self.get_mddata() hdu = fits.PrimaryHDU(data=data, header=header) return hdu
[ "def", "as_hdu", "(", "self", ")", ":", "from", "astropy", ".", "io", "import", "fits", "# transfer header, preserving ordering", "ahdr", "=", "self", ".", "get_header", "(", ")", "header", "=", "fits", ".", "Header", "(", "ahdr", ".", "items", "(", ")", ...
Return a version of ourself as an astropy.io.fits.PrimaryHDU object
[ "Return", "a", "version", "of", "ourself", "as", "an", "astropy", ".", "io", ".", "fits", ".", "PrimaryHDU", "object" ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/AstroImage.py#L366-L376
26,261
ejeschke/ginga
ginga/AstroImage.py
AstroImage.astype
def astype(self, type_name): """Convert AstroImage object to some other kind of object. """ if type_name == 'nddata': return self.as_nddata() if type_name == 'hdu': return self.as_hdu() raise ValueError("Unrecognized conversion type '%s'" % (type_name))
python
def astype(self, type_name): if type_name == 'nddata': return self.as_nddata() if type_name == 'hdu': return self.as_hdu() raise ValueError("Unrecognized conversion type '%s'" % (type_name))
[ "def", "astype", "(", "self", ",", "type_name", ")", ":", "if", "type_name", "==", "'nddata'", ":", "return", "self", ".", "as_nddata", "(", ")", "if", "type_name", "==", "'hdu'", ":", "return", "self", ".", "as_hdu", "(", ")", "raise", "ValueError", "...
Convert AstroImage object to some other kind of object.
[ "Convert", "AstroImage", "object", "to", "some", "other", "kind", "of", "object", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/AstroImage.py#L378-L387
26,262
ejeschke/ginga
ginga/util/wcs.py
hmsToDeg
def hmsToDeg(h, m, s): """Convert RA hours, minutes, seconds into an angle in degrees.""" return h * degPerHMSHour + m * degPerHMSMin + s * degPerHMSSec
python
def hmsToDeg(h, m, s): return h * degPerHMSHour + m * degPerHMSMin + s * degPerHMSSec
[ "def", "hmsToDeg", "(", "h", ",", "m", ",", "s", ")", ":", "return", "h", "*", "degPerHMSHour", "+", "m", "*", "degPerHMSMin", "+", "s", "*", "degPerHMSSec" ]
Convert RA hours, minutes, seconds into an angle in degrees.
[ "Convert", "RA", "hours", "minutes", "seconds", "into", "an", "angle", "in", "degrees", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/util/wcs.py#L41-L43
26,263
ejeschke/ginga
ginga/util/wcs.py
hmsStrToDeg
def hmsStrToDeg(ra): """Convert a string representation of RA into a float in degrees.""" hour, min, sec = ra.split(':') ra_deg = hmsToDeg(int(hour), int(min), float(sec)) return ra_deg
python
def hmsStrToDeg(ra): hour, min, sec = ra.split(':') ra_deg = hmsToDeg(int(hour), int(min), float(sec)) return ra_deg
[ "def", "hmsStrToDeg", "(", "ra", ")", ":", "hour", ",", "min", ",", "sec", "=", "ra", ".", "split", "(", "':'", ")", "ra_deg", "=", "hmsToDeg", "(", "int", "(", "hour", ")", ",", "int", "(", "min", ")", ",", "float", "(", "sec", ")", ")", "re...
Convert a string representation of RA into a float in degrees.
[ "Convert", "a", "string", "representation", "of", "RA", "into", "a", "float", "in", "degrees", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/util/wcs.py#L108-L112
26,264
ejeschke/ginga
ginga/util/wcs.py
dmsStrToDeg
def dmsStrToDeg(dec): """Convert a string representation of DEC into a float in degrees.""" sign_deg, min, sec = dec.split(':') sign = sign_deg[0:1] if sign not in ('+', '-'): sign = '+' deg = sign_deg else: deg = sign_deg[1:] dec_deg = decTimeToDeg(sign, int(deg), int(min), float(sec)) return dec_deg
python
def dmsStrToDeg(dec): sign_deg, min, sec = dec.split(':') sign = sign_deg[0:1] if sign not in ('+', '-'): sign = '+' deg = sign_deg else: deg = sign_deg[1:] dec_deg = decTimeToDeg(sign, int(deg), int(min), float(sec)) return dec_deg
[ "def", "dmsStrToDeg", "(", "dec", ")", ":", "sign_deg", ",", "min", ",", "sec", "=", "dec", ".", "split", "(", "':'", ")", "sign", "=", "sign_deg", "[", "0", ":", "1", "]", "if", "sign", "not", "in", "(", "'+'", ",", "'-'", ")", ":", "sign", ...
Convert a string representation of DEC into a float in degrees.
[ "Convert", "a", "string", "representation", "of", "DEC", "into", "a", "float", "in", "degrees", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/util/wcs.py#L115-L125
26,265
ejeschke/ginga
ginga/util/wcs.py
eqToEq2000
def eqToEq2000(ra_deg, dec_deg, eq): """Convert Eq to Eq 2000.""" ra_rad = math.radians(ra_deg) dec_rad = math.radians(dec_deg) x = math.cos(dec_rad) * math.cos(ra_rad) y = math.cos(dec_rad) * math.sin(ra_rad) z = math.sin(dec_rad) p11, p12, p13, p21, p22, p23, p31, p32, p33 = trans_coeff(eq, x, y, z) x0 = p11 * x + p21 * y + p31 * z y0 = p12 * x + p22 * y + p32 * z z0 = p13 * x + p23 * y + p33 * z new_dec = math.asin(z0) if x0 == 0.0: new_ra = math.pi / 2.0 else: new_ra = math.atan(y0 / x0) if ((y0 * math.cos(new_dec) > 0.0 and x0 * math.cos(new_dec) <= 0.0) or (y0 * math.cos(new_dec) <= 0.0 and x0 * math.cos(new_dec) < 0.0)): new_ra += math.pi elif new_ra < 0.0: new_ra += 2.0 * math.pi #new_ra = new_ra * 12.0 * 3600.0 / math.pi new_ra_deg = new_ra * 12.0 / math.pi * 15.0 #new_dec = new_dec * 180.0 * 3600.0 / math.pi new_dec_deg = new_dec * 180.0 / math.pi return (new_ra_deg, new_dec_deg)
python
def eqToEq2000(ra_deg, dec_deg, eq): ra_rad = math.radians(ra_deg) dec_rad = math.radians(dec_deg) x = math.cos(dec_rad) * math.cos(ra_rad) y = math.cos(dec_rad) * math.sin(ra_rad) z = math.sin(dec_rad) p11, p12, p13, p21, p22, p23, p31, p32, p33 = trans_coeff(eq, x, y, z) x0 = p11 * x + p21 * y + p31 * z y0 = p12 * x + p22 * y + p32 * z z0 = p13 * x + p23 * y + p33 * z new_dec = math.asin(z0) if x0 == 0.0: new_ra = math.pi / 2.0 else: new_ra = math.atan(y0 / x0) if ((y0 * math.cos(new_dec) > 0.0 and x0 * math.cos(new_dec) <= 0.0) or (y0 * math.cos(new_dec) <= 0.0 and x0 * math.cos(new_dec) < 0.0)): new_ra += math.pi elif new_ra < 0.0: new_ra += 2.0 * math.pi #new_ra = new_ra * 12.0 * 3600.0 / math.pi new_ra_deg = new_ra * 12.0 / math.pi * 15.0 #new_dec = new_dec * 180.0 * 3600.0 / math.pi new_dec_deg = new_dec * 180.0 / math.pi return (new_ra_deg, new_dec_deg)
[ "def", "eqToEq2000", "(", "ra_deg", ",", "dec_deg", ",", "eq", ")", ":", "ra_rad", "=", "math", ".", "radians", "(", "ra_deg", ")", "dec_rad", "=", "math", ".", "radians", "(", "dec_deg", ")", "x", "=", "math", ".", "cos", "(", "dec_rad", ")", "*",...
Convert Eq to Eq 2000.
[ "Convert", "Eq", "to", "Eq", "2000", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/util/wcs.py#L175-L209
26,266
ejeschke/ginga
ginga/util/wcs.py
get_rotation_and_scale
def get_rotation_and_scale(header, skew_threshold=0.001): """Calculate rotation and CDELT.""" ((xrot, yrot), (cdelt1, cdelt2)) = get_xy_rotation_and_scale(header) if math.fabs(xrot) - math.fabs(yrot) > skew_threshold: raise ValueError("Skew detected: xrot=%.4f yrot=%.4f" % ( xrot, yrot)) rot = yrot lonpole = float(header.get('LONPOLE', 180.0)) if lonpole != 180.0: rot += 180.0 - lonpole return (rot, cdelt1, cdelt2)
python
def get_rotation_and_scale(header, skew_threshold=0.001): ((xrot, yrot), (cdelt1, cdelt2)) = get_xy_rotation_and_scale(header) if math.fabs(xrot) - math.fabs(yrot) > skew_threshold: raise ValueError("Skew detected: xrot=%.4f yrot=%.4f" % ( xrot, yrot)) rot = yrot lonpole = float(header.get('LONPOLE', 180.0)) if lonpole != 180.0: rot += 180.0 - lonpole return (rot, cdelt1, cdelt2)
[ "def", "get_rotation_and_scale", "(", "header", ",", "skew_threshold", "=", "0.001", ")", ":", "(", "(", "xrot", ",", "yrot", ")", ",", "(", "cdelt1", ",", "cdelt2", ")", ")", "=", "get_xy_rotation_and_scale", "(", "header", ")", "if", "math", ".", "fabs...
Calculate rotation and CDELT.
[ "Calculate", "rotation", "and", "CDELT", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/util/wcs.py#L304-L318
26,267
ejeschke/ginga
ginga/util/wcs.py
get_relative_orientation
def get_relative_orientation(image, ref_image): """Computes the relative orientation and scale of an image to a reference image. Parameters ---------- image AstroImage based object ref_image AstroImage based object Returns ------- result Bunch object containing the relative scale in x and y and the relative rotation in degrees. """ # Get reference image rotation and scale header = ref_image.get_header() ((xrot_ref, yrot_ref), (cdelt1_ref, cdelt2_ref)) = get_xy_rotation_and_scale(header) scale_x, scale_y = math.fabs(cdelt1_ref), math.fabs(cdelt2_ref) # Get rotation and scale of image header = image.get_header() ((xrot, yrot), (cdelt1, cdelt2)) = get_xy_rotation_and_scale(header) # Determine relative scale of this image to the reference rscale_x = math.fabs(cdelt1) / scale_x rscale_y = math.fabs(cdelt2) / scale_y # Figure out rotation relative to our orientation rrot_dx, rrot_dy = xrot - xrot_ref, yrot - yrot_ref # flip_x = False # flip_y = False # ## # Flip X due to negative CDELT1 # ## if np.sign(cdelt1) < 0: # ## flip_x = True # ## # Flip Y due to negative CDELT2 # ## if np.sign(cdelt2) < 0: # ## flip_y = True # # Optomization for 180 rotations # if np.isclose(math.fabs(rrot_dx), 180.0): # flip_x = not flip_x # rrot_dx = 0.0 # if np.isclose(math.fabs(rrot_dy), 180.0): # flip_y = not flip_y # rrot_dy = 0.0 rrot_deg = max(rrot_dx, rrot_dy) res = Bunch.Bunch(rscale_x=rscale_x, rscale_y=rscale_y, rrot_deg=rrot_deg) return res
python
def get_relative_orientation(image, ref_image): # Get reference image rotation and scale header = ref_image.get_header() ((xrot_ref, yrot_ref), (cdelt1_ref, cdelt2_ref)) = get_xy_rotation_and_scale(header) scale_x, scale_y = math.fabs(cdelt1_ref), math.fabs(cdelt2_ref) # Get rotation and scale of image header = image.get_header() ((xrot, yrot), (cdelt1, cdelt2)) = get_xy_rotation_and_scale(header) # Determine relative scale of this image to the reference rscale_x = math.fabs(cdelt1) / scale_x rscale_y = math.fabs(cdelt2) / scale_y # Figure out rotation relative to our orientation rrot_dx, rrot_dy = xrot - xrot_ref, yrot - yrot_ref # flip_x = False # flip_y = False # ## # Flip X due to negative CDELT1 # ## if np.sign(cdelt1) < 0: # ## flip_x = True # ## # Flip Y due to negative CDELT2 # ## if np.sign(cdelt2) < 0: # ## flip_y = True # # Optomization for 180 rotations # if np.isclose(math.fabs(rrot_dx), 180.0): # flip_x = not flip_x # rrot_dx = 0.0 # if np.isclose(math.fabs(rrot_dy), 180.0): # flip_y = not flip_y # rrot_dy = 0.0 rrot_deg = max(rrot_dx, rrot_dy) res = Bunch.Bunch(rscale_x=rscale_x, rscale_y=rscale_y, rrot_deg=rrot_deg) return res
[ "def", "get_relative_orientation", "(", "image", ",", "ref_image", ")", ":", "# Get reference image rotation and scale", "header", "=", "ref_image", ".", "get_header", "(", ")", "(", "(", "xrot_ref", ",", "yrot_ref", ")", ",", "(", "cdelt1_ref", ",", "cdelt2_ref",...
Computes the relative orientation and scale of an image to a reference image. Parameters ---------- image AstroImage based object ref_image AstroImage based object Returns ------- result Bunch object containing the relative scale in x and y and the relative rotation in degrees.
[ "Computes", "the", "relative", "orientation", "and", "scale", "of", "an", "image", "to", "a", "reference", "image", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/util/wcs.py#L321-L382
26,268
ejeschke/ginga
ginga/util/wcs.py
deg2fmt
def deg2fmt(ra_deg, dec_deg, format): """Format coordinates.""" rhr, rmn, rsec = degToHms(ra_deg) dsgn, ddeg, dmn, dsec = degToDms(dec_deg) if format == 'hms': return rhr, rmn, rsec, dsgn, ddeg, dmn, dsec elif format == 'str': #ra_txt = '%02d:%02d:%06.3f' % (rhr, rmn, rsec) ra_txt = '%d:%02d:%06.3f' % (rhr, rmn, rsec) if dsgn < 0: dsgn = '-' else: dsgn = '+' #dec_txt = '%s%02d:%02d:%05.2f' % (dsgn, ddeg, dmn, dsec) dec_txt = '%s%d:%02d:%05.2f' % (dsgn, ddeg, dmn, dsec) return ra_txt, dec_txt
python
def deg2fmt(ra_deg, dec_deg, format): rhr, rmn, rsec = degToHms(ra_deg) dsgn, ddeg, dmn, dsec = degToDms(dec_deg) if format == 'hms': return rhr, rmn, rsec, dsgn, ddeg, dmn, dsec elif format == 'str': #ra_txt = '%02d:%02d:%06.3f' % (rhr, rmn, rsec) ra_txt = '%d:%02d:%06.3f' % (rhr, rmn, rsec) if dsgn < 0: dsgn = '-' else: dsgn = '+' #dec_txt = '%s%02d:%02d:%05.2f' % (dsgn, ddeg, dmn, dsec) dec_txt = '%s%d:%02d:%05.2f' % (dsgn, ddeg, dmn, dsec) return ra_txt, dec_txt
[ "def", "deg2fmt", "(", "ra_deg", ",", "dec_deg", ",", "format", ")", ":", "rhr", ",", "rmn", ",", "rsec", "=", "degToHms", "(", "ra_deg", ")", "dsgn", ",", "ddeg", ",", "dmn", ",", "dsec", "=", "degToDms", "(", "dec_deg", ")", "if", "format", "==",...
Format coordinates.
[ "Format", "coordinates", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/util/wcs.py#L465-L483
26,269
ejeschke/ginga
ginga/util/wcs.py
deltaStarsRaDecDeg1
def deltaStarsRaDecDeg1(ra1_deg, dec1_deg, ra2_deg, dec2_deg): """Spherical triangulation.""" phi, dist = dispos(ra1_deg, dec1_deg, ra2_deg, dec2_deg) return arcsecToDeg(dist * 60.0)
python
def deltaStarsRaDecDeg1(ra1_deg, dec1_deg, ra2_deg, dec2_deg): phi, dist = dispos(ra1_deg, dec1_deg, ra2_deg, dec2_deg) return arcsecToDeg(dist * 60.0)
[ "def", "deltaStarsRaDecDeg1", "(", "ra1_deg", ",", "dec1_deg", ",", "ra2_deg", ",", "dec2_deg", ")", ":", "phi", ",", "dist", "=", "dispos", "(", "ra1_deg", ",", "dec1_deg", ",", "ra2_deg", ",", "dec2_deg", ")", "return", "arcsecToDeg", "(", "dist", "*", ...
Spherical triangulation.
[ "Spherical", "triangulation", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/util/wcs.py#L553-L556
26,270
ejeschke/ginga
ginga/util/wcs.py
get_starsep_RaDecDeg
def get_starsep_RaDecDeg(ra1_deg, dec1_deg, ra2_deg, dec2_deg): """Calculate separation.""" sep = deltaStarsRaDecDeg(ra1_deg, dec1_deg, ra2_deg, dec2_deg) sgn, deg, mn, sec = degToDms(sep) if deg != 0: txt = '%02d:%02d:%06.3f' % (deg, mn, sec) else: txt = '%02d:%06.3f' % (mn, sec) return txt
python
def get_starsep_RaDecDeg(ra1_deg, dec1_deg, ra2_deg, dec2_deg): sep = deltaStarsRaDecDeg(ra1_deg, dec1_deg, ra2_deg, dec2_deg) sgn, deg, mn, sec = degToDms(sep) if deg != 0: txt = '%02d:%02d:%06.3f' % (deg, mn, sec) else: txt = '%02d:%06.3f' % (mn, sec) return txt
[ "def", "get_starsep_RaDecDeg", "(", "ra1_deg", ",", "dec1_deg", ",", "ra2_deg", ",", "dec2_deg", ")", ":", "sep", "=", "deltaStarsRaDecDeg", "(", "ra1_deg", ",", "dec1_deg", ",", "ra2_deg", ",", "dec2_deg", ")", "sgn", ",", "deg", ",", "mn", ",", "sec", ...
Calculate separation.
[ "Calculate", "separation", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/util/wcs.py#L577-L585
26,271
ejeschke/ginga
ginga/util/wcs.py
get_RaDecOffsets
def get_RaDecOffsets(ra1_deg, dec1_deg, ra2_deg, dec2_deg): """Calculate offset.""" delta_ra_deg = ra1_deg - ra2_deg adj = math.cos(math.radians(dec2_deg)) if delta_ra_deg > 180.0: delta_ra_deg = (delta_ra_deg - 360.0) * adj elif delta_ra_deg < -180.0: delta_ra_deg = (delta_ra_deg + 360.0) * adj else: delta_ra_deg *= adj delta_dec_deg = dec1_deg - dec2_deg return (delta_ra_deg, delta_dec_deg)
python
def get_RaDecOffsets(ra1_deg, dec1_deg, ra2_deg, dec2_deg): delta_ra_deg = ra1_deg - ra2_deg adj = math.cos(math.radians(dec2_deg)) if delta_ra_deg > 180.0: delta_ra_deg = (delta_ra_deg - 360.0) * adj elif delta_ra_deg < -180.0: delta_ra_deg = (delta_ra_deg + 360.0) * adj else: delta_ra_deg *= adj delta_dec_deg = dec1_deg - dec2_deg return (delta_ra_deg, delta_dec_deg)
[ "def", "get_RaDecOffsets", "(", "ra1_deg", ",", "dec1_deg", ",", "ra2_deg", ",", "dec2_deg", ")", ":", "delta_ra_deg", "=", "ra1_deg", "-", "ra2_deg", "adj", "=", "math", ".", "cos", "(", "math", ".", "radians", "(", "dec2_deg", ")", ")", "if", "delta_ra...
Calculate offset.
[ "Calculate", "offset", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/util/wcs.py#L619-L631
26,272
ejeschke/ginga
ginga/util/wcs.py
lon_to_deg
def lon_to_deg(lon): """Convert longitude to degrees.""" if isinstance(lon, str) and (':' in lon): # TODO: handle other coordinate systems lon_deg = hmsStrToDeg(lon) else: lon_deg = float(lon) return lon_deg
python
def lon_to_deg(lon): if isinstance(lon, str) and (':' in lon): # TODO: handle other coordinate systems lon_deg = hmsStrToDeg(lon) else: lon_deg = float(lon) return lon_deg
[ "def", "lon_to_deg", "(", "lon", ")", ":", "if", "isinstance", "(", "lon", ",", "str", ")", "and", "(", "':'", "in", "lon", ")", ":", "# TODO: handle other coordinate systems", "lon_deg", "=", "hmsStrToDeg", "(", "lon", ")", "else", ":", "lon_deg", "=", ...
Convert longitude to degrees.
[ "Convert", "longitude", "to", "degrees", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/util/wcs.py#L646-L653
26,273
ejeschke/ginga
ginga/util/wcs.py
lat_to_deg
def lat_to_deg(lat): """Convert latitude to degrees.""" if isinstance(lat, str) and (':' in lat): # TODO: handle other coordinate systems lat_deg = dmsStrToDeg(lat) else: lat_deg = float(lat) return lat_deg
python
def lat_to_deg(lat): if isinstance(lat, str) and (':' in lat): # TODO: handle other coordinate systems lat_deg = dmsStrToDeg(lat) else: lat_deg = float(lat) return lat_deg
[ "def", "lat_to_deg", "(", "lat", ")", ":", "if", "isinstance", "(", "lat", ",", "str", ")", "and", "(", "':'", "in", "lat", ")", ":", "# TODO: handle other coordinate systems", "lat_deg", "=", "dmsStrToDeg", "(", "lat", ")", "else", ":", "lat_deg", "=", ...
Convert latitude to degrees.
[ "Convert", "latitude", "to", "degrees", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/util/wcs.py#L656-L663
26,274
ejeschke/ginga
ginga/util/wcs.py
get_ruler_distances
def get_ruler_distances(image, p1, p2): """Get the distance calculated between two points. A Bunch of results is returned, containing pixel values and distance values if the image contains a valid WCS. """ x1, y1 = p1[:2] x2, y2 = p2[:2] dx, dy = x2 - x1, y2 - y1 res = Bunch.Bunch(x1=x1, y1=y1, x2=x2, y2=y2, theta=np.arctan2(y2 - y1, x2 - x1), dx_pix=dx, dy_pix=dy, dh_pix=np.sqrt(dx**2 + dy**2), ra_org=None, dec_org=None, ra_dst=None, dec_dst=None, ra_heel=None, dec_heel=None, dx_deg=None, dy_deg=None, dh_deg=None) if image is not None and hasattr(image, 'wcs') and image.wcs is not None: # Calculate RA and DEC for the three points try: # origination point ra_org, dec_org = image.pixtoradec(x1, y1) res.ra_org, res.dec_org = ra_org, dec_org # destination point ra_dst, dec_dst = image.pixtoradec(x2, y2) res.ra_dst, res.dec_dst = ra_dst, dec_dst # "heel" point making a right triangle ra_heel, dec_heel = image.pixtoradec(x2, y1) res.ra_heel, res.dec_heel = ra_heel, dec_heel res.dh_deg = deltaStarsRaDecDeg(ra_org, dec_org, ra_dst, dec_dst) res.dx_deg = deltaStarsRaDecDeg(ra_org, dec_org, ra_heel, dec_heel) res.dy_deg = deltaStarsRaDecDeg(ra_heel, dec_heel, ra_dst, dec_dst) except Exception as e: pass return res
python
def get_ruler_distances(image, p1, p2): x1, y1 = p1[:2] x2, y2 = p2[:2] dx, dy = x2 - x1, y2 - y1 res = Bunch.Bunch(x1=x1, y1=y1, x2=x2, y2=y2, theta=np.arctan2(y2 - y1, x2 - x1), dx_pix=dx, dy_pix=dy, dh_pix=np.sqrt(dx**2 + dy**2), ra_org=None, dec_org=None, ra_dst=None, dec_dst=None, ra_heel=None, dec_heel=None, dx_deg=None, dy_deg=None, dh_deg=None) if image is not None and hasattr(image, 'wcs') and image.wcs is not None: # Calculate RA and DEC for the three points try: # origination point ra_org, dec_org = image.pixtoradec(x1, y1) res.ra_org, res.dec_org = ra_org, dec_org # destination point ra_dst, dec_dst = image.pixtoradec(x2, y2) res.ra_dst, res.dec_dst = ra_dst, dec_dst # "heel" point making a right triangle ra_heel, dec_heel = image.pixtoradec(x2, y1) res.ra_heel, res.dec_heel = ra_heel, dec_heel res.dh_deg = deltaStarsRaDecDeg(ra_org, dec_org, ra_dst, dec_dst) res.dx_deg = deltaStarsRaDecDeg(ra_org, dec_org, ra_heel, dec_heel) res.dy_deg = deltaStarsRaDecDeg(ra_heel, dec_heel, ra_dst, dec_dst) except Exception as e: pass return res
[ "def", "get_ruler_distances", "(", "image", ",", "p1", ",", "p2", ")", ":", "x1", ",", "y1", "=", "p1", "[", ":", "2", "]", "x2", ",", "y2", "=", "p2", "[", ":", "2", "]", "dx", ",", "dy", "=", "x2", "-", "x1", ",", "y2", "-", "y1", "res"...
Get the distance calculated between two points. A Bunch of results is returned, containing pixel values and distance values if the image contains a valid WCS.
[ "Get", "the", "distance", "calculated", "between", "two", "points", ".", "A", "Bunch", "of", "results", "is", "returned", "containing", "pixel", "values", "and", "distance", "values", "if", "the", "image", "contains", "a", "valid", "WCS", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/util/wcs.py#L666-L708
26,275
ejeschke/ginga
ginga/fonts/font_asst.py
add_font
def add_font(font_file, font_name=None): """Add a font description to our directory of externally loadable fonts. `font_file` is the path to the font, and optional `font_name` is the name to register it under. """ global font_dir if font_name is None: # determine family name from filename of font dirname, filename = os.path.split(font_file) font_name, ext = os.path.splitext(filename) font_dir[font_name] = Bunch.Bunch(name=font_name, font_path=font_file) return font_name
python
def add_font(font_file, font_name=None): global font_dir if font_name is None: # determine family name from filename of font dirname, filename = os.path.split(font_file) font_name, ext = os.path.splitext(filename) font_dir[font_name] = Bunch.Bunch(name=font_name, font_path=font_file) return font_name
[ "def", "add_font", "(", "font_file", ",", "font_name", "=", "None", ")", ":", "global", "font_dir", "if", "font_name", "is", "None", ":", "# determine family name from filename of font", "dirname", ",", "filename", "=", "os", ".", "path", ".", "split", "(", "f...
Add a font description to our directory of externally loadable fonts. `font_file` is the path to the font, and optional `font_name` is the name to register it under.
[ "Add", "a", "font", "description", "to", "our", "directory", "of", "externally", "loadable", "fonts", ".", "font_file", "is", "the", "path", "to", "the", "font", "and", "optional", "font_name", "is", "the", "name", "to", "register", "it", "under", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/fonts/font_asst.py#L56-L70
26,276
ejeschke/ginga
ginga/fonts/font_asst.py
have_font
def have_font(font_name): """Return True if the given font name is registered as one of our externally loadable fonts. If `font_name` is not found, it will try to look it up as an alias and report if that is found. """ if font_name in font_dir: return True # try it as an alias font_name = resolve_alias(font_name, font_name) return font_name in font_dir
python
def have_font(font_name): if font_name in font_dir: return True # try it as an alias font_name = resolve_alias(font_name, font_name) return font_name in font_dir
[ "def", "have_font", "(", "font_name", ")", ":", "if", "font_name", "in", "font_dir", ":", "return", "True", "# try it as an alias", "font_name", "=", "resolve_alias", "(", "font_name", ",", "font_name", ")", "return", "font_name", "in", "font_dir" ]
Return True if the given font name is registered as one of our externally loadable fonts. If `font_name` is not found, it will try to look it up as an alias and report if that is found.
[ "Return", "True", "if", "the", "given", "font", "name", "is", "registered", "as", "one", "of", "our", "externally", "loadable", "fonts", ".", "If", "font_name", "is", "not", "found", "it", "will", "try", "to", "look", "it", "up", "as", "an", "alias", "...
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/fonts/font_asst.py#L73-L83
26,277
ejeschke/ginga
ginga/rv/plugins/Drawing.py
Drawing.toggle_create_button
def toggle_create_button(self): """Enable or disable Create Mask button based on drawn objects.""" if len(self._drawn_tags) > 0: self.w.create_mask.set_enabled(True) else: self.w.create_mask.set_enabled(False)
python
def toggle_create_button(self): if len(self._drawn_tags) > 0: self.w.create_mask.set_enabled(True) else: self.w.create_mask.set_enabled(False)
[ "def", "toggle_create_button", "(", "self", ")", ":", "if", "len", "(", "self", ".", "_drawn_tags", ")", ">", "0", ":", "self", ".", "w", ".", "create_mask", ".", "set_enabled", "(", "True", ")", "else", ":", "self", ".", "w", ".", "create_mask", "."...
Enable or disable Create Mask button based on drawn objects.
[ "Enable", "or", "disable", "Create", "Mask", "button", "based", "on", "drawn", "objects", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/Drawing.py#L355-L360
26,278
ejeschke/ginga
ginga/rv/plugins/Drawing.py
Drawing.create_mask
def create_mask(self): """Create boolean mask from drawing. All areas enclosed by all the shapes drawn will be set to 1 (True) in the mask. Otherwise, the values will be set to 0 (False). The mask will be inserted as a new image buffer, like ``Mosaic``. """ ntags = len(self._drawn_tags) if ntags == 0: return old_image = self.fitsimage.get_image() if old_image is None: return mask = None obj_kinds = set() # Create mask for tag in self._drawn_tags: obj = self.canvas.get_object_by_tag(tag) try: cur_mask = old_image.get_shape_mask(obj) except Exception as e: self.logger.error('Cannot create mask: {0}'.format(str(e))) continue if mask is not None: mask |= cur_mask else: mask = cur_mask obj_kinds.add(obj.kind) # Might be useful to inherit header from displayed image (e.g., WCS) # but the displayed image should not be modified. # Bool needs to be converted to int so FITS writer would not crash. image = dp.make_image(mask.astype('int16'), old_image, {}, pfx=self._mask_prefix) imname = image.get('name') # Insert new image self.fv.gui_call(self.fv.add_image, imname, image, chname=self.chname) # Add description to ChangeHistory s = 'Mask created from {0} drawings ({1})'.format( ntags, ','.join(sorted(obj_kinds))) info = dict(time_modified=datetime.utcnow(), reason_modified=s) self.fv.update_image_info(image, info) self.logger.info(s)
python
def create_mask(self): ntags = len(self._drawn_tags) if ntags == 0: return old_image = self.fitsimage.get_image() if old_image is None: return mask = None obj_kinds = set() # Create mask for tag in self._drawn_tags: obj = self.canvas.get_object_by_tag(tag) try: cur_mask = old_image.get_shape_mask(obj) except Exception as e: self.logger.error('Cannot create mask: {0}'.format(str(e))) continue if mask is not None: mask |= cur_mask else: mask = cur_mask obj_kinds.add(obj.kind) # Might be useful to inherit header from displayed image (e.g., WCS) # but the displayed image should not be modified. # Bool needs to be converted to int so FITS writer would not crash. image = dp.make_image(mask.astype('int16'), old_image, {}, pfx=self._mask_prefix) imname = image.get('name') # Insert new image self.fv.gui_call(self.fv.add_image, imname, image, chname=self.chname) # Add description to ChangeHistory s = 'Mask created from {0} drawings ({1})'.format( ntags, ','.join(sorted(obj_kinds))) info = dict(time_modified=datetime.utcnow(), reason_modified=s) self.fv.update_image_info(image, info) self.logger.info(s)
[ "def", "create_mask", "(", "self", ")", ":", "ntags", "=", "len", "(", "self", ".", "_drawn_tags", ")", "if", "ntags", "==", "0", ":", "return", "old_image", "=", "self", ".", "fitsimage", ".", "get_image", "(", ")", "if", "old_image", "is", "None", ...
Create boolean mask from drawing. All areas enclosed by all the shapes drawn will be set to 1 (True) in the mask. Otherwise, the values will be set to 0 (False). The mask will be inserted as a new image buffer, like ``Mosaic``.
[ "Create", "boolean", "mask", "from", "drawing", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/Drawing.py#L362-L415
26,279
ejeschke/ginga
ginga/rv/plugins/Command.py
CommandInterpreter.cmd_load
def cmd_load(self, *args, **kwargs): """load file ... ch=chname Read files or URLs into the given channel. If the item is a path and it does not begin with a slash it is assumed to be relative to the current working directory. File patterns can also be provided. """ ch = kwargs.get('ch', None) for item in args: # TODO: check for URI syntax files = glob.glob(item) self.fv.gui_do(self.fv.open_uris, files, chname=ch)
python
def cmd_load(self, *args, **kwargs): ch = kwargs.get('ch', None) for item in args: # TODO: check for URI syntax files = glob.glob(item) self.fv.gui_do(self.fv.open_uris, files, chname=ch)
[ "def", "cmd_load", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "ch", "=", "kwargs", ".", "get", "(", "'ch'", ",", "None", ")", "for", "item", "in", "args", ":", "# TODO: check for URI syntax", "files", "=", "glob", ".", "glob", ...
load file ... ch=chname Read files or URLs into the given channel. If the item is a path and it does not begin with a slash it is assumed to be relative to the current working directory. File patterns can also be provided.
[ "load", "file", "...", "ch", "=", "chname" ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/Command.py#L280-L294
26,280
ejeschke/ginga
ginga/rv/plugins/Command.py
CommandInterpreter.cmd_cuts
def cmd_cuts(self, lo=None, hi=None, ch=None): """cuts lo=val hi=val ch=chname If neither `lo` nor `hi` is provided, returns the current cut levels. Otherwise sets the corresponding cut level for the given channel. If `ch` is omitted, assumes the current channel. """ viewer = self.get_viewer(ch) if viewer is None: self.log("No current viewer/channel.") return loval, hival = viewer.get_cut_levels() if (lo is None) and (hi is None): self.log("lo=%f hi=%f" % (loval, hival)) else: if lo is not None: loval = lo if hi is not None: hival = hi viewer.cut_levels(loval, hival) self.log("lo=%f hi=%f" % (loval, hival))
python
def cmd_cuts(self, lo=None, hi=None, ch=None): viewer = self.get_viewer(ch) if viewer is None: self.log("No current viewer/channel.") return loval, hival = viewer.get_cut_levels() if (lo is None) and (hi is None): self.log("lo=%f hi=%f" % (loval, hival)) else: if lo is not None: loval = lo if hi is not None: hival = hi viewer.cut_levels(loval, hival) self.log("lo=%f hi=%f" % (loval, hival))
[ "def", "cmd_cuts", "(", "self", ",", "lo", "=", "None", ",", "hi", "=", "None", ",", "ch", "=", "None", ")", ":", "viewer", "=", "self", ".", "get_viewer", "(", "ch", ")", "if", "viewer", "is", "None", ":", "self", ".", "log", "(", "\"No current ...
cuts lo=val hi=val ch=chname If neither `lo` nor `hi` is provided, returns the current cut levels. Otherwise sets the corresponding cut level for the given channel. If `ch` is omitted, assumes the current channel.
[ "cuts", "lo", "=", "val", "hi", "=", "val", "ch", "=", "chname" ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/Command.py#L296-L320
26,281
ejeschke/ginga
ginga/rv/plugins/Command.py
CommandInterpreter.cmd_ac
def cmd_ac(self, ch=None): """ac ch=chname Calculate and set auto cut levels for the given channel. If `ch` is omitted, assumes the current channel. """ viewer = self.get_viewer(ch) if viewer is None: self.log("No current viewer/channel.") return viewer.auto_levels() self.cmd_cuts(ch=ch)
python
def cmd_ac(self, ch=None): viewer = self.get_viewer(ch) if viewer is None: self.log("No current viewer/channel.") return viewer.auto_levels() self.cmd_cuts(ch=ch)
[ "def", "cmd_ac", "(", "self", ",", "ch", "=", "None", ")", ":", "viewer", "=", "self", ".", "get_viewer", "(", "ch", ")", "if", "viewer", "is", "None", ":", "self", ".", "log", "(", "\"No current viewer/channel.\"", ")", "return", "viewer", ".", "auto_...
ac ch=chname Calculate and set auto cut levels for the given channel. If `ch` is omitted, assumes the current channel.
[ "ac", "ch", "=", "chname" ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/Command.py#L322-L334
26,282
ejeschke/ginga
ginga/rv/plugins/Command.py
CommandInterpreter.cmd_cm
def cmd_cm(self, nm=None, ch=None): """cm nm=color_map_name ch=chname Set a color map (name `nm`) for the given channel. If no value is given, reports the current color map. """ viewer = self.get_viewer(ch) if viewer is None: self.log("No current viewer/channel.") return if nm is None: rgbmap = viewer.get_rgbmap() cmap = rgbmap.get_cmap() self.log(cmap.name) else: viewer.set_color_map(nm)
python
def cmd_cm(self, nm=None, ch=None): viewer = self.get_viewer(ch) if viewer is None: self.log("No current viewer/channel.") return if nm is None: rgbmap = viewer.get_rgbmap() cmap = rgbmap.get_cmap() self.log(cmap.name) else: viewer.set_color_map(nm)
[ "def", "cmd_cm", "(", "self", ",", "nm", "=", "None", ",", "ch", "=", "None", ")", ":", "viewer", "=", "self", ".", "get_viewer", "(", "ch", ")", "if", "viewer", "is", "None", ":", "self", ".", "log", "(", "\"No current viewer/channel.\"", ")", "retu...
cm nm=color_map_name ch=chname Set a color map (name `nm`) for the given channel. If no value is given, reports the current color map.
[ "cm", "nm", "=", "color_map_name", "ch", "=", "chname" ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/Command.py#L343-L360
26,283
ejeschke/ginga
ginga/rv/plugins/Command.py
CommandInterpreter.cmd_cminv
def cmd_cminv(self, ch=None): """cminv ch=chname Invert the color map in the channel/viewer """ viewer = self.get_viewer(ch) if viewer is None: self.log("No current viewer/channel.") return viewer.invert_cmap()
python
def cmd_cminv(self, ch=None): viewer = self.get_viewer(ch) if viewer is None: self.log("No current viewer/channel.") return viewer.invert_cmap()
[ "def", "cmd_cminv", "(", "self", ",", "ch", "=", "None", ")", ":", "viewer", "=", "self", ".", "get_viewer", "(", "ch", ")", "if", "viewer", "is", "None", ":", "self", ".", "log", "(", "\"No current viewer/channel.\"", ")", "return", "viewer", ".", "in...
cminv ch=chname Invert the color map in the channel/viewer
[ "cminv", "ch", "=", "chname" ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/Command.py#L362-L372
26,284
ejeschke/ginga
ginga/rv/plugins/Command.py
CommandInterpreter.cmd_dist
def cmd_dist(self, nm=None, ch=None): """dist nm=dist_name ch=chname Set a color distribution for the given channel. Possible values are linear, log, power, sqrt, squared, asinh, sinh, and histeq. If no value is given, reports the current color distribution algorithm. """ viewer = self.get_viewer(ch) if viewer is None: self.log("No current viewer/channel.") return if nm is None: rgbmap = viewer.get_rgbmap() dist = rgbmap.get_dist() self.log(str(dist)) else: viewer.set_color_algorithm(nm)
python
def cmd_dist(self, nm=None, ch=None): viewer = self.get_viewer(ch) if viewer is None: self.log("No current viewer/channel.") return if nm is None: rgbmap = viewer.get_rgbmap() dist = rgbmap.get_dist() self.log(str(dist)) else: viewer.set_color_algorithm(nm)
[ "def", "cmd_dist", "(", "self", ",", "nm", "=", "None", ",", "ch", "=", "None", ")", ":", "viewer", "=", "self", ".", "get_viewer", "(", "ch", ")", "if", "viewer", "is", "None", ":", "self", ".", "log", "(", "\"No current viewer/channel.\"", ")", "re...
dist nm=dist_name ch=chname Set a color distribution for the given channel. Possible values are linear, log, power, sqrt, squared, asinh, sinh, and histeq. If no value is given, reports the current color distribution algorithm.
[ "dist", "nm", "=", "dist_name", "ch", "=", "chname" ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/Command.py#L374-L394
26,285
ejeschke/ginga
ginga/rv/plugins/Command.py
CommandInterpreter.cmd_imap
def cmd_imap(self, nm=None, ch=None): """imap nm=intensity_map_name ch=chname Set an intensity map (name `nm`) for the given channel. If no value is given, reports the current intensity map. """ viewer = self.get_viewer(ch) if viewer is None: self.log("No current viewer/channel.") return if nm is None: rgbmap = viewer.get_rgbmap() imap = rgbmap.get_imap() self.log(imap.name) else: viewer.set_intensity_map(nm)
python
def cmd_imap(self, nm=None, ch=None): viewer = self.get_viewer(ch) if viewer is None: self.log("No current viewer/channel.") return if nm is None: rgbmap = viewer.get_rgbmap() imap = rgbmap.get_imap() self.log(imap.name) else: viewer.set_intensity_map(nm)
[ "def", "cmd_imap", "(", "self", ",", "nm", "=", "None", ",", "ch", "=", "None", ")", ":", "viewer", "=", "self", ".", "get_viewer", "(", "ch", ")", "if", "viewer", "is", "None", ":", "self", ".", "log", "(", "\"No current viewer/channel.\"", ")", "re...
imap nm=intensity_map_name ch=chname Set an intensity map (name `nm`) for the given channel. If no value is given, reports the current intensity map.
[ "imap", "nm", "=", "intensity_map_name", "ch", "=", "chname" ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/Command.py#L403-L420
26,286
ejeschke/ginga
ginga/rv/plugins/Command.py
CommandInterpreter.cmd_rot
def cmd_rot(self, deg=None, ch=None): """rot deg=num_deg ch=chname Rotate the image for the given viewer/channel by the given number of degrees. If no value is given, reports the current rotation. """ viewer = self.get_viewer(ch) if viewer is None: self.log("No current viewer/channel.") return if deg is None: self.log("%f deg" % (viewer.get_rotation())) else: viewer.rotate(deg)
python
def cmd_rot(self, deg=None, ch=None): viewer = self.get_viewer(ch) if viewer is None: self.log("No current viewer/channel.") return if deg is None: self.log("%f deg" % (viewer.get_rotation())) else: viewer.rotate(deg)
[ "def", "cmd_rot", "(", "self", ",", "deg", "=", "None", ",", "ch", "=", "None", ")", ":", "viewer", "=", "self", ".", "get_viewer", "(", "ch", ")", "if", "viewer", "is", "None", ":", "self", ".", "log", "(", "\"No current viewer/channel.\"", ")", "re...
rot deg=num_deg ch=chname Rotate the image for the given viewer/channel by the given number of degrees. If no value is given, reports the current rotation.
[ "rot", "deg", "=", "num_deg", "ch", "=", "chname" ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/Command.py#L444-L460
26,287
ejeschke/ginga
ginga/rv/plugins/Command.py
CommandInterpreter.cmd_tr
def cmd_tr(self, x=None, y=None, xy=None, ch=None): """tr x=0|1 y=0|1 xy=0|1 ch=chname Transform the image for the given viewer/channel by flipping (x=1 and/or y=1) or swapping axes (xy=1). If no value is given, reports the current rotation. """ viewer = self.get_viewer(ch) if viewer is None: self.log("No current viewer/channel.") return fx, fy, sxy = viewer.get_transforms() if x is None and y is None and xy is None: self.log("x=%s y=%s xy=%s" % (fx, fy, sxy)) else: # turn these into True or False if x is None: x = fx else: x = (x != 0) if y is None: y = fy else: y = (y != 0) if xy is None: xy = sxy else: xy = (xy != 0) viewer.transform(x, y, xy)
python
def cmd_tr(self, x=None, y=None, xy=None, ch=None): viewer = self.get_viewer(ch) if viewer is None: self.log("No current viewer/channel.") return fx, fy, sxy = viewer.get_transforms() if x is None and y is None and xy is None: self.log("x=%s y=%s xy=%s" % (fx, fy, sxy)) else: # turn these into True or False if x is None: x = fx else: x = (x != 0) if y is None: y = fy else: y = (y != 0) if xy is None: xy = sxy else: xy = (xy != 0) viewer.transform(x, y, xy)
[ "def", "cmd_tr", "(", "self", ",", "x", "=", "None", ",", "y", "=", "None", ",", "xy", "=", "None", ",", "ch", "=", "None", ")", ":", "viewer", "=", "self", ".", "get_viewer", "(", "ch", ")", "if", "viewer", "is", "None", ":", "self", ".", "l...
tr x=0|1 y=0|1 xy=0|1 ch=chname Transform the image for the given viewer/channel by flipping (x=1 and/or y=1) or swapping axes (xy=1). If no value is given, reports the current rotation.
[ "tr", "x", "=", "0|1", "y", "=", "0|1", "xy", "=", "0|1", "ch", "=", "chname" ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/Command.py#L462-L494
26,288
ejeschke/ginga
ginga/rv/plugins/Command.py
CommandInterpreter.cmd_scale
def cmd_scale(self, x=None, y=None, ch=None): """scale x=scale_x y=scale_y ch=chname Scale the image for the given viewer/channel by the given amounts. If only one scale value is given, the other is assumed to be the same. If no value is given, reports the current scale. """ viewer = self.get_viewer(ch) if viewer is None: self.log("No current viewer/channel.") return scale_x, scale_y = viewer.get_scale_xy() if x is None and y is None: self.log("x=%f y=%f" % (scale_x, scale_y)) else: if x is not None: if y is None: y = x if y is not None: if x is None: x = y viewer.scale_to(x, y)
python
def cmd_scale(self, x=None, y=None, ch=None): viewer = self.get_viewer(ch) if viewer is None: self.log("No current viewer/channel.") return scale_x, scale_y = viewer.get_scale_xy() if x is None and y is None: self.log("x=%f y=%f" % (scale_x, scale_y)) else: if x is not None: if y is None: y = x if y is not None: if x is None: x = y viewer.scale_to(x, y)
[ "def", "cmd_scale", "(", "self", ",", "x", "=", "None", ",", "y", "=", "None", ",", "ch", "=", "None", ")", ":", "viewer", "=", "self", ".", "get_viewer", "(", "ch", ")", "if", "viewer", "is", "None", ":", "self", ".", "log", "(", "\"No current v...
scale x=scale_x y=scale_y ch=chname Scale the image for the given viewer/channel by the given amounts. If only one scale value is given, the other is assumed to be the same. If no value is given, reports the current scale.
[ "scale", "x", "=", "scale_x", "y", "=", "scale_y", "ch", "=", "chname" ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/Command.py#L496-L520
26,289
ejeschke/ginga
ginga/rv/plugins/Command.py
CommandInterpreter.cmd_z
def cmd_z(self, lvl=None, ch=None): """z lvl=level ch=chname Zoom the image for the given viewer/channel to the given zoom level. Levels can be positive or negative numbers and are relative to a scale of 1:1 at zoom level 0. """ viewer = self.get_viewer(ch) if viewer is None: self.log("No current viewer/channel.") return cur_lvl = viewer.get_zoom() if lvl is None: self.log("zoom=%f" % (cur_lvl)) else: viewer.zoom_to(lvl)
python
def cmd_z(self, lvl=None, ch=None): viewer = self.get_viewer(ch) if viewer is None: self.log("No current viewer/channel.") return cur_lvl = viewer.get_zoom() if lvl is None: self.log("zoom=%f" % (cur_lvl)) else: viewer.zoom_to(lvl)
[ "def", "cmd_z", "(", "self", ",", "lvl", "=", "None", ",", "ch", "=", "None", ")", ":", "viewer", "=", "self", ".", "get_viewer", "(", "ch", ")", "if", "viewer", "is", "None", ":", "self", ".", "log", "(", "\"No current viewer/channel.\"", ")", "retu...
z lvl=level ch=chname Zoom the image for the given viewer/channel to the given zoom level. Levels can be positive or negative numbers and are relative to a scale of 1:1 at zoom level 0.
[ "z", "lvl", "=", "level", "ch", "=", "chname" ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/Command.py#L522-L540
26,290
ejeschke/ginga
ginga/rv/plugins/Command.py
CommandInterpreter.cmd_zf
def cmd_zf(self, ch=None): """zf ch=chname Zoom the image for the given viewer/channel to fit the window. """ viewer = self.get_viewer(ch) if viewer is None: self.log("No current viewer/channel.") return viewer.zoom_fit() cur_lvl = viewer.get_zoom() self.log("zoom=%f" % (cur_lvl))
python
def cmd_zf(self, ch=None): viewer = self.get_viewer(ch) if viewer is None: self.log("No current viewer/channel.") return viewer.zoom_fit() cur_lvl = viewer.get_zoom() self.log("zoom=%f" % (cur_lvl))
[ "def", "cmd_zf", "(", "self", ",", "ch", "=", "None", ")", ":", "viewer", "=", "self", ".", "get_viewer", "(", "ch", ")", "if", "viewer", "is", "None", ":", "self", ".", "log", "(", "\"No current viewer/channel.\"", ")", "return", "viewer", ".", "zoom_...
zf ch=chname Zoom the image for the given viewer/channel to fit the window.
[ "zf", "ch", "=", "chname" ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/Command.py#L542-L554
26,291
ejeschke/ginga
ginga/rv/plugins/Command.py
CommandInterpreter.cmd_c
def cmd_c(self, ch=None): """c ch=chname Center the image for the given viewer/channel. """ viewer = self.get_viewer(ch) if viewer is None: self.log("No current viewer/channel.") return viewer.center_image()
python
def cmd_c(self, ch=None): viewer = self.get_viewer(ch) if viewer is None: self.log("No current viewer/channel.") return viewer.center_image()
[ "def", "cmd_c", "(", "self", ",", "ch", "=", "None", ")", ":", "viewer", "=", "self", ".", "get_viewer", "(", "ch", ")", "if", "viewer", "is", "None", ":", "self", ".", "log", "(", "\"No current viewer/channel.\"", ")", "return", "viewer", ".", "center...
c ch=chname Center the image for the given viewer/channel.
[ "c", "ch", "=", "chname" ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/Command.py#L556-L566
26,292
ejeschke/ginga
ginga/rv/plugins/Command.py
CommandInterpreter.cmd_pan
def cmd_pan(self, x=None, y=None, ch=None): """scale ch=chname x=pan_x y=pan_y Set the pan position for the given viewer/channel to the given pixel coordinates. If no coordinates are given, reports the current position. """ viewer = self.get_viewer(ch) if viewer is None: self.log("No current viewer/channel.") return pan_x, pan_y = viewer.get_pan() if x is None and y is None: self.log("x=%f y=%f" % (pan_x, pan_y)) else: if x is not None: if y is None: y = pan_y if y is not None: if x is None: x = pan_x viewer.set_pan(x, y)
python
def cmd_pan(self, x=None, y=None, ch=None): viewer = self.get_viewer(ch) if viewer is None: self.log("No current viewer/channel.") return pan_x, pan_y = viewer.get_pan() if x is None and y is None: self.log("x=%f y=%f" % (pan_x, pan_y)) else: if x is not None: if y is None: y = pan_y if y is not None: if x is None: x = pan_x viewer.set_pan(x, y)
[ "def", "cmd_pan", "(", "self", ",", "x", "=", "None", ",", "y", "=", "None", ",", "ch", "=", "None", ")", ":", "viewer", "=", "self", ".", "get_viewer", "(", "ch", ")", "if", "viewer", "is", "None", ":", "self", ".", "log", "(", "\"No current vie...
scale ch=chname x=pan_x y=pan_y Set the pan position for the given viewer/channel to the given pixel coordinates. If no coordinates are given, reports the current position.
[ "scale", "ch", "=", "chname", "x", "=", "pan_x", "y", "=", "pan_y" ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/rv/plugins/Command.py#L568-L592
26,293
ejeschke/ginga
ginga/util/heaptimer.py
TimerHeap.timer
def timer(self, jitter, action, *args, **kwargs): """Convenience method to create a Timer from the heap""" return Timer(self, jitter, action, *args, **kwargs)
python
def timer(self, jitter, action, *args, **kwargs): return Timer(self, jitter, action, *args, **kwargs)
[ "def", "timer", "(", "self", ",", "jitter", ",", "action", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "Timer", "(", "self", ",", "jitter", ",", "action", ",", "*", "args", ",", "*", "*", "kwargs", ")" ]
Convenience method to create a Timer from the heap
[ "Convenience", "method", "to", "create", "a", "Timer", "from", "the", "heap" ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/util/heaptimer.py#L123-L125
26,294
ejeschke/ginga
ginga/util/heaptimer.py
TimerHeap.add
def add(self, timer): """Add a timer to the heap""" with self.lock: if self.heap: top = self.heap[0] else: top = None assert timer not in self.timers self.timers[timer] = timer heapq.heappush(self.heap, timer) # Check to see if we need to reschedule our main timer. # Only do this if we aren't expiring in the other thread. if self.heap[0] != top and not self.expiring: if self.rtimer is not None: self.rtimer.cancel() # self.rtimer.join() self.rtimer = None # If we are expiring timers right now then that will reschedule # as appropriate otherwise let's start a timer if we don't have # one if self.rtimer is None and not self.expiring: top = self.heap[0] ival = top.expire - time.time() if ival < 0: ival = 0 self.rtimer = threading.Timer(ival, self.expire) self.rtimer.start()
python
def add(self, timer): with self.lock: if self.heap: top = self.heap[0] else: top = None assert timer not in self.timers self.timers[timer] = timer heapq.heappush(self.heap, timer) # Check to see if we need to reschedule our main timer. # Only do this if we aren't expiring in the other thread. if self.heap[0] != top and not self.expiring: if self.rtimer is not None: self.rtimer.cancel() # self.rtimer.join() self.rtimer = None # If we are expiring timers right now then that will reschedule # as appropriate otherwise let's start a timer if we don't have # one if self.rtimer is None and not self.expiring: top = self.heap[0] ival = top.expire - time.time() if ival < 0: ival = 0 self.rtimer = threading.Timer(ival, self.expire) self.rtimer.start()
[ "def", "add", "(", "self", ",", "timer", ")", ":", "with", "self", ".", "lock", ":", "if", "self", ".", "heap", ":", "top", "=", "self", ".", "heap", "[", "0", "]", "else", ":", "top", "=", "None", "assert", "timer", "not", "in", "self", ".", ...
Add a timer to the heap
[ "Add", "a", "timer", "to", "the", "heap" ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/util/heaptimer.py#L127-L156
26,295
ejeschke/ginga
ginga/util/heaptimer.py
TimerHeap._remove
def _remove(self, timer): """Remove timer from heap lock and presence are assumed""" assert timer.timer_heap == self del self.timers[timer] assert timer in self.heap self.heap.remove(timer) heapq.heapify(self.heap)
python
def _remove(self, timer): assert timer.timer_heap == self del self.timers[timer] assert timer in self.heap self.heap.remove(timer) heapq.heapify(self.heap)
[ "def", "_remove", "(", "self", ",", "timer", ")", ":", "assert", "timer", ".", "timer_heap", "==", "self", "del", "self", ".", "timers", "[", "timer", "]", "assert", "timer", "in", "self", ".", "heap", "self", ".", "heap", ".", "remove", "(", "timer"...
Remove timer from heap lock and presence are assumed
[ "Remove", "timer", "from", "heap", "lock", "and", "presence", "are", "assumed" ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/util/heaptimer.py#L201-L207
26,296
ejeschke/ginga
ginga/util/heaptimer.py
TimerHeap.remove
def remove(self, timer): """Remove a timer from the heap, return True if already run""" with self.lock: # This is somewhat expensive as we have to heapify. if timer in self.timers: self._remove(timer) return False else: return True
python
def remove(self, timer): with self.lock: # This is somewhat expensive as we have to heapify. if timer in self.timers: self._remove(timer) return False else: return True
[ "def", "remove", "(", "self", ",", "timer", ")", ":", "with", "self", ".", "lock", ":", "# This is somewhat expensive as we have to heapify.", "if", "timer", "in", "self", ".", "timers", ":", "self", ".", "_remove", "(", "timer", ")", "return", "False", "els...
Remove a timer from the heap, return True if already run
[ "Remove", "a", "timer", "from", "the", "heap", "return", "True", "if", "already", "run" ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/util/heaptimer.py#L209-L217
26,297
ejeschke/ginga
ginga/util/heaptimer.py
TimerHeap.remove_all_timers
def remove_all_timers(self): """Remove all waiting timers and terminate any blocking threads.""" with self.lock: if self.rtimer is not None: self.rtimer.cancel() self.timers = {} self.heap = [] self.rtimer = None self.expiring = False
python
def remove_all_timers(self): with self.lock: if self.rtimer is not None: self.rtimer.cancel() self.timers = {} self.heap = [] self.rtimer = None self.expiring = False
[ "def", "remove_all_timers", "(", "self", ")", ":", "with", "self", ".", "lock", ":", "if", "self", ".", "rtimer", "is", "not", "None", ":", "self", ".", "rtimer", ".", "cancel", "(", ")", "self", ".", "timers", "=", "{", "}", "self", ".", "heap", ...
Remove all waiting timers and terminate any blocking threads.
[ "Remove", "all", "waiting", "timers", "and", "terminate", "any", "blocking", "threads", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/util/heaptimer.py#L219-L228
26,298
ejeschke/ginga
ginga/canvas/CompoundMixin.py
CompoundMixin.get_llur
def get_llur(self): """ Get lower-left and upper-right coordinates of the bounding box of this compound object. Returns ------- x1, y1, x2, y2: a 4-tuple of the lower-left and upper-right coords """ points = np.array([obj.get_llur() for obj in self.objects]) t_ = points.T x1, y1 = t_[0].min(), t_[1].min() x2, y2 = t_[2].max(), t_[3].max() return (x1, y1, x2, y2)
python
def get_llur(self): points = np.array([obj.get_llur() for obj in self.objects]) t_ = points.T x1, y1 = t_[0].min(), t_[1].min() x2, y2 = t_[2].max(), t_[3].max() return (x1, y1, x2, y2)
[ "def", "get_llur", "(", "self", ")", ":", "points", "=", "np", ".", "array", "(", "[", "obj", ".", "get_llur", "(", ")", "for", "obj", "in", "self", ".", "objects", "]", ")", "t_", "=", "points", ".", "T", "x1", ",", "y1", "=", "t_", "[", "0"...
Get lower-left and upper-right coordinates of the bounding box of this compound object. Returns ------- x1, y1, x2, y2: a 4-tuple of the lower-left and upper-right coords
[ "Get", "lower", "-", "left", "and", "upper", "-", "right", "coordinates", "of", "the", "bounding", "box", "of", "this", "compound", "object", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/canvas/CompoundMixin.py#L36-L49
26,299
ejeschke/ginga
ginga/web/pgw/ipg.py
BasicCanvasView.build_gui
def build_gui(self, container): """ This is responsible for building the viewer's UI. It should place the UI in `container`. Override this to make a custom UI. """ vbox = Widgets.VBox() vbox.set_border_width(0) w = Viewers.GingaViewerWidget(viewer=self) vbox.add_widget(w, stretch=1) # need to put this in an hbox with an expanding label or the # browser wants to resize the canvas, distorting it hbox = Widgets.HBox() hbox.add_widget(vbox, stretch=0) hbox.add_widget(Widgets.Label(''), stretch=1) container.set_widget(hbox)
python
def build_gui(self, container): vbox = Widgets.VBox() vbox.set_border_width(0) w = Viewers.GingaViewerWidget(viewer=self) vbox.add_widget(w, stretch=1) # need to put this in an hbox with an expanding label or the # browser wants to resize the canvas, distorting it hbox = Widgets.HBox() hbox.add_widget(vbox, stretch=0) hbox.add_widget(Widgets.Label(''), stretch=1) container.set_widget(hbox)
[ "def", "build_gui", "(", "self", ",", "container", ")", ":", "vbox", "=", "Widgets", ".", "VBox", "(", ")", "vbox", ".", "set_border_width", "(", "0", ")", "w", "=", "Viewers", ".", "GingaViewerWidget", "(", "viewer", "=", "self", ")", "vbox", ".", "...
This is responsible for building the viewer's UI. It should place the UI in `container`. Override this to make a custom UI.
[ "This", "is", "responsible", "for", "building", "the", "viewer", "s", "UI", ".", "It", "should", "place", "the", "UI", "in", "container", ".", "Override", "this", "to", "make", "a", "custom", "UI", "." ]
a78c893ec6f37a837de851947e9bb4625c597915
https://github.com/ejeschke/ginga/blob/a78c893ec6f37a837de851947e9bb4625c597915/ginga/web/pgw/ipg.py#L42-L60