Ejemplo n.º 1
0
    def get_spotfinder_data(self, params):

        pointdata = []
        test_pattern = False
        if (
            test_pattern is True
            and self.raw_image.__class__.__name__.find("CSPadDetector") >= 0
        ):
            key_count = -1
            for key, asic in self.raw_image._tiles.items():
                key_count += 1
                focus = asic.focus()
                for slow in range(0, focus[0], 20):
                    for fast in range(0, focus[1], 20):
                        slowpic, fastpic = self.flex_image.tile_readout_to_picture(
                            key_count, slow, fast
                        )
                        mr1, mr2 = self.picture_fast_slow_to_map_relative(
                            fastpic, slowpic
                        )
                        pointdata.append((mr1, mr2, {"data": key}))

        elif self.raw_image.__class__.__name__.find("CSPadDetector") >= 0:
            from cxi_xdr_xes.cftbx.spotfinder.speckfinder import spotfind_readout

            key_count = -1
            for key, asic in self.raw_image._tiles.items():
                key_count += 1
                indexing = spotfind_readout(
                    readout=asic, peripheral_margin=params.spotfinder.peripheral_margin
                )

                for spot in indexing:
                    slow = int(round(spot[0]))
                    fast = int(round(spot[1]))

                    slowpic, fastpic = self.flex_image.tile_readout_to_picture(
                        key_count, slow, fast
                    )
                    mr1, mr2 = self.picture_fast_slow_to_map_relative(fastpic, slowpic)
                    pointdata.append((mr1, mr2, {"data": key}))

        else:
            from spotfinder.command_line.signal_strength import master_params

            working_params = master_params.fetch(
                sources=[]
            )  # placeholder for runtime mods
            working_params.show(expert_level=1)
            distl_params = working_params.extract()

            spotfinder, frameno = self.raw_image.get_spotfinder(distl_params)
            spots = spotfinder.images[frameno]["spots_total"]
            for spot in spots:
                mr = self.picture_fast_slow_to_map_relative(
                    spot.max_pxl_y() + 0.5, spot.max_pxl_x() + 0.5
                )
                #             spot.ctr_mass_y() + 0.5, spot.ctr_mass_x() + 0.5)
                pointdata.append(mr)
        return pointdata
Ejemplo n.º 2
0
def get_initial_cxi_scope():
    from spotfinder.command_line.signal_strength import master_params

    argument_interpreter = master_params.command_line_argument_interpreter(
        home_scope="distl")
    object1 = argument_interpreter.process(arg="distl.detector_tiling=%s" %
                                           run3_cxi_limits().as_string())
    working_params = master_params.fetch(sources=[object1])
    return working_params.extract()
Ejemplo n.º 3
0
def run(args, command_name="distl.image_viewer"):
    help_str = """Same as distl.signal_strength (type that command for help) except that
  the image_viewer starts up an interactive GUI to visualize spotfinder spots.
"""

    if (len(args) == 0
            or args[0] in ["H", "h", "-H", "-h", "help", "--help", "-help"]):
        print "usage:   %s image_filename [parameter=value ...]" % command_name
        print "example: %s lysozyme_001.img distl.res.outer=2.0 distl.res.inner=6.0 distl.minimum_spot_area=8" % command_name
        master_params.show(attributes_level=1, expert_level=1)
        print help_str
        return

    print "%s: characterization of candidate Bragg spots" % command_name

    phil_objects = []
    argument_interpreter = master_params.command_line_argument_interpreter(
        home_scope="distl")
    image_file_name = None
    moving_pdb_file_name = None
    for arg in args:
        if (os.path.isfile(arg)):
            if (image_file_name is None): image_file_name = arg
            else: raise Sorry("Too many file names.")
        else:
            try:
                command_line_params = argument_interpreter.process(arg=arg)
            except KeyboardInterrupt:
                raise
            except Exception:
                raise Sorry("Unknown file or keyword: %s" % arg)
            else:
                phil_objects.append(command_line_params)

    working_params = master_params.fetch(sources=phil_objects)
    params = working_params.extract()

    def raise_missing(what):
        raise Sorry("""\
Missing file name for %(what)s structure:
  Please add
    %(what)s=file_name
  to the command line to specify the %(what)s structure.""" % vars())

    if (image_file_name is None):
        if (params.distl.image is None): raise_missing("file name")
    else:
        params.distl.image = image_file_name

    working_params = master_params.format(python_object=params)
    #working_params.show(expert_level=1)

    #Now actually run the program logic
    from spotfinder.applications import image_viewer as app_image_viewer
    modeler = app_image_viewer.run_signal_strength_class(
        params=working_params.extract())
    modeler.view()
Ejemplo n.º 4
0
def get_initial_cxi_scope():
  from spotfinder.command_line.signal_strength import master_params

  argument_interpreter = master_params.command_line_argument_interpreter(
    home_scope="distl")
  object1 = argument_interpreter.process(arg=
    "distl.detector_tiling=%s"%run3_cxi_limits().as_string())
  working_params = master_params.fetch(sources=[object1])
  return working_params.extract()
Ejemplo n.º 5
0
def run(args, command_name="distl.image_viewer"):
  help_str="""Same as distl.signal_strength (type that command for help) except that
  the image_viewer starts up an interactive GUI to visualize spotfinder spots.
"""

  if (len(args) == 0 or args[0] in ["H","h","-H","-h","help","--help","-help"]):
    print "usage:   %s image_filename [parameter=value ...]" % command_name
    print "example: %s lysozyme_001.img distl.res.outer=2.0 distl.res.inner=6.0 distl.minimum_spot_area=8"%command_name
    master_params.show(attributes_level=1,expert_level=1)
    print help_str
    return

  print "%s: characterization of candidate Bragg spots"%command_name

  phil_objects = []
  argument_interpreter = master_params.command_line_argument_interpreter(
    home_scope="distl")
  image_file_name = None
  moving_pdb_file_name = None
  for arg in args:
    if (os.path.isfile(arg)):
      if (image_file_name is None): image_file_name = arg
      else: raise Sorry("Too many file names.")
    else:
      try: command_line_params = argument_interpreter.process(arg=arg)
      except KeyboardInterrupt: raise
      except Exception: raise Sorry("Unknown file or keyword: %s" % arg)
      else: phil_objects.append(command_line_params)

  working_params = master_params.fetch(sources=phil_objects)
  params = working_params.extract()

  def raise_missing(what):
      raise Sorry("""\
Missing file name for %(what)s structure:
  Please add
    %(what)s=file_name
  to the command line to specify the %(what)s structure.""" % vars())

  if (image_file_name is None):
    if (params.distl.image is None): raise_missing("file name")
  else:
    params.distl.image = image_file_name

  working_params = master_params.format(python_object=params)
  #working_params.show(expert_level=1)

  #Now actually run the program logic
  from spotfinder.applications import image_viewer as app_image_viewer
  modeler = app_image_viewer.run_signal_strength_class(params=working_params.extract())
  modeler.view()
Ejemplo n.º 6
0
    def get_spotfinder_data(self, params):

      pointdata = []
      test_pattern = False
      if test_pattern is True and self.raw_image.__class__.__name__.find("CSPadDetector") >= 0:
        key_count = -1
        for key, asic in self.raw_image._tiles.iteritems():
          key_count += 1
          focus = asic.focus()
          for slow in xrange(0,focus[0],20):
            for fast in xrange(0,focus[1],20):
              slowpic,fastpic = self.flex_image.tile_readout_to_picture(key_count,slow,fast)
              mr1,mr2 = self.picture_fast_slow_to_map_relative(fastpic,slowpic)
              pointdata.append((mr1,mr2,{"data":key}))

      elif (self.raw_image.__class__.__name__.find("CSPadDetector") >= 0):
        from cxi_xdr_xes.cftbx.spotfinder.speckfinder import spotfind_readout

        key_count = -1
        for key, asic in self.raw_image._tiles.iteritems():
          key_count += 1
          indexing = spotfind_readout(
              readout=asic,
              peripheral_margin=params.spotfinder.peripheral_margin)

          for spot in indexing:
            slow = int(round(spot[0]))
            fast = int(round(spot[1]))

            slowpic,fastpic = self.flex_image.tile_readout_to_picture(key_count,slow,fast)
            mr1,mr2 = self.picture_fast_slow_to_map_relative(fastpic,slowpic)
            pointdata.append((mr1,mr2,{"data":key}))

      else:
        from spotfinder.command_line.signal_strength import master_params
        working_params = master_params.fetch(sources = []) #placeholder for runtime mods
        working_params.show(expert_level=1)
        distl_params = working_params.extract()

        spotfinder,frameno = self.raw_image.get_spotfinder(distl_params)
        spots = spotfinder.images[frameno]["spots_total"]
        for spot in spots:
          mr = self.picture_fast_slow_to_map_relative(
              spot.max_pxl_y() + 0.5, spot.max_pxl_x() + 0.5)
#             spot.ctr_mass_y() + 0.5, spot.ctr_mass_x() + 0.5)
          pointdata.append(mr)
      return pointdata
Ejemplo n.º 7
0
def run(args, verbose=False):
    from libtbx.utils import Sorry
    import os
    from spotfinder.command_line.signal_strength import master_params
    from spotfinder.servers import LoggingFramework

    # For the Apache server version, do not allow site, user, or dataset preferences
    # all parameters are to be passed in through the http: query line

    logfile = LoggingFramework()

    phil_objects = []
    argument_interpreter = master_params.command_line_argument_interpreter(home_scope="distl")

    for key in args.keys():
        arg = "%s=%s" % (key, args.get(key, ""))
        try:
            command_line_params = argument_interpreter.process(arg=arg)
        except Exception:
            return str(Sorry("Unknown file or keyword: %s" % arg))
        else:
            phil_objects.append(command_line_params)

    working_params = master_params.fetch(sources=phil_objects)
    params = working_params.extract()
    # working_params.show()

    if not os.path.isfile(params.distl.image):
        return str(Sorry("%s is not a readable file" % params.distl.image))

    print "Image: %s" % params.distl.image

    from spotfinder.applications import signal_strength

    try:
        signal_strength.run_signal_strength(params)
    except Exception:
        import traceback

        logger = StringIO.StringIO()
        logger.write("Sorry, can't process %s.  Please contact authors.\n" % params.distl.image)
        traceback.print_exc(file=logger)
        return str(Sorry(logger.getvalue()))

    return logfile.getvalue()
Ejemplo n.º 8
0
def run(args, verbose=False):
    from libtbx.utils import Sorry
    import os
    from spotfinder.command_line.signal_strength import master_params
    from spotfinder.servers import LoggingFramework

    #For the Apache server version, do not allow site, user, or dataset preferences
    #all parameters are to be passed in through the http: query line

    logfile = LoggingFramework()

    phil_objects = []
    argument_interpreter = master_params.command_line_argument_interpreter(
        home_scope="distl")

    for key in args.keys():
        arg = "%s=%s" % (key, args.get(key, ""))
        try:
            command_line_params = argument_interpreter.process(arg=arg)
        except Exception:
            return str(Sorry("Unknown file or keyword: %s" % arg))
        else:
            phil_objects.append(command_line_params)

    working_params = master_params.fetch(sources=phil_objects)
    params = working_params.extract()
    #working_params.show()

    if not os.path.isfile(params.distl.image):
        return str(Sorry("%s is not a readable file" % params.distl.image))

    print "Image: %s" % params.distl.image

    from spotfinder.applications import signal_strength
    try:
        signal_strength.run_signal_strength(params)
    except Exception:
        import traceback
        logger = StringIO()
        logger.write("Sorry, can't process %s.  Please contact authors.\n" %
                     params.distl.image)
        traceback.print_exc(file=logger)
        return str(Sorry(logger.getvalue()))

    return logfile.getvalue()
Ejemplo n.º 9
0
def run(args, command_name="distl.mp_spotfinder_server_read_file"):
    help_str = """Multiprocessing server to find Bragg spots & quantify signal strength.
Full documentation: http://cci.lbl.gov/publications/download/ccn_jul2010_page18.pdf
Allowed parameters:
"""

    if (len(args) >= 1
            and args[0] in ["H", "h", "-H", "-h", "help", "--help", "-help"]):
        print("usage:   %s [parameter=value ...]" % command_name)
        print("example: %s distl.port=8125 distl.processors=8" % command_name)
        print(help_str)
        return
    else:
        print(help_str)

    phil_objects = []
    argument_interpreter = master_params.command_line_argument_interpreter(
        home_scope="distl")
    for arg in args:
        try:
            command_line_params = argument_interpreter.process(arg=arg)
        except KeyboardInterrupt:
            raise
        except Exception:
            raise Sorry("Unknown file or keyword: %s" % arg)
        else:
            phil_objects.append(command_line_params)

    working_params = master_params.fetch(sources=phil_objects)
    params = working_params.extract()

    working_params = master_params.format(python_object=params)
    #working_params.show()

    screen = 100
    for D in working_params.all_definitions():
        fp = D.object.full_path()
        if fp in ["distl.image", "distl.verbose", "distl.pdf_output"]: continue
        name = "  %s=%s" % (D.object.full_path(), D.object.extract())
        help = D.object.help
        if D.object.expert_level > 1: continue
        if len(name) + len(help) < screen and len(name) < 36:
            print("%-36s" % name, "[%s]" % help)
        else:
            print("%-36s" % name, end=' ')
            tokens = ("[%s]" % help).split()
            reserve = min(screen - 36, screen - len(name))
            while len(tokens) > 0:
                reserve -= len(tokens[0])
                if len(tokens[0]) > (screen - 36): break
                while reserve < 0:
                    print()
                    print(" " * 36, end=' ')
                    reserve = screen - 36
                print(tokens.pop(0), end=' ')
            print()

    #Now actually run the program logic
    from spotfinder.servers import mp_spotfinder_server_read_file as srv

    NUMBER_OF_PROCESSES = params.distl.processors
    srv.generate_common_parameters(working_params)

    server_address = ('', params.distl.port)

    srv.image_request_handler.protocol_version = "HTTP/1.0"

    print("Serving %d-process HTTP on" % NUMBER_OF_PROCESSES,
          server_address[0], "port", server_address[1], "...")
    print("To exit press Ctrl-C")
    srv.runpool(server_address, NUMBER_OF_PROCESSES, srv.image_request_handler)
Ejemplo n.º 10
0
def run(args, verbose=False):
    from libtbx.utils import Sorry
    import os
    from spotfinder.command_line.signal_strength import master_params

    #For the Apache server version, do not allow site, user, or dataset preferences
    #all parameters are to be passed in through the http: query line

    phil_objects = []
    argument_interpreter = master_params.command_line_argument_interpreter(
        home_scope="distl")

    from spotfinder.servers.apache_utils import LongLineSimpleNode as SimpleNode
    from spotfinder.applications import signal_strength

    logger = StringIO()
    top = SimpleNode("spotfinder")

    try:
        for key in args.keys():
            arg = "%s=%s" % (key, args.get(key, ""))
            command_line_params = argument_interpreter.process(arg=arg)
            phil_objects.append(command_line_params)

        working_params = master_params.fetch(sources=phil_objects)
        params = working_params.extract()

        top.child(SimpleNode(tag="file_name", contents=params.distl.image))

        if not os.path.isfile(params.distl.image):
            raise Sorry("%s not a readable file" % params.distl.image)

        Org = signal_strength.run_signal_strength(params)
        assert len(list(Org.S.images.keys())) == 1  # there is only one image
        key = list(Org.S.images.keys())[0]

        # List of spots between specified high- and low-resolution limits
        if Org.S.images[key].has_extended_key('lo_pass_resolution_spots'):
            spots = Org.S.images[key]['lo_pass_resolution_spots']
        elif Org.S.images[key].has_extended_key('inlier_spots'):
            spots = Org.S.images[key]['inlier_spots']
        else:
            spots = []

        if Org.S.images[key].has_extended_key('N_spots_total'):
            total = "%d" % Org.S.images[key]["N_spots_total"]
        else:
            total = "0"

        if Org.S.images[key].has_extended_key('resolution'):
            resolution = Org.S.images[key]['resolution']
        elif Org.S.images[key].has_extended_key('distl_resolution'):
            resolution = Org.S.images[key]['distl_resolution']
        else:
            resolution = 0.0

        top.child(SimpleNode(tag="total_spots", contents=total))
        top.child(SimpleNode(tag="good_spots", contents="%d" % len(spots)))
        top.child(SimpleNode(tag="resolution", contents="%.3f" % resolution))

        if len(Org.S.reporters[key]) == 0:
            top.child(SimpleNode(tag="total_integrated", contents="0"))
            top.child(SimpleNode(tag="mean_isigi", contents="0"))
        else:
            reporter = Org.S.reporters[key][-1]
            normalizer = reporter.weights.sum()
            summation = 0
            for x in range(reporter.S_table_rows):
                summation += reporter.weights[x] * reporter.MeanIsigI[x]
            top.child(
                SimpleNode(tag="mean_isigi",
                           contents="%.3f" % (summation / normalizer)))
            integrated = reporter.Integrated.sum()
            top.child(
                SimpleNode(tag="integrated", contents="%.3f" % integrated))

    except Exception as e:
        top.child(SimpleNode(tag="status", contents=repr(e)))
        top.emit(logger)
        return logger.getvalue()

    top.child(SimpleNode(tag="status", contents="OK"))
    top.emit(logger)

    return logger.getvalue()
def run(args, command_name="distl.mp_spotfinder_server_read_file"):
  help_str="""Multiprocessing server to find Bragg spots & quantify signal strength.
Full documentation: http://cci.lbl.gov/publications/download/ccn_jul2010_page18.pdf
Allowed parameters:
"""

  if (len(args)>=1 and args[0] in ["H","h","-H","-h","help","--help","-help"]):
    print "usage:   %s [parameter=value ...]" % command_name
    print "example: %s distl.port=8125 distl.processors=8"%command_name
    print help_str
    return
  else:  print help_str

  phil_objects = []
  argument_interpreter = master_params.command_line_argument_interpreter(
    home_scope="distl")
  for arg in args:
      try: command_line_params = argument_interpreter.process(arg=arg)
      except KeyboardInterrupt: raise
      except Exception: raise Sorry("Unknown file or keyword: %s" % arg)
      else: phil_objects.append(command_line_params)

  working_params = master_params.fetch(sources=phil_objects)
  params = working_params.extract()

  working_params = master_params.format(python_object=params)
  #working_params.show()

  screen = 100
  for D in working_params.all_definitions():
    fp = D.object.full_path()
    if fp in ["distl.image", "distl.verbose", "distl.pdf_output"]: continue
    name = "  %s=%s"%(D.object.full_path(),D.object.extract())
    help = D.object.help
    if D.object.expert_level > 1: continue
    if len(name) + len(help) < screen and len(name) < 36:
        print "%-36s"%name,"[%s]"%help
    else:
      print "%-36s"%name,
      tokens = ("[%s]"%help).split()
      reserve = min(screen-36,screen-len(name))
      while len(tokens)>0:
        reserve -= len(tokens[0])
        if len(tokens[0])>(screen-36):break
        while reserve<0:
          print
          print " "*36,
          reserve = screen-36
        print tokens.pop(0),
      print

  #Now actually run the program logic
  from spotfinder.servers import mp_spotfinder_server_read_file as srv

  NUMBER_OF_PROCESSES = params.distl.processors
  srv.generate_common_parameters(working_params)

  server_address = ('', params.distl.port)

  srv.image_request_handler.protocol_version = "HTTP/1.0"

  print "Serving %d-process HTTP on"%NUMBER_OF_PROCESSES, server_address[0], "port", server_address[1], "..."
  print "To exit press Ctrl-C"
  srv.runpool(server_address,NUMBER_OF_PROCESSES,srv.image_request_handler)
Ejemplo n.º 12
0
def run(args, verbose=False):
  from libtbx.utils import Sorry
  import os
  from spotfinder.command_line.signal_strength import master_params

  #For the Apache server version, do not allow site, user, or dataset preferences
  #all parameters are to be passed in through the http: query line

  phil_objects = []
  argument_interpreter = master_params.command_line_argument_interpreter(
    home_scope="distl")

  from spotfinder.servers.apache_utils import LongLineSimpleNode as SimpleNode
  from spotfinder.applications import signal_strength

  logger = StringIO.StringIO()
  top = SimpleNode("spotfinder")

  try:
    for key in args.keys():
        arg = "%s=%s"%(key,args.get(key,""))
        command_line_params = argument_interpreter.process(arg=arg)
        phil_objects.append(command_line_params)

    working_params = master_params.fetch(sources=phil_objects)
    params = working_params.extract()

    top.child(SimpleNode(tag="file_name",contents=params.distl.image))

    if not os.path.isfile(params.distl.image):
      raise Sorry("%s not a readable file"%params.distl.image)

    Org = signal_strength.run_signal_strength(params)
    assert len(Org.S.images.keys())==1 # there is only one image
    key = Org.S.images.keys()[0]

    # List of spots between specified high- and low-resolution limits
    if Org.S.images[key].has_key('lo_pass_resolution_spots'):
      spots = Org.S.images[key]['lo_pass_resolution_spots']
    elif Org.S.images[key].has_key('inlier_spots'):
      spots = Org.S.images[key]['inlier_spots']
    else:
      spots = []

    if Org.S.images[key].has_key('N_spots_total'):
      total = "%d"%Org.S.images[key]["N_spots_total"]
    else:
      total = "0"

    if Org.S.images[key].has_key('resolution'):
      resolution = Org.S.images[key]['resolution']
    elif Org.S.images[key].has_key('distl_resolution'):
      resolution = Org.S.images[key]['distl_resolution']
    else:
      resolution = 0.0

    top.child(SimpleNode(tag="total_spots",contents=total))
    top.child(SimpleNode(tag="good_spots",contents="%d"%len(spots)))
    top.child(SimpleNode(tag="resolution",contents="%.3f"%resolution))

    if len(Org.S.reporters[key])==0:
      top.child(SimpleNode(tag="total_integrated",contents="0"))
      top.child(SimpleNode(tag="mean_isigi",contents="0"))
    else:
      reporter = Org.S.reporters[key][-1]
      normalizer = reporter.weights.sum()
      summation = 0;
      for x in xrange(reporter.S_table_rows):
        summation += reporter.weights[x] * reporter.MeanIsigI[x]
      top.child(SimpleNode(tag="mean_isigi",contents="%.3f"%(summation/normalizer)))
      integrated = reporter.Integrated.sum()
      top.child(SimpleNode(tag="integrated",contents="%.3f"%integrated))

  except Exception,e:
    top.child(SimpleNode(tag="status",contents=repr(e)))
    top.emit(logger)
    return logger.getvalue()