Exemplo n.º 1
0
def two_level_threshold(data, number_of_bins=40) -> dict:
    """ Determine threshold for separation of two-level signal

    Typical examples of such a signal are an RTS signal or Elzerman readout.

    Args:
        traces: Two dimensional array with single traces
        number_of_bins: Number of bins to use for calculation of double histogram

    Returns:
        Dictionary with results. The key readout_threshold contains the calculated threshold
    """
    counts, bins = np.histogram(data, bins=number_of_bins)
    bin_centres = np.array([(bins[i] + bins[i + 1]) / 2
                            for i in range(0,
                                           len(bins) - 1)])
    _, result_dict = fit_double_gaussian(bin_centres, counts)
    result_dict = refit_double_gaussian(result_dict, bin_centres, counts)

    result = {
        'signal_threshold': result_dict['split'],
        'double_gaussian_fit': result_dict,
        'separation': result_dict['separation'],
        'histogram': {
            'counts': counts,
            'bins': bins,
            'bin_centres': bin_centres
        }
    }
    return result
Exemplo n.º 2
0
    def test_fit_double_gaussian(self):
        x_data = np.arange(-4, 4, .05)
        initial_parameters = [10, 20, 1, 1, -2, 2]
        y_data = double_gaussian(x_data, initial_parameters)

        fitted_parameters, _ = fit_double_gaussian(x_data, y_data)
        parameter_diff = np.abs(fitted_parameters - initial_parameters)
        self.assertTrue(np.all(parameter_diff < 1e-3))
Exemplo n.º 3
0
    def test_refit_double_gaussian(self):
        dataset = qtt.data.load_example_dataset('double_gaussian_dataset.json')
        x_data = np.array(dataset.signal)
        y_data = np.array(dataset.counts)

        _, result_dict = fit_double_gaussian(x_data, y_data)
        result_dict = refit_double_gaussian(result_dict, x_data, y_data)

        self.assertAlmostEqual(result_dict['left'][0], -1.23, places=1)
        self.assertAlmostEqual(result_dict['right'][0], -0.77, places=1)
        self.assertAlmostEqual(result_dict['left'][2], 162.8, places=0)
        self.assertAlmostEqual(result_dict['right'][2], 1971, places=-1)