Skip to content

Commit 79031b2

Browse files
committed
Make so Python EnergyCal channelEnergies() function returns a proper Python list
1 parent f5a4233 commit 79031b2

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

bindings/python/SpecFile_py.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,17 @@ bool loadFromUri_wrapper(SpecUtils::SpecFile* info, py::object pystream) {
979979
info->set_parse_warnings( remarks );
980980
}
981981

982+
py::list cal_channel_energies_wrapper( const SpecUtils::EnergyCalibration *cal )
983+
{
984+
py::list l;
985+
if( !cal->channel_energies() )
986+
return l;
987+
988+
for( auto p : *cal->channel_energies() )
989+
l.append( p );
990+
return l;
991+
}
992+
982993
std::shared_ptr<SpecUtils::EnergyCalibration> energyCalFromPolynomial_wrapper( const size_t num_channels,
983994
py::list py_coefs )
984995
{
@@ -1373,9 +1384,8 @@ py::class_<SpecUtils::EnergyCalibration>(m, "EnergyCalibration")
13731384
.def( "coefficients", &SpecUtils::EnergyCalibration::coefficients, py::rv_policy::reference_internal,
13741385
"Returns the list of energy calibration coeficients.\n"
13751386
"Will only be empty for SpecUtils.EnergyCalType.InvalidEquationType." )
1376-
// TODO: I think we should put a wrapper around channel_energies, and return a proper python list
1377-
.def( "channelEnergies", &SpecUtils::EnergyCalibration::channel_energies, py::rv_policy::reference_internal,
1378-
"Returns lower channel energies; will have one more entry than the number of channels." )
1387+
.def( "channelEnergies", &cal_channel_energies_wrapper,
1388+
"Returns lower channel energies; will have one more entry than the number of channels." )
13791389
.def( "deviationPairs", &SpecUtils::EnergyCalibration::deviation_pairs, py::rv_policy::reference_internal )
13801390
.def( "numChannels", &SpecUtils::EnergyCalibration::num_channels,
13811391
"Returns the number of channels this energy calibration is for." )

0 commit comments

Comments
 (0)