diff options
author | Onderwaater <onderwaa@esrf.fr> | 2015-11-25 11:37:42 +0100 |
---|---|---|
committer | Onderwaater <onderwaa@esrf.fr> | 2015-11-25 11:37:42 +0100 |
commit | a6582c0e3cd9bf77f3554b2cbeee2e65d1478c78 (patch) | |
tree | 8dc73fd33ec085dc23cfef7880168feda13a0866 | |
parent | 0a6258cd353f205fa4cf7c4decc6b83465f5accc (diff) |
renaming of scripts + main folder
-rw-r--r-- | BINoculars/__init__.py | 100 | ||||
-rw-r--r-- | binoculars-fitaid.py (renamed from fitaid.py) | 44 | ||||
-rwxr-xr-x | binoculars-gui.py (renamed from gui.py) | 50 | ||||
-rwxr-xr-x | binoculars-processgui.py (renamed from processgui.py) | 24 | ||||
-rw-r--r-- | binoculars-server.py (renamed from server.py) | 10 | ||||
-rwxr-xr-x | binoculars.py | 74 | ||||
-rw-r--r-- | examples/scripts/demo.py | 16 | ||||
-rw-r--r-- | examples/scripts/demo_fit.py | 14 |
8 files changed, 166 insertions, 166 deletions
diff --git a/BINoculars/__init__.py b/BINoculars/__init__.py index dfbbec4..e7824cf 100644 --- a/BINoculars/__init__.py +++ b/BINoculars/__init__.py @@ -10,10 +10,10 @@ def run(args): All additonal configuration file overides can be included Returns - A BINoculars space + A binoculars space Examples: - >>> space = BINoculars.run('config.txt 10') + >>> space = binoculars.run('config.txt 10') >>> space Axes (3 dimensions, 2848 points, 33.0 kB) { Axis qx (min=-0.01, max=0.0, res=0.01, count=2) @@ -22,14 +22,14 @@ def run(args): } ''' - import BINoculars.main - BINoculars.util.register_python_executable(__file__) - main = BINoculars.main.Main.from_args(args.split(' ')) - if isinstance(main.result, BINoculars.space.Space): + import binoculars.main + binoculars.util.register_python_executable(__file__) + main = binoculars.main.Main.from_args(args.split(' ')) + if isinstance(main.result, binoculars.space.Space): return main.result if type(main.result) == bool: filename = main.dispatcher.config.destination.final_filename() - return BINoculars.space.Space.fromfile(filename) + return binoculars.space.Space.fromfile(filename) def load(filename, key = None): ''' Parameters @@ -38,10 +38,10 @@ def load(filename, key = None): key: a tuple with slices in as much dimensions as the space is Returns - A BINoculars space + A binoculars space Examples: - >>> space = BINoculars.load('test.hdf5') + >>> space = binoculars.load('test.hdf5') >>> space Axes (3 dimensions, 2848 points, 33.0 kB) { Axis qx (min=-0.01, max=0.0, res=0.01, count=2) @@ -49,9 +49,9 @@ def load(filename, key = None): Axis qz (min=0.48, max=4.03, res=0.01, count=356) } ''' - import BINoculars.space + import binoculars.space if os.path.exists(filename): - return BINoculars.space.Space.fromfile(filename, key = key) + return binoculars.space.Space.fromfile(filename, key = key) else: raise IOError("File '{0}' does not exist".format(filename)) @@ -62,7 +62,7 @@ def save(filename, space): Parameters filename: string filename to which the data is saved. '.txt', '.hdf5' are supported. - space: BINoculars space + space: binoculars space the space containing the data that needs to be saved Examples: @@ -72,27 +72,27 @@ def save(filename, space): Axis qy (min=-0.04, max=-0.01, res=0.01, count=4) Axis qz (min=0.48, max=4.03, res=0.01, count=356) } - >>> BINoculars.save('test.hdf5', space) + >>> binoculars.save('test.hdf5', space) ''' - import BINoculars.space, BINoculars.util - if isinstance(space, BINoculars.space.Space): + import binoculars.space, binoculars.util + if isinstance(space, binoculars.space.Space): ext = os.path.splitext(filename)[-1] if ext == '.txt': - BINoculars.util.space_to_txt(space, filename) + binoculars.util.space_to_txt(space, filename) elif ext == '.edf': - BINoculars.util.space_to_edf(space, filename) + binoculars.util.space_to_edf(space, filename) else: space.tofile(filename) else: - raise TypeError("'{0!r}' is not a BINoculars space".format(space)) + raise TypeError("'{0!r}' is not a binoculars space".format(space)) def plotspace(space, log=True, clipping=0.0, fit=None, norm=None, colorbar=True, labels=True, **plotopts): ''' plots a space with the correct axes. The space can be either one or two dimensinal. Parameters - space: BINoculars space + space: binoculars space the space containing the data that needs to be plotted log: bool axes or colorscale logarithmic @@ -116,33 +116,33 @@ def plotspace(space, log=True, clipping=0.0, fit=None, norm=None, colorbar=True, Axis qy (min=-0.04, max=-0.01, res=0.01, count=4) Axis qz (min=0.48, max=4.03, res=0.01, count=356) } - >>> BINoculars.plotspace('test.hdf5') + >>> binoculars.plotspace('test.hdf5') ''' import matplotlib.pyplot as pyplot - import BINoculars.plot, BINoculars.space + import binoculars.plot, binoculars.space - if isinstance(space, BINoculars.space.Space): + if isinstance(space, binoculars.space.Space): if space.dimension == 3: from mpl_toolkits.mplot3d import Axes3D ax = pyplot.gcf().gca(projection='3d') - return BINoculars.plot.plot(space, pyplot.gcf(), ax, log=log, clipping=clipping, fit=None, norm=norm, colorbar=colorbar, labels=labels, **plotopts) + return binoculars.plot.plot(space, pyplot.gcf(), ax, log=log, clipping=clipping, fit=None, norm=norm, colorbar=colorbar, labels=labels, **plotopts) if fit is not None and space.dimension == 2: ax = pyplot.gcf().add_subplot(121) - BINoculars.plot.plot(space, pyplot.gcf(), ax, log=log, clipping=clipping, fit=None, norm=norm, colorbar=colorbar, labels=labels, **plotopts) + binoculars.plot.plot(space, pyplot.gcf(), ax, log=log, clipping=clipping, fit=None, norm=norm, colorbar=colorbar, labels=labels, **plotopts) ax = pyplot.gcf().add_subplot(122) - return BINoculars.plot.plot(space, pyplot.gcf(), ax, log=log, clipping=clipping, fit=fit, norm=norm, colorbar=colorbar, labels=labels, **plotopts) + return binoculars.plot.plot(space, pyplot.gcf(), ax, log=log, clipping=clipping, fit=fit, norm=norm, colorbar=colorbar, labels=labels, **plotopts) else: - return BINoculars.plot.plot(space, pyplot.gcf(), pyplot.gca(), log=log, clipping=clipping, fit=fit, norm=norm, colorbar=colorbar, labels=labels, **plotopts) + return binoculars.plot.plot(space, pyplot.gcf(), pyplot.gca(), log=log, clipping=clipping, fit=fit, norm=norm, colorbar=colorbar, labels=labels, **plotopts) else: - raise TypeError("'{0!r}' is not a BINoculars space".format(space)) + raise TypeError("'{0!r}' is not a binoculars space".format(space)) def transform(space, labels, resolutions, exprs): ''' transformation of the coordinates. Parameters - space: BINoculars space + space: binoculars space labels: list a list of length N with the labels resolutions: list @@ -152,28 +152,28 @@ def transform(space, labels, resolutions, exprs): all numpy funtions can be called without adding 'numpy.' to the functions. Returns - A BINoculars space of dimension N with labels and resolutions specified in the input + A binoculars space of dimension N with labels and resolutions specified in the input Examples: - >>> space = BINoculars.load('test.hdf5') + >>> space = binoculars.load('test.hdf5') >>> space Axes (3 dimensions, 2848 points, 33.0 kB) { Axis qx (min=-0.01, max=0.0, res=0.01, count=2) Axis qy (min=-0.04, max=-0.01, res=0.01, count=4) Axis qz (min=0.48, max=4.03, res=0.01, count=356) } - >>> newspace = BINoculars.transform(space, ['twotheta'], [0.003], ['2 * arcsin(0.51 * (sqrt(qx**2 + qy**2 + qz**2) / (4 * pi)) / (pi * 180))']) + >>> newspace = binoculars.transform(space, ['twotheta'], [0.003], ['2 * arcsin(0.51 * (sqrt(qx**2 + qy**2 + qz**2) / (4 * pi)) / (pi * 180))']) >>> newspace Axes (1 dimensions, 152 points, 1.0 kB) { Axis twotheta (min=0.066, max=0.519, res=0.003, count=152) } ''' - import BINoculars.util, BINoculars.space - if isinstance(space, BINoculars.space.Space): - transformation = BINoculars.util.transformation_from_expressions(space, exprs) + import binoculars.util, binoculars.space + if isinstance(space, binoculars.space.Space): + transformation = binoculars.util.transformation_from_expressions(space, exprs) newspace = space.transform_coordinates(resolutions, labels, transformation) else: - raise TypeError("'{0!r}' is not a BINoculars space".format(space)) + raise TypeError("'{0!r}' is not a binoculars space".format(space)) return newspace def fitspace(space, function, guess = None): @@ -181,7 +181,7 @@ def fitspace(space, function, guess = None): fit the space data. Parameters - space: BINoculars space + space: binoculars space function: list a string with the name of the desired function. supported are: lorentzian (automatically selects 1d or 2d), gaussian1d and voigt1d @@ -189,10 +189,10 @@ def fitspace(space, function, guess = None): a list of length N with the resolution per label Returns - A BINoculars fit object. + A binoculars fit object. Examples: - >>> fit = BINoculars.fitspace(space, 'lorentzian') + >>> fit = binoculars.fitspace(space, 'lorentzian') >>> print fit.summary I: 1.081e-07 +/- inf loc: 0.3703 +/- inf @@ -201,15 +201,15 @@ def fitspace(space, function, guess = None): offset: -0.001888 +/- inf >>> parameters = fit.parameters >>> data = fit.fitdata - >>> BINoculars.plotspace(space, fit = data) + >>> binoculars.plotspace(space, fit = data) ''' - import BINoculars.fit - if isinstance(space, BINoculars.space.Space): - fitclass = BINoculars.fit.get_class_by_name(function) + import binoculars.fit + if isinstance(space, binoculars.space.Space): + fitclass = binoculars.fit.get_class_by_name(function) return fitclass(space, guess) else: - raise TypeError("'{0!r}' is not a BINoculars space".format(space)) + raise TypeError("'{0!r}' is not a binoculars space".format(space)) return newspace @@ -221,7 +221,7 @@ def info(filename): filename: filename or space Examples: - >>> print BINoculars.info('test.hdf5') + >>> print binoculars.info('test.hdf5') Axes (3 dimensions, 46466628 points, 531.0 MB) { Axis H (min=-0.1184, max=0.0632, res=0.0008, count=228) Axis K (min=-1.1184, max=-0.9136, res=0.0008, count=257) @@ -233,8 +233,8 @@ def info(filename): [input] } origin = test.hdf5 - >>> space = BINoculars.load('test.hdf5') - >>> print BINoculars.info(space) + >>> space = binoculars.load('test.hdf5') + >>> print binoculars.info(space) Axes (3 dimensions, 46466628 points, 531.0 MB) { Axis H (min=-0.1184, max=0.0632, res=0.0008, count=228) Axis K (min=-1.1184, max=-0.9136, res=0.0008, count=257) @@ -249,19 +249,19 @@ def info(filename): ''' - import BINoculars.space + import binoculars.space ret = '' - if isinstance(filename, BINoculars.space.Space): + if isinstance(filename, binoculars.space.Space): ret += '{!r}\n{!r}'.format(filename, filename.config) elif type(filename) == str: if os.path.exists(filename): try: - axes = BINoculars.space.Axes.fromfile(filename) + axes = binoculars.space.Axes.fromfile(filename) except Exception as e: raise IOError('{0}: unable to load Space: {1!r}'.format(filename, e)) ret += '{!r}\n'.format(axes) try: - config = BINoculars.util.ConfigFile.fromfile(filename) + config = binoculars.util.ConfigFile.fromfile(filename) except Exception as e: raise IOError('{0}: unable to load util.ConfigFile: {1!r}'.format(filename, e)) ret += '{!r}'.format(config) diff --git a/fitaid.py b/binoculars-fitaid.py index a9728b9..af65ba0 100644 --- a/fitaid.py +++ b/binoculars-fitaid.py @@ -3,7 +3,7 @@ import sys import numpy import os.path from PyQt4 import QtGui, QtCore, Qt -import BINoculars.main, BINoculars.space, BINoculars.plot, BINoculars.fit, BINoculars.util +import binoculars.main, binoculars.space, binoculars.plot, binoculars.fit, binoculars.util from scipy.interpolate import griddata from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg, NavigationToolbar2QTAgg @@ -44,7 +44,7 @@ class Window(QtGui.QMainWindow): def newproject(self): dialog = QtGui.QFileDialog(self, "project filename"); - dialog.setFilter('BINoculars fit file (*.fit)'); + dialog.setFilter('binoculars fit file (*.fit)'); dialog.setDefaultSuffix('fit'); dialog.setFileMode(QtGui.QFileDialog.AnyFile); dialog.setAcceptMode(QtGui.QFileDialog.AcceptSave); @@ -63,7 +63,7 @@ class Window(QtGui.QMainWindow): def loadproject(self, filename = None): if not filename: dialog = QtGui.QFileDialog(self, "Load project"); - dialog.setFilter('BINoculars fit file (*.fit)'); + dialog.setFilter('binoculars fit file (*.fit)'); dialog.setFileMode(QtGui.QFileDialog.ExistingFiles); dialog.setAcceptMode(QtGui.QFileDialog.AcceptOpen); if not dialog.exec_(): @@ -89,7 +89,7 @@ class Window(QtGui.QMainWindow): if not filename: dialog = QtGui.QFileDialog(self, "Import spaces"); - dialog.setFilter('BINoculars space file (*.hdf5)'); + dialog.setFilter('binoculars space file (*.hdf5)'); dialog.setFileMode(QtGui.QFileDialog.ExistingFiles); dialog.setAcceptMode(QtGui.QFileDialog.AcceptOpen); if not dialog.exec_(): @@ -141,9 +141,9 @@ class TopWidget(QtGui.QWidget): self.functions = list() self.function_box = QtGui.QComboBox() - for function in dir(BINoculars.fit): - cls = getattr(BINoculars.fit, function) - if isinstance(cls, type) and issubclass(cls, BINoculars.fit.PeakFitBase): + for function in dir(binoculars.fit): + cls = getattr(binoculars.fit, function) + if isinstance(cls, type) and issubclass(cls, binoculars.fit.PeakFitBase): self.functions.append(cls) self.function_box.addItem(function) self.function_box.setCurrentIndex(self.function_box.findText('PolarLorentzian2D')) @@ -345,7 +345,7 @@ class TableWidget(QtGui.QWidget): self.table.insertRow(index) - axes = BINoculars.space.Axes.fromfile(filename) + axes = binoculars.space.Axes.fromfile(filename) checkboxwidget = QtGui.QCheckBox() checkboxwidget.rodkey = rodkey @@ -428,14 +428,14 @@ class FitData(object): if not spacename: raise IOError('Select proper input') db[rodkey].attrs['filename'] = spacename - self.axdict[rodkey] = BINoculars.space.Axes.fromfile(spacename) + self.axdict[rodkey] = binoculars.space.Axes.fromfile(spacename) def create_rod(self, rodkey, spacename): with h5py.File(self.filename,'a') as db: if rodkey not in db.keys(): db.create_group(rodkey) db[rodkey].attrs['filename'] = spacename - self.axdict[rodkey] = BINoculars.space.Axes.fromfile(spacename) + self.axdict[rodkey] = binoculars.space.Axes.fromfile(spacename) def delete_rod(self, rodkey): with h5py.File(self.filename,'a') as db: @@ -503,7 +503,7 @@ class RodData(FitData): axindex = axes.index(self.axis) ax = axes[axindex] - bins = BINoculars.space.get_bins(ax, self.resolution) + bins = binoculars.space.get_bins(ax, self.resolution) return bins, ax, axindex def rodlength(self): @@ -511,7 +511,7 @@ class RodData(FitData): return numpy.alen(bins) - 1 def get_index_value(self, index): - return BINoculars.space.get_axis_values(self.axdict[self.rodkey], self.axis, self.resolution)[index] + return binoculars.space.get_axis_values(self.axdict[self.rodkey], self.axis, self.resolution)[index] def get_key(self, index): axes = self.axdict[self.rodkey] @@ -524,7 +524,7 @@ class RodData(FitData): def space_from_index(self, index): with h5py.File(self.filename,'a') as db: filename = db[self.rodkey].attrs['filename'] - return BINoculars.space.Space.fromfile(filename, self.get_key(index)).project(self.axis) + return binoculars.space.Space.fromfile(filename, self.get_key(index)).project(self.axis) def save_data(self, index, key, data): with h5py.File(self.filename,'a') as db: @@ -587,7 +587,7 @@ class RodData(FitData): with h5py.File(self.filename,'a') as db: group = db[self.rodkey][self.slicekey]['attrs'] if key in group.keys(): - return BINoculars.space.get_axis_values(axes, self.axis, self.resolution), numpy.ma.array(group[key], mask = numpy.array(group[mkey])) + return binoculars.space.get_axis_values(axes, self.axis, self.resolution), numpy.ma.array(group[key], mask = numpy.array(group[mkey])) def load_loc(self, index): loc = list() @@ -666,15 +666,15 @@ class FitWidget(QtGui.QWidget): if fitdata is not None: if space.dimension == 1: self.ax = self.figure.add_subplot(111) - BINoculars.plot.plot(space, self.figure, self.ax, fit = fitdata) + binoculars.plot.plot(space, self.figure, self.ax, fit = fitdata) elif space.dimension == 2: self.ax = self.figure.add_subplot(121) - BINoculars.plot.plot(space, self.figure, self.ax, fit = None) + binoculars.plot.plot(space, self.figure, self.ax, fit = None) self.ax = self.figure.add_subplot(122) - BINoculars.plot.plot(space, self.figure, self.ax, fit = fitdata) + binoculars.plot.plot(space, self.figure, self.ax, fit = fitdata) else: self.ax = self.figure.add_subplot(111) - BINoculars.plot.plot(space, self.figure, self.ax) + binoculars.plot.plot(space, self.figure, self.ax) self.figure.suptitle('{0}, res = {1}, {2} = {3}'.format(self.database.rodkey, self.database.resolution, label, info)) self.canvas.draw() @@ -972,15 +972,15 @@ class IntegrateWidget(QtGui.QWidget): if interdata is not None: if space.dimension == 1: self.ax = self.figure.add_subplot(111) - BINoculars.plot.plot(space, self.figure, self.ax, fit = interdata) + binoculars.plot.plot(space, self.figure, self.ax, fit = interdata) elif space.dimension == 2: self.ax = self.figure.add_subplot(121) - BINoculars.plot.plot(space, self.figure, self.ax, fit = None) + binoculars.plot.plot(space, self.figure, self.ax, fit = None) self.ax = self.figure.add_subplot(122) - BINoculars.plot.plot(space, self.figure, self.ax, fit = interdata) + binoculars.plot.plot(space, self.figure, self.ax, fit = interdata) else: self.ax = self.figure.add_subplot(111) - BINoculars.plot.plot(space, self.figure, self.ax) + binoculars.plot.plot(space, self.figure, self.ax) self.figure.suptitle('{0}, res = {1}, {2} = {3}'.format(self.database.rodkey, self.database.resolution, label, info)) diff --git a/gui.py b/binoculars-gui.py index fdfef91..15143a6 100755 --- a/gui.py +++ b/binoculars-gui.py @@ -4,7 +4,7 @@ import sys import os import glob from PyQt4 import QtGui, QtCore, Qt -import BINoculars.main, BINoculars.space, BINoculars.plot, BINoculars.util +import binoculars.main, binoculars.space, binoculars.plot, binoculars.util import numpy import json import itertools @@ -277,7 +277,7 @@ class Window(QtGui.QMainWindow): def loadproject(self, filename = None): if not filename: dialog = QtGui.QFileDialog(self, "Load project"); - dialog.setFilter('BINoculars project file (*.proj)'); + dialog.setFilter('binoculars project file (*.proj)'); dialog.setFileMode(QtGui.QFileDialog.ExistingFiles); dialog.setAcceptMode(QtGui.QFileDialog.AcceptOpen); if not dialog.exec_(): @@ -299,7 +299,7 @@ class Window(QtGui.QMainWindow): def saveproject(self): widget = self.tab_widget.currentWidget() dialog = QtGui.QFileDialog(self, "Save project"); - dialog.setFilter('BINoculars project file (*.proj)'); + dialog.setFilter('binoculars project file (*.proj)'); dialog.setDefaultSuffix('proj'); dialog.setFileMode(QtGui.QFileDialog.AnyFile); dialog.setAcceptMode(QtGui.QFileDialog.AcceptSave); @@ -320,7 +320,7 @@ class Window(QtGui.QMainWindow): self.newproject() dialog = QtGui.QFileDialog(self, "Import spaces"); - dialog.setFilter('BINoculars space file (*.hdf5)'); + dialog.setFilter('binoculars space file (*.hdf5)'); dialog.setFileMode(QtGui.QFileDialog.ExistingFiles); dialog.setAcceptMode(QtGui.QFileDialog.AcceptOpen); if not dialog.exec_(): @@ -357,7 +357,7 @@ class Window(QtGui.QMainWindow): def merge(self): widget = self.tab_widget.currentWidget() dialog = QtGui.QFileDialog(self, "save mesh"); - dialog.setFilter('BINoculars space file (*.hdf5)'); + dialog.setFilter('binoculars space file (*.hdf5)'); dialog.setDefaultSuffix('hdf5'); dialog.setFileMode(QtGui.QFileDialog.AnyFile); dialog.setAcceptMode(QtGui.QFileDialog.AcceptSave); @@ -374,7 +374,7 @@ class Window(QtGui.QMainWindow): def subtract(self): dialog = QtGui.QFileDialog(self, "subtract space"); - dialog.setFilter('BINoculars space file (*.hdf5)'); + dialog.setFilter('binoculars space file (*.hdf5)'); dialog.setFileMode(QtGui.QFileDialog.ExistingFiles); dialog.setAcceptMode(QtGui.QFileDialog.AcceptOpen); if not dialog.exec_(): @@ -402,7 +402,7 @@ class Window(QtGui.QMainWindow): self.ip, self.port = server.server_address if startq: - cmd = ['python', os.path.join(os.path.dirname(__file__), 'server.py'), str(self.ip), str(self.port)] + cmd = ['python', os.path.join(os.path.dirname(__file__), 'binoculars-server.py'), str(self.ip), str(self.port)] self.pro = subprocess.Popen(cmd, stdin=None, stdout=None, stderr=None, preexec_fn=os.setsid) server_thread = threading.Thread(target=server.serve_forever) @@ -454,7 +454,7 @@ class UpdateThread(QtCore.QThread): fq = Queue.Queue() data_found = QtCore.pyqtSignal(object) def run(self): - delay = BINoculars.util.loop_delayer(1) + delay = binoculars.util.loop_delayer(1) jobs = [] labels = [] while 1: @@ -466,7 +466,7 @@ class UpdateThread(QtCore.QThread): jobs.append([space]) labels.append(command) elif self.q.empty() and len(jobs) > 0: - self.fq.put((labels.pop(), BINoculars.space.sum(jobs.pop()))) + self.fq.put((labels.pop(), binoculars.space.sum(jobs.pop()))) self.data_found.emit('data found') else: next(delay) @@ -476,12 +476,12 @@ class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer): class SpaceTCPHandler(SocketServer.BaseRequestHandler): def handle(self): - command, config, metadata, axes, photons, contributions = BINoculars.util.socket_recieve(self) - space = BINoculars.space.Space(BINoculars.space.Axes.fromarray(axes)) - space.config = BINoculars.util.ConfigFile.fromserial(config) + command, config, metadata, axes, photons, contributions = binoculars.util.socket_recieve(self) + space = binoculars.space.Space(binoculars.space.Axes.fromarray(axes)) + space.config = binoculars.util.ConfigFile.fromserial(config) space.config.command = command space.config.origin = 'server' - space.metadata = BINoculars.util.MetaData.fromserial(metadata) + space.metadata = binoculars.util.MetaData.fromserial(metadata) space.photons = photons space.contributions = contributions self.server.q.put((command, space)) @@ -801,7 +801,7 @@ class ProjectWidget(QtGui.QWidget): space = space.reorder(list(ax.label for ax in space.axes)[::-1]) self.ax.space = space - im = BINoculars.plot.plot(space, self.figure, self.ax, log = log, loglog = loglog, label = basename, norm = norm[i]) + im = binoculars.plot.plot(space, self.figure, self.ax, log = log, loglog = loglog, label = basename, norm = norm[i]) self.figure_images.append(im) @@ -814,7 +814,7 @@ class ProjectWidget(QtGui.QWidget): def merge(self, filename): try: spaces = tuple(self.table.getspace(selected_filename) for selected_filename in self.table.selection) - newspace = BINoculars.space.sum(BINoculars.space.make_compatible(spaces)) + newspace = binoculars.space.sum(binoculars.space.make_compatible(spaces)) newspace.tofile(filename) map(self.table.remove, self.table.selection) self.table.addspace(filename, True) @@ -823,11 +823,11 @@ class ProjectWidget(QtGui.QWidget): def subtractspace(self, filename): try: - subtractspace = BINoculars.space.Space.fromfile(filename) + subtractspace = binoculars.space.Space.fromfile(filename) spaces = tuple(self.table.getspace(selected_filename) for selected_filename in self.table.selection) newspaces = tuple(space - subtractspace for space in spaces) for space, selected_filename in zip(newspaces, self.table.selection): - newfilename = BINoculars.util.find_unused_filename(selected_filename) + newfilename = binoculars.util.find_unused_filename(selected_filename) space.tofile(newfilename) self.table.remove(selected_filename) self.table.addspace(newfilename, True) @@ -935,14 +935,14 @@ class ProjectWidget(QtGui.QWidget): space = space.project(*projection) space.trim() - outfile = BINoculars.util.find_unused_filename(fname) + outfile = binoculars.util.find_unused_filename(fname) if ext == '.edf': - BINoculars.util.space_to_edf(space, outfile) + binoculars.util.space_to_edf(space, outfile) self.parent.statusbar.showMessage('saved at {0}'.format(outfile)) elif ext == '.txt': - BINoculars.util.space_to_txt(space, outfile) + binoculars.util.space_to_txt(space, outfile) self.parent.statusbar.showMessage('saved at {0}'.format(outfile)) elif ext == '.hdf5': @@ -963,7 +963,7 @@ class SpaceContainer(QtGui.QTableWidgetItem): def get_space(self, key = None): if self.space == None: - return BINoculars.space.Space.fromfile(self.label, key = key) + return binoculars.space.Space.fromfile(self.label, key = key) else: if key == None: key = Ellipsis @@ -971,13 +971,13 @@ class SpaceContainer(QtGui.QTableWidgetItem): def get_ax(self): if self.space == None: - return BINoculars.space.Axes.fromfile(self.label) + return binoculars.space.Axes.fromfile(self.label) else: return self.space.axes def add_to_space(space): if self.space == None: - newspace = BINoculars.space.Space.fromfile(self.label) + space + newspace = binoculars.space.Space.fromfile(self.label) + space newspsace.tofile(self.label) else: self.space += space @@ -1049,7 +1049,7 @@ class TableWidget(QtGui.QWidget): axes = tuple(container.get_ax() for checkbox, container in zip(self.itercheckbox(), self.itercontainer()) if checkbox.checkState()) if len(axes) > 0: try: - return BINoculars.space.Axes(BINoculars.space.union_unequal_axes(ax) for ax in zip(*axes)) + return binoculars.space.Axes(binoculars.space.union_unequal_axes(ax) for ax in zip(*axes)) except ValueError: return () else: @@ -1270,7 +1270,7 @@ def is_empty(key): if __name__ == '__main__': app = QtGui.QApplication(sys.argv) - BINoculars.space.silence_numpy_errors() + binoculars.space.silence_numpy_errors() main = Window() main.resize(1000, 600) diff --git a/processgui.py b/binoculars-processgui.py index 838ba3c..865d83e 100755 --- a/processgui.py +++ b/binoculars-processgui.py @@ -1,6 +1,6 @@ #!/usr/bin/env python """ -BINoculars gui for data processing +binoculars gui for data processing Created on 2015-06-04 author: Remy Nencib (remy.nencib@esrf.r) """ @@ -14,7 +14,7 @@ import sys,os import itertools import inspect import glob -import BINoculars.util, BINoculars.main +import binoculars.util, binoculars.main import time #--------------------------------------------CREATE MAIN WINDOW---------------------------------------- @@ -118,7 +118,7 @@ class Window(QtGui.QMainWindow): if pd.wasCanceled(): raise KeyboardInterrupt QtGui.QApplication.processEvents() - return BINoculars.main.Main.from_object(cfg, command) + return binoculars.main.Main.from_object(cfg, command) try: for index in range(self.ListCommand.rowCount()): pd.setValue(index) @@ -270,7 +270,7 @@ class Conf_Tab(QtGui.QWidget): self.Inp = Table(QtGui.QLabel('<strong>Input :</strong>')) self.Pro = Table(QtGui.QLabel('<strong>Projection :<strong>')) self.select = QtGui.QComboBox() - backends = list(backend.lower() for backend in BINoculars.util.get_backends()) + backends = list(backend.lower() for backend in binoculars.util.get_backends()) #we add the list of different backends on the select combobox self.select.addItems(QtCore.QStringList(backends)) self.add = QtGui.QPushButton('add') @@ -308,32 +308,32 @@ class Conf_Tab(QtGui.QWidget): self.setLayout(vbox) #Here we call all methods for selected an ellement on differents combobox - self.Dis.add_to_combo(QtCore.QStringList(BINoculars.util.get_dispatchers())) + self.Dis.add_to_combo(QtCore.QStringList(binoculars.util.get_dispatchers())) self.select.activated['QString'].connect(self.DataCombo) self.Inp.combobox.activated.connect(self.DataTableInp) self.Pro.combobox.activated.connect(self.DataTableInpPro) self.Dis.combobox.activated.connect(self.DataTableInpDis) def DataCombo(self,text): - self.Inp.add_to_combo(QtCore.QStringList(BINoculars.util.get_inputs(str(text)))) - self.Pro.add_to_combo(QtCore.QStringList(BINoculars.util.get_projections(str(text)))) + self.Inp.add_to_combo(QtCore.QStringList(binoculars.util.get_inputs(str(text)))) + self.Pro.add_to_combo(QtCore.QStringList(binoculars.util.get_projections(str(text)))) self.DataTableInp() self.DataTableInpPro() self.DataTableInpDis() def DataTableInp(self): backend = str(self.select.currentText()) - inp = BINoculars.util.get_input_configkeys(backend, str(self.Inp.combobox.currentText())) + inp = binoculars.util.get_input_configkeys(backend, str(self.Inp.combobox.currentText())) self.Inp.addDataConf(inp) def DataTableInpPro(self): backend = str(self.select.currentText()) - proj = BINoculars.util.get_projection_configkeys(backend, str(self.Pro.combobox.currentText())) + proj = binoculars.util.get_projection_configkeys(backend, str(self.Pro.combobox.currentText())) self.Pro.addDataConf(proj) def DataTableInpDis(self): backend = str(self.select.currentText()) - disp = BINoculars.util.get_dispatcher_configkeys(str(self.Dis.combobox.currentText())) + disp = binoculars.util.get_dispatcher_configkeys(str(self.Dis.combobox.currentText())) self.Dis.addDataConf(disp) #The save method we take all ellements on tables and we put them in this format {0} = {1} #{2} @@ -373,7 +373,7 @@ class Conf_Tab(QtGui.QWidget): value = '{0}:{1}'.format(str(self.select.currentText()).strip(),value) inPro[key] = value - cfg = BINoculars.util.ConfigFile('processgui {0}'.format(time.strftime('%d %b %Y %H:%M:%S', time.localtime()))) + cfg = binoculars.util.ConfigFile('processgui {0}'.format(time.strftime('%d %b %Y %H:%M:%S', time.localtime()))) setattr(cfg, 'input', inInp) setattr(cfg, 'dispatcher', inDis) setattr(cfg, 'projection', inPro) @@ -381,7 +381,7 @@ class Conf_Tab(QtGui.QWidget): #This method take elements on a text file or the binocular script and put them on tables def read_data(self, filename): - cfg = BINoculars.util.ConfigFile.fromtxtfile(str(filename)) + cfg = binoculars.util.ConfigFile.fromtxtfile(str(filename)) input_type = cfg.input['type'] backend, value = input_type.strip(' ').split(':') self.select.setCurrentIndex(self.select.findText(backend, QtCore.Qt.MatchFixedString)) diff --git a/server.py b/binoculars-server.py index 91ec1ea..23b61c7 100644 --- a/server.py +++ b/binoculars-server.py @@ -11,7 +11,7 @@ import threading import SocketServer import time import sys -import BINoculars.util, BINoculars.main +import binoculars.util, binoculars.main import traceback import re import json @@ -66,11 +66,11 @@ def process(run_event, ip, port, q): overrides = parse_job(job)[1]# [1] are the succesfully parsed jobs print 'Start processing: {0}'.format(command) try: - configobj = BINoculars.util.ConfigFile.fromtxtfile(configfilename, overrides = overrides) - if BINoculars.util.parse_bool(configobj.dispatcher['send_to_gui']): + configobj = binoculars.util.ConfigFile.fromtxtfile(configfilename, overrides = overrides) + if binoculars.util.parse_bool(configobj.dispatcher['send_to_gui']): configobj.dispatcher['host'] = ip configobj.dispatcher['port'] = port - BINoculars.main.Main.from_object(configobj, [command]) + binoculars.main.Main.from_object(configobj, [command]) print 'Succesfully finished processing: {0}.'.format(command) except Exception as exc: errorfilename = 'error_{0}.txt'.format(command) @@ -90,7 +90,7 @@ if __name__ == '__main__': q = Queue.Queue() - BINoculars.util.register_python_executable(os.path.join(os.path.dirname(__file__), 'binoculars.py')) + binoculars.util.register_python_executable(os.path.join(os.path.dirname(__file__), 'binoculars.py')) HOST, PORT = socket.gethostbyname(socket.gethostname()), 0 diff --git a/binoculars.py b/binoculars.py index a14a238..986e439 100755 --- a/binoculars.py +++ b/binoculars.py @@ -5,7 +5,7 @@ import os import argparse import numpy -import BINoculars.space, BINoculars.util +import binoculars.space, binoculars.util ### INFO def command_info(args): @@ -18,19 +18,19 @@ def command_info(args): if args.output: if len(args.infile)>1: print 'only one space file argument is support with extractconfig -> using the first' - config = BINoculars.util.ConfigFile.fromfile(args.infile[0]) + config = binoculars.util.ConfigFile.fromfile(args.infile[0]) config.totxtfile(args.output) else: for f in args.infile: try: - axes = BINoculars.space.Axes.fromfile(f) + axes = binoculars.space.Axes.fromfile(f) except Exception as e: print '{0}: unable to load Space: {1!r}'.format(f, e) else: print '{0} \n{1!r}'.format(f, axes) if args.config: try: - config = BINoculars.util.ConfigFile.fromfile(f) + config = binoculars.util.ConfigFile.fromfile(f) except Exception as e: print '{0}: unable to load util.ConfigFile: {1!r}'.format(f, e) else: @@ -41,7 +41,7 @@ def command_info(args): def command_convert(args): parser = argparse.ArgumentParser(prog='binoculars convert') parser.add_argument('--wait', action='store_true', help='wait for input files to appear') - BINoculars.util.argparse_common_arguments(parser, 'project', 'slice', 'pslice', 'rebin', 'transform', 'subtract') + binoculars.util.argparse_common_arguments(parser, 'project', 'slice', 'pslice', 'rebin', 'transform', 'subtract') parser.add_argument('--read-trusted-zpi', action='store_true', help='read legacy .zpi files, ONLY FROM A TRUSTED SOURCE!') parser.add_argument('infile', help='input file, must be a .hdf5') parser.add_argument('outfile', help='output file, can be .hdf5 or .edf or .txt') @@ -49,30 +49,30 @@ def command_convert(args): args = parser.parse_args(args) if args.wait: - BINoculars.util.statusnl('waiting for {0} to appear'.format(args.infile)) - BINoculars.util.wait_for_file(args.infile) - BINoculars.util.statusnl('processing...') + binoculars.util.statusnl('waiting for {0} to appear'.format(args.infile)) + binoculars.util.wait_for_file(args.infile) + binoculars.util.statusnl('processing...') if args.infile.endswith('.zpi'): if not args.read_trusted_zpi: print 'error: .zpi files are unsafe, use --read-trusted-zpi to open' sys.exit(1) - space = BINoculars.util.zpi_load(args.infile) + space = binoculars.util.zpi_load(args.infile) else: - space = BINoculars.space.Space.fromfile(args.infile) + space = binoculars.space.Space.fromfile(args.infile) ext = os.path.splitext(args.outfile)[-1] if args.subtract: - space -= BINoculars.space.Space.fromfile(args.subtract) + space -= binoculars.space.Space.fromfile(args.subtract) - space, info = BINoculars.util.handle_ordered_operations(space, args) + space, info = binoculars.util.handle_ordered_operations(space, args) if ext == '.edf': - BINoculars.util.space_to_edf(space, args.outfile) + binoculars.util.space_to_edf(space, args.outfile) print 'saved at {0}'.format(args.outfile) elif ext == '.txt': - BINoculars.util.space_to_txt(space, args.outfile) + binoculars.util.space_to_txt(space, args.outfile) print 'saved at {0}'.format(args.outfile) elif ext == '.hdf5': @@ -87,19 +87,19 @@ def command_convert(args): ### PLOT def command_plot(args): import matplotlib.pyplot as pyplot - import BINoculars.fit, BINoculars.plot + import binoculars.fit, binoculars.plot parser = argparse.ArgumentParser(prog='binoculars plot') parser.add_argument('infile', nargs='+') - BINoculars.util.argparse_common_arguments(parser, 'savepdf', 'savefile', 'clip', 'nolog', 'project', 'slice', 'pslice', 'subtract', 'rebin', 'transform') + binoculars.util.argparse_common_arguments(parser, 'savepdf', 'savefile', 'clip', 'nolog', 'project', 'slice', 'pslice', 'subtract', 'rebin', 'transform') parser.add_argument('--multi', default=None, choices=('grid', 'stack')) parser.add_argument('--fit', default = None) parser.add_argument('--guess', default = None) args = parser.parse_args(args) if args.subtract: - subtrspace = BINoculars.space.Space.fromfile(args.subtract) - subtrspace, subtrinfo = BINoculars.util.handle_ordered_operations(subtrspace, args, auto3to2=True) + subtrspace = binoculars.space.Space.fromfile(args.subtract) + subtrspace, subtrinfo = binoculars.util.handle_ordered_operations(subtrspace, args, auto3to2=True) args.nolog = True guess = [] @@ -114,12 +114,12 @@ def command_plot(args): plotrows = int(numpy.ceil(float(plotcount) / plotcolumns)) for i, filename in enumerate(args.infile): - space = BINoculars.space.Space.fromfile(filename) - space, info = BINoculars.util.handle_ordered_operations(space, args, auto3to2=True) + space = binoculars.space.Space.fromfile(filename) + space, info = binoculars.util.handle_ordered_operations(space, args, auto3to2=True) fitdata = None if args.fit: - fit = BINoculars.fit.get_class_by_name(args.fit)(space, guess) + fit = binoculars.fit.get_class_by_name(args.fit)(space, guess) print fit if fit.success: fitdata = fit.fitdata @@ -144,7 +144,7 @@ def command_plot(args): if args.multi == 'grid': pyplot.subplot(plotrows, plotcolumns, i+1) - BINoculars.plot.plot(space, pyplot.gcf(), pyplot.gca(), label=basename, log=not args.nolog, clipping=float(args.clip), fit=fitdata) + binoculars.plot.plot(space, pyplot.gcf(), pyplot.gca(), label=basename, log=not args.nolog, clipping=float(args.clip), fit=fitdata) if plotcount > 1 and args.multi == 'grid': pyplot.gca().set_title(basename) @@ -169,7 +169,7 @@ def command_plot(args): #print 'saved at {0}'.format(args.savefile) else: filename = '{0}_plot.pdf'.format(os.path.splitext(args.infile[0])[0]) - filename = BINoculars.util.find_unused_filename(filename) + filename = binoculars.util.find_unused_filename(filename) pyplot.savefig(filename) #print 'saved at {0}'.format(filename) else: @@ -179,7 +179,7 @@ def command_plot(args): ### FIT def command_fit(args): import matplotlib.pyplot as pyplot - import BINoculars.fit, BINoculars.plot + import binoculars.fit, binoculars.plot parser = argparse.ArgumentParser(prog='binoculars fit') parser.add_argument('infile') @@ -187,10 +187,10 @@ def command_fit(args): parser.add_argument('resolution') parser.add_argument('func') parser.add_argument('--follow', action='store_true', help='use the result of the previous fit as guess for the next') - BINoculars.util.argparse_common_arguments(parser, 'savepdf', 'savefile', 'clip', 'nolog') + binoculars.util.argparse_common_arguments(parser, 'savepdf', 'savefile', 'clip', 'nolog') args = parser.parse_args(args) - axes = BINoculars.space.Axes.fromfile(args.infile) + axes = binoculars.space.Axes.fromfile(args.infile) axindex = axes.index(args.axis) ax = axes[axindex] axlabel = ax.label @@ -209,17 +209,17 @@ def command_fit(args): if args.savepdf or args.savefile: if args.savefile: - filename = BINoculars.util.filename_enumerator(args.savefile) + filename = binoculars.util.filename_enumerator(args.savefile) else: - filename = BINoculars.util.filename_enumerator('{0}_fit.pdf'.format(basename)) + filename = binoculars.util.filename_enumerator('{0}_fit.pdf'.format(basename)) - fitclass = BINoculars.fit.get_class_by_name(args.func) + fitclass = binoculars.fit.get_class_by_name(args.func) for start, stop in zip(bins[:-1], bins[1:]): info = [] key = [slice(None) for i in axes] key[axindex] = slice(start, stop) - newspace = BINoculars.space.Space.fromfile(args.infile, key) + newspace = binoculars.space.Space.fromfile(args.infile, key) left, right = newspace.axes[axindex].min,newspace.axes[axindex].max if newspace.dimension == axes.dimension: newspace = newspace.project(axindex) @@ -248,13 +248,13 @@ def command_fit(args): if newspace.dimension == 1: pyplot.figure(figsize=(12, 9)) pyplot.subplot(111) - BINoculars.plot.plot(newspace, pyplot.gcf(), pyplot.gca(), label=basename, log=not args.nolog, clipping=float(args.clip), fit = fit) + binoculars.plot.plot(newspace, pyplot.gcf(), pyplot.gca(), label=basename, log=not args.nolog, clipping=float(args.clip), fit = fit) elif newspace.dimension == 2: pyplot.figure(figsize=(12, 9)) pyplot.subplot(121) - BINoculars.plot.plot(newspace, pyplot.gcf(), pyplot.gca(), label=basename, log=not args.nolog, clipping=float(args.clip), fit = None) + binoculars.plot.plot(newspace, pyplot.gcf(), pyplot.gca(), label=basename, log=not args.nolog, clipping=float(args.clip), fit = None) pyplot.subplot(122) - BINoculars.plot.plot(newspace, pyplot.gcf(), pyplot.gca(), label=basename, log=not args.nolog, clipping=float(args.clip), fit = fit) + binoculars.plot.plot(newspace, pyplot.gcf(), pyplot.gca(), label=basename, log=not args.nolog, clipping=float(args.clip), fit = fit) info.append('sliced in {0} from {1} to {2}'.format(axlabel, left, right)) pyplot.suptitle('{0}'.format(' '.join(info))) @@ -300,10 +300,10 @@ def command_fit(args): ### PROCESS def command_process(args): - import BINoculars.main + import binoculars.main - BINoculars.util.register_python_executable(__file__) - BINoculars.main.Main.from_args(args)# start of main thread + binoculars.util.register_python_executable(__file__) + binoculars.main.Main.from_args(args)# start of main thread @@ -325,7 +325,7 @@ run binoculars COMMAND --help more info on that command if __name__ == '__main__': - BINoculars.space.silence_numpy_errors() + binoculars.space.silence_numpy_errors() subcommands = {'info': command_info, 'convert': command_convert, 'plot': command_plot, 'fit': command_fit, 'process': command_process} diff --git a/examples/scripts/demo.py b/examples/scripts/demo.py index 8848c27..57ef2f1 100644 --- a/examples/scripts/demo.py +++ b/examples/scripts/demo.py @@ -1,8 +1,8 @@ -import BINoculars +import binoculars # to load a binoculars space file in a python script use the load function. You can supply a key if you do not # want to load the entire space. By default the space is loaded entirely. -space = BINoculars.load('test.hdf5') +space = binoculars.load('test.hdf5') # if you quickly want to see what the content of the space is you can print the space. This will provide information about the # dimension, the labels, and the range of the space, but not of the data in the space. @@ -25,19 +25,19 @@ data = space.get_masked() grid = space.get_grid() # you can add two spaces provided they have the same labels and the same resolution. The range of the space can be arbitrary. -total = BINoculars.load('test.hdf5') + BINoculars.load('test1.hdf5') +total = binoculars.load('test.hdf5') + binoculars.load('test1.hdf5') # you can view the configuration settings used to create the space. -BINoculars.info(space) +binoculars.info(space) # if you now want to reuse this configuration file as an input you can extract the configuration file by space.config.totxtfile('config.txt') # You can save the space in another format by changing the extension, currently only txt and hdf5 supported, and EDF if you have PyMca installed -BINoculars.save('test.txt', space) +binoculars.save('test.txt', space) -# you can plot a space in a python script, or in an interactive terminal using the BINoculars.plotspace function. This function -# automatically puts the right coordinates on the axes. Check the advanced options by typing 'help(BINoculars.plotspace)' +# you can plot a space in a python script, or in an interactive terminal using the binoculars.plotspace function. This function +# automatically puts the right coordinates on the axes. Check the advanced options by typing 'help(binoculars.plotspace)' import matplotlib.pyplot as pyplot -BINoculars.plotspace(specular) +binoculars.plotspace(specular) pyplot.show() diff --git a/examples/scripts/demo_fit.py b/examples/scripts/demo_fit.py index 77abe2b..daaaa70 100644 --- a/examples/scripts/demo_fit.py +++ b/examples/scripts/demo_fit.py @@ -1,19 +1,19 @@ import numpy import matplotlib.pyplot as pyplot -import BINoculars -import BINoculars.space +import binoculars +import binoculars.space -space = BINoculars.load('test.hdf5').slice('delta', slice(-0.035, 0.035)).project('delta').slice('g-m', slice(None, 0.4)) +space = binoculars.load('test.hdf5').slice('delta', slice(-0.035, 0.035)).project('delta').slice('g-m', slice(None, 0.4)) results = [] -x = BINoculars.space.get_axis_values(space, 'g+m') +x = binoculars.space.get_axis_values(space, 'g+m') -for index, curve in enumerate(BINoculars.space.iterate_over_axis(space, 'g+m')): +for index, curve in enumerate(binoculars.space.iterate_over_axis(space, 'g+m')): try: - fit = BINoculars.fitspace(curve, 'lorentzian') + fit = binoculars.fitspace(curve, 'lorentzian') results.append(numpy.append(x[index], fit.result)) #pyplot.figure() - #BINoculars.plotspace(curve, fit = fit.fitdata, log = False) + #binoculars.plotspace(curve, fit = fit.fitdata, log = False) #pyplot.savefig('fit_{0}'.format(index)) #pyplot.close() except Exception as e: |