コード例 #1
0
def main():
    pm = PixelMasks()
    dead = np.where(np.logical_or(pm.dead, np.repeat(pm.bad_hv, 4)))[0]

    ref_path = CameraConfiguration("1.1.0").GetReferencePulsePath()
    cc = CrossCorrelation(1, 96, reference_pulse_path=ref_path)

    spe_path = get_astri_2019('d2019-04-23_nudges/spe_+0.h5')
    with pd.HDFStore(spe_path) as store:
        coeff = store['coeff_pixel']
        coeff = coeff.loc[~coeff['pixel'].isin(dead)]

    spe = cc.get_pulse_height(np.median(coeff['spe']))
    spe_sigma = cc.get_pulse_height(np.median(coeff['spe_sigma']))
    opct = np.median(coeff['opct'])

    output_dir = get_plot("d190716_simtel_cfg")
    generate_spectrum.call(output_dir, spe, spe_sigma, opct, 0, 0)
コード例 #2
0
def main():
    input_path = "/Volumes/gct-jason/data_checs/dynamicrange_180514/tf_pchip/spe_three.h5"
    file_dir = os.path.dirname(os.path.abspath(__file__))
    output_dir = os.path.join(file_dir, "outputs")

    dead = [677, 293, 27, 1925]

    store = pd.HDFStore(input_path)
    df = store['coeff_pixel']
    df_array = store['array_camera']
    df = df.loc[~df['pixel'].isin(dead)]
    df_mean = df.mean().to_dict()

    norm = (df_mean['norm0'] + df_mean['norm1'] + df_mean['norm2']) / 3
    spe = df_mean['spe']

    config = CameraConfiguration("1.1.0")
    ref_path = config.GetReferencePulsePath()
    cc = CrossCorrelation(1, 96, reference_pulse_path=ref_path)

    d = dict(norm=1,
             eped=cc.get_pulse_height(df_mean['eped']),
             eped_sigma=cc.get_pulse_height(df_mean['eped_sigma']),
             spe=cc.get_pulse_height(df_mean['spe']),
             spe_sigma=cc.get_pulse_height(df_mean['spe_sigma']),
             lambda_=1,
             opct=df_mean['opct'],
             pap=df_mean['pap'],
             dap=df_mean['dap'])

    hist = df_array.loc[0, 'hist'] / (norm * 800)
    edges = cc.get_pulse_height(df_array.loc[0, 'edges'])
    between = cc.get_pulse_height(df_array.loc[0, 'between'])

    x = np.linspace(-5, 15, 1000)
    y = pe_signal(1, x, **d)

    p_hist = SPEHist()
    label = "fadc_amplitude = spe = {:.3f}".format(d['spe'])
    p_hist.plot(hist, edges, between, x, y, label)
    output_path = os.path.join(output_dir, "checs_fadc_amplitude.pdf")
    p_hist.save(output_path)
コード例 #3
0
def main():
    input_path = "/Volumes/gct-jason/thesis_data/checs/lab/dynrange/tf/tf_poly/spe.h5"
    file_dir = os.path.dirname(os.path.abspath(__file__))
    output_dir = os.path.join(file_dir, "outputs")

    dead = [677, 293, 27, 1925]

    store = pd.HDFStore(input_path)
    df = store['coeff_pixel']
    df_array = store['array_camera']
    df = df.loc[~df['pixel'].isin(dead)]
    df_mean = df.mean().to_dict()

    norm = (df_mean['norm0'] + df_mean['norm1'] + df_mean['norm2']) / 3

    config = CameraConfiguration("1.1.0")
    ref_path = config.GetReferencePulsePath()
    cc = CrossCorrelation(1, 96, reference_pulse_path=ref_path)

    d = dict(norm=1,
             eped=cc.get_pulse_height(df_mean['eped']),
             eped_sigma=cc.get_pulse_height(df_mean['eped_sigma']),
             lambda_=1)

    hist = df_array.loc[0, 'hist'] / (norm * 1000)
    edges = cc.get_pulse_height(df_array.loc[0, 'edges'])
    between = cc.get_pulse_height(df_array.loc[0, 'between'])

    x = np.linspace(-5, 15, 1000)
    y = pedestal_signal(x, **d)

    p_hist = SPEHist()
    label = "fadc_noise = eped_sigma = {:.3f}".format(d['eped_sigma'])
    p_hist.plot(hist, edges, between, x, y, label)
    output_path = os.path.join(output_dir, "checs_fadc_noise.pdf")
    p_hist.save(output_path)
コード例 #4
0
def main():
    description = ''
    parser = argparse.ArgumentParser(description=description,
                                     formatter_class=Formatter)
    parser.add_argument('-f',
                        '--file',
                        dest='input_path',
                        action='store',
                        required=True,
                        help='path to the extract_average_vs_amplitude '
                        'numpy file')
    parser.add_argument('-o',
                        '--output',
                        dest='output_dir',
                        action='store',
                        required=True,
                        help='directory to store the plots')
    args = parser.parse_args()

    input_path = args.input_path
    output_dir = args.output_dir

    if not os.path.exists(output_dir):
        os.makedirs(output_dir)
        print("Created directory: {}".format(output_dir))

    ref_output_dir = os.path.join(output_dir, "reference_pulses")
    if not os.path.exists(ref_output_dir):
        os.makedirs(ref_output_dir)
        print("Created directory: {}".format(ref_output_dir))

    p_average = WaveformPlotter(
        "Average WF Over Module for each Input Amplitude", "mV")
    p_cc_average = WaveformPlotter("Average Cross-Correlated WF", "mV ns")
    p_ref = WaveformPlotterDual("Reference Pulse")
    p_fwhm = Scatter("FWHM", "Input Amplitude (mV)", "FWHM (ns)")
    p_rise_time = Scatter("Rise Time", "Input Amplitude (mV)",
                          "Rise Time (ns)")
    p_charge = Scatter("Charge", "Input Amplitude (mV)", "Charge (mV ns)")

    average_wf_dict = np.load(input_path)
    amplitudes_str = np.array(average_wf_dict.keys())
    sort = np.argsort([float(a) for a in amplitudes_str])
    sorted_dict = {a: average_wf_dict[a] for a in amplitudes_str[sort]}
    amplitudes = amplitudes_str.astype(np.float)[sort]
    n_amps = len(average_wf_dict.keys())
    n_pixels = 1
    n_samples = average_wf_dict[amplitudes_str[0]].size

    cc = CrossCorrelation(
        n_pixels, n_samples
    )  #, reference_pulse_path = "/Users/Jason/Software/CHECLabPy/CHECLabPy/data/checs_reference_pulse.txt")

    fwhm = np.zeros(n_amps)
    rise_time = np.zeros(n_amps)
    charge = np.zeros(n_amps)
    cc_ref = None

    for i, (a_str, wf) in enumerate(sorted_dict.items()):
        a = float(a_str)
        # if a > 1000:
        #     continue
        ccwf = cc._apply_cc(wf)
        x = np.arange(wf.size)
        p_average.add(x, wf, a)
        p_cc_average.add(x, ccwf, a)
        wf_norm = wf / np.max(wf)
        p_ref.add(x, wf_norm, a)
        params = cc.process(wf[None, :])
        fwhm[i] = params['fwhm'][0]
        rise_time[i] = params['tr'][0]
        charge[i] = params['charge'][0]
        if (a > 50) & (cc_ref is None):
            cc_ref = cc.get_reference_pulse_at_t(cc.t_event)
            cc_ref = cc_ref / np.max(cc_ref)

        ref_pulse = wf / np.trapz(wf)
        x_ref_pulse = np.arange(ref_pulse.size) * 1E-9
        ref_save = np.column_stack((x_ref_pulse, ref_pulse))
        ref_output = os.path.join(ref_output_dir, "amplitude_{}.txt".format(a))
        np.savetxt(ref_output, ref_save, fmt='%.5e')
        print("Created reference pulse: {}".format(ref_output))

    p_ref.add_reference_pulse(cc_ref)

    # from IPython import embed
    # embed()

    p_fwhm.add(amplitudes, fwhm)
    p_rise_time.add(amplitudes, rise_time)
    p_charge.add(amplitudes, charge)

    p_fwhm.add_saturation_region(1500, np.max(amplitudes) + 10)
    p_rise_time.add_saturation_region(1500, np.max(amplitudes) + 10)
    p_charge.add_saturation_region(1500, np.max(amplitudes) + 10)

    output_path = os.path.join(output_dir, "average_wfs.pdf")
    # p_average.add_legend()
    p_average.save(output_path)

    output_path = os.path.join(output_dir, "average_cc_wfs.pdf")
    p_cc_average.save(output_path)

    output_path = os.path.join(output_dir, "ref_wfs.pdf")
    p_ref.save(output_path)

    output_path = os.path.join(output_dir, "fwhm.pdf")
    p_fwhm.save(output_path)

    output_path = os.path.join(output_dir, "rise_time.pdf")
    p_rise_time.save(output_path)

    output_path = os.path.join(output_dir, "charge.pdf")
    p_charge.save(output_path)
コード例 #5
0
ファイル: spe.py プロジェクト: watsonjj/sstcam-sandbox
def main():
    initial = dict(
            eped=-1,
            eped_sigma=0.27,
            pe=2.4,
            pe_sigma=0.06,
            opct=0.25,
            lambda_0=0.63,
            lambda_1=0.84,
            lambda_2=1.07,
    )
    path = get_data(f"d200805_charge_resolution/1_extract_lab_old/charge_0MHz_{matched_voltage}mV.h5")
    with HDF5Reader(path) as reader:
        df = reader.read('data')
        df = df.loc[df['pixel'] == poi]

    spe_illuminations = np.unique(df['expected_illumination_pe'])[5:8]
    n_illuminations = len(spe_illuminations)

    charges_raw = []
    pulse_path = "/Users/Jason/Software/sstcam-simulation/tutorials/d201209_workshop/pulse_shape.txt"
    cc = CrossCorrelation(1, 1, reference_pulse_path=pulse_path)
    for illumination in spe_illuminations:
        df_i = df.loc[df['expected_illumination_pe'] == illumination]
        charge = cc.get_pulse_height(df_i['charge'].values)
        charges_raw.append(ChargeContainer(charge, n_bins=100, range_=(-3, 15)))

    pdf = SiPMModifiedPoisson(n_illuminations)
    pdf.update_parameters_initial(**initial)
    cost = UnbinnedNLL(pdf, charges_raw)
    values, errors = minimize_with_iminuit(cost)

    charges = []
    for container in charges_raw:
        charge = container.values - values['eped']
        charges.append(ChargeContainer(charge, n_bins=100, range_=(-3, 15)))

    pdf = SiPMModifiedPoisson(n_illuminations)
    pdf.update_parameters_initial(**initial)
    cost = UnbinnedNLL(pdf, charges)
    values, errors = minimize_with_iminuit(cost)
    values_array = np.array(list(values.values()))

    output = dict(
        n_illuminations=n_illuminations,
        hist=[],
        between=[],
        edges=[],
        fit_x=[],
        fit_y=[],
        values=values,
        errors=errors
    )

    fig = plt.figure(figsize=(10, 5))
    for i in range(n_illuminations):
        ax = fig.add_subplot(n_illuminations, 1, i+1)
        ax.hist(
            charges[i].between,
            weights=charges[i].hist,
            bins=charges[i].edges,
            density=True,
            histtype='step',
        )

        fit_x = np.linspace(charges[i].edges.min(), charges[i].edges.max(), 1000)
        fit_y = pdf(fit_x, values_array, i)
        lambda_ = values[f'lambda_{i}']
        lambda_err = errors[f'lambda_{i}']
        label = f"λ = {lambda_:.3f} ± {lambda_err:.3f} p.e."
        ax.plot(fit_x, fit_y, label=label)
        ax.legend()

        output['hist'].append(charges[i].hist)
        output['between'].append(charges[i].between)
        output['edges'].append(charges[i].edges)
        output['fit_x'].append(fit_x)
        output['fit_y'].append(fit_y)
    output_path = get_plot(f"d201202_tutorial_material/spe_0MHz_{matched_voltage}mV.pdf")
    fig.savefig(output_path)

    output_path = get_data(f"d201202_tutorial_material/spe_0MHz_{matched_voltage}mV.pkl")
    with open(output_path, 'wb') as file:
        pickle.dump(output, file, protocol=pickle.HIGHEST_PROTOCOL)
コード例 #6
0
def main():
    description = ''
    parser = argparse.ArgumentParser(description=description,
                                     formatter_class=Formatter)
    parser.add_argument('-f',
                        '--file',
                        dest='input_path',
                        action='store',
                        required=True,
                        help='path to the extract_average_vs_amplitude '
                        'numpy file')
    parser.add_argument('-o',
                        '--output',
                        dest='output_dir',
                        action='store',
                        required=True,
                        help='directory to store the plots')
    args = parser.parse_args()

    input_path = args.input_path
    output_dir = args.output_dir

    if not os.path.exists(output_dir):
        os.makedirs(output_dir)
        print("Created directory: {}".format(output_dir))

    ref_output_dir = os.path.join(output_dir, "reference_pulses")
    if not os.path.exists(ref_output_dir):
        os.makedirs(ref_output_dir)
        print("Created directory: {}".format(ref_output_dir))

    p_average = WaveformPlotter("Average WF for each Input Amplitude", "mV")
    p_cc_average = WaveformPlotter("Average Cross-Correlated WF", "mV ns")
    p_ref = WaveformPlotterDual("Reference Pulse")
    p_fwhm = Scatter("FWHM", "Illumination (p.e.)", "FWHM (ns)")
    p_rise_time = Scatter("Rise Time", "Illumination (p.e.)", "Rise Time (ns)")
    p_charge = Scatter("Charge", "Illumination (p.e.)", "Charge (mV ns)")
    p_average_norm = NormalisedWaveformPlotter(
        "Average WF for each Input Amplitude", "mV", cunits="mV")

    average_wf_dict = np.load(input_path)
    average_wf_keys_float = [float(a) for a in average_wf_dict.keys()]
    sorted_key = ["{:.3f}".format(a) for a in np.sort(average_wf_keys_float)]

    n_amps = len(average_wf_dict.keys())
    n_pixels = 1
    n_samples = average_wf_dict[list(average_wf_dict.keys())[0]].size

    cc = CrossCorrelation(
        n_pixels,
        n_samples,
        reference_pulse_path=
        "/Users/Jason/Software/TargetCalib/install/dev/reference_pulse_checs_V1-1-0.cfg"
    )

    illumination = np.zeros(n_amps)
    fwhm = np.zeros(n_amps)
    rise_time = np.zeros(n_amps)
    charge = np.zeros(n_amps)
    cc_ref = None

    for i, ill_str in enumerate(sorted_key):
        ill = float(ill_str)
        if ill > 500:
            continue
        wf = average_wf_dict[ill_str]
        wf_norm = wf / np.max(wf)

        params = cc.process(wf[None, :])
        ccwf = cc._apply_cc(wf)

        x = np.arange(wf.size)
        p_average.add(x, wf, ill_str)
        p_cc_average.add(x, ccwf, ill_str)
        p_ref.add(x, wf_norm, ill_str)
        p_average_norm.add(x, wf, ill)

        illumination[i] = ill
        fwhm[i] = params['fwhm'][0]
        rise_time[i] = params['tr'][0]
        charge[i] = params['charge'][0]
        if (ill > 50) & (cc_ref is None):
            cc_ref = cc.get_reference_pulse_at_t(cc.t_event)
            cc_ref = cc_ref / np.max(cc_ref)

        ref_pulse = wf / np.trapz(wf)
        x_ref_pulse = np.arange(ref_pulse.size) * 1E-9
        ref_save = np.column_stack((x_ref_pulse, ref_pulse))
        fp = "amplitude_{}.txt"
        ref_output = os.path.join(ref_output_dir, fp.format(ill))
        np.savetxt(ref_output, ref_save, fmt='%.5e')
        print("Created reference pulse: {}".format(ref_output))

    p_ref.add_reference_pulse(cc_ref)

    p_fwhm.add(illumination, fwhm)
    p_rise_time.add(illumination, rise_time)
    p_charge.add(illumination, charge)

    p_fwhm.add_saturation_region(1500, np.max(illumination) + 10)
    p_rise_time.add_saturation_region(1500, np.max(illumination) + 10)
    p_charge.add_saturation_region(1500, np.max(illumination) + 10)

    output_path = os.path.join(output_dir, "average_wfs.pdf")
    # p_average.add_legend()
    p_average.save(output_path)

    output_path = os.path.join(output_dir, "average_cc_wfs.pdf")
    p_cc_average.save(output_path)

    output_path = os.path.join(output_dir, "ref_wfs.pdf")
    p_ref.save(output_path)

    output_path = os.path.join(output_dir, "average_wfs_norm.pdf")
    p_average_norm.save(output_path)

    output_path = os.path.join(output_dir, "fwhm.pdf")
    p_fwhm.save(output_path)

    output_path = os.path.join(output_dir, "rise_time.pdf")
    p_rise_time.save(output_path)

    output_path = os.path.join(output_dir, "charge.pdf")
    p_charge.save(output_path)
コード例 #7
0
def main():
    runlist_path = get_astri_2019("d2019-04-23_nudges/bright_50pe/runlist.txt")
    df_runlist = pd.read_csv(runlist_path, sep='\t')
    output = get_astri_2019("d2019-04-23_nudges/bright_50pe/charge.h5")

    with HDF5Writer(output) as writer:
        mapping = None
        for _, row in df_runlist.iterrows():
            run = row['run']
            nudge = int(row['nudge'])
            path = join(dirname(runlist_path), f"Run{run:05d}_r1.tio")
            reader = ReaderR1(path, max_events=500)
            mapping = reader.mapping

            kw = dict(
                n_pixels=reader.n_pixels,
                n_samples=reader.n_samples,
                mapping=reader.mapping,
                reference_pulse_path=reader.reference_pulse_path,
            )
            baseline_subtractor = BaselineSubtractor(reader)
            time_calibrator = TimeCalibrator()
            extractor_cc = CrossCorrelation(**kw)
            extractor_onsky_calib = OnskyCalibExtractor(**kw)
            extractor_onsky = OnskyExtractor(**kw)
            common = Common(**kw, _disable_by_default=True, waveform_max=True)

            pixel_array = np.arange(reader.n_pixels)

            monitor = get_nudge_and_temperature_from_reader(reader)
            nudge_from_dac, temperature = monitor
            assert nudge == nudge_from_dac

            desc = "Looping over file"
            for wfs in tqdm(reader, total=reader.n_events, desc=desc):
                iev = wfs.iev
                if wfs.stale.any():
                    continue

                wfs = time_calibrator(wfs)
                wfs = baseline_subtractor.subtract(wfs)

                cc = extractor_cc.process(wfs)['charge_cc']
                onsky_calib = extractor_onsky_calib.process(
                    wfs)['charge_onskycalib']
                onsky = extractor_onsky.process(wfs)['charge_onsky']
                waveform_max = common.process(wfs)['waveform_max']

                params = dict(
                    nudge=nudge,
                    nudge_from_dac=nudge_from_dac,
                    temperature=temperature,
                    iev=iev,
                    pixel=pixel_array,
                    cc=cc,
                    onsky_calib=onsky_calib,
                    onsky=onsky,
                    waveform_max=waveform_max,
                )

                df = pd.DataFrame(params)
                writer.append(df, key='data')

        writer.add_mapping(mapping)