def choose_entry(self): if self.layout.count() == 2: self.insert_layout(1, self.parameters.grid_layout) self.insert_layout(2, self.prepare_layout) self.reduce = NXReduce(self.entry) self.parameters['first'].value = self.reduce.first self.parameters['last'].value = self.reduce.last
def main(): parser = argparse.ArgumentParser( description="Find maximum counts of the signal in the specified path") parser.add_argument('-d', '--directory', required=True, help='scan directory') parser.add_argument('-e', '--entries', default=['f1', 'f2', 'f3'], nargs='+', help='names of entries to be processed') parser.add_argument('-f', '--first', type=int, help='first frame') parser.add_argument('-l', '--last', type=int, help='last frame') parser.add_argument('-o', '--overwrite', action='store_true', help='overwrite existing maximum') parser.add_argument('-q', '--queue', action='store_true', help='add to server task queue') args = parser.parse_args() for entry in args.entries: reduce = NXReduce(entry, args.directory, maxcount=True, first=args.first, last=args.last, overwrite=args.overwrite) if args.queue: reduce.queue() else: reduce.nxmax()
def choose_root(self): self.checkbox['overwrite'].setVisible(False) for entry in [e for e in self.root if e != 'entry']: reduce = NXReduce(self.root[entry]) if not reduce.not_complete('nxcopy'): self.checkbox['overwrite'].setVisible(True) self._selected = True
def main(): parser = argparse.ArgumentParser( description="Refine lattice parameters and goniometer angles") parser.add_argument('-d', '--directory', required=True, help='scan directory') parser.add_argument('-e', '--entries', default=['f1', 'f2', 'f3'], nargs='+', help='names of entries to be processed') parser.add_argument('-l', '--lattice', action='store_true', help='refine lattice parameters') parser.add_argument('-o', '--overwrite', action='store_true', help='overwrite existing maximum') parser.add_argument('-q', '--queue', action='store_true', help='add to server task queue') args = parser.parse_args() for i, entry in enumerate(args.entries): if i == 0: lattice = args.lattice else: lattice = False reduce = NXReduce(entry, args.directory, refine=True, lattice=lattice, overwrite=args.overwrite) if args.queue: reduce.queue() else: reduce.nxrefine()
def choose_entry(self): self.reduce = NXReduce(self.entry) self.maximum = self.reduce.maximum if self.reduce.first: self.parameters['first'].value = self.reduce.first if self.reduce.last: self.parameters['last'].value = self.reduce.last
def main(): parser = argparse.ArgumentParser( description="Find peaks within the NeXus data") parser.add_argument('-d', '--directory', required=True, help='scan directory') parser.add_argument('-e', '--entries', default=['f1', 'f2', 'f3'], nargs='+', help='names of entries to be searched') parser.add_argument('-t', '--threshold', type=float, help='peak threshold - defaults to maximum counts/10') parser.add_argument('-f', '--first', type=int, help='first frame') parser.add_argument('-l', '--last', type=int, help='last frame') parser.add_argument('-o', '--overwrite', action='store_true', help='overwrite existing peaks') parser.add_argument('-p', '--parent', default=None, help='The parent .nxs file to use') parser.add_argument('-q', '--queue', action='store_true', help='add to server task queue') args = parser.parse_args() for entry in args.entries: reduce = NXReduce(entry, args.directory, find=True, threshold=args.threshold, first=args.first, last=args.last, overwrite=args.overwrite) if args.queue: reduce.queue() else: reduce.nxfind()
def main(): parser = argparse.ArgumentParser(description="Perform CCTW transform") parser.add_argument('-d', '--directory', required=True, help='scan directory') parser.add_argument('-e', '--entries', default=['f1', 'f2', 'f3'], nargs='+', help='names of entries to be processed') parser.add_argument('-m', '--mask', action='store_true', help='use 3D mask') parser.add_argument('-qh', nargs=3, help='Qh - min, step, max') parser.add_argument('-qk', nargs=3, help='Qk - min, step, max') parser.add_argument('-ql', nargs=3, help='Ql - min, step, max') parser.add_argument('-r', '--radius', default=200, help='radius of mask around each peak (in pixels)') parser.add_argument('-w', '--width', default=3, help='width of masked region (in frames)') parser.add_argument('-o', '--overwrite', action='store_true', help='overwrite existing transforms') parser.add_argument('-q', '--queue', action='store_true', help='add to server task queue') args = parser.parse_args() for entry in args.entries: reduce = NXReduce(entry, args.directory, transform=True, mask=args.mask, Qh=args.qh, Qk=args.qk, Ql=args.ql, radius=args.radius, width=args.width, overwrite=args.overwrite) if args.mask: if args.queue: reduce.queue() else: reduce.nxmasked_transform() else: if args.queue: reduce.queue() else: reduce.nxtransform()
def make_parent(self): reduce = NXReduce(directory=self.get_scan(self.get_filename()), overwrite=True) reduce.make_parent() nxdb.update_file(reduce.wrapper_file) if self.parent_file: nxdb.update_file(self.parent_file) self.parent_file = reduce.wrapper_file self.filename.setText(os.path.basename(self.parent_file)) self.update()
def accept(self): if not self._selected: raise NeXusError("Need to select output file before saving") elif self.root.nxfilemode == 'r': raise NeXusError("NeXus file is locked") if self.overwrite: for entry in [e for e in self.root if e != 'entry']: reduce = NXReduce(self.root[entry], copy=True, overwrite=True) reduce.nxcopy() else: raise NeXusError("Much check 'overwrite' to save parameters") super(CopyDialog, self).accept()
def find_peaks(self): self.check_lock(self.reduce.data_file) self.start_thread() self.reduce = NXReduce(self.entry, threshold=self.threshold, first=self.first, last=self.last, find=True, overwrite=True, gui=True) self.reduce.moveToThread(self.thread) self.reduce.start.connect(self.start_progress) self.reduce.update.connect(self.update_progress) self.reduce.result.connect(self.get_peaks) self.reduce.stop.connect(self.stop) self.thread.started.connect(self.reduce.nxfind) self.thread.start(QtCore.QThread.LowestPriority)
def choose_entry(self): self.reduce = NXReduce(self.entry) if self.reduce.first: self.parameters['first'].value = self.reduce.first if self.reduce.last: self.parameters['last'].value = self.reduce.last else: try: self.parameters['last'].value = len(self.entry.data.nxaxes[0]) except Exception: pass if self.reduce.threshold: self.parameters['threshold'].value = self.reduce.threshold
def main(): parser = argparse.ArgumentParser( description="Set scan file as parent by creating a symbolic link") parser.add_argument('-d', '--directory', required=True, help='scan directory') args = parser.parse_args() reduce = NXReduce(directory=args.directory) reduce.make_parent()
def write_parameters(self): if self.entry.nxfilemode == 'r': display_message("NeXus file opened as readonly") return elif ('nxrefine' in self.entry or 'orientation_matrix' in self.entry['instrument/detector']): if not self.confirm_action('Overwrite existing refinement?'): return self.transfer_parameters() polar_angles, azimuthal_angles = self.refine.calculate_angles( self.refine.xp, self.refine.yp) self.refine.write_angles(polar_angles, azimuthal_angles) self.refine.write_parameters() reduce = NXReduce(self.entry) reduce.record_start('nxrefine') reduce.record('nxrefine', fit_report='\n'.join(self.fit_report)) reduce.logger.info('Orientation refined in NeXpy') reduce.record_end('nxrefine') root = self.entry.nxroot entries = [ entry for entry in root.entries if entry != 'entry' and entry != self.entry.nxname ] if entries and self.confirm_action( f'Copy orientation to other entries? ({", ".join(entries)})', answer='yes'): om = self.entry['instrument/detector/orientation_matrix'] for entry in entries: root[entry]['instrument/detector/orientation_matrix'] = om self.define_data() if len(self.paths) > 0: self.update_scaling()
def calculate_mask(self): self.check_lock(self.reduce.wrapper_file) self.thread = QtCore.QThread() self.reduce = NXReduce(self.entry, radius=self.radius, width=self.width, mask=True, overwrite=True, gui=True) self.reduce.moveToThread(self.thread) self.reduce.start.connect(self.start_progress) self.reduce.update.connect(self.update_progress) self.reduce.result.connect(self.calculate_mask) self.reduce.stop.connect(self.stop) self.thread.started.connect(self.reduce.nxfind) self.thread.start(QtCore.QThread.LowestPriority)
def sum_scans(self): server = NXServer(self.experiment_directory) if not server.is_running(): raise NeXusError('Server not running') scan_filter = ';;'.join(("NeXus Files (*.nxs)", "Any Files (*.* *)")) preferred_name = os.path.join(self.sample_directory, self.sample + '_' + 'sum.nxs') scan_file = getSaveFileName(self, 'Choose Summed File Name', preferred_name, scan_filter) if not scan_file: return prefix = self.sample + '_' if not os.path.basename(scan_file).startswith(prefix): raise NeXusError("Summed file name must start with '%s'" % prefix) self.scan_label = self.get_label(scan_file) scan_dir = os.path.join(self.sample_directory, self.scan_label) scan_file = os.path.join(self.sample_directory, self.sample + '_' + self.scan_label + '.nxs') copy_file = os.path.join(self.sample_directory, self.scan_files[0]) if os.path.exists(scan_dir): if not confirm_action( "New scan directory already exists. Overwrite?"): return else: os.mkdir(scan_dir) copyfile(copy_file, scan_file) self.clean_scan(scan_file) self.treeview.tree.load(scan_file, 'rw') reduce = NXReduce(directory=scan_dir) for entry in reduce.entries: server.add_task('nxsum -d %s -e %s -o -s %s' % (scan_dir, entry, self.scan_list))
def write_parameters(self): self.transfer_parameters() polar_angles, azimuthal_angles = self.refine.calculate_angles( self.refine.xp, self.refine.yp) self.refine.write_angles(polar_angles, azimuthal_angles) self.refine.write_parameters() reduce = NXReduce(self.entry) reduce.record('nxrefine', fit_report='\n'.join(self.fit_report)) root = self.entry.nxroot entries = [entry for entry in root.entries if entry != 'entry'] if entries and self.confirm_action( 'Copy orientation to other entries? (%s)' % (', '.join(entries))): om = self.entry['instrument/detector/orientation_matrix'] for entry in entries: root[entry]['instrument/detector/orientation_matrix'] = om
def find_maximum(self): self.check_lock(self.reduce.data_file) self.start_thread() self.reduce = NXReduce(self.entry, first=self.first, last=self.last, maxcount=True, overwrite=True, gui=True) self.reduce.moveToThread(self.thread) self.reduce.start.connect(self.start_progress) self.reduce.update.connect(self.update_progress) self.reduce.result.connect(self.get_maximum) self.reduce.stop.connect(self.stop) self.thread.started.connect(self.reduce.nxmax) self.thread.finished.connect(self.stop) self.thread.start(QtCore.QThread.LowestPriority)
def choose_entry(self): if self.layout.count() == 2: self.insert_layout(1, self.parameters.grid_layout) self.insert_layout(2, self.find_layout) self.reduce = NXReduce(self.entry) self.refine = NXRefine(self.entry) self.refine.polar_max = self.refine.two_theta_max() if self.reduce.first is not None: self.parameters['first'].value = self.reduce.first if self.reduce.last: self.parameters['last'].value = self.reduce.last else: try: self.parameters['last'].value = self.reduce.shape[0] except Exception: pass self.parameters['threshold'].value = self.reduce.threshold
def main(): parser = argparse.ArgumentParser( description="Restore orientation from CCTW parameter file") parser.add_argument('-d', '--directory', required=True, help='scan directory') parser.add_argument('-e', '--entries', default=['f1', 'f2', 'f3'], nargs='+', help='names of entries to be processed') args = parser.parse_args() for entry in args.entries: reduce = NXReduce(entry, args.directory) if os.path.exists(reduce.settings_file): refine = NXRefine(reduce.entry) refine.read_settings(reduce.settings_file) refine.write_parameters() if os.path.exists(reduce.transform_file): refine.prepare_transform(reduce.transform_file) if os.path.exists(reduce.masked_transform_file): refine.prepare_transform(reduce.masked_transform_file, mask=True) reduce = NXMultiReduce(args.directory) if os.path.exists(reduce.transform_file): reduce.prepare_combine() if os.path.exists(reduce.masked_transform_file): reduce.mask = True reduce.prepare_combine()
def main(): parser = argparse.ArgumentParser(description="Perform CCTW transform") parser.add_argument('-d', '--directory', required=True, help='scan directory') parser.add_argument('-e', '--entries', nargs='+', help='names of entries to be processed') parser.add_argument('-qh', nargs=3, help='Qh - min, step, max') parser.add_argument('-qk', nargs=3, help='Qk - min, step, max') parser.add_argument('-ql', nargs=3, help='Ql - min, step, max') parser.add_argument('-R', '--regular', action='store_true', help='perform regular transform') parser.add_argument('-M', '--mask', action='store_true', help='perform transform with 3D mask') parser.add_argument('-o', '--overwrite', action='store_true', help='overwrite existing transforms') parser.add_argument('-q', '--queue', action='store_true', help='add to server task queue') args = parser.parse_args() if args.entries: entries = args.entries else: entries = NXMultiReduce(args.directory).entries for entry in entries: reduce = NXReduce(entry, args.directory, transform=True, Qh=args.qh, Qk=args.qk, Ql=args.ql, regular=args.regular, mask=args.mask, overwrite=args.overwrite) if args.queue: reduce.queue('nxtransform', args) else: if reduce.regular: reduce.nxtransform() if reduce.mask: reduce.nxtransform(mask=True)
def main(): parser = argparse.ArgumentParser( description="Find peaks within the NeXus data") parser.add_argument('-d', '--directory', required=True, help='directory containing summed files') parser.add_argument('-e', '--entries', default=['f1', 'f2', 'f3'], nargs='+', help='names of entries to be summed') parser.add_argument('-s', '--scans', nargs='+', required=True, help='list of scan directories to be summed') parser.add_argument('-o', '--overwrite', action='store_true', help='overwrite existing peaks') args = parser.parse_args() for entry in args.entries: reduce = NXReduce(entry, args.directory, overwrite=args.overwrite) reduce.nxsum(args.scans)
def find_peaks(self): if is_file_locked(self.reduce.data_file): return self.start_thread() self.reduce = NXReduce(self.entry, threshold=self.threshold, first=self.first, last=self.last, min_pixels=self.min_pixels, find=True, overwrite=True, gui=True) self.reduce.moveToThread(self.thread) self.reduce.start.connect(self.start_progress) self.reduce.update.connect(self.update_progress) self.reduce.result.connect(self.get_peaks) self.reduce.stop.connect(self.stop) self.thread.started.connect(self.reduce.nxfind) self.thread.start()
def main(): parser = argparse.ArgumentParser( description="Link data and metadata to NeXus file") parser.add_argument('-d', '--directory', required=True, help='scan directory') parser.add_argument('-e', '--entries', nargs='+', help='names of entries to be searched') parser.add_argument('-o', '--overwrite', action='store_true', help='overwrite existing peaks') parser.add_argument('-q', '--queue', action='store_true', help='add to server task queue') args = parser.parse_args() if args.entries: entries = args.entries else: entries = NXMultiReduce(args.directory).entries for entry in entries: reduce = NXReduce(entry, args.directory, link=True, overwrite=args.overwrite) if args.queue: reduce.queue('nxlink', args) else: reduce.nxlink()
def add_tasks(self): if self.grid is None: raise NeXusError('Need to update status') for scan in [s for s in self.enabled_scans if self.any_selected(s)]: for i, entry in enumerate(self.enabled_scans[scan]['entries']): if self.only_combined(scan): if i == 0: reduce = NXMultiReduce(scan) reduce.regular = reduce.mask = False else: break else: reduce = NXReduce(entry, scan) reduce.regular = reduce.mask = False if self.selected(scan, 'link'): reduce.link = True if self.selected(scan, 'copy'): reduce.copy = True if self.selected(scan, 'max'): reduce.maxcount = True if self.selected(scan, 'find'): reduce.find = True if self.selected(scan, 'refine'): reduce.refine = True if self.selected(scan, 'prepare'): reduce.prepare = True if self.selected(scan, 'transform'): reduce.transform = True reduce.regular = True if self.selected(scan, 'masked_transform'): reduce.transform = True reduce.mask = True if self.selected(scan, 'combine'): reduce.combine = True reduce.regular = True if self.selected(scan, 'masked_combine'): reduce.combine = True reduce.mask = True if self.selected(scan, 'pdf'): reduce.pdf = True reduce.regular = True if self.selected(scan, 'masked_pdf'): reduce.pdf = True reduce.mask = True if self.selected(scan, 'overwrite'): reduce.overwrite = True reduce.queue('nxreduce') time.sleep(0.5) for task in self.tasks: if self.selected(scan, task): self.queued(scan, task) self.deselect_all()
def prepare_mask(self): if is_file_locked(self.reduce.data_file): return self.start_thread() self.reduce = NXReduce(self.entry, prepare=True, first=self.first, last=self.last, overwrite=True, gui=True) self.reduce.mask_parameters['threshold_1'] = self.threshold1 self.reduce.mask_parameters['threshold_1'] = self.threshold1 self.reduce.mask_parameters['horizontal_size_1'] = self.horizontal1 self.reduce.mask_parameters['threshold_2'] = self.threshold2 self.reduce.mask_parameters['horizontal_size_2'] = self.horizontal2 self.reduce.moveToThread(self.thread) self.reduce.start.connect(self.start_progress) self.reduce.update.connect(self.update_progress) self.reduce.result.connect(self.get_mask) self.reduce.stop.connect(self.stop) self.thread.started.connect(self.reduce.nxprepare) self.thread.start()
def main(): parser = argparse.ArgumentParser( description="Prepare 3D mask around Bragg peaks") parser.add_argument('-d', '--directory', required=True, help='scan directory') parser.add_argument('-e', '--entries', default=['f1', 'f2', 'f3'], nargs='+', help='names of entries to be processed') parser.add_argument('-o', '--overwrite', action='store_true', help='overwrite existing mask') parser.add_argument('-q', '--queue', action='store_true', help='add to server task queue') args = parser.parse_args() for entry in args.entries: reduce = NXReduce(entry, args.directory, prepare=True, overwrite=args.overwrite) if args.queue: reduce.queue() else: reduce.nxprepare()
def main(): parser = argparse.ArgumentParser( description="Choose parameters for NXReduce operations") parser.add_argument('-d', '--directory', required=True, help='scan directory') parser.add_argument('-t', '--threshold', type=float, help='peak threshold') parser.add_argument('-f', '--first', type=int, help='first frame') parser.add_argument('-l', '--last', type=int, help='last frame') parser.add_argument('-m', '--monitor', help='monitor to use in normalizations') parser.add_argument('-n', '--norm', type=float, help='normalization to monitor') parser.add_argument('-r', '--radius', type=float, help='radius of punched holes in Å-1') parser.add_argument('-Q', '--Qmax', type=float, help='maximum Q in Å-1 used in PDF tapers') parser.add_argument('-p', '--print', action='store_true', help='print current parameters') args = parser.parse_args() reduce = NXReduce(directory=args.directory) if args.print: print('Current NXReduce parameters\n---------------------------') print(f"Threshold = {reduce.threshold:g}") print(f"First Frame = {reduce.first}") print(f"Last Frame = {reduce.last}") print(f"Monitor = {reduce.monitor}") print(f"Normalization = {reduce.norm:g}") print(f"Radius = {reduce.radius:g}") print(f"Qmax = {reduce.Qmax:g}") else: reduce.write_parameters(threshold=args.threshold, first=args.first, last=args.last, monitor=args.monitor, norm=args.norm, radius=args.radius, qmax=args.Qmax)
def main(): parser = argparse.ArgumentParser( description="Copy instrument parameters from a parent file") parser.add_argument('-d', '--directory', required=True, help='scan directory') parser.add_argument('-e', '--entries', default=['f1', 'f2', 'f3'], nargs='+', help='names of entries to be searched') parser.add_argument('-p', '--parent', help='file name of file to copy from') parser.add_argument('-o', '--overwrite', action='store_true', help='overwrite existing peaks') parser.add_argument('-q', '--queue', action='store_true', help='add to server task queue') args = parser.parse_args() for entry in args.entries: reduce = NXReduce(entry, args.directory, parent=args.parent, copy=True, overwrite=args.overwrite) if args.queue: reduce.queue() else: reduce.nxcopy()
def update_parameters(self): reduce = NXReduce(self.entries[0]) if reduce.first: self.parameters['first'].value = reduce.first if reduce.last: self.parameters['last'].value = reduce.last if reduce.threshold: self.parameters['threshold'].value = reduce.threshold if reduce.radius: self.parameters['radius'].value = reduce.radius if reduce.width: self.parameters['width'].value = reduce.width if reduce.norm: self.parameters['norm'].value = reduce.norm
def main(): parser = argparse.ArgumentParser( description="Find peaks within the NeXus data") parser.add_argument('-d', '--directory', required=True, help='scan directory') parser.add_argument('-e', '--entries', nargs='+', help='names of entries to be searched') parser.add_argument('-t', '--threshold', type=float, help='peak threshold') parser.add_argument('-f', '--first', type=int, help='first frame') parser.add_argument('-l', '--last', type=int, help='last frame') parser.add_argument('-P', '--pixels', type=int, help='minimum pixels in a peak') parser.add_argument('-o', '--overwrite', action='store_true', help='overwrite existing peaks') parser.add_argument('-p', '--parent', default=None, help='The parent .nxs file to use') parser.add_argument('-m', '--monitor', action='store_true', help='monitor progress in the command line') parser.add_argument('-q', '--queue', action='store_true', help='add to server task queue') args = parser.parse_args() if args.entries: entries = args.entries else: entries = NXMultiReduce(args.directory).entries for entry in entries: reduce = NXReduce(entry, args.directory, find=True, threshold=args.threshold, first=args.first, last=args.last, min_pixels=args.pixels, overwrite=args.overwrite, monitor_progress=args.monitor) if args.queue: reduce.queue('nxfind', args) else: reduce.nxfind()
def main(): parser = argparse.ArgumentParser( description="Perform transform with 3D mask around Bragg peaks") parser.add_argument('-d', '--directory', required=True, help='scan directory') parser.add_argument('-e', '--entries', default=['f1', 'f2', 'f3'], nargs='+', help='names of entries to be processed') parser.add_argument('-r', '--radius', default=200, help='radius of mask around each peak (in pixels)') parser.add_argument('-w', '--width', default=3, help='width of masked region (in frames)') parser.add_argument('-o', '--overwrite', action='store_true', help='overwrite existing maximum') args = parser.parse_args() for entry in args.entries: reduce = NXReduce(entry, args.directory, mask=True, radius=args.radius, width=args.width, overwrite=args.overwrite) reduce.nxmask()
def main(): parser = argparse.ArgumentParser( description="Perform CCTW transform") parser.add_argument('-d', '--directory', required=True, help='scan directory') parser.add_argument('-e', '--entries', default=['f1', 'f2', 'f3'], nargs='+', help='names of entries to be processed') parser.add_argument('-m', '--mask', action='store_true', help='use 3D mask') parser.add_argument('-qh', nargs=3, help='Qh - min, step, max') parser.add_argument('-qk', nargs=3, help='Qk - min, step, max') parser.add_argument('-ql', nargs=3, help='Ql - min, step, max') parser.add_argument('-r', '--radius', default=200, help='radius of mask around each peak (in pixels)') parser.add_argument('-w', '--width', default=3, help='width of masked region (in frames)') parser.add_argument('-o', '--overwrite', action='store_true', help='overwrite existing transforms') parser.add_argument('-q', '--queue', action='store_true', help='add to server task queue') args = parser.parse_args() for entry in args.entries: reduce = NXReduce(entry, args.directory, transform=True, mask=args.mask, Qh=args.qh, Qk=args.qk, Ql=args.ql, radius=args.radius, width=args.width, overwrite=args.overwrite) if args.mask: if args.queue: reduce.queue() else: reduce.nxmasked_transform() else: if args.queue: reduce.queue() else: reduce.nxtransform()
def main(): parser = argparse.ArgumentParser( description="Refine lattice parameters and goniometer angles") parser.add_argument('-d', '--directory', required=True, help='scan directory') parser.add_argument('-e', '--entries', nargs='+', help='names of entries to be processed') parser.add_argument('-l', '--lattice', action='store_true', help='refine lattice parameters') parser.add_argument('-o', '--overwrite', action='store_true', help='overwrite existing maximum') parser.add_argument('-q', '--queue', action='store_true', help='add to server task queue') args = parser.parse_args() if args.entries: entries = args.entries else: entries = NXMultiReduce(args.directory).entries for i, entry in enumerate(entries): if i == 0: lattice = args.lattice else: lattice = False reduce = NXReduce(entry, args.directory, refine=True, lattice=lattice, overwrite=args.overwrite) if args.queue: reduce.queue('nxrefine', args) else: reduce.nxrefine()
def main(): parser = argparse.ArgumentParser( description="Find maximum counts of the signal in the specified path") parser.add_argument('-d', '--directory', required=True, help='scan directory') parser.add_argument('-e', '--entries', nargs='+', help='names of entries to be processed') parser.add_argument('-f', '--first', type=int, help='first frame') parser.add_argument('-l', '--last', type=int, help='last frame') parser.add_argument('-o', '--overwrite', action='store_true', help='overwrite existing maximum') parser.add_argument('-m', '--monitor', action='store_true', help='monitor progress in the command line') parser.add_argument('-q', '--queue', action='store_true', help='add to server task queue') args = parser.parse_args() if args.entries: entries = args.entries else: entries = NXMultiReduce(args.directory).entries for entry in entries: reduce = NXReduce(entry, args.directory, maxcount=True, first=args.first, last=args.last, overwrite=args.overwrite, monitor_progress=args.monitor) if args.queue: reduce.queue('nxmax', args) else: reduce.nxmax()
def main(): parser = argparse.ArgumentParser(description="Sum raw data files") parser.add_argument('-d', '--directory', required=True, help='directory containing summed files') parser.add_argument('-c', '--create', action='store_true', help='create the sum file and directory') parser.add_argument('-e', '--entries', nargs='+', help='names of entries to be summed') parser.add_argument('-s', '--scans', nargs='+', required=True, help='list of scan directories to be summed') parser.add_argument('-u', '--update', action='store_true', help='update links to existing summed files') parser.add_argument('-o', '--overwrite', action='store_true', help='overwrite existing summed files') args = parser.parse_args() if args.create: reduce = NXMultiReduce(args.directory, overwrite=True) reduce.nxsum(args.scans) else: for entry in args.entries: reduce = NXReduce(entry, args.directory, overwrite=args.overwrite) reduce.nxsum(args.scans, update=args.update)
def read_parameters(self): if 'nxreduce' in self.root['entry']: reduce = self.root['entry/nxreduce'] if 'threshold' in reduce: self.parameters['threshold'].value = reduce['threshold'] if 'first_frame' in reduce: self.parameters['first'].value = reduce['first_frame'] if 'last_frame' in reduce: self.parameters['last'].value = reduce['last_frame'] if 'monitor' in reduce: self.parameters['monitor'].value = reduce['monitor'] if 'norm' in reduce: self.parameters['norm'].value = reduce['norm'] if 'radius' in reduce: self.parameters['radius'].value = reduce['radius'] if 'qmax' in reduce: self.parameters['qmax'].value = reduce['qmax'] else: try: reduce = NXReduce(self.entries[0]) if reduce.first: self.parameters['first'].value = reduce.first if reduce.last: self.parameters['last'].value = reduce.last if reduce.threshold: self.parameters['threshold'].value = reduce.threshold if reduce.monitor: self.parameters['monitor'].value = reduce.monitor if reduce.norm: self.parameters['norm'].value = reduce.norm if reduce.radius: self.parameters['radius'].value = reduce.radius if reduce.qmax: self.parameters['qmax'].value = reduce.qmax except Exception: pass
class FindDialog(BaseDialog): def __init__(self, parent=None): super(FindDialog, self).__init__(parent) self.select_entry(self.choose_entry) self.parameters = GridParameters() self.parameters.add('threshold', '', 'Threshold') self.parameters.add('first', '', 'First Frame') self.parameters.add('last', '', 'Last Frame') find_layout = QtWidgets.QHBoxLayout() self.find_button = QtWidgets.QPushButton('Find Peaks') self.find_button.clicked.connect(self.find_peaks) self.peak_count = QtWidgets.QLabel() self.peak_count.setVisible(False) find_layout.addStretch() find_layout.addWidget(self.find_button) find_layout.addWidget(self.peak_count) find_layout.addStretch() self.set_layout(self.entry_layout, self.parameters.grid(), find_layout, self.progress_layout(save=True)) self.progress_bar.setVisible(False) self.progress_bar.setValue(0) self.set_title('Find Peaks') self.reduce = None def choose_entry(self): self.reduce = NXReduce(self.entry) if self.reduce.first: self.parameters['first'].value = self.reduce.first if self.reduce.last: self.parameters['last'].value = self.reduce.last else: try: self.parameters['last'].value = len(self.entry.data.nxaxes[0]) except Exception: pass if self.reduce.threshold: self.parameters['threshold'].value = self.reduce.threshold @property def threshold(self): try: _threshold = np.int32(self.parameters['threshold'].value) if _threshold > 0.0: return _threshold else: return None except Exception: return None @property def first(self): try: _first = np.int32(self.parameters['first'].value) if _first >= 0: return _first else: return None except Exception as error: return None @property def last(self): try: _last = np.int32(self.parameters['last'].value) if _last > 0: return _last else: return None except Exception as error: return None def find_peaks(self): self.check_lock(self.reduce.data_file) self.start_thread() self.reduce = NXReduce(self.entry, threshold=self.threshold, first=self.first, last=self.last, find=True, overwrite=True, gui=True) self.reduce.moveToThread(self.thread) self.reduce.start.connect(self.start_progress) self.reduce.update.connect(self.update_progress) self.reduce.result.connect(self.get_peaks) self.reduce.stop.connect(self.stop) self.thread.started.connect(self.reduce.nxfind) self.thread.start(QtCore.QThread.LowestPriority) def check_lock(self, file_name): try: with Lock(file_name, timeout=2): pass except LockException as error: if self.confirm_action('Clear lock?', str(error)): Lock(file_name).release() def get_peaks(self, peaks): self.peaks = peaks self.peak_count.setText('%s peaks found' % len(self.peaks)) self.peak_count.setVisible(True) def stop(self): self.stop_progress() if self.thread and self.thread.isRunning(): self.reduce.stopped = True self.stop_thread() def accept(self): try: with Lock(self.reduce.wrapper_file): self.reduce.write_peaks(self.peaks) except LockException as error: if self.confirm_action('Clear lock?', str(error)): Lock(self.reduce.wrapper_file).release() self.stop() super(FindDialog, self).accept() def reject(self): self.stop() super(FindDialog, self).reject()
def add_tasks(self): if self.grid is None: raise NeXusError('Need to update status') for scan in self.enabled_scans: for entry in self.entries: reduce = NXReduce(entry, scan) if self.selected(scan, 'link'): reduce.link = True if self.selected(scan, 'max'): reduce.maxcount = True if self.selected(scan, 'find'): reduce.find = True if self.selected(scan, 'copy'): reduce.copy = True if self.selected(scan, 'refine'): reduce.refine = True if self.selected(scan, 'prepare'): reduce.prepare = True if self.selected(scan, 'transform'): reduce.transform = True if self.selected(scan, 'masked_transform'): reduce.mask = True if self.selected(scan, 'overwrite'): reduce.overwrite = True reduce.queue() if self.selected(scan, 'link'): self.queued(scan, 'link') if self.selected(scan, 'max'): self.queued(scan, 'max') if self.selected(scan, 'find'): self.queued(scan, 'find') if self.selected(scan, 'copy'): self.queued(scan, 'copy') if self.selected(scan, 'refine'): self.queued(scan, 'refine') if self.selected(scan, 'prepare'): self.queued(scan, 'prepare') if self.selected(scan, 'transform'): self.queued(scan, 'transform') if self.selected(scan, 'masked_transform'): self.queued(scan, 'masked_transform') if self.selected(scan, 'combine'): reduce = NXMultiReduce(scan, self.entries) if self.selected(scan, 'overwrite'): reduce.overwrite = True reduce.queue() self.queued(scan, 'combine') if self.selected(scan, 'masked_combine'): reduce = NXMultiReduce(scan, self.entries, mask=True) if self.selected(scan, 'overwrite'): reduce.overwrite = True reduce.queue() self.queued(scan, 'masked_combine') self.scans[scan] self.deselect_all()
class Mask3DDialog(BaseDialog): def __init__(self, parent=None): super(Mask3DDialog, self).__init__(parent) self.select_entry(self.choose_entry) self.parameters = GridParameters() self.parameters.add('radius', 200, 'Radius') self.parameters.add('width', 3, 'Frame Width') self.set_layout(self.entry_layout, self.parameters.grid(), self.action_buttons(('Calculate 3D Mask', self.calculate_mask)), self.progress_layout(save=True)) self.progress_bar.setVisible(False) self.progress_bar.setValue(0) self.set_title('Calculate 3D Mask') self.reduce = None def choose_entry(self): self.reduce = NXReduce(self.entry) @property def radius(self): return self.parameters['radius'].value @property def width(self): return self.parameters['width'].value def calculate_mask(self): self.check_lock(self.reduce.wrapper_file) self.thread = QtCore.QThread() self.reduce = NXReduce(self.entry, radius=self.radius, width=self.width, mask=True, overwrite=True, gui=True) self.reduce.moveToThread(self.thread) self.reduce.start.connect(self.start_progress) self.reduce.update.connect(self.update_progress) self.reduce.result.connect(self.calculate_mask) self.reduce.stop.connect(self.stop) self.thread.started.connect(self.reduce.nxfind) self.thread.start(QtCore.QThread.LowestPriority) def check_lock(self, file_name): try: with Lock(file_name, timeout=2): pass except LockException as error: if self.confirm_action('Clear lock?', str(error)): Lock(file_name).release() def calculate_mask(self, mask): self.mask = mask def stop(self): self.stop_progress() if self.thread and self.thread.isRunning(): self.reduce.stopped = True self.thread.exit() def accept(self): try: with Lock(self.reduce.wrapper_file): self.reduce.write_peaks(self.peaks) except LockException as error: if self.confirm_action('Clear lock?', str(error)): Lock(self.reduce.wrapper_file).release() if self.thread: self.stop() super(Mask3DDialog, self).accept() def reject(self): if self.thread: self.stop() super(Mask3DDialog, self).reject()
def choose_entry(self): self.reduce = NXReduce(self.entry)
def main(): parser = argparse.ArgumentParser( description="Set scan file as parent by creating a symbolic link") parser.add_argument('-d', '--directory', required=True, help='scan directory') parser.add_argument('-e', '--entries', default=['f1', 'f2', 'f3'], nargs='+', help='names of entries to be searched') parser.add_argument('-t', '--threshold', type=float, help='peak threshold - defaults to maximum counts/10') parser.add_argument('-f', '--first', type=int, help='first frame') parser.add_argument('-l', '--last', type=int, help='last frame') parser.add_argument('-r', '--radius', type=int, default=200, help='radius of mask around each peak (in pixels)') parser.add_argument('-w', '--width', type=int, default=3, help='width of masked region (in frames)') parser.add_argument('-n', '--norm', default=50000, help='normalization to monitor1') parser.add_argument('-s', '--start', action='store_true', help='start data reduction') parser.add_argument('-o', '--overwrite', action='store_true', help='overwrite existing parent') args = parser.parse_args() reduce = NXReduce(directory=args.directory, overwrite=args.overwrite) reduce.make_parent() if args.start: for entry in args.entries: reduce = NXReduce(entry, args.directory, link=True, maxcount=True, find=True, mask=True, threshold=args.threshold, first=args.first, last=args.last, radius=args.radius, width=args.width, norm=args.norm, overwrite=args.overwrite) reduce.nxlink() reduce.nxmax() reduce.nxfind() reduce.nxmask()
class MaximumDialog(BaseDialog): def __init__(self, parent=None): super(MaximumDialog, self).__init__(parent) self.select_entry(self.choose_entry) self.parameters = GridParameters() self.parameters.add('first', '', 'First Frame') self.parameters.add('last', '', 'Last Frame') self.output = QtWidgets.QLabel('Maximum Value:') self.set_layout(self.entry_layout, self.output, self.parameters.grid(), self.action_buttons(('Find Maximum', self.find_maximum)), self.progress_layout(save=True)) self.progress_bar.setVisible(False) self.progress_bar.setValue(0) self.set_title('Find Maximum Value') self.reduce = None def choose_entry(self): self.reduce = NXReduce(self.entry) self.maximum = self.reduce.maximum if self.reduce.first: self.parameters['first'].value = self.reduce.first if self.reduce.last: self.parameters['last'].value = self.reduce.last @property def first(self): try: _first = np.int32(self.parameters['first'].value) if _first >= 0: return _first else: return None except Exception as error: return None @property def last(self): try: _last = np.int32(self.parameters['last'].value) if _last > 0: return _last else: return None except Exception as error: return None @property def maximum(self): return np.float(self.output.text().split()[-1]) @maximum.setter def maximum(self, value): self.output.setText('Maximum Value: %s' % value) def find_maximum(self): self.check_lock(self.reduce.data_file) self.start_thread() self.reduce = NXReduce(self.entry, first=self.first, last=self.last, maxcount=True, overwrite=True, gui=True) self.reduce.moveToThread(self.thread) self.reduce.start.connect(self.start_progress) self.reduce.update.connect(self.update_progress) self.reduce.result.connect(self.get_maximum) self.reduce.stop.connect(self.stop) self.thread.started.connect(self.reduce.nxmax) self.thread.finished.connect(self.stop) self.thread.start(QtCore.QThread.LowestPriority) def check_lock(self, file_name): try: with Lock(file_name, timeout=2): pass except LockException as error: if self.confirm_action('Clear lock?', str(error)): Lock(file_name).release() def get_maximum(self, maximum): self.maximum = maximum def stop(self): self.stop_progress() if self.thread and self.thread.isRunning(): self.reduce.stopped = True self.stop_thread() def accept(self): try: with Lock(self.reduce.wrapper_file): self.reduce.write_maximum(self.maximum) except LockException as error: if self.confirm_action('Clear lock?', str(error)): Lock(self.reduce.wrapper_file).release() self.stop() super(MaximumDialog, self).accept() def reject(self): self.stop() super(MaximumDialog, self).reject()