Ejemplo n.º 1
0
    def make_event_holders(self):
        """Make appropriate Holder objects depending on the Event type."""

        self.system = self.in_dict['system']
        # arbgrad_file_path is only for arbitrary gradients
        arbgrad_file_path = self.all_event_defs['file_path'] if 'file_path' in self.all_event_defs else None
        self.all_event_holders = {}

        for event in self.all_event_defs:
            event_unique_name = event['event_unique_name']
            event_name = event['event_name']
            event_values = list(event['event_values'].values())
            include_in_loop = event['include_in_loop']

            if event_name == 'Delay':
                params = self.parse_config_params(event_values)
                delay = make_delay(params[0])
                self.all_event_holders[event_unique_name] = delay, include_in_loop
            elif event_name == 'SincRF':
                include_gz = event['include_gz']
                max_grad, max_slew, flip_angle, duration, freq_offset, phase_offset, time_bw_product, apodization, slice_thickness = self.parse_config_params(
                    event_values)
                flip_angle = math.radians(flip_angle)
                max_grad = convert.convert_from_to(max_grad, 'mT/m')
                max_slew = convert.convert_from_to(max_slew, 'mT/m/ms')
                max_grad = self.system.max_grad if max_grad == 0 else max_grad
                max_slew = self.system.max_slew if max_slew == 0 else max_slew
                kwargs_for_sinc = {"flip_angle": flip_angle, "system": self.system, "duration": duration,
                                   "freq_offset": freq_offset, "phase_offset": phase_offset,
                                   "time_bw_product": time_bw_product, "apodization": apodization,
                                   "max_grad": max_grad, "max_slew": max_slew, "slice_thickness": slice_thickness}
                if include_gz:
                    rf, gz = make_sinc_pulse(kwargs_for_sinc, 2)
                    self.all_event_holders[event_unique_name] = rf, include_in_loop
                    self.all_event_holders['gz_' + event_unique_name] = gz, include_in_loop
                else:
                    rf = make_sinc_pulse(kwargs_for_sinc)
                    self.all_event_holders[event_unique_name] = rf, include_in_loop
            elif event_name == 'BlockRF':
                include_gz = event['include_gz']
                max_grad, max_slew, flip_angle, duration, freq_offset, phase_offset, time_bw_product, bandwidth, slice_thickness = self.parse_config_params(
                    event_values)
                flip_angle = math.radians(flip_angle)
                max_grad = convert.convert_from_to(max_grad, 'mT/m')
                max_slew = convert.convert_from_to(max_slew, 'mT/m/ms')
                max_grad = self.system.max_grad if max_grad == 0 else max_grad
                max_slew = self.system.max_slew if max_slew == 0 else max_slew
                kwargs_for_block = {"flip_angle": flip_angle, "system": self.system, "duration": duration,
                                    "freq_offset": freq_offset, "phase_offset": phase_offset,
                                    "time_bw_product": time_bw_product, "bandwidth": bandwidth,
                                    "max_grad": max_grad, "max_slew": max_slew, "slice_thickness": slice_thickness}
                if include_gz:
                    rf, gz = make_block_pulse(kwargs_for_block, 2)
                    self.all_event_holders[event_unique_name] = rf, include_in_loop
                    self.all_event_holders['gz_' + event_unique_name] = gz, include_in_loop
                else:
                    rf = make_block_pulse(kwargs_for_block)
                    self.all_event_holders[event_unique_name] = rf, include_in_loop
            elif event_name == 'G':
                channel = event_values.pop(0)
                max_grad, max_slew, duration, area, flat_time, flat_area, amplitude, rise_time = self.parse_config_params(
                    event_values)

                # area, flat_area and amplitude should be reset to -1 if user does not input any values. This is
                # because the default values are -1 in maketrap method.
                area = area if area != 0 else -1
                flat_area = flat_area if flat_area != 0 else -1
                amplitude = amplitude if amplitude != 0 else -1

                max_grad = convert.convert_from_to(max_grad, 'mT/m')
                max_slew = convert.convert_from_to(max_slew, 'mT/m/ms')
                max_grad = self.system.max_grad if max_grad == 0 else max_grad
                max_slew = self.system.max_slew if max_slew == 0 else max_slew
                kwargs_for_trap = {"channel": channel, "system": self.system, "duration": duration, "area": area,
                                   "flat_time": flat_time, "flat_area": flat_area, "amplitude": amplitude,
                                   "max_grad": max_grad, "max_slew": max_slew, "rise_time": rise_time}
                trap = make_trapezoid(kwargs_for_trap)
                self.all_event_holders[event_unique_name] = trap, include_in_loop
            elif event_name == 'GyPre':
                duration, area = self.parse_config_params(event_values)
                Ny = self.system.Ny
                delta_k = 1 / self.system.fov
                gy_pre_list = []

                for i in range(int(Ny)):
                    kwargs_for_gy_pre = {"channel": 'y', "system": self.system, "area": (i - Ny / 2) * delta_k,
                                         "duration": duration}
                    if area != 0:
                        kwargs_for_gy_pre['area'] = area
                    gy_pre = make_trapezoid(kwargs_for_gy_pre)
                    gy_pre_list.append(gy_pre)

                self.all_event_holders[event_unique_name] = gy_pre_list, True
            elif event_name == 'ArbGrad':
                channel = event_values.pop(0)
                max_grad, max_slew = self.parse_config_params(event_values)
                file = h5py.File(gpi.TranslateFileURI(arbgrad_file_path), "r")
                self.dataset = str()

                def append_if_dataset(name, obj):
                    if isinstance(obj, h5py.Dataset):
                        self.dataset = name
                        return True

                file.visititems(append_if_dataset)

                waveform = file[self.dataset].value
                kwargs_for_arb_grad = {"channel": channel, "waveform": waveform, "max_grad": max_grad,
                                       "max_slew": max_slew, "system": self.system}
                arb_grad = makearbitrary_grad(kwargs_for_arb_grad)
                self.all_event_holders[event_unique_name] = arb_grad, include_in_loop
            elif event_name == 'ADC':
                num_samples, dwell, duration, delay, freq_offset, phase_offset = self.parse_config_params(
                    event_values)
                kwargs_for_adc = {"num_samples": num_samples, "system": self.system, "dwell": dwell,
                                  "duration": duration, "delay": delay, "freq_offset": freq_offset,
                                  "phase_offset": phase_offset}
                adc = makeadc(kwargs_for_adc)
                self.all_event_holders[event_unique_name] = adc, include_in_loop
Ejemplo n.º 2
0
delta_k = 1 / fov
kWidth = Nx * delta_k
readoutTime = 6.4e-3
kwargs_for_gx = {
    "channel": 'x',
    "system": system,
    "flat_area": kWidth,
    "flat_time": readoutTime
}
gx = make_trapezoid(kwargs_for_gx)
kwargs_for_adc = {
    "num_samples": Nx,
    "duration": gx.flat_time,
    "delay": gx.rise_time
}
adc = makeadc(kwargs_for_adc)

kwargs_for_gxpre = {
    "channel": 'x',
    "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)
Ejemplo n.º 3
0
    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