class SmootherTest(object):
    """Test a bare parameter set with the smoother"""
    def __init__(self, plots=False):

        # make scatterplots
        self.do_plots = plots

        # 7 values, all set to 1.0
        self.myparam = ScanVaryingParameterSet(1.0, 7)

        # Adjust a couple of the values
        self.myparam.value[3:4] = [2.0, 2.0]

        # Make a smoother with x_range as an 'image range', between 1 and 100.
        # This smoother needs 5 intervals (for 7 total values). The default
        # smoother uses an averaging window of 3 values
        self.smoother = GaussianSmoother((1, 100), 5)

    def run(self):

        assert self.smoother.num_values() == 7
        assert self.smoother.num_samples() == 5
        assert self.smoother.num_average() == 3

        # The smoother positions depend on the number of intervals but not on
        # the x_range
        assert self.smoother.positions() == [
            -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5
        ]

        # By contrast the spacing is in units of the original, unnormalised
        # coordinate
        assert self.smoother.spacing() == 19.8

        # Use the single value smoother multiple times...
        smooth_at = [e for e in range(1, 101)]
        data = [self.smoother.value_weight(e, self.myparam) for e in smooth_at]
        vals, weights, sumweights = zip(*data)
        assert len(smooth_at) == len(vals)

        # ...and the multi value smoother once
        mvals, mweights, msumweights = self.smoother.multi_value_weight(
            smooth_at, self.myparam)

        # the results should be identical.
        assert (flex.double(vals) == mvals).all_eq(True)
        assert (flex.double(sumweights) == msumweights).all_eq(True)
        for v1, v2 in zip(weights, mweights.transpose().cols()):
            assert (v1.as_dense_vector() == v2.as_dense_vector()).all_eq(True)

        if self.do_plots:
            try:
                import matplotlib.pyplot as plt
                plt.ion()
                plt.scatter(smooth_at, vals)
                plt.draw()
            except ImportError as e:
                print "pyplot not available", e

        print "OK"
class SmootherTest(object):
  """Test a bare parameter set with the smoother"""
  def __init__(self, plots = False):

    # make scatterplots
    self.do_plots = plots

    # 7 values, all set to 1.0
    self.myparam = ScanVaryingParameterSet(1.0, 7)

    # Adjust a couple of the values
    self.myparam.value[3:4] = [2.0, 2.0]

    # Make a smoother with x_range as an 'image range', between 1 and 100.
    # This smoother needs 5 intervals (for 7 total values). The default
    # smoother uses an averaging window of 3 values
    self.smoother = GaussianSmoother((1, 100), 5)

  def run(self):

    assert self.smoother.num_values() == 7
    assert self.smoother.num_samples() == 5
    assert self.smoother.num_average() == 3

    # The smoother positions depend on the number of intervals but not on
    # the x_range
    assert self.smoother.positions() == [-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5]

    # By contrast the spacing is in units of the original, unnormalised
    # coordinate
    assert self.smoother.spacing() == 19.8

    # Use the single value smoother multiple times...
    smooth_at = [e for e in range(1, 101)]
    data = [self.smoother.value_weight(e, self.myparam) for e in smooth_at]
    vals, weights, sumweights = zip(*data)
    assert len(smooth_at) == len(vals)

    # ...and the multi value smoother once
    mvals, mweights, msumweights = self.smoother.multi_value_weight(smooth_at, self.myparam)

    # the results should be identical.
    assert (flex.double(vals) == mvals).all_eq(True)
    assert (flex.double(sumweights) == msumweights).all_eq(True)
    for v1, v2 in zip(weights, mweights.transpose().cols()):
      assert (v1.as_dense_vector() == v2.as_dense_vector()).all_eq(True)

    if self.do_plots:
      try:
        import matplotlib.pyplot as plt
        plt.ion()
        plt.scatter(smooth_at, vals)
        plt.draw()
      except ImportError as e:
        print "pyplot not available", e

    print "OK"
class SmootherTest(object):
  """Test a bare parameter set with the smoother"""
  def __init__(self, plots = False):

    # make scatterplots
    self.do_plots = plots

    # 7 values, all set to 1.0
    self.myparam = ScanVaryingParameterSet(1.0, 7)

    # Adjust a couple of the values
    self.myparam.value[3:4] = [2.0, 2.0]

    # Make a smoother with x_range as an 'image range', between 1 and 100.
    # This smoother needs 5 intervals (for 7 total values). The default
    # smoother uses an averaging window of 3 values
    self.smoother = GaussianSmoother((1, 100), 5)

  def run(self):

    assert self.smoother.num_values() == 7
    assert self.smoother.num_samples() == 5
    assert self.smoother.num_average() == 3

    # The smoother positions depend on the number of intervals but not on
    # the x_range
    assert self.smoother.positions() == [-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5]

    # By contrast the spacing is in units of the original, unnormalised
    # coordinate
    assert self.smoother.spacing() == 19.8

    smooth_at = [e for e in range(1, 101)]
    data = [self.smoother.value_weight(e, self.myparam) for e in smooth_at]
    vals = [v for v, w, sw in data]
    assert len(smooth_at) == len(vals)

    if self.do_plots:
      try:
        import matplotlib.pyplot as plt
        plt.ion()
        plt.scatter(smooth_at, vals)
        plt.draw()
      except ImportError as e:
        print "pyplot not available", e

    print "OK"
class SmootherTest(object):
  """Test a bare parameter set with the smoother"""
  def __init__(self, plots = False):

    # make scatterplots
    self.do_plots = plots

    # 7 values, all set to 1.0
    self.myparam = ScanVaryingParameterSet(1.0, 7)

    # Adjust a couple of the values
    self.myparam.value[3:4] = [2.0, 2.0]

    # Make a smoother with x_range as an 'image range', between 1 and 100.
    # This smoother needs 5 intervals (for 7 total values). The default
    # smoother uses an averaging window of 3 values
    self.smoother = GaussianSmoother((1, 100), 5)

  def run(self):

    assert self.smoother.num_values() == 7
    assert self.smoother.num_samples() == 5
    assert self.smoother.num_average() == 3

    # The smoother positions depend on the number of intervals but not on
    # the x_range
    assert self.smoother.positions() == [-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5]

    # By contrast the spacing is in units of the original, unnormalised
    # coordinate
    assert self.smoother.spacing() == 19.8

    smooth_at = [e for e in range(1, 101)]
    data = [self.smoother.value_weight(e, self.myparam) for e in smooth_at]
    vals = [v for v, w, sw in data]
    assert len(smooth_at) == len(vals)

    if self.do_plots:
      try:
        import matplotlib.pyplot as plt
        plt.ion()
        plt.scatter(smooth_at, vals)
        plt.draw()
      except ImportError as e:
        print "pyplot not available", e

    print "OK"