Beispiel #1
0
    def duration(self):
        num_blocks = len(self.block_events)
        event_count = 0
        duration = 0
        for i in range(1, num_blocks + 1):
            block = self.get_block(i)
            duration += calc_duration(block)

        return duration, num_blocks, event_count
Beispiel #2
0
    "system": system,
    "area": -gx.area / 2,
    "duration": 2e-3
}
gx_pre = make_trapezoid(kwargs_for_gxpre)
kwargs_for_gz_reph = {
    "channel": 'z',
    "system": system,
    "area": -gz.area / 2,
    "duration": 2e-3
}
gz_reph = make_trapezoid(kwargs_for_gz_reph)
phase_areas = (np.arange(Ny) - (Ny / 2)) * delta_k

TE, TR = 10e-3, 1000e-3
delayTE = TE - calc_duration(
    gx_pre) - calc_duration(gz) / 2 - calc_duration(gx) / 2
delayTR = TR - calc_duration(gx_pre) - calc_duration(gz) - calc_duration(
    gx) - delayTE
delay1 = make_delay(delayTE)
delay2 = make_delay(delayTR)

for i in range(Ny):
    seq.add_block(rf, gz)
    kwargsForGyPre = {
        "channel": 'y',
        "system": system,
        "area": phase_areas[i],
        "duration": 2e-3
    }
    gyPre = make_trapezoid(kwargsForGyPre)
    seq.add_block(gx_pre, gyPre, gz_reph)
Beispiel #3
0
    "duration": readoutTime / 2
}
gyPre = make_trapezoid(kwargs_for_gy_pre)

flip = 180 * pi / 180
kwargs_for_sinc = {
    "flip_angle": flip,
    "system": system,
    "duration": 3e-3,
    "slice_thickness": Slicethickness,
    "apodization": 0.5,
    "time_bw_product": 4
}
rf180, gz180 = make_sinc_pulse(kwargs_for_sinc, 2)

delayTE1 = TE / 2 - calc_duration(gzReph) - calc_duration(
    rf) - calc_duration(rf180) / 2
a = calc_duration(gx) / 2
b = calc_duration(rf180) / 2
delayTE2 = TE / 2 - calc_duration(gx) / 2 - calc_duration(rf180) / 2
delayTE3 = TR - TE - calc_duration(gx)
delay1 = make_delay(delayTE1)
delay2 = make_delay(delayTE2)
delay3 = make_delay(delayTE3)

# phaseAreas = ((0:Ny-1)-Ny/2)*deltak
# phaseAreas = round((0 in (Ny-1) - Ny/2) * delta_k)
# phase_areas = np.array(([x for x in range(0, Ny - 1)]))
phase_areas = np.arange(Ny)
phase_areas = (phase_areas - (Ny / 2)) * delta_k
kwargs_for_gz_spoil = {
    "channel": 'z',
    "system": system,
    "area": gz.area * 2,
    "duration": 3 * pre_time
}
gz_spoil = make_trapezoid(kwargs_for_gz_spoil)

kwargs_for_arb_gx = {
    "channel": 'x',
    "system": system,
    "waveform": np.squeeze(np.real(G[:, 0]))
}
gx = makearbitrary_grad(kwargs_for_arb_gx)

delayTE = TE - calc_duration(gz_reph) - (calc_duration(rf) / 2)
delayTR = TR - calc_duration(gz_reph) - calc_duration(rf) - calc_duration(
    gx) - calc_duration(gz_spoil)
delay1 = make_delay(delayTE)
delay2 = make_delay(delayTR)

for s in range(n_slices):
    w
freq_offset = gz.amplitude * z[s]
rf.freq_offset = freq_offset

for ns in range(n_shots):
    seq.add_block(rf, gz)
    seq.add_block(gz_reph)

    kwargs_for_arb_gx = {
Beispiel #5
0
    def set_plot_outputs(self):
        t0, time_range = 0, [0, np.inf]
        adc_values = [[], []]
        rf_mag_values = [[], []]
        rf_phase_values = [[], []]
        t_x_values = [[], []]
        t_y_values = [[], []]
        t_z_values = [[], []]

        for iB in range(1, len(self.seq.block_events)):
            block = self.seq.get_block(iB)
            is_valid = time_range[0] <= t0 <= time_range[1]
            if is_valid:
                if block is not None:
                    if 'adc' in block:
                        adc = block['adc']
                        t = adc.delay + [(x * adc.dwell) for x in range(0, int(adc.num_samples))]
                        adc_values[0].extend(t0 + t)
                        adc_values[1].extend(np.ones(len(t)))
                    if 'rf' in block:
                        rf = block['rf']
                        t = rf.t
                        rf_mag_values[0].extend(t0 + t[0])
                        rf_mag_values[1].extend(abs(rf.signal))
                        rf_phase_values[0].extend(t0 + t[0])
                        rf_phase_values[1].extend(np.angle(rf.signal))
                    grad_channels = ['gx', 'gy', 'gz']
                    for x in range(0, len(grad_channels)):
                        if grad_channels[x] in block:
                            grad = block[grad_channels[x]]
                            if grad.type == 'grad':
                                t = grad.t
                                waveform = 1e-3 * grad.waveform
                            else:
                                t = np.cumsum([0, grad.rise_time, grad.flat_time, grad.fall_time])
                                waveform = [1e-3 * grad.amplitude * x for x in [0, 1, 1, 0]]
                                if grad.channel == 'x':
                                    t_x_values[0].extend(t0 + t)
                                    t_x_values[1].extend(waveform)
                                elif grad.channel == 'y':
                                    t_y_values[0].extend(t0 + t)
                                    t_y_values[1].extend(waveform)
                                elif grad.channel == 'z':
                                    t_z_values[0].extend(t0 + t)
                                    t_z_values[1].extend(waveform)
            t0 += calc_duration(block)

        # Setting outputs
        # ADC
        adc_output = np.array(adc_values)
        adc_output = adc_output.transpose()
        self.setData('adc_output', adc_output)

        # RF Mag
        rf_mag_output = np.array(rf_mag_values)
        rf_mag_output = rf_mag_output.transpose()
        self.setData('rf_mag_output', rf_mag_output)

        # RF Phase
        rf_ph_output = np.array(rf_phase_values)
        rf_ph_output = rf_ph_output.transpose()
        self.setData('rf_phase_output', rf_ph_output)

        # TrapX
        t_x_output = np.array(t_x_values)
        t_x_output = t_x_output.transpose()
        self.setData('trap_x_output', t_x_output)

        # TrapY
        t_y_output = np.array(t_y_values)
        t_y_output = t_y_output.transpose()
        self.setData('trap_y_output', t_y_output)

        # TrapZ
        t_z_output = np.array(t_z_values)
        t_z_output = t_z_output.transpose()
        self.setData('trap_z_output', t_z_output)
    def make_se_epi(self):
        kwargs_for_opts = {
            "max_grad": self.max_grad,
            "grad_unit": "mT/m",
            "max_slew": self.max_slew,
            "slew_unit": "T/m/s",
            "rf_dead_time": 10e-6,
            "adc_dead_time": 10e-6
        }
        system = Opts(kwargs_for_opts)
        seq = Sequence(system)

        slice_thickness = 3e-3

        flip = 90 * pi / 180
        kwargs_for_sinc = {
            "flip_angle": flip,
            "system": system,
            "duration": 2.5e-3,
            "slice_thickness": slice_thickness,
            "apodization": 0.5,
            "time_bw_product": 4
        }
        rf, gz = make_sinc_pulse(kwargs_for_sinc, 2)
        # plt.plot(rf.t[0], rf.signal[0])
        # plt.show()

        delta_k = 1 / self.fov
        k_width = self.Nx * delta_k
        readout_time = self.Nx * 4e-6
        kwargs_for_gx = {
            "channel": 'x',
            "system": system,
            "flat_area": k_width,
            "flat_time": readout_time
        }
        gx = make_trapezoid(kwargs_for_gx)
        kwargs_for_adc = {
            "num_samples": self.Nx,
            "system": system,
            "duration": gx.flat_time,
            "delay": gx.rise_time
        }
        adc = makeadc(kwargs_for_adc)

        pre_time = 8e-4
        kwargs_for_gxpre = {
            "channel": 'x',
            "system": system,
            "area": -gx.area / 2,
            "duration": pre_time
        }
        gx_pre = make_trapezoid(kwargs_for_gxpre)
        kwargs_for_gz_reph = {
            "channel": 'z',
            "system": system,
            "area": -gz.area / 2,
            "duration": pre_time
        }
        gz_reph = make_trapezoid(kwargs_for_gz_reph)
        kwargs_for_gy_pre = {
            "channel": 'y',
            "system": system,
            "area": -self.Ny / 2 * delta_k,
            "duration": pre_time
        }
        gy_pre = make_trapezoid(kwargs_for_gy_pre)

        dur = ceil(2 * sqrt(delta_k / system.max_slew) / 10e-6) * 10e-6
        kwargs_for_gy = {
            "channel": 'y',
            "system": system,
            "area": delta_k,
            "duration": dur
        }
        gy = make_trapezoid(kwargs_for_gy)

        flip = 180 * pi / 180
        kwargs_for_sinc = {
            "flip_angle": flip,
            "system": system,
            "duration": 2.5e-3
        }
        rf180 = make_block_pulse(kwargs_for_sinc)
        kwargs_for_gz_spoil = {
            "channel": 'z',
            "system": system,
            "area": gz.area * 2,
            "duration": 3 * pre_time
        }
        gz_spoil = make_trapezoid(kwargs_for_gz_spoil)

        TE = self.te
        duration_to_center = (self.Nx / 2 + 0.5) * calc_duration(
            gx) + self.Ny / 2 * calc_duration(gy)
        delayTE1 = TE / 2 - calc_duration(gz) / 2 - pre_time - calc_duration(
            gz_spoil) - calc_duration(rf180) / 2
        delayTE2 = TE / 2 - calc_duration(rf180) / 2 - calc_duration(
            gz_spoil) - duration_to_center
        delay1 = make_delay(delayTE1)
        delay2 = make_delay(delayTE2)

        seq.add_block(rf, gz)
        seq.add_block(gx_pre, gy_pre, gz_reph)
        seq.add_block(delay1)
        seq.add_block(gz_spoil)
        seq.add_block(rf180)
        seq.add_block(gz_spoil)
        seq.add_block(delay2)
        for i in range(self.Ny):
            seq.add_block(gx, adc)
            seq.add_block(gy)
            gx.amplitude = -gx.amplitude
        seq.add_block(make_delay(1))

        return seq
Beispiel #7
0
    def plot(self, time_range=(0, np.inf)):
        """
        Show Matplotlib plot of all Events in the Sequence object.

        Parameters
        ----------
        time_range : List
            Time range (x-axis limits) for plot to be shown. Default is 0 to infinity (entire plot shown).
        """

        fig1, fig2 = plt.figure(1), plt.figure(2)
        f11, f12, f13 = fig1.add_subplot(311), fig1.add_subplot(
            312), fig1.add_subplot(313)
        f2 = [
            fig2.add_subplot(311),
            fig2.add_subplot(312),
            fig2.add_subplot(313)
        ]
        t0 = 0
        for iB in range(1, len(self.block_events) + 1):
            block = self.get_block(iB)
            is_valid = time_range[0] <= t0 <= time_range[1]
            if is_valid:
                if block is not None:
                    if 'adc' in block:
                        adc = block['adc']
                        t = adc.delay + [
                            (x * adc.dwell)
                            for x in range(0, int(adc.num_samples))
                        ]
                        f11.plot((t0 + t), np.zeros(len(t)))
                    if 'rf' in block:
                        rf = block['rf']
                        t = rf.t
                        f12.plot(np.squeeze(t0 + t), abs(rf.signal))
                        f13.plot(np.squeeze(t0 + t), np.angle(rf.signal))
                    grad_channels = ['gx', 'gy', 'gz']
                    for x in range(0, len(grad_channels)):
                        if grad_channels[x] in block:
                            grad = block[grad_channels[x]]
                            if grad.type == 'grad':
                                t = grad.t
                                waveform = 1e-3 * grad.waveform
                            else:
                                t = np.cumsum([
                                    0, grad.rise_time, grad.flat_time,
                                    grad.fall_time
                                ])
                                waveform = [
                                    1e-3 * grad.amplitude * x
                                    for x in [0, 1, 1, 0]
                                ]
                            f2[x].plot(np.squeeze(t0 + t), waveform)
            t0 += calc_duration(block)

        f11.set_ylabel('adc')
        f12.set_ylabel('rf mag hz')
        f13.set_ylabel('rf phase rad')
        [f2[x].set_ylabel(grad_channels[x]) for x in range(3)]
        # Setting display limits
        disp_range = [time_range[0], min(t0, time_range[1])]
        f11.set_xlim(disp_range)
        f12.set_xlim(disp_range)
        f13.set_xlim(disp_range)
        [x.set_xlim(disp_range) for x in f2]

        plt.show()
gy = make_trapezoid(kwargs_for_gy)

flip = 180 * pi / 180
kwargs_for_sinc = {"flip_angle": flip, "system": system, "duration": 2.5e-3}
rf180 = make_block_pulse(kwargs_for_sinc)
kwargs_for_gz_spoil = {
    "channel": 'z',
    "system": system,
    "area": gz.area * 2,
    "duration": 3 * pre_time
}
gz_spoil = make_trapezoid(kwargs_for_gz_spoil)

TE, TR = 200e-3, 1000e-3
duration_to_center = (Nx / 2 +
                      0.5) * calc_duration(gx) + Ny / 2 * calc_duration(gy)
delayTE1 = TE / 2 - calc_duration(gz) / 2 - pre_time - calc_duration(
    gz_spoil) - calc_duration(rf180) / 2
delayTE2 = TE / 2 - calc_duration(rf180) / 2 - calc_duration(
    gz_spoil) - duration_to_center
delay1 = make_delay(delayTE1)
delay2 = make_delay(delayTE2)

seq.add_block(rf, gz)
seq.add_block(gx_pre, gy_pre, gz_reph)
seq.add_block(delay1)
seq.add_block(gz_spoil)
seq.add_block(rf180)
seq.add_block(gz_spoil)
seq.add_block(delay2)
for i in range(Ny):