Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self):
"""Default constructor."""
#logger = log.get_logger(log_stderr=True, level=20)
logger = log.get_logger(null=True)
# Initialize base class
GingaCanvas.__init__(self, logger=logger)
# Keep track of all patches
self.patches={}
#self.zorder=10
self.get_bindings().enable_all(True)
self.enable_draw(True)
self.enable_edit(True)
self.set_drawtype('line', color='green', cap='ball',
linewidth=2)
#self.add_callback('draw-event', self.draw_cb)
#self.add_callback('edit-event', self.edit_cb)
return viewer.dc.CompoundObject(*objs)
def plot_sphere(viewer, r):
# sphere
u = np.linspace(0, np.pi, 30)
v = np.linspace(0, 2 * np.pi, 30)
x = np.outer(np.sin(u), np.sin(v)) * r
y = np.outer(np.sin(u), np.cos(v)) * r
z = np.outer(np.cos(u), np.ones_like(v)) * r
wf = get_wireframe(viewer, x, y, z, color='cyan', alpha=0.3)
viewer.canvas.add(wf)
logger = log.get_logger('example', level=20, log_stderr=True)
app = Widgets.Application(logger)
v = Viewer(app)
v.top.resize(512, 512)
v.top.show()
# put viewer in camera mode
bm = v.vw.get_bindmap()
bm.set_mode('camera', mode_type='locked')
# toggle 3D view
bd = v.vw.get_bindings()
bd.kp_camera_toggle3d(v.vw, None, 0, 0)
r = 100
def main(self, options, args):
"""
Main routine for running the reference viewer.
`options` is a OptionParser object that has been populated with
values from parsing the command line. It should at least include
the options from add_default_options()
`args` is a list of arguments to the viewer after parsing out
options. It should contain a list of files or URLs to load.
"""
# Create a logger
logger = log.get_logger(name='ginga', options=options)
if options.basedir is not None:
paths.ginga_home = os.path.expanduser(options.basedir)
# Get settings (preferences)
basedir = paths.ginga_home
if not os.path.exists(basedir):
try:
os.mkdir(basedir)
except OSError as e:
logger.warning(
"Couldn't create ginga settings area (%s): %s" % (
basedir, str(e)))
logger.warning("Preferences will not be able to be saved")
# Set up preferences
def main(options, args):
#QtGui.QApplication.setGraphicsSystem('raster')
app = QtGui.QApplication(args)
logger = log.get_logger("example2", options=options)
# Check whether user wants to use OpenCv
if options.opencv:
from ginga import trcalc
try:
trcalc.use('opencv')
except Exception as e:
logger.warning("failed to set OpenCv preference: %s" % (str(e)))
# Check whether user wants to use OpenCL
elif options.opencl:
from ginga import trcalc
try:
trcalc.use('opencl')
except Exception as e:
logger.warning("failed to set OpenCL preference: %s" % (str(e)))
def main(options, args):
logger = log.get_logger("ginga", options=options)
# create a new plot with default tools, using figure
fig = figure(x_range=[0, 600], y_range=[0, 600],
plot_width=600, plot_height=600, toolbar_location=None)
viewer = ib.CanvasView(logger)
viewer.set_figure(fig)
def load_file(path):
image = load_data(path, logger=logger)
viewer.set_image(image)
def load_file_cb(attr_name, old_val, new_val):
#print(attr_name, old_val, new_val)
load_file(new_val)
matplotlib.use('Qt4Agg')
import matplotlib.pyplot as plt
import matplotlib.patches as patches
from ginga.mplw.ImageViewCanvasMpl import ImageViewCanvas
from ginga.misc import log
from ginga import cmap
from ginga.util.loader import load_data
# add matplotlib colormaps to ginga's own set
cmap.add_matplotlib_cmaps()
# Set to True to get diagnostic logging output
use_logger = True
logger = log.get_logger(null=not use_logger, log_stderr=True)
# create a regular matplotlib figure
fig = plt.figure()
# create a ginga object, initialize some defaults and
# tell it about the figure
fi = ImageViewCanvas(logger=logger)
fi.enable_autocuts('on')
fi.set_autocut_params('zscale')
#fi.set_cmap(cmap.get_cmap('rainbow3'))
fi.set_figure(fig)
# enable all interactive ginga features
fi.get_bindings().enable_all(True)
# load an image
return False
def draw_event(self, canvas, tag):
obj = canvas.get_object_by_tag(tag)
data_x, data_y = obj.x, obj.y
ra, dec = self.get_wcs(data_x, data_y)
print("A %s was drawn at data %d,%d ra=%s dec=%s" % (
obj.kind, data_x, data_y, ra, dec))
return True
# create a regular matplotlib figure
fig = plt.figure()
# Here is our object
logger = log.get_logger(null=not use_logger, log_stderr=True)
foo = MyGingaFigure(logger, fig)
# load an image, if one was provided
if len(sys.argv) > 1:
foo.load(sys.argv[1])
# Press 'x' to turn on capture of events. Press it again to resume normal
# processing of events.
# Press 'c' to clear the canvas of drawn points.
plt.show()
def main(options, args):
if options.render == 'opengl':
set_default_opengl_context()
#QtGui.QApplication.setGraphicsSystem('raster')
app = QtGui.QApplication(args)
logger = log.get_logger("example2", options=options)
# Check whether user wants to use OpenCv
if options.opencv:
from ginga import trcalc
try:
trcalc.use('opencv')
except Exception as e:
logger.warning("failed to set OpenCv preference: %s" % (str(e)))
# Check whether user wants to use OpenCL
elif options.opencl:
from ginga import trcalc
try:
trcalc.use('opencl')
except Exception as e:
logger.warning("failed to set OpenCL preference: %s" % (str(e)))
def __init__(self, obj, host='localhost', port=9000, ev_quit=None,
logger=None):
super(RemoteServer, self).__init__()
self.robj = obj
# What port to listen for requests
self.port = port
# If blank, listens on all interfaces
self.host = host
if logger is None:
logger = log.get_logger(null=True)
self.logger = logger
if ev_quit is None:
ev_quit = threading.Event()
self.ev_quit = ev_quit
def main(options, args):
logger = log.get_logger(name="mosaic", options=options)
img_mosaic = mosaic(logger, args, fov_deg=options.fov)
if options.outfile:
outfile = options.outfile
io_fits.use('astropy')
logger.info("Writing output to '%s'..." % (outfile))
try:
os.remove(outfile)
except OSError:
pass
img_mosaic.save_as_file(outfile)