How to use the nexusformat.nexus.nxload 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 / treeview.py View on Github external
def load(self, filename, mode='r'):
        name = self.get_name(filename)
        self[name] = nxload(filename, mode)
        return self[name]
github nexpy / nexpy / src / nexpy / gui / datadialogs.py View on Github external
def restore(self):
        for backup in self.checkbox:
            if self.checkbox[backup].isChecked():
                name = self.tree.get_name(self.get_name(backup))
                self.tree[name] = self.mainwindow.user_ns[name] = nxload(backup)
                self.checkbox[backup].setChecked(False)
                self.checkbox[backup].setDisabled(True)
github nexpy / nexpy / src / nexpy / gui / plotview.py View on Github external
def keep_data(data):
    from .consoleapp import _nexpy_dir, _tree
    if 'w0' not in _tree:
        _tree['w0'] = nxload(os.path.join(_nexpy_dir, 'w0.nxs'), 'rw')
    ind = []
    for key in _tree['w0']:
        try:
            if key.startswith('s'):
                ind.append(int(key[1:]))
        except ValueError:
            pass
    if ind == []: ind = [0]
    data.nxname = 's'+six.text_type(sorted(ind)[-1]+1)
    _tree['w0'][data.nxname] = data
github nexpy / nexpy / src / nexpy / gui / consoleapp.py View on Github external
"import matplotlib as mpl\n",
                 "from matplotlib import pylab, mlab, pyplot\n",
                 "plt = pyplot\n",
                 "os.chdir(os.path.expanduser('~'))\n"]
            with open(config_file, 'w') as f:
                f.writelines(s)
        else:
            with open(config_file) as f:
                s = f.readlines()
        six.exec_('\n'.join(s), self.window.user_ns)
        if filename is not None:
            try:
                fname = os.path.expanduser(filename)
                name = self.window.treeview.tree.get_name(fname)
                self.window.treeview.tree[name] = self.window.user_ns[name] \
                                                = nxload(fname)
                self.window.treeview.select_node(
                    self.window.treeview.tree[name])
                logging.info("NeXus file '%s' opened as workspace '%s'"
                              % (fname, name))
                self.window.user_ns[name].plot()
            except Exception:
                pass
github nexpy / nexpy / src / nexpy / gui / fitdialogs.py View on Github external
fit.message = self.fit.result.message
            group['statistics'] = fit
            group.note = NXnote(self.fit.result.message,
                ('Chi^2 = %s\n' % self.fit.result.chisqr +
                 'Reduced Chi^2 = %s\n' % self.fit.result.redchi +

                 'No. of Function Evaluations = %s\n' % self.fit.result.nfev +
                 'No. of Variables = %s\n' % self.fit.result.nvarys +
                 'No. of Data Points = %s\n' % self.fit.result.ndata +
                 'No. of Degrees of Freedom = %s\n' % self.fit.result.nfree +
                 '%s' % self.fit.fit_report()))
        else:
            group['title'] = 'Fit Model'
            group['model'] = self.get_model()
        if 'w0' not in self.tree:
            self.tree['w0'] = nxload(self.mainwindow.scratch_file, 'rw')
        ind = []
        for key in self.tree['w0']:
            try:
                if key.startswith('f'): 
                    ind.append(int(key[1:]))
            except ValueError:
                pass
        if not ind:
            ind = [0]
        name = 'f'+str(sorted(ind)[-1]+1)
        self.tree['w0'][name] = group