Skip to content
23 changes: 21 additions & 2 deletions python/MRzeroCore/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ def import_file(cls, file_name: str,
default_shim: torch.Tensor = torch.asarray([[1, 0]], dtype=torch.float32),
ref_voltage: float = 300.0,
resolution: Optional[int] = None,
output_dir: Optional[str] = None,
) -> Sequence:
"""Import a pulseq .seq file or a bundle of .dsv files.

Expand All @@ -441,7 +442,9 @@ def import_file(cls, file_name: str,
The shim_array used for pulses that do not specify it themselves.
ref_voltage : float
If a .dsv file is imported, this is used to convert pulses from
volts to angles. A 1 ms block pulse of ref_voltage is a 180 ° flip
volts to angles. Make sure to use 1Tx systems for dsv simulation,
otherwise the ref_voltage will not match to the concerted flip angle!!
A 1 ms block pulse of ref_voltage is a 180 ° flip
resolution : int | None
.dsv files do not contain data for the number of ADC samples.
This is used to specify the number of samples per ADC block.
Expand All @@ -456,7 +459,23 @@ def import_file(cls, file_name: str,
if file_name.endswith(".seq"):
parser = pydisseqt.load_pulseq(file_name)
else:
parser = pydisseqt.load_dsv(file_name, ref_voltage, resolution)
#try import of from dsv2pulseq import read_dsv
try:
from dsv2pulseq import read_dsv
import os
except ImportError:
raise ImportError(
"To import .dsv files, please install the dsv2pulseq package"
)
seq_temp = read_dsv(file_name, ref_volt=ref_voltage)
os.makedirs(output_dir, exist_ok=True)
seq_name = os.path.basename(file_name) + '_dsv2seq.seq'
seq_dsv_path = os.path.join(output_dir, seq_name)
seq_pulseq_dsv = seq_temp.make_pulseq_sequence(seq_dsv_path)
print(f"Saved .seq file to: {seq_dsv_path}")
parser = pydisseqt.load_pulseq(seq_dsv_path)
#parser = pydisseqt.load_dsv(file_name, ref_voltage, resolution)

if print_stats:
print(f"Importing the .seq file took {time() - start} s")
start = time()
Expand Down
Loading