Exemplo n.º 1
0
    def OnRestoreMetrology(self, event):
        print("Not implemented")
        return

        dialog = wx.FileDialog(
            self,
            defaultDir="",
            message="Restore metrology file",
            style=wx.FD_OPEN,
            wildcard="Phil files (*.eff; *.def)|*.eff;*.def")
        if dialog.ShowModal() == wx.ID_OK:
            path = dialog.GetPath()
            if (path != ""):
                from xfel.cftbx.detector.metrology import \
                  master_phil, metrology_as_transformation_matrices
                from libtbx import phil

                frame = self.GetParent().GetParent()
                stream = open(path)
                metrology_phil = master_phil.fetch(
                    sources=[phil.parse(stream.read())])
                stream.close()

                # Merge restored metrology into the raw image
                from libtbx.phil import experimental
                experimental.merge_params_by_key(
                    frame.pyslip.tiles.raw_image._metrology_params,
                    metrology_phil.extract(), 'serial')

                img = frame.pyslip.tiles.raw_image
                img.apply_metrology_from_matrices(
                    metrology_as_transformation_matrices(
                        metrology_phil.extract()))

                # Update the view, trigger redraw.  XXX Duplication
                # w.r.t. OnUpdateQuad().
                tiles = frame.pyslip.tiles
                tiles.flex_image = frame.pyslip.tiles.raw_image.get_flex_image(
                    brightness=tiles.current_brightness / 100)
                tiles.flex_image.adjust(
                    color_scheme=tiles.current_color_scheme)

                tiles.reset_the_cache()
                tiles.tile_cache = tiles.cache[tiles.zoom_level]
                tiles.tile_list = tiles.lru[tiles.zoom_level]
                frame.pyslip.Update()

                # Update the controls, remember to reset the default values
                # for the spinners.
                for serial in range(4):
                    fast, slow = img.get_panel_fast_slow(serial)
                    name_quadrant = ["Q0", "Q1", "Q2", "Q3"][serial]

                    spinner = getattr(self, "_" + name_quadrant + "_fast_ctrl")
                    spinner.SetDefaultValue(fast)
                    spinner.SetValue(fast)

                    spinner = getattr(self, "_" + name_quadrant + "_slow_ctrl")
                    spinner.SetDefaultValue(slow)
                    spinner.SetValue(slow)
Exemplo n.º 2
0
  def OnRestoreMetrology(self, event):
    print "Not implemented"
    return

    dialog = wx.FileDialog(
      self,
      defaultDir="",
      message="Restore metrology file",
      style=wx.FD_OPEN,
      wildcard="Phil files (*.eff; *.def)|*.eff;*.def")
    if dialog.ShowModal() == wx.ID_OK:
      path = dialog.GetPath()
      if (path != "") :
        from xfel.cftbx.detector.metrology import \
          master_phil, metrology_as_transformation_matrices
        from libtbx import phil

        frame = self.GetParent().GetParent()
        stream = open(path)
        metrology_phil = master_phil.fetch(sources=[phil.parse(stream.read())])
        stream.close()

        # Merge restored metrology into the raw image
        from libtbx.phil import experimental
        experimental.merge_params_by_key(
          frame.pyslip.tiles.raw_image._metrology_params,
          metrology_phil.extract(),
          'serial')

        img = frame.pyslip.tiles.raw_image
        img.apply_metrology_from_matrices(metrology_as_transformation_matrices(
          metrology_phil.extract()))

        # Update the view, trigger redraw.  XXX Duplication
        # w.r.t. OnUpdateQuad().
        tiles = frame.pyslip.tiles
        tiles.flex_image = frame.pyslip.tiles.raw_image.get_flex_image(
          brightness=tiles.current_brightness / 100)
        tiles.flex_image.adjust(color_scheme=tiles.current_color_scheme)

        tiles.reset_the_cache()
        tiles.tile_cache = tiles.cache[tiles.zoom_level]
        tiles.tile_list = tiles.lru[tiles.zoom_level]
        frame.pyslip.Update()

        # Update the controls, remember to reset the default values
        # for the spinners.
        for serial in xrange(4):
          fast, slow = img.get_panel_fast_slow(serial)
          name_quadrant = ["Q0", "Q1", "Q2", "Q3"][serial]

          spinner = getattr(self, "_" + name_quadrant + "_fast_ctrl")
          spinner.SetDefaultValue(fast)
          spinner.SetValue(fast)

          spinner = getattr(self, "_" + name_quadrant + "_slow_ctrl")
          spinner.SetDefaultValue(slow)
          spinner.SetValue(slow)
Exemplo n.º 3
0
def exercise():
  master_phil = libtbx.phil.parse("""
first_prop = 0
  .type = int
second_prop = "default text"
  .type = str
first_scope
  .multiple = True
  .optional = True
{
  key = None
    .type = int
    .optional = False
  number = None
    .type = int
    .optional = False
  text = "Default first scope text"
    .type = str
    .optional = False
  second_scope
    .multiple = True
    .optional = True
  {
    key = None
      .type = int
      .optional = False
    flag = None
      .type = bool
    list = None
      .type = floats(size=2)
  }
}
""")

  default_str = """
first_scope {
  key = 1
  number = 1.0
  text = "First key 1 text"
  second_scope {
    key = 0
    flag = False
  }
  second_scope {
    key = 1
    list = [0, 0]
  }
  second_scope {
    key = 2
  }
}
first_scope {
  key = 2
  text = "First key 2 text"
  second_scope {
    key = 0
    flag = True
    list = [0, 1]
  }
}
"""

  overlay_str = """
first_prop = 1
first_scope {
  key = 1
  number = 2
  second_scope {
    key = 0
    list = [1, 0]
  }
  second_scope {
    key = 1
    flag = False
    list = [1, 1]
  }
  second_scope {
    key = 4
    list = [0, 2]
  }
}
"""

  # XXX Correct use of _phil and _params?
  default_phil = master_phil.fetch(sources=[libtbx.phil.parse(default_str)])
  default_params = default_phil.extract()

  overlay_phil = master_phil.fetch(sources=[libtbx.phil.parse(overlay_str)])
  overlay_params = overlay_phil.extract()

  experimental.merge_params_by_key(default_params, overlay_params, "key")

  assert default_params.first_prop == 1
  assert default_params.second_prop == "default text"
  assert len(default_params.first_scope) == 2

  for fs in default_params.first_scope:
    if (fs.key == 1):
      assert fs.number == 2 and fs.text == "Default first scope text"
      assert len(fs.second_scope) == 4
      for ss in fs.second_scope:
        if (ss.key == 0):
          assert ss.flag == False and ss.list == [1, 0]
        elif (ss.key == 1):
          assert ss.flag == False and ss.list == [1, 1]
        elif (ss.key == 2):
          assert ss.flag is None and ss.list is None
        elif (ss.key == 4):
          assert ss.flag is None and ss.list == [0, 2]

    elif (fs.key == 2):
      assert fs.number is None and fs.text == "First key 2 text"
      assert len(fs.second_scope) == 1
      assert fs.second_scope[0].key == 0 and \
          fs.second_scope[0].flag == True and \
          fs.second_scope[0].list == [0, 1]
Exemplo n.º 4
0
def exercise():
    master_phil = libtbx.phil.parse("""
first_prop = 0
  .type = int
second_prop = "default text"
  .type = str
first_scope
  .multiple = True
  .optional = True
{
  key = None
    .type = int
    .optional = False
  number = None
    .type = int
    .optional = False
  text = "Default first scope text"
    .type = str
    .optional = False
  second_scope
    .multiple = True
    .optional = True
  {
    key = None
      .type = int
      .optional = False
    flag = None
      .type = bool
    list = None
      .type = floats(size=2)
  }
}
""")

    default_str = """
first_scope {
  key = 1
  number = 1.0
  text = "First key 1 text"
  second_scope {
    key = 0
    flag = False
  }
  second_scope {
    key = 1
    list = [0, 0]
  }
  second_scope {
    key = 2
  }
}
first_scope {
  key = 2
  text = "First key 2 text"
  second_scope {
    key = 0
    flag = True
    list = [0, 1]
  }
}
"""

    overlay_str = """
first_prop = 1
first_scope {
  key = 1
  number = 2
  second_scope {
    key = 0
    list = [1, 0]
  }
  second_scope {
    key = 1
    flag = False
    list = [1, 1]
  }
  second_scope {
    key = 4
    list = [0, 2]
  }
}
"""

    # XXX Correct use of _phil and _params?
    default_phil = master_phil.fetch(sources=[libtbx.phil.parse(default_str)])
    default_params = default_phil.extract()

    overlay_phil = master_phil.fetch(sources=[libtbx.phil.parse(overlay_str)])
    overlay_params = overlay_phil.extract()

    experimental.merge_params_by_key(default_params, overlay_params, "key")

    assert default_params.first_prop == 1
    assert default_params.second_prop == "default text"
    assert len(default_params.first_scope) == 2

    for fs in default_params.first_scope:
        if (fs.key == 1):
            assert fs.number == 2 and fs.text == "Default first scope text"
            assert len(fs.second_scope) == 4
            for ss in fs.second_scope:
                if (ss.key == 0):
                    assert ss.flag == False and ss.list == [1, 0]
                elif (ss.key == 1):
                    assert ss.flag == False and ss.list == [1, 1]
                elif (ss.key == 2):
                    assert ss.flag is None and ss.list is None
                elif (ss.key == 4):
                    assert ss.flag is None and ss.list == [0, 2]

        elif (fs.key == 2):
            assert fs.number is None and fs.text == "First key 2 text"
            assert len(fs.second_scope) == 1
            assert fs.second_scope[0].key == 0 and \
                fs.second_scope[0].flag == True and \
                fs.second_scope[0].list == [0, 1]