How to use the nexusformat.nexus.NeXusError function in nexusformat

To help you get started, we’ve selected a few nexusformat examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nexpy / nexpy / src / nexpy / gui / fitdialogs.py View on Github external
def initialize_data(self, data):
        if isinstance(data, NXdata):
            if len(data.nxsignal.shape) > 1:
                raise NeXusError(
                    "Fitting only possible on one-dimensional arrays")
            signal, axes = data.nxsignal, data.nxaxes[0]
            if signal.shape[0] == axes.shape[0] - 1:
                axes = axes.centers()
            fit_data = NXdata(signal, axes, title=data.nxtitle)
            if data.nxerrors:
                fit_data.errors = data.nxerrors
            return fit_data
        else:
            raise NeXusError("Must be an NXdata group")
github nexpy / nexpy / src / nexpy / gui / plotview.py View on Github external
def plot_smooth(self):
        """Add smooth line to 1D plot."""
        num = str(self.num)
        if self.plots[num]['smooth_function']:
            self.plots[num]['smoothing'] = self.ytab.smoothing
        else:
            raise NeXusError("Unable to smooth this data")
        for num in self.plots:
            p = self.plots[num]
            if p['smooth_line']:
                p['smooth_line'].remove()
            xs_min, xs_max = self.ax.get_xlim()
            if (p['smoothing'] and p['smooth_function'] and
                xs_min < p['x'].max() and xs_max > p['x'].min()):
                p['plot'].set_linestyle('None')
                xs = np.linspace(max(xs_min, p['x'].min()), 
                                 min(xs_max, p['x'].max()), 1000)
                if p['linestyle'] == 'None':
                    p['smooth_linestyle'] = '-'
                else:
                    p['smooth_linestyle'] = p['linestyle']
                p['smooth_line'] = self.ax.plot(xs, 
                                                p['smooth_function'](xs),
github nexpy / nexpy / src / nexpy / gui / plotview.py View on Github external
ax.set_xlim(xmax, xmin)
        else:
            ax.set_xlim(xmin, xmax)
        if ((self.yaxis.reversed and not self.ytab.flipped) or
            (not self.yaxis.reversed and self.ytab.flipped)):
            ax.set_ylim(ymax, ymin)
        else:
            ax.set_ylim(ymin, ymax)
        ax.set_xlabel(self.xaxis.label)
        ax.set_ylabel(self.yaxis.label)
        self.otab.push_current()
        self.update_panels()
        if self.ndim == 1:
            try:
                self.plot_smooth()
            except NeXusError:
                pass
        if draw:
            self.draw()
github nexpy / nexpy / src / nexpy / gui / plotview.py View on Github external
over = opts.pop("over", False)
        image = opts.pop("image", False)
        log = opts.pop("log", False)
        logx = opts.pop("logx", False)
        logy = opts.pop("logy", False)
        cmap = opts.pop("cmap", None)
        self._aspect = opts.pop("aspect", "auto")
        self._skew_angle = opts.pop("skew", None)

        self.data = data
        if not over:
            self.title = data.nxtitle

        if self.data.nxsignal is None:
            raise NeXusError('No plotting signal defined')

        if image:
            self.rgb_image = True
        else:
            self.rgb_image = False

        self.plotdata = self.get_plotdata(over)

        #One-dimensional Plot
        if self.ndim == 1:
            if over:
                self.num = self.num + 1
            else:
                self.num = 0
                if xmin:
                    self.xaxis.lo = xmin
github nexpy / nexpy / src / nexpy / gui / datadialogs.py View on Github external
def install_plugin(self):        
        plugin_directory = self.get_directory()
        plugin_name = os.path.basename(os.path.normpath(plugin_directory))
        plugin_path = os.path.dirname(plugin_directory)
        plugin_menu_name = self.get_menu_name(plugin_name, plugin_path)
        if plugin_menu_name is None:
            raise NeXusError("This directory does not contain a valid plugin")
        if self.radiobutton['local'].isChecked():
            plugin_path = self.local_directory
        else:
            plugin_path = self.nexpy_directory
        installed_path = os.path.join(plugin_path, plugin_name)
        if os.path.exists(installed_path):
            if self.confirm_action("Overwrite plugin?", 
                                   "Plugin '%s' already exists" % plugin_name):
                backup = os.path.join(self.backup_dir, timestamp())
                os.mkdir(backup)
                shutil.move(installed_path, backup)
                self.mainwindow.settings.set('plugins', 
                                             os.path.join(backup, plugin_name))
                self.mainwindow.settings.save()
            else:
                return
github nexpy / nexpy / src / nexpy / gui / datadialogs.py View on Github external
def get_axes(self):
        axes = [self.get_axis(axis) for axis in range(self.ndim)]
        names = [axis.nxname for axis in axes]
        if len(names) != len(set(names)):
            raise NeXusError("Duplicate axes selected")
        return axes
github nexpy / nexpy / src / nexpy / gui / datadialogs.py View on Github external
def add(self, label, tab=None, idx=None):
        if label in self.tabs:
            raise NeXusError("'%s' already in %s" % (label, self.title))
        self.tabs[label] = tab
        self.labels[tab] = label
        tab.panel = self
        if idx is not None:
            self.tabwidget.insertTab(idx, tab, label)
        else:
            self.tabwidget.addTab(tab, label)
        self.tabwidget.setCurrentWidget(tab)
        self.tabwidget.tabBar().setTabToolTip(self.tabwidget.indexOf(tab), label)
        self.setVisible(True)
github nexpy / nexpy / src / nexpy / gui / remotedialogs.py View on Github external
def exec_sleep(parent=None):
    try:
        dialog = SleepDialog(parent)
        dialog.show()
    except NeXusError as error:
        report_error("Exec Sleep", error)
github nexpy / nexpy / src / nexpy / gui / fitdialogs.py View on Github external
def initialize_data(self, data):
        if isinstance(data, NXdata):
            if len(data.nxsignal.shape) > 1:
                raise NeXusError(
                    "Fitting only possible on one-dimensional arrays")
            signal, axes = data.nxsignal, data.nxaxes[0]
            if signal.shape[0] == axes.shape[0] - 1:
                axes = axes.centers()
            fit_data = NXdata(signal, axes, title=data.nxtitle)
            if data.nxerrors:
                fit_data.errors = data.nxerrors
            return fit_data
        else:
            raise NeXusError("Must be an NXdata group")