def cal_report(cal):
    hist_a = dashi.histogram.hist1d(
        np.linspace(np.nanmin(cal.a), np.nanmax(cal.a), 100))
    hist_a.fill(cal.a)
    hist_b = dashi.histogram.hist1d(
        np.linspace(np.nanmin(cal.b), np.nanmax(cal.b), 100))
    hist_b.fill(cal.b)
    hist_c = dashi.histogram.hist1d(
        np.linspace(np.nanmin(cal.c), np.nanmax(cal.c), 100))
    hist_c.fill(cal.c)
    thresh = (-cal.b + np.sqrt(cal.b**2 - 4 * cal.a * cal.c)) / (2 * cal.a)
    hist_thresh = dashi.histogram.hist1d(
        np.linspace(np.nanmin(thresh), np.nanmax(thresh), 100))
    hist_thresh.fill(thresh)

    plt.figure(figsize=(10, 8))
    hist_a.line()
    hist_a.statbox()
    plt.title("a parameter")
    plt.savefig("plots/cal_report_a_par_hist.png")
    plt.figure(figsize=(10, 8))
    hist_b.line()
    hist_b.statbox()
    plt.title("b parameter")
    plt.savefig("plots/cal_report_b_par_hist.png")
    plt.figure(figsize=(10, 8))
    hist_c.line()
    hist_c.statbox()
    plt.title("c parameter")
    plt.savefig("plots/cal_report_c_par_hist.png")

    plt.figure(figsize=(10, 8))
    hist_thresh.line()
    hist_thresh.statbox()
    plt.title("Threshold")
    plt.savefig("plots/cal_report_threshold_hist.png")

    from target_calib import CameraConfiguration

    cam_config = CameraConfiguration("1.1.0")
    mapping = cam_config.GetMapping()
    pixsize = mapping.GetSize()
    pix_posx = np.array(mapping.GetXPixVector())
    pix_posy = np.array(mapping.GetYPixVector())
    from CHECLabPy.plotting.camera import CameraImage

    f, a = plt.subplots(figsize=(13, 8))
    camera = CameraImage(pix_posx, pix_posy, pixsize, ax=a)
    camera.image = cal.a
    camera.add_colorbar("")
    camera.ax.set_title("a parameter")
    camera.highlight_pixels(list(cal.badpixs["unphysical_cal"]),
                            color="r",
                            linewidth=2)
    # camera.highlight_pixels(np.where(unphysical_rate)[0],color='b',linewidth=1.4)
    camera.highlight_pixels(list(cal.badpixs["no_cal"]), color="k")
    camera.highlight_pixels(list(cal.badpixs["bad_fit"]),
                            color="b",
                            linewidth=1.4)
    camera.set_limits_minmax(np.nanmin(cal.a), 0)
    plt.savefig("plots/cal_report_a_par.png")

    f, a = plt.subplots(figsize=(13, 8))
    camera = CameraImage(pix_posx, pix_posy, pixsize, ax=a)
    camera.image = cal.b
    camera.add_colorbar("")
    camera.ax.set_title("b parameter")
    camera.highlight_pixels(list(cal.badpixs["unphysical_cal"]),
                            color="r",
                            linewidth=2)
    # camera.highlight_pixels(np.where(unphysical_rate)[0],color='b',linewidth=1.4)
    camera.highlight_pixels(list(cal.badpixs["no_cal"]), color="k")
    camera.highlight_pixels(list(cal.badpixs["bad_fit"]),
                            color="b",
                            linewidth=1.4)
    camera.set_limits_minmax(0, np.nanmax(cal.b))
    plt.savefig("plots/cal_report_b_par.png")

    f, a = plt.subplots(figsize=(13, 8))
    camera = CameraImage(pix_posx, pix_posy, pixsize, ax=a)
    camera.image = cal.c
    camera.add_colorbar("")
    camera.ax.set_title("c parameter")
    camera.highlight_pixels(list(cal.badpixs["unphysical_cal"]),
                            color="r",
                            linewidth=2)
    # camera.highlight_pixels(np.where(unphysical_rate)[0],color='b',linewidth=1.4)
    camera.highlight_pixels(list(cal.badpixs["no_cal"]), color="k")
    camera.highlight_pixels(list(cal.badpixs["bad_fit"]),
                            color="b",
                            linewidth=1.4)
    camera.set_limits_minmax(np.nanmin(cal.c), 0)
    plt.savefig("plots/cal_report_c_par.png")

    f, a = plt.subplots(figsize=(13, 8))
    camera = CameraImage(pix_posx, pix_posy, pixsize, ax=a)
    camera.image = thresh
    camera.add_colorbar("photon rate (MHz)")
    camera.ax.set_title("NSB threshold")
    camera.highlight_pixels(list(cal.badpixs["unphysical_cal"]),
                            color="r",
                            linewidth=2)
    # camera.highlight_pixels(np.where(unphysical_rate)[0],color='b',linewidth=1.4)
    camera.highlight_pixels(list(cal.badpixs["no_cal"]), color="k")
    camera.highlight_pixels(list(cal.badpixs["bad_fit"]),
                            color="b",
                            linewidth=1.4)
    # camera.set_limits_minmax(np.nanmin(cal.c),0)
    plt.savefig("plots/cal_report_nsb_thres.png")
Exemple #2
0
def make_ssmovie(data,
                 red,
                 highlightpix=None,
                 minmax=(-10, 100),
                 path='movie',
                 dpi=800,
                 scale=0.2,
                 title="",
                 fps=25,
                 filename="out",
                 zlabel="Amplitude (mV)"):
    """Summary

    Args:
        data (TYPE): A SlowsignalData object
        red (TYPE): A range object or a list of indices
        highlightpix (None, optional): A list of pixel highlight index arrays
        minmax (tuple, optional): min max for the z-scale
        path (str, optional): The path from the current working directory where to store images for the movie
        dpi (int, optional): Description
        scale (float, optional): Description
        title (str, optional): The title to be shown
        fps (int, optional): Number of frames per second in the movie
        filename (str, optional): output name of the movie
        zlabel (str, optional): The colorbar label
    """
    import os
    import subprocess

    import glob
    impath = os.path.join(os.getcwd(), path)
    if not os.path.isdir(impath):
        os.mkdir(impath)

    files = glob.glob(os.path.join(impath, "*"))
    for f in files:
        os.remove(f)

    dpi -= int(scale * 19.20 * dpi) % 2
    dpii = 400
    scale = 0.70
    fig, ax = plt.subplots(figsize=(1920 / dpii * scale, 1080 / dpii * scale),
                           dpi=dpii * scale)
    camera = CameraImage(data.xpix, data.ypix, data.size, ax=ax)

    camera.add_colorbar('Amplitdue (mV)')
    camera.set_limits_minmax(*minmax)
    im = copy.deepcopy(data.data[0])
    camera.image = im
    highl = None
    for i in tqdm(red, total=len(red)):
        im = copy.deepcopy(data.data[i])
        im[np.isnan(im)] = np.nanmean(im)

        camera.ax.set_title(title)
        if highl is None:
            highl = camera.highlight_pixels(highlightpix[i])
        else:
            lw_array = np.zeros(camera.image.shape[0])
            lw_array[highlightpix[i]] = 0.5
            highl.set_linewidth(lw_array)

        camera.image = im
        plt.savefig(os.path.join(path, "SlowSignalImage%.10d.png" % i),
                    dpi=dpi)
    subprocess.check_call([
        "ffmpeg", "-pattern_type", "glob", "-i", "{}".format(
            os.path.join(impath, "SlowSignalImage*.png")), "-c:v", "libx264",
        "-vf", " scale=iw:-2", "-vf", "fps={}".format(fps), "-pix_fmt",
        "yuv420p", '-y', "{}.mp4".format(filename)
    ],
                          cwd=os.getcwd())
        frame_n = 100
        range_frames = 20
    else:
        frame_n = 1000
        range_frames = 200
#    plt.set_cmap('Greys_r')

#Different average camera images
    camera = CameraImage(smooth_data.xpix, smooth_data.ypix, smooth_data.size)
    im = copy.deepcopy(smooth_data.data[frame_n])
    im[np.isnan(im)] = np.nanmean(im)
    camera.image = im

    camera.add_colorbar('Amplitude / MHz')
    camera.highlight_pixels(
        [item for sublist in clusters[frame_n] for item in sublist],
        color='red')
    camera.set_limits_minmax(zmin_calbat, zmax_calbat)

    #for each frame put all the cluster pixels in one list
    c = []
    for cc in clusters:
        c.append([item for sublist in cc for item in sublist])

    #We only make the movie with every 200th frame
    sel = range(0, len(smooth_data.data), range_frames)
    #make_ssmovie(smooth_data,sel,c, minmax = (0,250))
    read_from_path = os.path.join(os.getcwd(), path)

    #    moviefolder = os.path.join('cal_movie_'+read_from_path[-16:-5])
    #    if not os.path.isdir(moviefolder):