Skip to content

Commit 4d16249

Browse files
author
Arthur Glowacki
committed
added function to replace NaN/Inf with low values near zero
1 parent 57aa4f2 commit 4d16249

5 files changed

Lines changed: 36 additions & 0 deletions

File tree

src/data_struct/spectra.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,18 @@ class Spectra : public ArrayTr<_T>
164164
}
165165
}
166166

167+
void set_nan_to_near_zero()
168+
{
169+
for(Eigen::Index i = 0; i < this->size(); i++)
170+
{
171+
if( false == std::isfinite((*this)[i]) )
172+
{
173+
(*this)[i] = default_time_and_io_counts;
174+
}
175+
}
176+
// this = this.unaryExpr([](double v) { return std::isfinite(v) ? v : default_time_and_io_counts; });
177+
}
178+
167179
void add(const Spectra<_T>& spectra)
168180
{
169181
*this += (ArrayTr<_T>)spectra;

src/data_struct/spectra_line.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,16 @@ void Spectra_Line<T_real>::recalc_elapsed_livetime()
136136
_data_line[i].recalc_elapsed_livetime();
137137
}
138138
}
139+
// ----------------------------------------------------------------------------
140+
141+
template<typename T_real>
142+
void Spectra_Line<T_real>::set_nan_to_near_zero()
143+
{
144+
for(size_t i=0; i<_data_line.size(); i++)
145+
{
146+
_data_line[i].set_nan_to_near_zero();
147+
}
148+
}
139149

140150
// ----------------------------------------------------------------------------
141151
// ----------------------------------------------------------------------------

src/data_struct/spectra_line.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ class DLL_EXPORT Spectra_Line
8383

8484
size_t samples_size() const { if (_data_line.size() > 0) return _data_line[0].size(); else return 0; }
8585

86+
void set_nan_to_near_zero();
87+
8688
private:
8789

8890

src/data_struct/spectra_volume.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,17 @@ void Spectra_Volume<T_real>::recalc_elapsed_livetime()
212212

213213
// ----------------------------------------------------------------------------
214214

215+
template<typename T_real>
216+
void Spectra_Volume<T_real>::set_nan_to_near_zero()
217+
{
218+
for(size_t i=0; i<_data_vol.size(); i++)
219+
{
220+
_data_vol[i].set_nan_to_near_zero();
221+
}
222+
}
223+
224+
// ----------------------------------------------------------------------------
225+
215226
template<typename T_real>
216227
void Spectra_Volume<T_real>::generate_scaler_maps(std::map<std::string, Scaler_Map<T_real>> *scaler_maps)
217228
{

src/data_struct/spectra_volume.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class DLL_EXPORT Spectra_Volume
9292

9393
int rank() { return 3; }
9494

95+
void set_nan_to_near_zero();
9596
private:
9697

9798
std::vector<Spectra_Line<T_real> > _data_vol;

0 commit comments

Comments
 (0)