<commit_before>#
# Cuts.py -- Cuts plugin for Ginga reference viewer
#
# This is open-source software licensed under a BSD license.
# Please see the file LICENSE.txt for details.
#
import numpy

from ginga.gw import Widgets, Plot
from ginga import GingaPlugin, colors
from ginga.util.six.moves import map, zip
from ginga.canvas.coordmap import OffsetMapper
from ginga.util import plots

# default cut colors
cut_colors = ['magenta', 'skyblue2', 'chartreuse2', 'cyan', 'pink',
              'burlywood2', 'yellow3', 'turquoise', 'coral1', 'mediumpurple2']


class Cuts(GingaPlugin.LocalPlugin):
    """
    A plugin for generating a plot of the values along a line or path.

    There are four kinds of cuts available: line, path, freepath and
    beziercurve:

    - The 'line' cut is a straight line between two points.
    - The 'path' cut is drawn like an open polygon, with straight segments
      in-between.
    - The 'freepath' cut is like a path cut, but drawn using a free-form
      stroke following the cursor movement.
    - The 'beziercurve' path is a cubic Bezier curve.

    Multiple cuts can be plotted.

    Drawing Cuts
    ------------
    The New Cut Type menu chooses what kind of cut you are going to draw.

    Choose "New Cut" from the Cut dropdown menu if you want to draw a
    new cut. Otherwise, if a particular named cut is selected then that
    will be replaced by any newly drawn cut.

    While drawing a path or beziercurve cut, press 'v' to add a vertex,
    or 'z' to remove the last vertex added.

    Keyboard Shortcuts
    ------------------
    While hovering the cursor, press 'h' for a full horizontal cut and
    'j' for a full vertical cut.

    Deleting Cuts
    -------------
    To delete a cut select its name from the Cut dropdown and click the
    Delete button.  To delete all cuts press "Delete All".

    Editing Cuts
    ------------
    Using the edit canvas function it is possible to add new vertexes to
    an existing path, and to move vertexes around.   Click the "Edit"
    radio button to put the canvas in edit mode.  If a cut is not
    automatically selected you can now select the line, path or curve by
    clicking on it, which should enable the control points at the ends or
    vertices--you can drag these around.  To add a new vertex to a path,
    hover the cursor carefully on the line where you want the new vertex
    and press 'v'.  To get rid of a vertex, hover the cursor over it and
    press 'z'.

    You will notice one extra control point for most objects, which has
    a center of a different color--this is a movement control point for
    moving the entire object around the image when in edit mode.

    Changing Width of Cuts
    ----------------------
    The width of 'line' cuts can be changed using the "Width Type" menu:

    - "none" indicates a cut of zero radius; i.e. only showing the pixel
      values along the line
    - "x" will plot the sum of values along the X axis orthoginal to the
      cut.
    - "y" will plot the sum of values along the Y axis orthoginal to the
      cut.
    - "perpendicular" will plot the sum of values along an axis perpendicular
      to the cut.

    The "Width radius" controls the width of the orthoginal summation by
    an amount on either side of the cut--1 would be 3 pixels, 2 would be 5
    pixels, etc.

    """
    def __init__(self, fv, fitsimage):
        # superclass defines some variables for us, like logger
        super(Cuts, self).__init__(fv, fitsimage)

        self.layertag = 'cuts-canvas'
        self._new_cut = 'New Cut'
        self.cutstag = self._new_cut
        self.tags = [self._new_cut]
        self.count = 0
        self.cuttypes = ['line', 'path', 'freepath', 'beziercurve']
        self.cuttype = 'line'
        self.save_enabled = False
        # for 3D Slit functionality
        self.transpose_enabled = False
        self.selected_axis = None
        self.hbox_axes = None

        # For collecting data orthogonal to the cut
        self.widthtypes = ['none', 'x', 'y', 'perpendicular']
        self.widthtype = 'none'
        self.width_radius = 5
        self.tine_spacing_px = 100

        # get Cuts preferences
        prefs = self.fv.get_preferences()
        self.settings = prefs.createCategory('plugin_Cuts')
        self.settings.addDefaults(select_new_cut=True, draw_then_move=True,
                                  label_cuts=True, colors=cut_colors,
                                  drag_update=False,
                                  show_cuts_legend=False, enable_slit=False)
        self.settings.load(onError='silent')
        self.colors = self.settings.get('colors', cut_colors)

        self.dc = fv.getDrawClasses()
        canvas = self.dc.DrawingCanvas()
        canvas.enable_draw(True)
        canvas.enable_edit(True)
        canvas.set_drawtype('line', color='cyan', linestyle='dash')
        canvas.set_callback('draw-event', self.draw_cb)
        canvas.set_callback('edit-event', self.edit_cb)
        canvas.add_draw_mode('move', down=self.buttondown_cb,
                             move=self.motion_cb, up=self.buttonup_cb,
                             key=self.keydown)
        canvas.set_draw_mode('draw')
        canvas.register_for_cursor_drawing(self.fitsimage)
        #canvas.set_callback('key-press', self.keydown)
        canvas.setSurface(self.fitsimage)
        self.canvas = canvas

        self.use_slit = self.settings.get('enable_slit', False)
        self.cuts_image = None
<commit_msg>Change slit to be on by default<commit_after>#
# Cuts.py -- Cuts plugin for Ginga reference viewer
#
# This is open-source software licensed under a BSD license.
# Please see the file LICENSE.txt for details.
#
import numpy

from ginga.gw import Widgets, Plot
from ginga import GingaPlugin, colors
from ginga.util.six.moves import map, zip
from ginga.canvas.coordmap import OffsetMapper
from ginga.util import plots

# default cut colors
cut_colors = ['magenta', 'skyblue2', 'chartreuse2', 'cyan', 'pink',
              'burlywood2', 'yellow3', 'turquoise', 'coral1', 'mediumpurple2']


class Cuts(GingaPlugin.LocalPlugin):
    """
    A plugin for generating a plot of the values along a line or path.

    There are four kinds of cuts available: line, path, freepath and
    beziercurve:

    - The 'line' cut is a straight line between two points.
    - The 'path' cut is drawn like an open polygon, with straight segments
      in-between.
    - The 'freepath' cut is like a path cut, but drawn using a free-form
      stroke following the cursor movement.
    - The 'beziercurve' path is a cubic Bezier curve.

    Multiple cuts can be plotted.

    Drawing Cuts
    ------------
    The New Cut Type menu chooses what kind of cut you are going to draw.

    Choose "New Cut" from the Cut dropdown menu if you want to draw a
    new cut. Otherwise, if a particular named cut is selected then that
    will be replaced by any newly drawn cut.

    While drawing a path or beziercurve cut, press 'v' to add a vertex,
    or 'z' to remove the last vertex added.

    Keyboard Shortcuts
    ------------------
    While hovering the cursor, press 'h' for a full horizontal cut and
    'j' for a full vertical cut.

    Deleting Cuts
    -------------
    To delete a cut select its name from the Cut dropdown and click the
    Delete button.  To delete all cuts press "Delete All".

    Editing Cuts
    ------------
    Using the edit canvas function it is possible to add new vertexes to
    an existing path, and to move vertexes around.   Click the "Edit"
    radio button to put the canvas in edit mode.  If a cut is not
    automatically selected you can now select the line, path or curve by
    clicking on it, which should enable the control points at the ends or
    vertices--you can drag these around.  To add a new vertex to a path,
    hover the cursor carefully on the line where you want the new vertex
    and press 'v'.  To get rid of a vertex, hover the cursor over it and
    press 'z'.

    You will notice one extra control point for most objects, which has
    a center of a different color--this is a movement control point for
    moving the entire object around the image when in edit mode.

    Changing Width of Cuts
    ----------------------
    The width of 'line' cuts can be changed using the "Width Type" menu:

    - "none" indicates a cut of zero radius; i.e. only showing the pixel
      values along the line
    - "x" will plot the sum of values along the X axis orthoginal to the
      cut.
    - "y" will plot the sum of values along the Y axis orthoginal to the
      cut.
    - "perpendicular" will plot the sum of values along an axis perpendicular
      to the cut.

    The "Width radius" controls the width of the orthoginal summation by
    an amount on either side of the cut--1 would be 3 pixels, 2 would be 5
    pixels, etc.

    """
    def __init__(self, fv, fitsimage):
        # superclass defines some variables for us, like logger
        super(Cuts, self).__init__(fv, fitsimage)

        self.layertag = 'cuts-canvas'
        self._new_cut = 'New Cut'
        self.cutstag = self._new_cut
        self.tags = [self._new_cut]
        self.count = 0
        self.cuttypes = ['line', 'path', 'freepath', 'beziercurve']
        self.cuttype = 'line'
        self.save_enabled = False
        # for 3D Slit functionality
        self.transpose_enabled = False
        self.selected_axis = None
        self.hbox_axes = None

        # For collecting data orthogonal to the cut
        self.widthtypes = ['none', 'x', 'y', 'perpendicular']
        self.widthtype = 'none'
        self.width_radius = 5
        self.tine_spacing_px = 100

        # get Cuts preferences
        prefs = self.fv.get_preferences()
        self.settings = prefs.createCategory('plugin_Cuts')
        self.settings.addDefaults(select_new_cut=True, draw_then_move=True,
                                  label_cuts=True, colors=cut_colors,
                                  drag_update=False,
                                  show_cuts_legend=False, enable_slit=False)
        self.settings.load(onError='silent')
        self.colors = self.settings.get('colors', cut_colors)

        self.dc = fv.getDrawClasses()
        canvas = self.dc.DrawingCanvas()
        canvas.enable_draw(True)
        canvas.enable_edit(True)
        canvas.set_drawtype('line', color='cyan', linestyle='dash')
        canvas.set_callback('draw-event', self.draw_cb)
        canvas.set_callback('edit-event', self.edit_cb)
        canvas.add_draw_mode('move', down=self.buttondown_cb,
                             move=self.motion_cb, up=self.buttonup_cb,
                             key=self.keydown)
        canvas.set_draw_mode('draw')
        canvas.register_for_cursor_drawing(self.fitsimage)
        #canvas.set_callback('key-press', self.keydown)
        canvas.setSurface(self.fitsimage)
        self.canvas = canvas

        self.use_slit = self.settings.get('enable_slit', True)
        self.cuts_image = None

{'fraction_non_alphanumeric': 0.0859806317313784, 'fraction_numerical': 0.002896189700425378, 'mean_word_length': 2.3843797856049003, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4481223', 'n_tokens_mistral': 3208, 'n_tokens_neox': 3082, 'n_words': 1250}