Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add OSSPS set_relaxation_gamma #1204

Merged
merged 4 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# ChangeLog

## v3.6.0

* PET:
- added extra members to ScatterEstimation to set behaviour of OSEM used during scatter estimation
- added test for scatter simulation and estimation

## v3.5.1
- added missing `set`/`get` methods for OSSPS `relaxation_parameter`, `relaxation_gamma` and `upper_bound`.

* CMake/building:
- default `DISABLE_MATLAB` to `ON` as our Matlab support is out-of-date and could
Expand Down
1 change: 1 addition & 0 deletions doc/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ Class for reconstructor objects using Ordered Subsets Separable Paraboloidal Sur

OSSPSReconstructor Constructor. Creates new OSSPS reconstructor object.
set_relaxation_parameter Sets relaxation parameter.
set_relaxation_gamma Sets relaxation gamma parameter.

##### FullySampledReconstructor (MR)

Expand Down
10 changes: 10 additions & 0 deletions src/xSTIR/cSTIR/cstir_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,10 @@ sirf::cSTIR_setOSSPSParameter(DataHandle* hp, const char* name, const DataHandle
objectFromHandle<xSTIR_OSSPSReconstruction3DF >(hp);
if (sirf::iequals(name, "relaxation_parameter"))
recon.relaxation_parameter_value() = dataFromHandle<float>(hv);
else if (sirf::iequals(name, "relaxation_gamma"))
recon.relaxation_gamma_value() = dataFromHandle<float>(hv);
else if (sirf::iequals(name, "upper_bound"))
recon.upper_bound_value() = dataFromHandle<double>(hv);
else
return parameterNotFound(name, __FILE__, __LINE__);
return new DataHandle;
Expand All @@ -1168,6 +1172,12 @@ sirf::cSTIR_OSSPSParameter(const DataHandle* handle, const char* name)
{
xSTIR_OSSPSReconstruction3DF& recon =
objectFromHandle<xSTIR_OSSPSReconstruction3DF>(handle);
if (sirf::iequals(name, "relaxation_parameter"))
return dataHandle<float>(recon.relaxation_parameter_value());
else if (sirf::iequals(name, "relaxation_gamma"))
return dataHandle<float>(recon.relaxation_gamma_value());
else if (sirf::iequals(name, "upper_bound"))
return dataHandle<double>(recon.upper_bound_value());
return parameterNotFound(name, __FILE__, __LINE__);
}

Expand Down
6 changes: 6 additions & 0 deletions src/xSTIR/cSTIR/include/sirf/STIR/stir_x.h
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,12 @@ The actual algorithm is described in
float& relaxation_parameter_value() {
return relaxation_parameter;
}
float& relaxation_gamma_value() {
return relaxation_gamma;
}
double& upper_bound_value() {
return upper_bound;
}
};

class xSTIR_FBP2DReconstruction : public stir::FBP2DReconstruction {
Expand Down
22 changes: 22 additions & 0 deletions src/xSTIR/pSTIR/STIR.py
Original file line number Diff line number Diff line change
Expand Up @@ -3435,6 +3435,28 @@ def set_relaxation_parameter(self, value):
parms.set_float_par(
self.handle, self.name, 'relaxation_parameter', value)

def set_relaxation_gamma(self, value):
"""Sets relaxation gamma parameter."""
parms.set_float_par(
self.handle, self.name, 'relaxation_gamma', value)

def set_upper_bound(self, value):
"""Sets upper bound parameter."""
parms.set_double_par(
self.handle, self.name, 'upper_bound', value)

def get_relaxation_parameter(self):
"""Returns relaxation parameter value."""
return parms.float_par(self.handle, self.name, 'relaxation_parameter')

def get_relaxation_gamma(self):
"""Returns relaxation gamma value."""
return parms.float_par(self.handle, self.name, 'relaxation_gamma')

def get_upper_bound(self):
"""Returns upper bound value."""
return parms.double_par(self.handle, self.name, 'upper_bound')


def make_Poisson_loglikelihood(acq_data, likelihood_type='LinearModelForMean',
acq_model=None):
Expand Down
15 changes: 15 additions & 0 deletions src/xSTIR/pSTIR/STIR_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,19 @@ def set_bool_par(handle, group, par, value):
set_parameter(handle, group, par, h, inspect.stack()[1])
pyiutil.deleteDataHandle(h)


def set_float_par(handle, group, par, value):
h = pyiutil.floatDataHandle(float(value))
set_parameter(handle, group, par, h, inspect.stack()[1])
pyiutil.deleteDataHandle(h)


def set_double_par(handle, group, par, value):
h = pyiutil.doubleDataHandle(float(value))
set_parameter(handle, group, par, h, inspect.stack()[1])
pyiutil.deleteDataHandle(h)


def bool_par(handle, group, par):
h = parameter(handle, group, par)
check_status(h, inspect.stack()[1])
Expand Down Expand Up @@ -144,6 +151,14 @@ def float_pars(handle, group, par, n):
return value


def double_par(handle, group, par):
h = parameter(handle, group, par)
check_status(h)
v = pyiutil.doubleDataFromHandle(h)
pyiutil.deleteDataHandle(h)
return v


def parameter_handle(hs, group, par):
handle = parameter(hs, group, par)
check_status(handle, inspect.stack()[1])
Expand Down
6 changes: 6 additions & 0 deletions src/xSTIR/pSTIR/tests/tests_three.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ def test_main(rec=False, verb=False, throw=True):
recon.set_num_subiterations(2)
recon.set_objective_function(obj_fun)
recon.set_input(acq_data)
recon.set_relaxation_parameter(2)
recon.set_relaxation_gamma(.3)
recon.set_upper_bound(4e5)
test.check_if_equal_within_tolerance(2, recon.get_relaxation_parameter(), rel_tol=1e-5)
test.check_if_equal_within_tolerance(.3, recon.get_relaxation_gamma(), rel_tol=1e-5)
test.check_if_equal_within_tolerance(4e5, recon.get_upper_bound(), rel_tol=1e-5)
if verb:
print('setting up, please wait...')
recon.set_up(image_data)
Expand Down
Loading