예제 #1
0
def plot_from_coordinates():
    """
    Plot directly with coordinates
    """
    from target_calib import CameraConfiguration
    c = CameraConfiguration("1.1.0")
    m = c.GetMapping()
    xpix = np.array(m.GetXPixVector())
    ypix = np.array(m.GetYPixVector())
    size = m.GetSize()
    camera = CameraImage(xpix, ypix, size)
    image = np.zeros(xpix.size)
    image[::2] = 1
    camera.image = image
    plt.show()
예제 #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())
예제 #3
0
plt.title("Interval of offset")
for i in [1,23,600,900,1200]:
    plt.plot(dt,calibrated_data[:,i])   
plt.savefig(os.path.join(current_path+'/'+ runfile, runfile+"_std_interval"))


#A time series plot
plt.figure()
plt.plot(data.time-data.time[0],int_space_averaged)
plt.xlabel('Time since run start (s)')
plt.ylabel("Average amplitude (mV)")
plt.savefig(os.path.join(current_path+'/'+ runfile, runfile+"_space_averaged_over_time"))

#Different average camera images
camera = CameraImage(data.xpix, data.ypix, data.size)
camera.image = int_time_averaged
zmin_intspace = min(int_space_averaged) - 0.05*min(int_space_averaged)
zmax_intspace = max(int_space_averaged) + 0.05*max(int_space_averaged)
camera.set_limits_minmax(zmin=zmin_intspace,zmax = zmax_intspace)
camera.add_colorbar('Amplitdue (mV)')
camera.ax.set_title('Time averaged data')
plt.savefig(os.path.join(current_path+'/'+ runfile, runfile+"_camera_time_averaged"))

camera = CameraImage(data.xpix, data.ypix, data.size)
camera.image = calibrated_data[0,:]
camera.add_colorbar('Amplitdue (mV)')
zmin_calbdat = min(int_space_averaged) - 0.01*min(int_space_averaged) 
#zmin_calbdat = 380
zmax_calbdat = max(int_space_averaged) + 0.01*max(int_space_averaged) 
camera.set_limits_minmax(zmin=zmin_calbdat,zmax = zmax_calbdat)
camera.ax.set_title('Calibrated Data')
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")
예제 #5
0
    # print(match[:, 2], match[:, 3], match[:, 1])
else:
    telescope_pointing = SkyCoord(alt=alt * u.rad,
                                  az=az * u.rad,
                                  frame=altaz_frame)
    print("True pointing:", telescope_pointing.transform_to("icrs"))
    if matched_hs is None or len(matched_hs) == 0:
        ra = dec = np.nan
        matched_hs = []
    else:
        ra, dec = matcher.determine_pointing(matched_hs)
    print("Estimated pointing:", np.rad2deg(ra), np.rad2deg(dec))
    fig, axs = plt.subplots(constrained_layout=True, figsize=(10, 6))
    # Different average camera images
    camera = CameraImage(xpix, ypix, mapping.GetSize(), ax=axs)
    camera.image = np.ones(2048)
    axs.plot(true_hotspots[0, 0], true_hotspots[0, 1], "ob")
    axs.plot(
        true_hotspots[:, 0],
        true_hotspots[:, 1],
        "o",
        color="gray",
        mfc="none",
        ms=25,
        mew=2,
    )
    for ths, hs in zip(true_hotspots, hotspots):
        if tuple(ths) != tuple(hs):
            axs.plot(hs[0], hs[1], "yo", mfc="none", ms=25, mew=3)
    for i, sid in enumerate(all_hips):
        # i = sid[0]
    smooth_data.data[:, new_good_pix[0, :] == 0] = 0
    ########################################################################################

    if smooth_data.data.shape[0] < 2000:
        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))
data_proc.run()

data = aggr.aggr["raw_resp"][0]
dt = data.time - data.time[0]

# Intensity
new_good_pix = np.ones(data.data.shape, dtype="bool")
new_good_pix[np.nan_to_num(data.data) == 0] = False
intensity = invf(data.data, a, b, d)
intensity[new_good_pix == 0] = 0  # Set bad pix to dummy intensity unequal zero

F_i = c_ * intensity
F_ioff = F_i - F_i[5000, :]

camera = CameraImage(data.xpix, data.ypix, data.size)
camera.image = F_i[0, :]
camera.add_colorbar('Intensity / MHz')
zmin_calbdat = min(int_space_averaged) - 0.01 * min(int_space_averaged)
#zmax_calbdat = 235
zmax_calbdat = max(int_space_averaged) + 0.01 * max(int_space_averaged)
#zmax_calbdat = 350
zmin_calbdat = 100
camera.set_limits_minmax(zmin=zmin_calbdat, zmax=zmax_calbdat)
camera.ax.set_title('Calibrated Data' + str(runfile))


def remback_int(calibrated_data, dt, new_good_pixel):
    # Get stable interval from minimum of std, from calibrated data in 4 min measurement intervals
    min_of_run = math.floor(dt[-1] / 60)
    #    min_of_run = 1
    number_of_intervals = int(min_of_run / 1)
예제 #8
0
def plot_calibration_properties(path_,
                                runfile_cal,
                                save=None,
                                camera_min=None,
                                camera_max=None,
                                cal_min=None,
                                cal_max=None):

    #import data:
    data, dt = get_your_data(runfile_cal)

    #Import calibration properties
    property_path = os.path.join(path_ + '/' + runfile_cal,
                                 "calibration_properties")
    with open(property_path, 'rb') as handle:
        readout = pickle.load(handle)
    int_begin, int_end = readout["Interval_offset"]
    int_time_averaged = readout["Time_averaged_int"]
    int_space_averaged = readout["Space_averaged"]
    calibrated_data = readout["Calibrated_data"]
    ff_c = readout["ff_coefficients_c"]
    offset_calibrated_data = readout["Offset_calibrated_data"]

    if camera_min == None:
        zmin_intspace = min(
            int_space_averaged) - 0.05 * min(int_space_averaged)
    else:
        zmin_intspace = camera_min
    if camera_max == None:
        zmax_intspace = max(
            int_space_averaged) + 0.05 * max(int_space_averaged)
    else:
        zmax_intspace = camera_max

    if cal_min == None:
        zmin_calbdat = min(int_space_averaged) - 0.01 * min(int_space_averaged)
    else:
        zmin_calbdat = cal_min
    if cal_max == None:
        zmax_calbdat = max(int_space_averaged) + 0.01 * max(int_space_averaged)
    else:
        zmax_calbdat = cal_max

    # Visualize for some pixels:
    plt.figure()
    plt.axvline(dt[int_begin], color="k")
    plt.axvline(dt[int_end], color="k")
    plt.xlabel("Time / s")
    plt.ylabel("Amplitude / (mV)")
    plt.title("Interval of offset")
    for i in [1, 23, 600, 900, 1200]:
        plt.plot(dt, calibrated_data[:, i])
    if save != None:
        plt.savefig(
            os.path.join(current_path + '/' + runfile_cal,
                         runfile_cal + "_std_interval"))

    plt.figure()
    plt.plot(data.time - data.time[0], int_space_averaged)
    plt.xlabel('Time since run start (s)')
    plt.ylabel("Average amplitude (mV)")
    if save != None:
        plt.savefig(
            os.path.join(current_path + '/' + runfile_cal,
                         runfile_cal + "_space_averaged_over_time"))

    camera = CameraImage(data.xpix, data.ypix, data.size)
    camera.image = int_time_averaged
    camera.set_limits_minmax(zmin=zmin_intspace, zmax=zmax_intspace)
    camera.add_colorbar('Amplitdue (mV)')
    camera.ax.set_title('Time averaged data')
    if save != None:
        plt.savefig(
            os.path.join(current_path + '/' + runfile_cal,
                         runfile_cal + "_camera_time_averaged"))

    camera = CameraImage(data.xpix, data.ypix, data.size)
    camera.image = calibrated_data[0, :]
    camera.add_colorbar('Amplitdue (mV)')
    zmin_calbdat = min(int_space_averaged) - 0.01 * min(int_space_averaged)
    #zmin_calbdat = 380
    zmax_calbdat = max(int_space_averaged) + 0.01 * max(int_space_averaged)
    camera.set_limits_minmax(zmin=zmin_calbdat, zmax=zmax_calbdat)
    camera.ax.set_title('Calibrated Data')
    if save != None:
        plt.savefig(
            os.path.join(current_path + '/' + runfile_cal,
                         runfile_cal + "_calibrated_data"))

    camera = CameraImage(data.xpix, data.ypix, data.size)
    camera.image = ff_c
    camera.add_colorbar('Amplitdue (mV)')
    camera.ax.set_title('Flat field coefficents $ff_{c}$')
    if save != None:
        plt.savefig(
            os.path.join(current_path + '/' + runfile_cal,
                         runfile_cal + "_flat_field_coeffs_c"))

    camera = CameraImage(data.xpix, data.ypix, data.size)
    camera.image = offset_calibrated_data[0, :]
    camera.add_colorbar('Amplitdue (mV)')
    camera.ax.set_title('Offset of calibrated data')
    zmin_offset = None
    zmax_offset = None
    #np.where(offset_calibrated_data > 50)
    #zmin_offset = 0
    #zmax_offset = 60
    camera.set_limits_minmax(zmin=zmin_offset, zmax=zmax_offset)
    if save != None:
        plt.savefig(
            os.path.join(current_path + '/' + runfile_cal,
                         runfile_cal + "_offset_calibrated_data"))
예제 #9
0
plt.title("Interval of offset")
for i in [1,23,600,900,1200]:
    plt.plot(dt,calibrated_data[:,i])   
#plt.savefig(os.path.join(current_path+'/'+ runfile, runfile+"_std_interval"))


#A time series plot
plt.figure()
plt.plot(data.time-data.time[0],int_space_averaged)
plt.xlabel('Time since run start (s)')
plt.ylabel("Average amplitude (mV)")
#plt.savefig(os.path.join(current_path+'/'+ runfile, runfile+"_space_averaged_over_time"))

#Different average camera images
camera = CameraImage(data.xpix, data.ypix, data.size)
camera.image = int_time_averaged
zmin_intspace = min(int_space_averaged) - 0.05*min(int_space_averaged)
zmax_intspace = max(int_space_averaged) + 0.05*max(int_space_averaged)
camera.set_limits_minmax(zmin=zmin_intspace,zmax = zmax_intspace)
camera.add_colorbar('Intensity / MHz')
camera.ax.set_title('Time averaged data')
#plt.savefig(os.path.join(current_path+'/'+ runfile, runfile+"_camera_time_averaged"))

camera = CameraImage(data.xpix, data.ypix, data.size)
camera.image = calibrated_data[0,:]
camera.add_colorbar('Intensity / MHz')
zmin_calbdat = min(int_space_averaged) - 0.05*min(int_space_averaged) 
#zmax_calbdat = 235
zmax_calbdat = max(int_space_averaged) + 0.05*max(int_space_averaged) -10
camera.set_limits_minmax(zmin=zmin_calbdat,zmax = zmax_calbdat)
camera.ax.set_title('Calibrated Data')