26 , m_vec(m_frame->size())
65 for (
double& e :
m_vec)
121 std::vector<double> ret(
size());
122 for (
size_t i = 0; i <
size(); ++i)
132 for (
size_t i = 0; i <
frame().
size(); ++i)
133 out[i] =
m_vec[i] / maxval;
139 return *std::max_element(
m_vec.begin(),
m_vec.end());
144 return *std::min_element(
m_vec.begin(),
m_vec.end());
149 const std::unique_ptr<IAxis> xaxis{
xAxis().
clone()};
150 const std::unique_ptr<IAxis> yaxis{
yAxis().
clone()};
151 xaxis->
clip(xmin, xmax);
152 yaxis->clip(ymin, ymax);
154 std::vector<double> out(
size());
156 for (
size_t i = 0; i <
size(); ++i) {
157 double x =
m_frame->projectedCoord(i, 0);
158 double y =
m_frame->projectedCoord(i, 1);
159 if (xaxis->contains(x) && yaxis->contains(y))
160 out[iout++] =
m_vec[i];
167 const std::unique_ptr<IAxis> xaxis{
xAxis().
clone()};
168 xaxis->
clip(xmin, xmax);
169 std::vector<double> out(
size());
171 for (
size_t i = 0; i <
size(); ++i) {
172 const double x =
m_frame->projectedCoord(i, 0);
173 if (xaxis->contains(x))
174 out[iout++] =
m_vec[i];
179 #ifdef BORNAGAIN_PYTHON
183 std::vector<size_t> dimensions;
184 for (
size_t i = 0; i <
rank(); i++)
185 dimensions.push_back(
axis(i).
size());
188 if (dimensions.size() == 2)
189 std::swap(dimensions[0], dimensions[1]);
192 npy_int ndim_numpy = (int)dimensions.size();
193 auto* ndimsizes_numpy =
new npy_intp[dimensions.size()];
194 for (
size_t i = 0; i < dimensions.size(); i++)
195 ndimsizes_numpy[i] = dimensions[i];
198 PyObject* pyarray = PyArray_SimpleNew(ndim_numpy, ndimsizes_numpy, NPY_DOUBLE);
199 delete[] ndimsizes_numpy;
203 double* array_buffer = (
double*)PyArray_DATA((PyArrayObject*)pyarray);
207 for (
size_t i = 0; i <
size(); ++i) {
208 std::vector<int> axes_indices =
m_frame->allIndices(i);
211 array_buffer[offset] = (*this)[i];
214 for (
size_t i = 0; i <
size(); ++i)
215 *array_buffer++ = (*
this)[i];
263 for (
size_t i = 0; i <
size(); ++i) {
264 int ybin =
static_cast<int>(
m_frame->projectedIndex(i, 1));
265 if (ybin >= ybinlow && ybin <= ybinup) {
266 double x =
m_frame->projectedCoord(i, 0);
269 out[iout] +=
valAt(i);
278 for (
size_t i = 0; i <
size(); ++i) {
279 int xbin =
static_cast<int>(
m_frame->projectedIndex(i, 0));
280 if (xbin >= xbinlow && xbin <= xbinup) {
284 double y =
m_frame->projectedCoord(i, 1);
287 out[iout] +=
valAt(i);
Defines the macro ASSERT.
#define ASSERT(condition)
Defines and implements templated class Datafield.
Defines class FixedBinAxis.
Defines and implements templated class Frame.
Includes python header and takes care of warnings.
Defines struct ThreadInfo.
Stores radiation power per bin.
std::vector< double > m_vec
PyObject * npArray() const
Returns data as Python numpy array.
const IAxis & axis(size_t k) const
double valAt(size_t i) const
Datafield(Frame *frame)
Constructor that takes ownership of supplied frame.
bool hasSameShape(const Datafield &other) const
Returns true if objects a) have same dimensions b) bin boundaries of axes coincide.
Datafield * clone() const
Datafield * crop(double xmin, double ymin, double xmax, double ymax) const
std::unique_ptr< Frame > m_frame
void setVector(const std::vector< double > &data_vector)
Sets new values to raw data vector.
Datafield * xProjection()
Project a 2D histogram into 1D histogram along X. The projection is made from all bins along y-axis.
bool hasSameSizes(const Datafield &other) const
Returns true if object have same dimensions and number of axes bins.
std::vector< double > flatVector() const
Returns copy of raw data vector.
Datafield * normalizedToMaximum() const
Datafield * create_yProjection(int xbinlow, int xbinup)
Creates projection along Y. The projections is made by collecting the data in the range between [xbin...
const IAxis & yAxis() const
Datafield * yProjection()
Project a 2D histogram into 1D histogram along Y. The projection is made from all bins along x-axis.
size_t size() const
Returns total size of data buffer (product of bin number in every dimension).
Datafield * create_xProjection(int ybinlow, int ybinup)
Creates projection along X. The projections is made by collecting the data in the range between [ybin...
void setAllTo(const double &value)
Sets content of output data to specific value.
const IAxis & xAxis() const
const Frame & frame() const
void setAt(size_t i, double val)
size_t size() const
Returns total number of bins.
bool hasSameSizes(const Frame &) const
Returns true if both Frames have same rank, and all axes have same sizes.
Abstract base class for one-dimensional axes.
virtual size_t findClosestIndex(double value) const =0
find bin index which is best match for given value
virtual IAxis * clone() const =0
virtual size_t size() const =0
Returns the number of bins.
virtual void clip(double lower, double upper)
Clips this axis to the given values.