Skip to content

Commit

Permalink
Use memory storage only for MR data (#887)
Browse files Browse the repository at this point in the history
* [ci skip] removed debugging leftovers from coil_sensitivity_maps.py

* [ci skip] covered for absent pylab in grappa_and_steepest_descent.py

* [ci skip] fixed spaces-in-path issue in MR run_all.py scripts

* [ci skip] removed MR file storage option from C++ code

* [ci skip] removed storage scheme handling from MR interfaces

* [ci skip] removed setting storage scheme from Python/MR demo scripts

* [ci skip] covered for absent pylab in PET_MCIR.py

* [ci skip] removed setting storage scheme from Python/PETMR/PET_MCIR

* [ci skip] added non-memory storage scheme warning to Gadgetron.AcquisitionData

* [ci skip] made MR acquisition data reading monitoring output more compact

* [ci skip] removed setting the storage scheme from Matlab/MR demo scripts

* [ci skip] restored erroneously removed PET storage scheme setting in PET_MCIR

* [ci skip] added non-memory storage scheme warning to +Gadgetron.AcquisitionData

* [ci skip] re-worded non-memory storage warning in Gadgetron.AcquisitionData

* [ci skip] covered for Python executables other than python.exe

* [ci skip] removed AcquisitionsVector.init()

* [ci skip] proper treatment of paths with spaces in run_all.py implemented

* [ci skip] cleaned up from commented-out lines

* [ci skip] cleaned up from commented-out lines

* [ci skip] corrected treatment of paths with spaces in MR/Gadgetron/run_all.py

* updated CHANGES.md
  • Loading branch information
evgueni-ovtchinnikov authored Apr 13, 2021
1 parent 7216b43 commit a491381
Show file tree
Hide file tree
Showing 19 changed files with 106 additions and 503 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# ChangeLog

## vX.X.X
## v3.0.0
* MR acquisition data storage scheme restricted to memory only.
* GE Signa randoms support added.
* If the `SIRF_DATA_PATH` environment variable is set, `examples_data_path` will search for the examples data there, or in `SIRF_INSTALL_PATH/share/SIRF-<versio_major>.<version_minor>/data` directory. In MATLAB, the `example_data_path` function has the version set by CMake at install time.
* Defines `__version__` in `sirf` python package.
Expand Down
12 changes: 0 additions & 12 deletions examples/Matlab/MR/acquisition_data.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,12 @@ function acquisition_data(engine)
if nargin < 1
engine = [];
end
% import_str = set_up_MR(engine);
% eval(import_str)
MR = set_up_MR(engine);
mr_data_path = sirf.Utilities.examples_data_path('MR');

% all acquisition data generated by this script will be stored in memory
% (the input data will remain in the input file)
AD = MR.AcquisitionData();
scheme = AD.get_storage_scheme();
AD.set_storage_scheme('memory');
% does not work this way:
% scheme = MR.AcquisitionData.get_storage_scheme();
% MR.AcquisitionData.set_storage_scheme('memory');

% read acquisitions from an HDF file
[filename, pathname] = uigetfile('*.h5', 'Select raw data file', mr_data_path);
Expand Down Expand Up @@ -117,9 +110,4 @@ function acquisition_data(engine)
'samples', 'readouts', 'coil');
sirf.Utilities.set_window(0.1, 0.1, 0.8, 0.8)

% % Reset the storage scheme to default
% AD.set_storage_scheme('default');
% Restore previous storage scheme
AD.set_storage_scheme(scheme);

end
13 changes: 0 additions & 13 deletions examples/Matlab/MR/acquisition_model.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,10 @@ function acquisition_model(engine)
if nargin < 1
engine = [];
end
% import_str = set_up_MR(engine);
% eval(import_str)
MR = set_up_MR(engine);
mr_data_path = sirf.Utilities.examples_data_path('MR');

% storage scheme 'file' keeps all acquisition data generated by
% the script in scratch files deleted after the script terminates;
% NOTE that subsequent SIRF script runs will continue to use this scheme
% unless the acquisition data storage scheme is explicitely set to 'memory'
% (see using_acquisition_data.m) or Matlab is re-started
AD = MR.AcquisitionData();
AD.set_storage_scheme('memory');
%AcquisitionData.set_storage_scheme('file');

% acquisitions will be read from an HDF file
[filename, pathname] = uigetfile('*.h5', 'Select raw data file', mr_data_path);
Expand Down Expand Up @@ -81,10 +72,6 @@ function acquisition_model(engine)
name = char(par(p));
fprintf('%s %d\n', name, image.info(name))
end
% fprintf('flags %d\n', image.flags())
% fprintf('channels %d\n', image.channels())
% fprintf('slice %d\n', image.slice())
% fprintf('repetition %d\n', image.info('repetition'))
fprintf('matrix size %dx%dx%d\n', image.matrix_size())
end

Expand Down
3 changes: 2 additions & 1 deletion examples/Python/MR/Gadgetron/run_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
args = ''
for a in range(1, narg):
args += ' ' + sys.argv[a]
err = os.system(sys.executable + ' ' + i + args)
exe = '"' + sys.executable + '" ' + i + args
err = os.system(exe)
if err:
raise RuntimeError(i + ' failed')
4 changes: 0 additions & 4 deletions examples/Python/MR/acquisition_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@
slcs = int(args['--slices'])
show_plot = not args['--non-interactive']

AcquisitionData.set_storage_scheme('memory')
scheme = AcquisitionData.get_storage_scheme()
print('storage scheme: %s' % repr(scheme))

def main():

# locate the input data file
Expand Down
4 changes: 1 addition & 3 deletions examples/Python/MR/coil_sensitivity_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,9 @@ def main():
show=False)

try:
from ismrmrdtools0 import coils
from ismrmrdtools import coils
except:
print('Inati method requires ismrmrd-python-tools')
import matplotlib.pyplot as plt
plt.show()
return
# calculate coil sensitivity maps using an approach suggested by
# Inati SJ, Hansen MS, Kellman P.
Expand Down
4 changes: 0 additions & 4 deletions examples/Python/MR/fully_sampled_recon.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ def main():
# locate the input data file
input_file = existing_filepath(data_path, data_file)

# all acquisition data generated by this script will be stored in memory
# (the input data will remain in the input file)
AcquisitionData.set_storage_scheme('memory')

# MR raw data formats from different vendors can be transformed to
# HDF file format using siemens_to_ismrmrd, philips_to_ismrmrd or
# bruker_to_ismrmrd on https://github.com/ismrmrd/.
Expand Down
15 changes: 9 additions & 6 deletions examples/Python/MR/grappa_and_steepest_descent.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,15 @@ def main():
postpone=(i < niter - 1))

if niter > 1 and show_plot:
import pylab
pylab.figure()
pylab.plot(numpy.arange(1, niter + 1, 1), res)
pylab.grid()
pylab.title('residual norm')
pylab.show()
try:
import pylab
pylab.figure()
pylab.plot(numpy.arange(1, niter + 1, 1), res)
pylab.grid()
pylab.title('residual norm')
pylab.show()
except:
print('pylab not found')

if output_file is not None:
print('writing to %s' % output_file)
Expand Down
3 changes: 2 additions & 1 deletion examples/Python/MR/run_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
args = ''
for a in range(1, narg):
args += ' ' + sys.argv[a]
err = os.system(sys.executable + ' ' + i + args)
exe = '"' + sys.executable + '" ' + i + args
err = os.system(exe)
if err:
raise RuntimeError(i + ' failed')
5 changes: 4 additions & 1 deletion examples/Python/PET/run_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@
args = ''
for a in range(1, narg):
args += ' ' + sys.argv[a]
os.system(sys.executable + ' ' + i + args)
exe = '"' + sys.executable + '" ' + i + args
err = os.system(exe)
if err:
raise RuntimeError(i + ' failed')
10 changes: 6 additions & 4 deletions examples/Python/PETMR/PET_MCIR.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@
from glob import glob
from docopt import docopt
from sirf.Utilities import error, show_2D_array
import pylab
try:
import pylab
have_pylab = True
except:
have_pylab = False
import sirf.Reg as reg
import sirf.STIR as pet
from ccpi.optimisation.algorithms import PDHG
Expand All @@ -85,8 +89,6 @@
from ccpi.filters import regularisers
import numpy as np

pet.AcquisitionData.set_storage_scheme('memory')

__version__ = '0.1.0'
args = docopt(__doc__, version=__version__)

Expand Down Expand Up @@ -120,7 +122,7 @@
# Initial estimate
initial_estimate = args['--initial']

visualisations = True if args['--visualisations'] else False
visualisations = True if args['--visualisations'] and have_pylab else False
nifti = True if args['--nifti'] else False
use_gpu = True if args['--gpu'] else False
descriptive_fname = True if args['--descriptive_fname'] else False
Expand Down
3 changes: 2 additions & 1 deletion src/Synergistic/tests/test_cSynergistic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ int main(int argc, char* argv[])
std::cout << "// Starting complex resampler test...\n";
std::cout << "//------------------------------------------------------------------------ //\n";

AcquisitionsFile raw_mr(raw_mr_filename);
AcquisitionsVector raw_mr;
raw_mr.read(raw_mr_filename);

std::vector<gadgetron::shared_ptr<Gadget> > gadgets;
ADD_GADGET(gadgets, NoiseAdjustGadget);
Expand Down
39 changes: 6 additions & 33 deletions src/xGadgetron/cGadgetron/cgadgetron.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,28 +421,6 @@ cGT_AcquisitionModelBackward(void* ptr_am, const void* ptr_acqs)
CATCH;
}

extern "C"
void*
cGT_setAcquisitionDataStorageScheme(const char* scheme)
{
try{
if (scheme[0] == 'f' || strcmp(scheme, "default") == 0)
AcquisitionsFile::set_as_template();
else
AcquisitionsVector::set_as_template();
return (void*)new DataHandle;
}
CATCH;
}

extern "C"
void*
cGT_getAcquisitionDataStorageScheme()
{
return charDataHandleFromCharData
(MRAcquisitionData::storage_scheme().c_str());
}

extern "C"
void*
cGT_sortAcquisitions(void* ptr_acqs)
Expand Down Expand Up @@ -479,17 +457,11 @@ cGT_ISMRMRDAcquisitionsFromFile(const char* file)
{
if (!file_exists(file))
return fileNotFound(file, __FILE__, __LINE__);
std::string scheme = MRAcquisitionData::storage_scheme();
try {
shared_ptr<MRAcquisitionData>
acquisitions(new AcquisitionsFile(file));
if (scheme[0] != 'm')
return newObjectHandle<MRAcquisitionData>(acquisitions);
else {
shared_ptr<MRAcquisitionData>
acqs(acquisitions->clone());
return newObjectHandle<MRAcquisitionData>(acqs);
}
shared_ptr<MRAcquisitionData>
acquisitions(new AcquisitionsVector);
acquisitions->read(file);
return newObjectHandle<MRAcquisitionData>(acquisitions);
}
CATCH;
}
Expand All @@ -500,7 +472,8 @@ cGT_ISMRMRDAcquisitionsFile(const char* file)
{
try {
shared_ptr<MRAcquisitionData>
acquisitions(new AcquisitionsFile(file, true));
acquisitions(new AcquisitionsVector);
acquisitions->read(file);
return newObjectHandle<MRAcquisitionData>(acquisitions);
}
CATCH;
Expand Down
Loading

0 comments on commit a491381

Please sign in to comment.