Exemplo n.º 1
0
  def integrate_one_character(self,setting,integration_limit):
    #from libtbx.development.timers import Profiler
    #P = Profiler("Preliminary")
    import copy
    local = copy.deepcopy(self.process_dictionary)
    local['cell']=cellstr(setting)

    print("Cell in setting",setting["counter"],local["cell"])

    frames = list(sorted(self.spotfinder_results.pd['osc_start'].keys()))

    local['maxcel']='0'
    local['xbeam']="%f"%setting['minimizer'].new['xbeam']
    local['ybeam']="%f"%setting['minimizer'].new['ybeam']
    local['distance']="%f"%setting['minimizer'].new['distance']
    local["resolution"]= "%f"%integration_limit

    from labelit.steps import primaries
    local['spacegroup'] = primaries[setting['bravais']]

    local['procstart'] = local['procend'] = "%d"%frames[0]

    self.pixel_size = float(local['pixel_size'])

    from labelit.dptbx import AutoIndexEngine, Parameters
    ai = AutoIndexEngine(local['endstation'])

    P = Parameters(xbeam=setting["refined x beam"],ybeam=setting["refined y beam"],
             distance=setting["refined distance"],twotheta=float(local["twotheta"]))
    ai.setBase(P)
    ai.setWavelength(float(local['wavelength']))
    ai.setMaxcell(float(local['ref_maxcel']))
    print("Deltaphi is",float(local['deltaphi']))
    ai.setDeltaphi(float(local['deltaphi'])*math.pi/180.)
    ai.setMosaicity(setting["mosaicity"])
    ai.setOrientation(setting["orient"])
    refimage = self.files.images[0]
    ai.set_active_areas(self.horizons_phil,
                        beam=(int(refimage.beamx/refimage.pixel_size),
                              int(refimage.beamy/refimage.pixel_size)))

    image_centers = [(math.pi/180.)*float(x) for x in local["osc_start"].values()]

    print("Limiting resolution",integration_limit)
    local["results"] = []
    for i in range(len(frames)):
      print("---------BEGIN Integrate one frame %d %s" % \
          (frames[i], os.path.split(self.files.filenames()[i])[-1]))
      #P = Profiler("worker")
      if self.horizons_phil.integration.combine_sym_constraints_and_3D_target and setting["counter"]>1:
        from rstbx.apps.stills.dials_refinement_preceding_integration import integrate_one_frame
        integrate_worker = integrate_one_frame(self.triclinic["integration"]["results"][0])
      else:
        from rstbx.apps.stills.deltapsi_refinement_preceding_integration import integrate_one_frame
        integrate_worker = integrate_one_frame()
      integrate_worker.inputai = ai

      integrate_worker.inputpd = dict(masks=local["masks"],
                                      size1=local["size1"],
                                      size2=local["size2"],
                                      symmetry=setting["best_subsym"])
        # carefully select only the data items needed for integrate_worker
        # avoid giving the whole process dictionary; reference to "local"
        # is a circular reference creating memory leak, while copying the
        # whole thing is a big performance hit.
      integrate_worker.frame_numbers = frames
      integrate_worker.imagefiles = self.files
      integrate_worker.spotfinder = self.spotfinder_results
      integrate_worker.image_centers = image_centers

      integrate_worker.limiting_resolution = integration_limit
      integrate_worker.setting_id = setting["counter"]
      integrate_worker.pixel_size = self.pixel_size
      integrate_worker.set_pixel_size(self.pixel_size)
      integrate_worker.set_detector_size(int(local["size1"]),int(local["size2"]))

      integrate_worker.set_detector_saturation(refimage.saturation)
      integrate_worker.set_up_mask_focus()
      integrate_worker.initialize_increments(i)
      integrate_worker.horizons_phil = self.horizons_phil
      if self.horizons_phil.indexing.verbose_cv:
        print("EFFECTIVE TILING"," ".join(
          ["%d"%z for z in refimage.get_tile_manager(self.horizons_phil).effective_tiling_as_flex_int()]))
      integrate_worker.integration_concept(image_number = i,
        cb_op_to_primitive = setting["cb_op_inp_best"].inverse(),
        verbose_cv = self.horizons_phil.indexing.verbose_cv,
        background_factor = self.horizons_phil.integration.background_factor,
        )
      #P = Profiler("proper")
      integrate_worker.integration_proper()
      local["results"].append(integrate_worker)
      local["r_xbeam"]=ai.xbeam()
      local["r_ybeam"]=ai.ybeam()
      local["r_distance"]=ai.distance()
      local["r_wavelength"]=ai.wavelength
      local["r_residual"]=integrate_worker.r_residual
      local["r_mosaicity"]=setting["mosaicity"]
      try:
        local["ewald_proximal_volume"]=integrate_worker.ewald_proximal_volume
      except Exception as e:
        local["ewald_proximal_volume"]=None

      if (self.horizons_phil.indexing.open_wx_viewer):
       if True: #use updated slip viewer
        try:
          import wx
          from rstbx.slip_viewer.frame import XrayFrame as SlipXrayFrame
          from rstbx.command_line.slip_viewer import master_str as slip_params
          from iotbx import phil
          from spotfinder import phil_str
          from spotfinder.command_line.signal_strength import additional_spotfinder_phil_defs

          work_phil = phil.process_command_line("",master_string=slip_params + phil_str + additional_spotfinder_phil_defs)
          work_params = work_phil.work.extract()

          app = wx.App(0)
          wx.SystemOptions.SetOption("osx.openfiledialog.always-show-types", "1")
          frame = SlipXrayFrame(None, -1, "X-ray image display", size=(800,720))
          frame.Show()

          # Update initial settings with values from the command line.  Needs
          # to be done before image is loaded (but after the frame is
          # instantiated).
          frame.inherited_params = integrate_worker.horizons_phil
          frame.params = work_params

          if (frame.pyslip is None):
            frame.init_pyslip()
          if (frame.settings_frame is None):
            frame.OnShowSettings(None)
          frame.Layout()

          frame.pyslip.tiles.user_requests_antialiasing = work_params.anti_aliasing
          frame.settings_frame.panel.center_ctrl.SetValue(True)
          frame.settings_frame.panel.integ_ctrl.SetValue(True)
          frame.settings_frame.panel.spots_ctrl.SetValue(False)
          frame.settings.show_effective_tiling = work_params.show_effective_tiling
          frame.settings_frame.panel.collect_values()
          paths = work_phil.remaining_args

          frame.user_callback = integrate_worker.slip_callback
          frame.load_image(self.files.filenames()[i])

          app.MainLoop()
          del app
        except Exception:
          pass # must use phenix.wxpython for wx display

       elif False : #original wx viewer
        try:
          from rstbx.viewer.frame import XrayFrame
          import wx
          from rstbx.viewer import display
          display.user_callback = integrate_worker.user_callback

          app = wx.App(0)
          frame = XrayFrame(None, -1, "X-ray image display", size=(1200,1080))
          frame.settings.show_spotfinder_spots = False
          frame.settings.show_integration = False
          #frame.settings.enable_collect_values = False
          frame.SetSize((1024,780))
          frame.load_image(self.files.filenames()[i])
          frame.Show()
          app.MainLoop()
          del app
        except Exception:
          pass # must use phenix.wxpython for wx display

      # for the wx image viewer
      filename = self.horizons_phil.indexing.indexing_pickle
      if filename != None:
        filename = "%s_%d_%d.pkl"%(filename,setting["counter"],keys[i])

        SIO = StringIO()
        table_raw = show_observations(integrate_worker.get_obs(
          local["spacegroup"]),out=SIO)
        limitobject = ResolutionAnalysisMetaClass(local, self.horizons_phil)
        info = dict(table = SIO.getvalue(),
          table_raw = table_raw,
          xbeam = setting["refined x beam"],
          ybeam = setting["refined y beam"],
          distance = setting["refined distance"],
          residual = integrate_worker.r_residual,
          resolution = limitobject.value, # FIXME not reliable?
          mosaicity = setting["mosaicity"],
          pointgroup = local["spacegroup"],
          hkllist = integrate_worker.hkllist,
          predictions = (1./integrate_worker.pixel_size)*integrate_worker.predicted,
          mapped_predictions = integrate_worker.detector_xy,
          integration_masks_xy = integrate_worker.integration_masks_as_xy_tuples(),
          background_masks_xy = integrate_worker.background_masks_as_xy_tuples()
        )
        assert info["predictions"].size() >= info["mapped_predictions"].size()
        assert info["predictions"].size() == info["hkllist"].size()
        G = open(filename,"wb")
        pickle.dump(info,G,pickle.HIGHEST_PROTOCOL)
      print("---------END Integrate one frame",frames[i])

    return local
Exemplo n.º 2
0
def run(argv=None):
    if (argv is None):
        argv = sys.argv

    # XXX Could/should handle effective metrology the same way, except
    # it does not have a single scope.
    work_phil = phil.process_command_line(args=argv[1:],
                                          master_string=master_str + phil_str +
                                          additional_spotfinder_phil_defs)
    work_params = work_phil.work.extract()

    app = wx.App(0)
    wx.SystemOptions.SetOptionInt("osx.openfiledialog.always-show-types", 1)
    frame = XrayFrame(None, -1, "X-ray image display", size=(800, 720))
    frame.Show()

    # show settings panel
    frame.OnShowSettings(None)
    frame.settings_frame.panel.center_ctrl.SetValue(work_params.beam_center)
    frame.settings_frame.panel.integ_ctrl.SetValue(
        work_params.show_integration_results)
    frame.settings_frame.panel.spots_ctrl.SetValue(
        work_params.show_spotfinder_results)
    frame.settings.show_effective_tiling = work_params.show_effective_tiling
    frame.settings_frame.panel.collect_values()

    if (work_params.effective_metrology is not None):
        from xfel.cftbx.detector.metrology import \
          master_phil, metrology_as_transformation_matrices

        stream = open(work_params.effective_metrology)
        metrology_phil = master_phil.fetch(sources=[phil.parse(stream.read())])
        stream.close()
        frame.metrology_matrices = metrology_as_transformation_matrices(
            metrology_phil.extract())

    # Update initial settings with values from the command line.  Needs
    # to be done before image is loaded (but after the frame is
    # instantiated).
    frame.params = work_params
    frame.init_pyslip()
    frame.pyslip.tiles.user_requests_antialiasing = work_params.anti_aliasing
    frame.pyslip.tiles.show_untrusted = frame.params.show_untrusted

    paths = work_phil.remaining_args
    if (len(paths) == 1 and os.path.basename(paths[0]) == "DISTL_pickle"):
        assert os.path.isfile(paths[0])
        frame.load_distl_output(paths[0])
    elif (len(paths) > 0):
        frame.CHOOSER_SIZE = 1500

        # from dxtbx.imageset import ImageSetFactory
        # sets = ImageSetFactory.new(paths)
        from dxtbx.model.experiment_list import ExperimentListFactory
        from rstbx.slip_viewer.frame import chooser_wrapper
        experiments = ExperimentListFactory.from_filenames(paths)
        sets = experiments.imagesets()

        for imgset in sets:
            for idx in imgset.indices():
                frame.add_file_name_or_data(chooser_wrapper(imgset, idx))
        idx = sets[0].indices()[0]
        frame.load_image(chooser_wrapper(sets[0], idx))

    app.MainLoop()

    return 0
Exemplo n.º 3
0
  def integrate_one_character(self,setting,integration_limit):
    #from libtbx.development.timers import Profiler
    #P = Profiler("Preliminary")
    import copy
    local = copy.deepcopy(self.process_dictionary)
    local['cell']=cellstr(setting)

    print "Cell in setting",setting["counter"],local["cell"]

    frames = self.spotfinder_results.pd['osc_start'].keys()
    frames.sort()

    local['maxcel']='0'
    local['xbeam']="%f"%setting['minimizer'].new['xbeam']
    local['ybeam']="%f"%setting['minimizer'].new['ybeam']
    local['distance']="%f"%setting['minimizer'].new['distance']
    local["resolution"]= "%f"%integration_limit

    from labelit.steps import primaries
    local['spacegroup'] = primaries[setting['bravais']]

    local['procstart'] = local['procend'] = "%d"%frames[0]

    self.pixel_size = float(local['pixel_size'])

    from labelit.dptbx import AutoIndexEngine, Parameters
    ai = AutoIndexEngine(local['endstation'])

    P = Parameters(xbeam=setting["refined x beam"],ybeam=setting["refined y beam"],
             distance=setting["refined distance"],twotheta=float(local["twotheta"]))
    ai.setBase(P)
    ai.setWavelength(float(local['wavelength']))
    ai.setMaxcell(float(local['ref_maxcel']))
    print "Deltaphi is",float(local['deltaphi'])
    ai.setDeltaphi(float(local['deltaphi'])*math.pi/180.)
    ai.setMosaicity(setting["mosaicity"])
    ai.setOrientation(setting["orient"])
    refimage = self.files.images[0]
    ai.set_active_areas(self.horizons_phil,
                        beam=(int(refimage.beamx/refimage.pixel_size),
                              int(refimage.beamy/refimage.pixel_size)))

    image_centers = [(math.pi/180.)*float(x) for x in local["osc_start"].values()]

    print "Limiting resolution",integration_limit
    local["results"] = []
    for i in xrange(len(frames)):
      print "---------BEGIN Integrate one frame %d %s" % \
          (frames[i], os.path.split(self.files.filenames()[i])[-1])
      #P = Profiler("worker")
      if self.horizons_phil.integration.combine_sym_constraints_and_3D_target and setting["counter"]>1:
        from rstbx.apps.stills.dials_refinement_preceding_integration import integrate_one_frame
        integrate_worker = integrate_one_frame(self.triclinic["integration"]["results"][0])
      else:
        from rstbx.apps.stills.deltapsi_refinement_preceding_integration import integrate_one_frame
        integrate_worker = integrate_one_frame()
      integrate_worker.inputai = ai

      integrate_worker.inputpd = dict(masks=local["masks"],
                                      size1=local["size1"],
                                      size2=local["size2"],
                                      symmetry=setting["best_subsym"])
        # carefully select only the data items needed for integrate_worker
        # avoid giving the whole process dictionary; reference to "local"
        # is a circular reference creating memory leak, while copying the
        # whole thing is a big performance hit.
      integrate_worker.frame_numbers = frames
      integrate_worker.imagefiles = self.files
      integrate_worker.spotfinder = self.spotfinder_results
      integrate_worker.image_centers = image_centers

      integrate_worker.limiting_resolution = integration_limit
      integrate_worker.setting_id = setting["counter"]
      integrate_worker.pixel_size = self.pixel_size
      integrate_worker.set_pixel_size(self.pixel_size)
      integrate_worker.set_detector_size(int(local["size1"]),int(local["size2"]))

      integrate_worker.set_detector_saturation(refimage.saturation)
      integrate_worker.set_up_mask_focus()
      integrate_worker.initialize_increments(i)
      integrate_worker.horizons_phil = self.horizons_phil
      if self.horizons_phil.indexing.verbose_cv:
        print "EFFECTIVE TILING"," ".join(
          ["%d"%z for z in refimage.get_tile_manager(self.horizons_phil).effective_tiling_as_flex_int()])
      integrate_worker.integration_concept(image_number = i,
        cb_op_to_primitive = setting["cb_op_inp_best"].inverse(),
        verbose_cv = self.horizons_phil.indexing.verbose_cv,
        background_factor = self.horizons_phil.integration.background_factor,
        )
      #P = Profiler("proper")
      integrate_worker.integration_proper()
      local["results"].append(integrate_worker)
      local["r_xbeam"]=ai.xbeam()
      local["r_ybeam"]=ai.ybeam()
      local["r_distance"]=ai.distance()
      local["r_wavelength"]=ai.wavelength
      local["r_residual"]=integrate_worker.r_residual
      local["r_mosaicity"]=setting["mosaicity"]
      try:
        local["ewald_proximal_volume"]=integrate_worker.ewald_proximal_volume
      except Exception, e:
        local["ewald_proximal_volume"]=None

      if (self.horizons_phil.indexing.open_wx_viewer) :
       if True: #use updated slip viewer
        try:
          import wx
          from rstbx.slip_viewer.frame import XrayFrame as SlipXrayFrame
          from rstbx.command_line.slip_viewer import master_str as slip_params
          from iotbx import phil
          from spotfinder import phil_str
          from spotfinder.command_line.signal_strength import additional_spotfinder_phil_defs

          work_phil = phil.process_command_line("",master_string=slip_params + phil_str + additional_spotfinder_phil_defs)
          work_params = work_phil.work.extract()

          app = wx.App(0)
          wx.SystemOptions.SetOptionInt("osx.openfiledialog.always-show-types", 1)
          frame = SlipXrayFrame(None, -1, "X-ray image display", size=(800,720))
          frame.Show()

          # Update initial settings with values from the command line.  Needs
          # to be done before image is loaded (but after the frame is
          # instantiated).
          frame.inherited_params = integrate_worker.horizons_phil
          frame.params = work_params

          if (frame.pyslip is None):
            frame.init_pyslip()
          if (frame.settings_frame is None):
            frame.OnShowSettings(None)
          frame.Layout()

          frame.pyslip.tiles.user_requests_antialiasing = work_params.anti_aliasing
          frame.settings_frame.panel.center_ctrl.SetValue(True)
          frame.settings_frame.panel.integ_ctrl.SetValue(True)
          frame.settings_frame.panel.spots_ctrl.SetValue(False)
          frame.settings.show_effective_tiling = work_params.show_effective_tiling
          frame.settings_frame.panel.collect_values()
          paths = work_phil.remaining_args

          frame.user_callback = integrate_worker.slip_callback
          frame.load_image(self.files.filenames()[i])

          app.MainLoop()
          del app
        except Exception:
          pass # must use phenix.wxpython for wx display

       elif False : #original wx viewer
        try:
          from rstbx.viewer.frame import XrayFrame
          import wx
          from rstbx.viewer import display
          display.user_callback = integrate_worker.user_callback

          app = wx.App(0)
          frame = XrayFrame(None, -1, "X-ray image display", size=(1200,1080))
          frame.settings.show_spotfinder_spots = False
          frame.settings.show_integration = False
          #frame.settings.enable_collect_values = False
          frame.SetSize((1024,780))
          frame.load_image(self.files.filenames()[i])
          frame.Show()
          app.MainLoop()
          del app
        except Exception:
          pass # must use phenix.wxpython for wx display

      # for the wx image viewer
      filename = self.horizons_phil.indexing.indexing_pickle
      if filename != None:
        filename = "%s_%d_%d.pkl"%(filename,setting["counter"],keys[i])

        SIO = StringIO.StringIO()
        table_raw = show_observations(integrate_worker.get_obs(
          local["spacegroup"]),out=SIO)
        limitobject = ResolutionAnalysisMetaClass(local, self.horizons_phil)
        info = dict(table = SIO.getvalue(),
          table_raw = table_raw,
          xbeam = setting["refined x beam"],
          ybeam = setting["refined y beam"],
          distance = setting["refined distance"],
          residual = integrate_worker.r_residual,
          resolution = limitobject.value, # FIXME not reliable?
          mosaicity = setting["mosaicity"],
          pointgroup = local["spacegroup"],
          hkllist = integrate_worker.hkllist,
          predictions = (1./integrate_worker.pixel_size)*integrate_worker.predicted,
          mapped_predictions = integrate_worker.detector_xy,
          integration_masks_xy = integrate_worker.integration_masks_as_xy_tuples(),
          background_masks_xy = integrate_worker.background_masks_as_xy_tuples()
        )
        assert info["predictions"].size() >= info["mapped_predictions"].size()
        assert info["predictions"].size() == info["hkllist"].size()
        G = open(filename,"wb")
        pickle.dump(info,G,pickle.HIGHEST_PROTOCOL)
      print "---------END Integrate one frame",frames[i]
Exemplo n.º 4
0
def run(argv=None):
  if (argv is None):
    argv = sys.argv

  # XXX Could/should handle effective metrology the same way, except
  # it does not have a single scope.
  work_phil = phil.process_command_line(
    args=argv[1:],
    master_string=master_str + phil_str + additional_spotfinder_phil_defs)
  work_params = work_phil.work.extract()

  app = wx.App(0)
  wx.SystemOptions.SetOptionInt("osx.openfiledialog.always-show-types", 1)
  frame = XrayFrame(None, -1, "X-ray image display", size=(800,720))
  frame.Show()

  # show settings panel
  frame.OnShowSettings(None)
  frame.settings_frame.panel.center_ctrl.SetValue(
    work_params.beam_center)
  frame.settings_frame.panel.integ_ctrl.SetValue(
    work_params.show_integration_results)
  frame.settings_frame.panel.spots_ctrl.SetValue(
    work_params.show_spotfinder_results)
  frame.settings.show_effective_tiling = work_params.show_effective_tiling
  frame.settings_frame.panel.collect_values()

  if (work_params.effective_metrology is not None):
    from xfel.cftbx.detector.metrology import \
      master_phil, metrology_as_transformation_matrices

    stream = open(work_params.effective_metrology)
    metrology_phil = master_phil.fetch(sources=[phil.parse(stream.read())])
    stream.close()
    frame.metrology_matrices = metrology_as_transformation_matrices(
      metrology_phil.extract())

  # Update initial settings with values from the command line.  Needs
  # to be done before image is loaded (but after the frame is
  # instantiated).
  frame.params = work_params
  frame.init_pyslip()
  frame.pyslip.tiles.user_requests_antialiasing = work_params.anti_aliasing
  frame.pyslip.tiles.show_untrusted = frame.params.show_untrusted

  paths = work_phil.remaining_args
  if (len(paths) == 1 and os.path.basename(paths[0]) == "DISTL_pickle"):
    assert os.path.isfile(paths[0])
    frame.load_distl_output(paths[0])
  elif (len(paths) > 0):
    frame.CHOOSER_SIZE = 1500

    from dxtbx.imageset import ImageSetFactory
    from rstbx.slip_viewer.frame import chooser_wrapper
    sets = ImageSetFactory.new(paths)

    for imgset in sets:
      for idx in imgset.indices():
        frame.add_file_name_or_data(chooser_wrapper(imgset, idx))
    idx = sets[0].indices()[0]
    frame.load_image(chooser_wrapper(sets[0],idx))

  app.MainLoop()

  return 0