def test_bssfp_data(self): '''Sample bSSFP data set.''' dset = pyport(file=self.sample, debug=False) import numpy as np import ismrmrd import ismrmrd.xsd from ismrmrdtools import show, transform header = ismrmrd.xsd.CreateFromDocument(dset.read_xml_header()) enc = header.encoding[0] # Matrix size eNx = enc.encodedSpace.matrixSize.x eNy = enc.encodedSpace.matrixSize.y eNz = enc.encodedSpace.matrixSize.z rNx = enc.reconSpace.matrixSize.x _rNy = enc.reconSpace.matrixSize.y _rNz = enc.reconSpace.matrixSize.z # Field of View _eFOVx = enc.encodedSpace.fieldOfView_mm.x _eFOVy = enc.encodedSpace.fieldOfView_mm.y _eFOVz = enc.encodedSpace.fieldOfView_mm.z _rFOVx = enc.reconSpace.fieldOfView_mm.x _rFOVy = enc.reconSpace.fieldOfView_mm.y _rFOVz = enc.reconSpace.fieldOfView_mm.z # Number of Slices, Reps, Contrasts, etc. ncoils = header.acquisitionSystemInformation.receiverChannels if enc.encodingLimits.slice is not None: nslices = enc.encodingLimits.slice.maximum + 1 else: nslices = 1 if enc.encodingLimits.average is not None: nreps = enc.encodingLimits.average.maximum + 1 else: nreps = 1 if enc.encodingLimits.contrast is not None: ncontrasts = enc.encodingLimits.contrast.maximum + 1 else: ncontrasts = 1 # TODO loop through the acquisitions looking for noise scans firstacq = 0 for acqnum in range(dset.number_of_acquisitions()): acq = dset.read_acquisition(acqnum) # TODO: Currently ignoring noise scans if acq.isFlagSet(ismrmrd.ACQ_IS_NOISE_MEASUREMENT): print("Found noise scan at acq ", acqnum) continue else: firstacq = acqnum print("Imaging acquisition starts acq ", acqnum) break # Initialiaze a storage array all_data = np.zeros( (nreps, ncontrasts, nslices, ncoils, eNz, eNy, rNx), dtype=np.complex64) #pylint: disable=E1101 # Loop through the rest of the acquisitions and stuff for acqnum in range(firstacq, dset.number_of_acquisitions()): acq = dset.read_acquisition(acqnum) # TODO: this is where we would apply noise pre-whitening # Remove oversampling if needed if eNx != rNx: xline = transform.transform_kspace_to_image(acq.data, [1]) x0 = int((eNx - rNx) / 2) x1 = int((eNx - rNx) / 2 + rNx) xline = xline[:, x0:x1] acq.resize(rNx, acq.active_channels, acq.trajectory_dimensions) #pylint: disable=E1101 acq.center_sample = int(rNx / 2) # need to use the [:] notation here to fill the data acq.data[:] = transform.transform_image_to_kspace(xline, [1]) # Stuff into the buffer rep = acq.idx.average #pylint: disable=E1101 contrast = acq.idx.contrast #pylint: disable=E1101 slise = acq.idx.slice #pylint: disable=E1101 y = acq.idx.kspace_encode_step_1 #pylint: disable=E1101 z = acq.idx.kspace_encode_step_2 #pylint: disable=E1101 all_data[rep, contrast, slise, :, z, y, :] = acq.data # Reconstruct images images = np.zeros((nreps, ncontrasts, nslices, eNz, eNy, rNx), dtype=np.float32) #pylint: disable=E1101 for rep in range(nreps): for contrast in range(ncontrasts): for slise in range(nslices): # FFT if eNz > 1: #3D im = transform.transform_kspace_to_image( all_data[rep, contrast, slise, ...], [1, 2, 3]) else: #2D im = transform.transform_kspace_to_image( all_data[rep, contrast, slise, :, 0, ...], [1, 2]) # Sum of squares im = np.sqrt(np.sum(np.abs(im)**2, 0)) # Stuff into the output if eNz > 1: #3D images[rep, contrast, slise, ...] = im else: #2D images[rep, contrast, slise, 0, ...] = im # Show an image show.imshow(np.squeeze(images[0, 0, 0, ...]))
def test_invalid_pmapstyle(self): '''Make sure we break on invalid pMapStyle.''' with self.assertRaises(IOError): pyport(file=self.emptydat, pMapStyle='invalidfile')
def test_supplied_user_style_sheet_and_pMapStyle(self): '''Make sure we can't supply a param map AND an embedded file.''' with self.assertRaises(ValueError): pyport(file=self.emptydat, pMapStyle='file.xsl', user_stylesheet='file.xml')
def test_invalid_user_style_sheet(self): '''Make sure we raise an exception if user stylesheet is not valud.''' with self.assertRaises(IOError): pyport(file=self.emptydat, user_stylesheet='myFile.xsl')
def test_require_filename(self): '''If we don't have a filename, we need to stop!''' with self.assertRaises(ValueError): pyport() with self.assertRaises(ValueError): pyport(file=None)
def test_extract_file_not_valid(self): '''Make sure we raise an error when embedded file is not valid.''' with self.assertRaises(ValueError): pyport(extract='myFile.xml')