BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
DataUtils.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Device/Data/DataUtils.h
6 //! @brief Defines namespace DataUtils.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_DEVICE_DATA_DATAUTILS_H
16 #define BORNAGAIN_DEVICE_DATA_DATAUTILS_H
17 
18 #include "Device/Data/OutputData.h"
19 #include <memory>
20 
21 namespace DataUtils {
22 
23 //! Returns relative difference between two data sets sum(dat[i] - ref[i])/ref[i]).
24 double relativeDataDifference(const OutputData<double>& dat, const OutputData<double>& ref);
25 
26 //! Returns true is relative difference is below threshold; prints informative output
28  const double threshold);
29 
30 //! Transforms coordinate on axis into the bin-fraction-coordinate.
31 double coordinateToBinf(double coordinate, const IAxis& axis);
32 
33 //! Transforms bin-fraction-coordinate into axis coordinate.
34 double coordinateFromBinf(double value, const IAxis& axis);
35 
36 //! Transforms x,y coordinate from OutputData axes coordinates to bin-fraction-coordinates.
37 void coordinateToBinf(double& x, double& y, const OutputData<double>& data);
38 
39 //! Transforms x,y coordinate from bin-fraction-coordinates to OutputData's axes coordinates.
40 void coordinateFromBinf(double& x, double& y, const OutputData<double>& data);
41 
42 //! Creates a vector of vectors of double (2D Array) from OutputData.
43 std::vector<std::vector<double>> create2DArrayfromOutputData(const OutputData<double>& data);
44 
45 //! Reads 1D array of doubles to Python, for use in persistence test
46 OutputData<double>* importArrayToOutputData(const std::vector<double>& vec);
47 //! Reads 2D array of doubles to Python, for use in persistence test
48 OutputData<double>* importArrayToOutputData(const std::vector<std::vector<double>>& vec);
49 
50 #ifndef SWIG
51 
52 std::unique_ptr<OutputData<double>>
54 
55 //! Returns new object with input data rotated by
56 //! n*90 deg counterclockwise (n > 0) or clockwise (n < 0)
57 //! Axes are swapped if the data is effectively rotated by 90 or 270 degrees
58 //! Applicable to 2D arrays only
59 std::unique_ptr<OutputData<double>> createRearrangedDataSet(const OutputData<double>& data, int n);
60 
61 //! Returns new IntensityData objects which axes clipped to represent the specified rectangle.
62 std::unique_ptr<OutputData<double>>
63 createClippedDataSet(const OutputData<double>& origin, double x1, double y1, double x2, double y2);
64 
65 //! Creates OutputData from a 2D Array.
66 std::unique_ptr<OutputData<double>>
67 createOutputDatafrom2DArray(const std::vector<std::vector<double>>& array_2d);
68 
69 //! Creates Fourier Transform (OutputData format) of intensity map (OutputData format).
70 std::unique_ptr<OutputData<double>> createFFT(const OutputData<double>& data);
71 
72 #endif // SWIG
73 
74 } // namespace DataUtils
75 
76 #endif // BORNAGAIN_DEVICE_DATA_DATAUTILS_H
Defines and implements templated class OutputData.
Interface for one-dimensional axes.
Definition: IAxis.h:25
double coordinateToBinf(double coordinate, const IAxis &axis)
Transforms coordinate on axis into the bin-fraction-coordinate.
Definition: DataUtils.cpp:169
bool checkRelativeDifference(const OutputData< double > &dat, const OutputData< double > &ref, const double threshold)
Returns true is relative difference is below threshold; prints informative output.
Definition: DataUtils.cpp:51
double relativeDataDifference(const OutputData< double > &dat, const OutputData< double > &ref)
Returns relative difference between two data sets sum(dat[i] - ref[i])/ref[i]).
Definition: DataUtils.cpp:35
std::unique_ptr< OutputData< double > > createRelativeDifferenceData(const OutputData< double > &data, const OutputData< double > &reference)
Definition: DataUtils.cpp:69
std::unique_ptr< OutputData< double > > createClippedDataSet(const OutputData< double > &origin, double x1, double y1, double x2, double y2)
Returns new IntensityData objects which axes clipped to represent the specified rectangle.
Definition: DataUtils.cpp:128
std::unique_ptr< OutputData< double > > createFFT(const OutputData< double > &data)
Creates Fourier Transform (OutputData format) of intensity map (OutputData format).
Definition: DataUtils.cpp:256
std::vector< std::vector< double > > create2DArrayfromOutputData(const OutputData< double > &data)
Creates a vector of vectors of double (2D Array) from OutputData.
Definition: DataUtils.cpp:209
std::unique_ptr< OutputData< double > > createOutputDatafrom2DArray(const std::vector< std::vector< double >> &array_2d)
Creates OutputData from a 2D Array.
Definition: DataUtils.cpp:235
double coordinateFromBinf(double value, const IAxis &axis)
Transforms bin-fraction-coordinate into axis coordinate.
Definition: DataUtils.cpp:177
OutputData< double > * importArrayToOutputData(const std::vector< double > &vec)
Reads 1D array of doubles to Python, for use in persistence test.
Definition: DataUtils.cpp:263
std::unique_ptr< OutputData< double > > createRearrangedDataSet(const OutputData< double > &data, int n)
Returns new object with input data rotated by n*90 deg counterclockwise (n > 0) or clockwise (n < 0) ...
Definition: DataUtils.cpp:82