In [1]:
%matplotlib inline

import numpy as np
from matplotlib import pyplot as plt
from matplotlib.ticker import MultipleLocator
from ipywidgets import widgets, interact

import UsefulUtils as uu
uu.init_notebook(dpi=120, fontsize=10)

from UsefulUtils import Bunch
import ScopeFoundry as sf

from PicoharpPTU import PicoHarpPTU
from picoharpdata import PicoHarpData

import glob

In [2]:
def make_histogram(filename, binCount, USE_PTU=False):
    #Use Ed's software to load the file
    if USE_PTU:
        PHD = PicoHarpPTU(filename, True)
    else:
        PHD = PicoHarpData(filename, True)

    # Find all of the record indices of channel 0 events.  These mark the laser sync signal.
    print 'Finding channel 0 events'
    c0events = np.where(PHD.t2_channels == 0)[0]

    #Compute the time differences between the channel 0 events.  Should be a regular interval.
    print 'Calculating time difference between channel 1 events'
    c0diffs = PHD.t2_times[c0events[1:]] - PHD.t2_times[c0events[:-1]]

    #Construct an empty histogram in which to bin the events.
    timeSpan = np.average(c0diffs)
    hist,bins = np.histogram(np.empty(0, np.int64), bins=binCount, range=[ 0, timeSpan ] )

    #For each channel 0 event, histogram the number of channel 1 events with respect to the delay after
    #the channel 0 event.
    for start,stop in np.nditer([c0events[:-1],c0events[1:]]):
        # Get the events for this excitation pulse
        c1events = np.where(PHD.t2_channels[start:stop] == 1)[0] + start

        # Histogram the times of the fluorescence events with respect to the excitation pulse
        hist = hist + (
          np.histogram(PHD.t2_times[c1events]-PHD.t2_times[start], bins=binCount, range=(0, timeSpan) ) 
          )[0]
    
    return bins[:-1]*4*10**-6, hist

In [3]:
background_file = ""
signal_file = "Er-enhanced-t2-100s-6mW-1.pt2"

if signal_file == "":
    files = glob.glob("./*.pt2")
    files.sort()
    signal_file = files[-1]

In [ ]:
signal = Bunch()
bins, ints = make_histogram(signal_file, 1000)
signal.time= bins
signal.intensity = ints

bg = Bunch()
if background_file == "":
    bg.time = signal.time.copy()
    bg.intensity = np.zeros(signal.intensity.shape)
else:
    bins, ints = make_histogram(background_file, 1000)
    bg.time = bins
    bg.intensity = ints


ident:  'PicoHarp 300'
format_version: '2.0'
V1 False V2 True
'PicoHarp Software'
'2.3.0.0'
file_time:  '18/10/17 16:57:47'
comment : 'T2 Mode'
binaryfile_header:  (0, 32, 1, 1, 0, 2, 0, 7, 0, 100000, 100, 0, 1, 1, 0, 12000, 0, 100)
number_of_curves 0
number_of_boards 1
array([0, 1, 2, 3, 4, 5, 6, 7])
array([ True,  True,  True,  True,  True,  True,  True,  True], dtype=bool)
board 0
board 0 resolution 0.512000024319
T2 records read 23601396
T2 records convert to numpy
{'V1': False,
 'V2': True,
 'active_curve': 0,
 'bits_per_histo_bin': 32,
 'boards': [PicoHarpBoard{'RtChan3_InputEdge': 0, 'RtChan2_CFDZeroCross': 0, 'sync_divider': 1, 'RtChan4_InputEdge': 0, 'RtChan4_CFDPresent': 0, 'RtChan4_InputLevel': 0, 'RtChan2_InputType': 0, 'cfd_level_1': 61, 'RtChan1_CFDLevel': 0, 'cfd_level_0': 91, 'RtChan1_CFDZeroCross': 0, 'RtChan4_CFDLevel': 0, 'RtChan3_CFDLevel': 0, 'cfd_zero_cross_0': 0, 'cfd_zero_cross_1': 0, 'RtChan2_InputEdge': 0, 'RtChan1_CFDPresent': 0, 'RtChan3_CFDPresent': 0, 'RtChan4_InputType': 0, 'RtChan3_InputLevel': 0, 'RtChan4_CFDZeroCross': 0, 'RouterEnabled': 1, 'hardware_ident': 'PicoHarp 300', 'RtChan3_CFDZeroCross': 0, 'RtChan1_InputType': 0, 'hardware_serial': 1005533, 'hardware_version': '2.0\x00\x00\x00_', 'RtChan2_CFDPresent': 0, 'RtChan1_InputLevel': 0, 'RtChan3_InputType': 0, 'RtChan2_InputLevel': 0, 'RtChan1_InputEdge': 0, 'resolution': 0.5120000243186951, 'RtChan2_CFDLevel': 0}],
 'comment': 'T2 Mode',
 'creator_name': 'PicoHarp Software',
 'creator_version': '2.3.0.0',
 'disp_count_axis_from': 0,
 'disp_count_axis_to': 100,
 'disp_curve_map_to': array([0, 1, 2, 3, 4, 5, 6, 7]),
 'disp_curve_show': array([ True,  True,  True,  True,  True,  True,  True,  True], dtype=bool),
 'disp_lin_log': 1,
 'disp_time_axis_from': 0,
 'disp_time_axis_to': 12000,
 'ext_devices': 0,
 'file_time': '18/10/17 16:57:47',
 'filename': 'Er-enhanced-t2-100s-6mW-1.pt2',
 'format_version': '2.0',
 'ident': 'PicoHarp 300',
 'img_hdr_size': 0,
 'inp_rate0': 100000,
 'inp_rate1': 134792,
 'measurement_mode': 2,
 'num_records': 23601396,
 'number_of_boards': 1,
 'number_of_curves': 0,
 'offset': 0,
 'param_end': [0.0, 0.0, 0.0],
 'param_start': [0.0, 0.0, 0.0],
 'param_step': [0.0, 0.0, 0.0],
 'phdfile': <open file 'Er-enhanced-t2-100s-6mW-1.pt2', mode 'rb' at 0x00000000074CDC90>,
 'range_no': 7,
 'repeat_mode': 0,
 'repeat_time': 0,
 'repeat_wait_time': 0,
 'repeats_per_curve': 1,
 'restart': 1,
 'routing_channels': 1,
 'script_name': 'TTTR Mode\x00e Mode',
 'stop_after': 100000,
 'stop_at': 100,
 'stop_on_ovf': 0,
 'stop_reason': 0,
 'stop_reason_name': 'timeover',
 'sub_mode': 0,
 't2_channels': array([1, 0, 0, ..., 1, 0, 1], dtype=uint32),
 't2_event_channels': array([1, 0, 0, ..., 1, 0, 1], dtype=uint32),
 't2_event_times': array([       2387279,        2477441,        4977302, ..., 24999098896430,
       24999099426935, 24999100605559], dtype=int64),
 't2_overflow_index': array([     195,      412,      632, ..., 23600846, 23601035, 23601231], dtype=int64),
 't2_overflow_mask': array([False, False, False, ..., False, False, False], dtype=bool),
 't2_rawdata': array([270822735,   2477441,   4977302, ..., 442552366, 174647415,
       444261495], dtype=uint32),
 't2_special_record_mask': array([False, False, False, ..., False, False, False], dtype=bool),
 't2_standard_record_mask': array([ True,  True,  True, ...,  True,  True,  True], dtype=bool),
 't2_times': array([       2387279,        2477441,        4977302, ..., 24999098896430,
       24999099426935, 24999100605559], dtype=int64),
 't2_times_c0': array([       2477441,        4977302,        7477076, ..., 24999094427190,
       24999096927099, 24999099426935], dtype=int64),
 't2_times_c1': array([       2387279,        5651707,        6597736, ..., 24999097729883,
       24999098896430, 24999100605559], dtype=int64),
 't2_times_wrapped': array([  2387279,   2477441,   4977302, ..., 174116910, 174647415,
       175826039], dtype=int64),
 'tacq': 100000}
Finding channel 0 events
Calculating time difference between channel 1 events

In [16]:
plt.semilogy(bg.time, bg.intensity)
plt.semilogy(signal.time, signal.intensity)


Out[16]:
[<matplotlib.lines.Line2D at 0x8145eb8>]

In [17]:
plt.semilogy(signal.time, signal.intensity - bg.intensity)


Out[17]:
[<matplotlib.lines.Line2D at 0x84f19e8>]

In [ ]: