def test_gaussian_smoother(plots=False): """Test a bare parameter set with the smoother""" # 7 values, all set to 1.0 myparam = ScanVaryingParameterSet(1.0, 7) # Adjust a couple of the values 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 smoother = GaussianSmoother((1, 100), 5) assert smoother.num_values() == 7 assert smoother.num_samples() == 5 assert smoother.num_average() == 3 # The smoother positions depend on the number of intervals but not on # the x_range assert 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 smoother.spacing() == 19.8 # Use the single value smoother multiple times... smooth_at = [e for e in range(1, 101)] data = [smoother.value_weight(e, 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 = smoother.multi_value_weight( smooth_at, 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) # make scatterplots if plots: import matplotlib.pyplot as plt plt.ion() plt.scatter(smooth_at, vals) plt.draw()
def __init__(self, phi_range_deg, deg_per_interval=5): n_intervals = max( int(abs(phi_range_deg[1] - phi_range_deg[0]) / deg_per_interval), 1) # Set up the smoother self._smoother = GaussianSmoother(phi_range_deg, n_intervals) self._num_samples = self._smoother.num_values() # initial value of scale factors is 1 value = 1 self._param = ScanVaryingParameterSet(value, self._num_samples, name="IncidentBeam")
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 parameter_type(value, axis, ptype, name): return ScanVaryingParameterSet(value, nv, axis, ptype, name)
def parameter_type(value, name): return ScanVaryingParameterSet(value, nv, name=name)