Пример #1
0
 def _mouse_event(self, signal, mpl_event):
     if mpl_event.inaxes is None:
         return
     axes = mpl_event.inaxes
     xpos = from_ui(axes.x_name[0], mpl_event.xdata)
     ypos = from_ui(axes.y_name[0], mpl_event.ydata)
     elem = self.get_element_by_mouse_position(axes, xpos)
     event = MouseEvent(mpl_event.button, xpos, ypos,
                        axes, elem, mpl_event.guiEvent)
     signal.emit(event)
Пример #2
0
 def _mouse_event(self, signal, mpl_event):
     if mpl_event.inaxes is None:
         return
     axes = mpl_event.inaxes
     xpos = from_ui(axes.x_name[0], mpl_event.xdata)
     ypos = from_ui(axes.y_name[0], mpl_event.ydata)
     elem = self.get_element_by_mouse_position(axes, xpos)
     event = MouseEvent(mpl_event.button, xpos, ypos, axes, elem,
                        mpl_event.guiEvent)
     signal.emit(event)
Пример #3
0
 def get_beam(self):
     units = unit.units
     e_para = ENERGY_PARAM.get(self._model().seq_name, 'E_HEBT')
     z_num = self._lib.GetFloatValue('Z_POSTSTRIP')
     mass = self._lib.GetFloatValue('A_POSTSTRIP') * units.u
     charge = self._lib.GetFloatValue('Q_POSTSTRIP') * units.e
     e_kin = (self._lib.GetFloatValue(e_para) or 1) * units.MeV / units.u
     return {
         'particle': PERIODIC_TABLE[round(z_num)],
         'charge': unit.from_ui('charge', charge),
         'mass': unit.from_ui('mass', mass),
         'energy': unit.from_ui('energy', mass * (e_kin + 1 * units.c**2)),
     }
Пример #4
0
def read_table(filename):
    """
    Read a data file that defines the column names and units in a comment.

    Simple example file:

        # s[mm] env[mm] envy[mm]
        0       1       1
        1       2       1
        2       1       2

    For which this function returns a dictionary:

        's'     -> np.array([0, 1000, 2000])
        'envx'  -> np.array([1000, 2000, 1000])
        'envy'  -> np.array([1000, 1000, 2000])
    """
    with open(filename) as f:
        titles = _parse_header(f)
    columns = [_parse_column_title(t) for t in titles]
    names = [name for name, unit in columns]
    data = np.genfromtxt(filename, dtype=None, encoding='utf-8', names=names)
    return {
        name: from_ui(name, _add_unit(data[name], unit))
        for name, unit in columns
    }
Пример #5
0
 def set_ui_value(self, value):
     self.set_value(from_ui(self.name, value))
Пример #6
0
def parse_datum(name, datum):
    value = float(datum.text)
    unit = from_config(datum.attrib['Unit'])
    return from_ui(name, unit, value)