BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
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 <memory>
19 #include <string>
20 #include <vector>
21 
22 class Datafield;
23 
24 namespace DataUtils::Data {
25 
26 //! Creates a vector of vectors of double (2D Array) from Datafield.
27 std::vector<std::vector<double>> create2DArrayfromDatafield(const Datafield& data);
28 
29 //! Reads 1D array of doubles to Python, for use in persistence test
30 Datafield* importArrayToDatafield(const std::vector<double>& vec);
31 //! Reads 2D array of doubles to Python, for use in persistence test
32 Datafield* importArrayToDatafield(const std::vector<std::vector<double>>& vec);
33 
34 //! Returns vector of peak center coordinates, for peaks in given histogram.
35 std::vector<std::pair<double, double>> FindPeaks(const Datafield& hist, double sigma = 2,
36  const std::string& option = {},
37  double threshold = 0.05);
38 
39 #ifndef SWIG
40 
41 //! Returns new object with input data rotated by
42 //! n*90 deg counterclockwise (n > 0) or clockwise (n < 0)
43 //! Axes are swapped if the data is effectively rotated by 90 or 270 degrees
44 //! Applicable to 2D arrays only
45 std::unique_ptr<Datafield> createRearrangedDataSet(const Datafield& data, int n);
46 
47 //! Creates Datafield from a 2D Array.
48 std::unique_ptr<Datafield> vecvecToDatafield(const std::vector<std::vector<double>>& array_2d);
49 
50 //! Creates Fourier Transform (Datafield format) of intensity map (Datafield format).
51 std::unique_ptr<Datafield> createFFT(const Datafield& data);
52 
53 #endif // SWIG
54 
55 } // namespace DataUtils::Data
56 
57 #endif // BORNAGAIN_DEVICE_DATA_DATAUTILS_H
Stores radiation power per bin.
Definition: Datafield.h:30
Datafield * importArrayToDatafield(const std::vector< double > &vec)
Reads 1D array of doubles to Python, for use in persistence test.
Definition: DataUtils.cpp:137
std::unique_ptr< Datafield > vecvecToDatafield(const std::vector< std::vector< double >> &array_2d)
Creates Datafield from a 2D Array.
Definition: DataUtils.cpp:109
std::unique_ptr< Datafield > createRearrangedDataSet(const Datafield &data, int n)
Returns new object with input data rotated by n*90 deg counterclockwise (n > 0) or clockwise (n < 0) ...
Definition: DataUtils.cpp:41
std::vector< std::pair< double, double > > FindPeaks(const Datafield &hist, double sigma=2, const std::string &option={}, double threshold=0.05)
Returns vector of peak center coordinates, for peaks in given histogram.
Definition: DataUtils.cpp:147
std::unique_ptr< Datafield > createFFT(const Datafield &data)
Creates Fourier Transform (Datafield format) of intensity map (Datafield format).
Definition: DataUtils.cpp:130
std::vector< std::vector< double > > create2DArrayfromDatafield(const Datafield &data)
Creates a vector of vectors of double (2D Array) from Datafield.
Definition: DataUtils.cpp:83