コード例 #1
0
ファイル: dist_cluster.py プロジェクト: lindat18/ffta
def plot_clust(h5_main, labels, mean_resp, x_pts, data_avg=None, tidx_off=0):
    try:
        _labels = np.array(labels.value).T[0]
    except:
        _labels = np.array(labels)
    labels_unique = np.unique(_labels)
    parms_dict = hdf_utils.get_params(h5_main)
    clust_tfp = []

    # color defaults are blue, orange, green, red, purple...
    colors = [
        '#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b',
        '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'
    ]

    fig, ax = plt.subplots(nrows=1, figsize=(12, 6))
    ax.set_xlabel('Distance to Nearest Boundary (um)')
    ax.set_ylabel('tfp (us)')

    for i in labels_unique:

        labels_tfp = []

        if not data_avg.any():

            for sig in h5_main[_labels == labels_unique[i], :]:
                pix = pixel.Pixel(sig, parms_dict)
                pix.inst_freq = sig
                pix.fit_freq_product()
                labels_tfp.append(pix.tfp)

            labels_tfp = np.array(labels_tfp)

        else:
            labels_tfp = data_avg[_labels == labels_unique[i]]

        ax.plot(x_pts[_labels == labels_unique[i]] * 1e6,
                labels_tfp * 1e6,
                c=colors[i],
                linestyle='None',
                marker='.')

        parms_dict['trigger'] += tidx_off / parms_dict['sampling_rate']
        pix = pixel.Pixel(mean_resp[i], parms_dict)
        pix.inst_freq = mean_resp[i]
        pix.fit_freq_product()
        clust_tfp.append(pix.tfp)
        parms_dict['trigger'] -= tidx_off / parms_dict['sampling_rate']

        ax.plot(np.mean(x_pts[_labels == labels_unique[i]] * 1e6),
                pix.tfp * 1e6,
                marker='o',
                markerfacecolor=colors[i],
                markersize=8,
                markeredgecolor='k')

    print('tfp of clusters: ', clust_tfp)

    return ax, fig
コード例 #2
0
def test_pixel(h5_file,
               param_changes={},
               pxls=1,
               showplots=True,
               verbose=True,
               clear_filter=False):
    """
    Takes a random pixel and does standard processing.

    :param h5_file: H5 file to process
    :type h5_file: h5Py File, path, Dataset

    :param param_changes:
    :type param_changes: dict, optional

    :param pxls: Number of random pixels to survey
    :type pxls: int, optional

    :param showplots: Whether to create a new plot or not.
    :type showplots: bool, optional

    :param verbose: To print to command line. Currently for future-proofing
    :type verbose : bool , optional

    :param clear_filter: Whether to do filtering (FIR) or not
    :type clear_filter: bool, optional


    """
    # get_pixel can work on Datasets or the H5_File
    if any(param_changes):
        hdf_utils.change_params(h5_file, new_vals=param_changes)

    parameters = hdf_utils.get_params(h5_file)
    cols = parameters['num_cols']
    rows = parameters['num_rows']

    # Creates random pixels to sample
    pixels = []
    if pxls == 1:
        pixels.append([0, 0])

    if pxls > 1:

        from numpy.random import randint
        for i in range(pxls):
            pixels.append([randint(0, rows), randint(0, cols)])

    # Analyzes all pixels
    for rc in pixels:

        h5_px = hdf_utils.get_pixel(h5_file, rc=rc)

        if clear_filter:
            h5_px.clear_filter_flags()

        h5_px.analyze()
        print(rc, h5_px.tfp)

        if showplots == True:
            plt.plot(h5_px.best_fit, 'r--')
            plt.plot(h5_px.cut, 'g-')

    return