def OnImportXtals(self, evt): """ File > Import Crystals handler """ filename = FileDialog( self.view, self.dialog_dirs, 'xtals', 'Select file to import crystals from', wildcard=WILDCARD_XTAL, ) if not filename: return error = None t = filetype.determine_filetype(filename) if t == filetype.FILE_CALIBRATION: ci = Calibration() ci.load(filename, header_only=True) self.model.xtals = ci.xtals elif t == filetype.FILE_XTALS or t == filetype.FILE_UNKNOWN: data = None try: data = np.loadtxt(filename) self.model.xtals = [ [[x1,y1],[x2,y2]] for x1,y1,x2,y2 in data ] except ValueError: if data is not None: if len(data.shape) == 1: num = data.shape[0] else: num = data.shape[1] if num != 4: error = "Crystal file must contain 4 columns." else: error = "Invalid file." else: error = "Invalid file." else: error = "Invalid filetype." if error: print error errmsg = "Unable to load crystal boundaries:\n\n%s" % error errdlg = wx.MessageDialog(self.view, errmsg, "Error", wx.OK | wx.ICON_ERROR) errdlg.ShowModal() errdlg.Destroy() self.range_tool.rects = self.model.xtals self.view.image_view.Refresh() self.CalibrationValid(False) self.Changed()
xtal_boundaries = [ #(x1, y1, x2, y2), (17, 7, 119, 190), (135, 6, 229, 190), (249, 7, 343, 187), (357, 9, 457, 189) ] if __name__ == "__main__": import os, sys from minixs.calibrate import Calibration from minixs.misc import read_scan_info import minixs.filter as filter from minixs.constants import * c = Calibration() c.dataset = dataset c.exposure_files = [os.path.abspath(e) for e in exposures] c.energies = read_scan_info(scan_file, [energy_col])[0] c.dispersive_direction = DIRECTION_NAMES.index(dispersive_direction) # load up filters for name, val in filters: f = filter.get_filter_by_name(name) if f is None: print "Unknown filter: %s" % name exit(1) f.set_val(val) c.filters.append(f)
bad_pixels = [(14,185)] # pixels whose values should be ignored xes_file = 'example.xes' # file to save spectrum to if __name__ == "__main__": from minixs.emission import EmissionSpectrum xes = EmissionSpectrum() xes.calibration_file = calibration_file xes.incident_energy = incident_energy xes.I0 = I0 xes.exposure_files = exposures # set up bad pixel filter if needed if bad_pixels: fltr = BadPixelFilter() calib = Calibration() calib.load(calibration_file) if calib.dispersive_direction in [mx.UP, mx.DOWN]: mode = fltr.MODE_INTERP_V else: mode = fltr.MODE_INTERP_H fltr.set_val((mode, bad_pixels)) xes.filters.append(fltr) # process print "Processing..." xes.process() print "Finished\n" print "Saving as '%s'" % xes_file
def __init__(self): Calibration.__init__(self)
bad_pixels = [(14, 185)] # pixels whose values should be ignored xes_file = 'example.xes' # file to save spectrum to if __name__ == "__main__": from minixs.emission import EmissionSpectrum xes = EmissionSpectrum() xes.calibration_file = calibration_file xes.incident_energy = incident_energy xes.I0 = I0 xes.exposure_files = exposures # set up bad pixel filter if needed if bad_pixels: fltr = BadPixelFilter() calib = Calibration() calib.load(calibration_file) if calib.dispersive_direction in [mx.UP, mx.DOWN]: mode = fltr.MODE_INTERP_V else: mode = fltr.MODE_INTERP_H fltr.set_val((mode, bad_pixels)) xes.filters.append(fltr) # process print "Processing..." xes.process() print "Finished\n" print "Saving as '%s'" % xes_file