Skip to content

Commit 20013fa

Browse files
Merge remote-tracking branch 'origin/master' into recondemopy
2 parents cd1009d + 19ef64e commit 20013fa

File tree

8 files changed

+327
-105
lines changed

8 files changed

+327
-105
lines changed

documentation/release_6.3.htm

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,14 @@ <h4>Python</h4>
7777
<code>a = b + c</code> and <code>a -= 3</code>. Note that <code>a = 1 + b</code> is not
7878
yet available.<br>
7979
<a href=https://github.com/UCL/STIR/pull/1630>PR #1630</a>
80-
</li>
80+
</li>
81+
<li>
82+
The above "container" classes now have an extra member `as_array()` which returns a numpy <code>ndarray</code>. This
83+
is equivalent to `stirextra.to_numpy()` which will become deprecated later. In addition, the
84+
<code>fill()</code> method now directly accepts an <code>ndarray</code>, avoiding the need to go via an iterator.
85+
These additions also make it easier to prt SIRF python code to STIR.<br>
86+
<a href=https://github.com/UCL/STIR/pull/1632>PR #1632</a>
87+
</li>
8188
<li>
8289
Added a Python script to convert e7tools generated Siemens Biograph Vision 600 sinograms to STIR compatible format.<br>
8390
<a href=https://github.com/UCL/STIR/pull/1593>PR #1593</a>

src/include/stir/recon_buildblock/PoissonLogLikelihoodWithLinearModelForMean.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,19 @@ class PoissonLogLikelihoodWithLinearModelForMean : public GeneralisedObjectiveFu
180180
bool get_recompute_sensitivity() const;
181181

182182
//! get filename to read (or write) the total sensitivity
183-
/*! will be a zero string if not set */
183+
/*! will be a zero-length string if not set */
184184
std::string get_sensitivity_filename() const;
185185
//! get filename pattern to read (or write) the subset sensitivities
186-
/*! will be a zero string if not set.
186+
/*! will be a zero-length string if not set.
187187
Could be e.g. "subsens_%d.hv"
188188
fmt::format is used with the pattern
189189
*/
190190
std::string get_subsensitivity_filenames() const;
191191

192+
//! Return the filename for a particular subset
193+
/*! \sa get_subsensitivity_filenames() */
194+
std::string get_subsensitivity_filename(const int subset_num) const;
195+
192196
/*! \name Functions to set parameters
193197
This can be used as alternative to the parsing mechanism.
194198
\warning After using any of these, you have to call set_up().

src/recon_buildblock/PoissonLogLikelihoodWithLinearModelForMean.cxx

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ PoissonLogLikelihoodWithLinearModelForMean<TargetT>::post_processing()
6767
{
6868
if (base_type::post_processing() == true)
6969
return true;
70-
70+
// call set, which will do some checks
71+
this->set_subsensitivity_filenames(this->subsensitivity_filenames);
7172
return false;
7273
}
7374

@@ -85,6 +86,19 @@ PoissonLogLikelihoodWithLinearModelForMean<TargetT>::get_subsensitivity_filename
8586
return this->subsensitivity_filenames;
8687
}
8788

89+
template <typename TargetT>
90+
std::string
91+
PoissonLogLikelihoodWithLinearModelForMean<TargetT>::get_subsensitivity_filename(const int subset_num) const
92+
{
93+
if (this->subsensitivity_filenames.empty())
94+
return this->subsensitivity_filenames;
95+
96+
if (this->subsensitivity_filenames.find("%") != std::string::npos)
97+
return boost::str(boost::format(this->subsensitivity_filenames) % subset_num);
98+
else
99+
return runtime_format(this->subsensitivity_filenames, subset_num);
100+
}
101+
88102
template <typename TargetT>
89103
void
90104
PoissonLogLikelihoodWithLinearModelForMean<TargetT>::set_sensitivity_filename(const std::string& filename)
@@ -101,20 +115,17 @@ PoissonLogLikelihoodWithLinearModelForMean<TargetT>::set_subsensitivity_filename
101115
this->subsensitivity_filenames = filenames;
102116
try
103117
{
104-
if (this->subsensitivity_filenames.find("%"))
118+
if (this->subsensitivity_filenames.find("%") != std::string::npos)
105119
{
106-
warning("The subsensitivity_filenames pattern is using the boost::format convention ('\%d')."
120+
warning("The subsensitivity_filenames pattern is using the boost::format convention ('%%d')."
107121
"It is recommended to use fmt::format/std::format style formatting ('{}').");
108-
const std::string test_sensitivity_filename = boost::str(boost::format(this->subsensitivity_filenames) % 0);
109-
}
110-
else
111-
{
112-
const std::string test_sensitivity_filename = runtime_format(this->subsensitivity_filenames.c_str(), 0);
113122
}
123+
const std::string test_sensitivity_filename = this->get_subsensitivity_filename(0);
114124
}
115125
catch (std::exception& e)
116126
{
117-
error(format("argument {} to set_subsensitivity_filenames is invalid (see fmt::format documentation)\n. Error message: {}",
127+
error(format("argument {} to set_subsensitivity_filenames is invalid (see fmt::format or boost::format documentation)\n. "
128+
"Error message: {}",
118129
filenames.c_str(),
119130
e.what()));
120131
}
@@ -224,35 +235,25 @@ PoissonLogLikelihoodWithLinearModelForMean<TargetT>::set_up(shared_ptr<TargetT>
224235
// read subsensitivies
225236
for (int subset = 0; subset < this->get_num_subsets(); ++subset)
226237
{
227-
std::string current_sensitivity_filename;
228-
try
238+
const std::string current_sensitivity_filename = this->get_subsensitivity_filename(subset);
239+
240+
if (subset > 0)
229241
{
230-
if (this->subsensitivity_filenames.find("%"))
231-
{
232-
warning("The subsensitivity_filenames pattern is using the boost::format convention ('\%d')."
233-
"It is recommended to use fmt::format/std::format style formatting ('{}').");
234-
current_sensitivity_filename = boost::str(boost::format(this->subsensitivity_filenames) % subset);
235-
}
236-
else
242+
if (current_sensitivity_filename == this->get_subsensitivity_filename(0))
237243
{
238-
current_sensitivity_filename = runtime_format(this->subsensitivity_filenames.c_str(), subset);
244+
error(format(
245+
"subset sensitivity filename pattern should lead to a different filename for every subset,"
246+
"but seems to always give '{}'",
247+
current_sensitivity_filename));
239248
}
240249
}
241-
catch (std::exception& e)
242-
{
243-
error(format("Error using 'subset sensitivity filenames' pattern (which is set to '{}'). "
244-
"Check syntax for fmt::format. Error is:\n{}",
245-
this->subsensitivity_filenames,
246-
e.what()));
247-
return Succeeded::no;
248-
}
249250
info(format("Reading sensitivity from '{}'", current_sensitivity_filename));
250251

251252
this->subsensitivity_sptrs[subset] = read_from_file<TargetT>(current_sensitivity_filename);
252253
string explanation;
253254
if (!target_sptr->has_same_characteristics(*this->subsensitivity_sptrs[subset], explanation))
254255
{
255-
error("sensitivity and target should have the same characteristics.\n%s", explanation.c_str());
256+
error("sensitivity and target should have the same characteristics.\n" + explanation);
256257
return Succeeded::no;
257258
}
258259
}
@@ -321,8 +322,7 @@ PoissonLogLikelihoodWithLinearModelForMean<TargetT>::set_up(shared_ptr<TargetT>
321322
{
322323
for (int subset = 0; subset < this->get_num_subsets(); ++subset)
323324
{
324-
const std::string current_sensitivity_filename
325-
= runtime_format(this->subsensitivity_filenames.c_str(), subset);
325+
const std::string current_sensitivity_filename = this->get_subsensitivity_filename(subset);
326326
info(format("Writing sensitivity to '{}'", current_sensitivity_filename));
327327
write_to_file(current_sensitivity_filename, this->get_subset_sensitivity(subset));
328328
}

0 commit comments

Comments
 (0)