From 3b322fb7a312677fb10f6d957a6b1d24ccfb2dc6 Mon Sep 17 00:00:00 2001 From: Gennady Pospelov <g.pospelov@fz-juelich.de> Date: Wed, 28 Oct 2015 14:50:18 +0100 Subject: [PATCH] New doxygen group for input/output classes. --- Core/InputOutput/IntensityDataIOFactory.cpp | 21 +---------- Core/InputOutput/IntensityDataIOFactory.h | 29 +++++++++++---- Core/InputOutput/OutputDataReadFactory.h | 2 +- Core/InputOutput/OutputDataReadStrategy.h | 8 ++-- Core/InputOutput/OutputDataReader.h | 2 +- Core/InputOutput/OutputDataWriteFactory.h | 2 +- Core/InputOutput/OutputDataWriteStrategy.h | 8 ++-- Core/InputOutput/OutputDataWriter.h | 2 +- Core/InputOutput/TiffHandler.h | 2 +- .../src/IntensityDataIOFactory.pypp.cpp | 37 +++++-------------- Doc/Doxygen/defgroups.doc | 8 +++- Doc/Doxygen/userapi.doc | 3 ++ .../python/utils/plot_intensity_data_diff.py | 22 +++++------ dev-tools/python-bindings/settings_core.py | 2 +- 14 files changed, 68 insertions(+), 80 deletions(-) diff --git a/Core/InputOutput/IntensityDataIOFactory.cpp b/Core/InputOutput/IntensityDataIOFactory.cpp index e91a16a4e7d..381598e97da 100644 --- a/Core/InputOutput/IntensityDataIOFactory.cpp +++ b/Core/InputOutput/IntensityDataIOFactory.cpp @@ -31,17 +31,12 @@ OutputData<double > *IntensityDataIOFactory::readOutputData( return P_reader->getOutputData(); } -IHistogram *IntensityDataIOFactory::readHistogram(const std::string &file_name) +IHistogram *IntensityDataIOFactory::readIntensityData(const std::string &file_name) { boost::scoped_ptr<OutputData<double> > data(readOutputData(file_name)); return IHistogram::createHistogram(*data); } -IHistogram *IntensityDataIOFactory::readIntensityData(const std::string &file_name) -{ - return readHistogram(file_name); -} - /* ************************************************************************* */ @@ -54,21 +49,9 @@ void IntensityDataIOFactory::writeOutputData(const OutputData<double>& data, return P_writer->writeOutputData(data); } -//void IntensityDataIOFactory::writeOutputData(const IHistogram &histogram, -// const std::string &file_name) -//{ -// writeHistogram(histogram, file_name); -//} - -void IntensityDataIOFactory::writeHistogram(const IHistogram &histogram, - const std::string &file_name) +void IntensityDataIOFactory::writeIntensityData(const IHistogram &histogram, const std::string &file_name) { boost::scoped_ptr<OutputData<double> > data(histogram.createOutputData()); writeOutputData(*data, file_name); } -void IntensityDataIOFactory::writeIntensityData(const IHistogram &histogram, const std::string &file_name) -{ - writeHistogram(histogram, file_name); -} - diff --git a/Core/InputOutput/IntensityDataIOFactory.h b/Core/InputOutput/IntensityDataIOFactory.h index 114a4b17e7e..5bd191e2ff5 100644 --- a/Core/InputOutput/IntensityDataIOFactory.h +++ b/Core/InputOutput/IntensityDataIOFactory.h @@ -28,24 +28,39 @@ class IHistogram; //! @class IntensityDataIOFactory //! @ingroup input_output //! @brief Provides users with possibility to read and write IntensityData from/to files -//! in different format. +//! in different format. Type of the file will be deduced from file name. +//! *.txt - ASCII file with 2D array [nrow][ncol], layout as in numpy. +//! *.int - BornAgain internal ASCII format. +//! *.tif - 32-bits tiff file. +//! If file name ends woth "*.gz" or "*.bz2" the file will be zipped on the fly using +//! appropriate algorithm. + +/*! Usage: +\code{.py} +# reading from ASCII file or g-zipped ASCII file +histogram = IntensityDataIOFactory.readIntensityData("filename.txt") +histogram = IntensityDataIOFactory.readIntensityData("filename.txt.gz") + +# writing to 32-bits tiff file or b-zipped tiff file +IntensityDataIOFactory.writeIntensityData(histogram, "filename.tif") +IntensityDataIOFactory.writeIntensityData(histogram, "filename.tif.bz2") +\endcode +*/ class BA_CORE_API_ IntensityDataIOFactory { public: + //! Reads file and returns newly created OutputData object static OutputData<double > *readOutputData(const std::string& file_name); - static IHistogram *readHistogram(const std::string& file_name); - + //! Reads file and returns newly created Histogram object static IHistogram *readIntensityData(const std::string& file_name); - + //! Writes OutputData in file static void writeOutputData(const OutputData<double>& data, const std::string& file_name); - static void writeHistogram(const IHistogram &histogram, - const std::string& file_name); - + //! Writes histogram in file static void writeIntensityData(const IHistogram &histogram, const std::string& file_name); diff --git a/Core/InputOutput/OutputDataReadFactory.h b/Core/InputOutput/OutputDataReadFactory.h index c27f1a9f588..cd62f83ef45 100644 --- a/Core/InputOutput/OutputDataReadFactory.h +++ b/Core/InputOutput/OutputDataReadFactory.h @@ -23,7 +23,7 @@ class IOutputDataReadStrategy; //! @class OutputDataReadFactory -//! @ingroup input_output +//! @ingroup input_output_internal //! @brief Creates reader appropariate for given type of files class BA_CORE_API_ OutputDataReadFactory diff --git a/Core/InputOutput/OutputDataReadStrategy.h b/Core/InputOutput/OutputDataReadStrategy.h index ca05637ad68..b18368b9ca0 100644 --- a/Core/InputOutput/OutputDataReadStrategy.h +++ b/Core/InputOutput/OutputDataReadStrategy.h @@ -22,7 +22,7 @@ template <class T> class OutputData; //! @class IOutputDataReadStrategy -//! @ingroup input_output +//! @ingroup input_output_internal //! @brief Interface for reading strategy of OutputData from file class BA_CORE_API_ IOutputDataReadStrategy { @@ -34,7 +34,7 @@ private: //! @class OutputDataReadINTStrategy -//! @ingroup input_output +//! @ingroup input_output_internal //! @brief Strategy to read BornAgain native IntensityData from ASCII file class OutputDataReadINTStrategy : public IOutputDataReadStrategy { @@ -43,7 +43,7 @@ public: }; //! @class OutputDataReadNumpyTXTStrategy -//! @ingroup input_output +//! @ingroup input_output_internal //! @brief Strategy to read OutputData from simple ASCII file with the layout as in numpy.savetxt class OutputDataReadNumpyTXTStrategy : public IOutputDataReadStrategy { @@ -57,7 +57,7 @@ public: class TiffHandler; //! @class OutputDataReadTiffStrategy -//! @ingroup input_output +//! @ingroup input_output_internal //! @brief Reads tiff files class BA_CORE_API_ OutputDataReadTiffStrategy : public IOutputDataReadStrategy diff --git a/Core/InputOutput/OutputDataReader.h b/Core/InputOutput/OutputDataReader.h index e07a409e68b..e8260dcebbc 100644 --- a/Core/InputOutput/OutputDataReader.h +++ b/Core/InputOutput/OutputDataReader.h @@ -25,7 +25,7 @@ template <class T> class OutputData; //! @class OutputDataReader -//! @ingroup input_output +//! @ingroup input_output_internal //! @brief Reads OutputData from file using different reading strategies. class BA_CORE_API_ OutputDataReader diff --git a/Core/InputOutput/OutputDataWriteFactory.h b/Core/InputOutput/OutputDataWriteFactory.h index 1143d95e605..161497fe1f3 100644 --- a/Core/InputOutput/OutputDataWriteFactory.h +++ b/Core/InputOutput/OutputDataWriteFactory.h @@ -23,7 +23,7 @@ class IOutputDataWriteStrategy; //! @class OutputDataWriteFactory -//! @ingroup input_output +//! @ingroup input_output_internal //! @brief Creates writer appropariate for given type of files class BA_CORE_API_ OutputDataWriteFactory diff --git a/Core/InputOutput/OutputDataWriteStrategy.h b/Core/InputOutput/OutputDataWriteStrategy.h index d91eead9d0c..18fc4774b30 100644 --- a/Core/InputOutput/OutputDataWriteStrategy.h +++ b/Core/InputOutput/OutputDataWriteStrategy.h @@ -23,7 +23,7 @@ template <class T> class OutputData; //! @class IOutputDataWriteStrategy -//! @ingroup input_output +//! @ingroup input_output_internal //! @brief Strategy interface to write OututData in file class BA_CORE_API_ IOutputDataWriteStrategy @@ -38,7 +38,7 @@ protected: }; //! @class OutputDataWriteINTStrategy -//! @ingroup input_output +//! @ingroup input_output_internal //! @brief Strategy to write OutputData to special BornAgain ASCII format class OutputDataWriteINTStrategy : public IOutputDataWriteStrategy { @@ -47,7 +47,7 @@ public: }; //! @class OutputDataWriteNumpyTXTStrategy -//! @ingroup input_output +//! @ingroup input_output_internal //! @brief Strategy to write OutputData to simple ASCII file with the layout as in numpy.savetxt class OutputDataWriteNumpyTXTStrategy : public IOutputDataWriteStrategy { @@ -61,7 +61,7 @@ public: class TiffHandler; //! @class OutputDataWriteTiffStrategy -//! @ingroup input_output +//! @ingroup input_output_internal //! @brief Strategy to write OutputData to tiff files class OutputDataWriteTiffStrategy : public IOutputDataWriteStrategy { diff --git a/Core/InputOutput/OutputDataWriter.h b/Core/InputOutput/OutputDataWriter.h index 04f4a631d2c..ad5e180a933 100644 --- a/Core/InputOutput/OutputDataWriter.h +++ b/Core/InputOutput/OutputDataWriter.h @@ -24,7 +24,7 @@ template <class T> class OutputData; //! @class OutputDataWriter -//! @ingroup input_output +//! @ingroup input_output_internal //! @brief Write OutputData to file using different witing strategies class BA_CORE_API_ OutputDataWriter { diff --git a/Core/InputOutput/TiffHandler.h b/Core/InputOutput/TiffHandler.h index 8b1b37bc7c1..d0333dab505 100644 --- a/Core/InputOutput/TiffHandler.h +++ b/Core/InputOutput/TiffHandler.h @@ -26,7 +26,7 @@ #include <boost/scoped_ptr.hpp> //! @class TiffHandler -//! @ingroup input_output +//! @ingroup input_output_internal //! @brief Reads/write tiff files, should be used through TiffReadStrategy class BA_CORE_API_ TiffHandler diff --git a/Core/PythonAPI/src/IntensityDataIOFactory.pypp.cpp b/Core/PythonAPI/src/IntensityDataIOFactory.pypp.cpp index db22ab74cfd..68198a45f64 100644 --- a/Core/PythonAPI/src/IntensityDataIOFactory.pypp.cpp +++ b/Core/PythonAPI/src/IntensityDataIOFactory.pypp.cpp @@ -30,19 +30,8 @@ void register_IntensityDataIOFactory_class(){ { //::IntensityDataIOFactory typedef bp::class_< IntensityDataIOFactory > IntensityDataIOFactory_exposer_t; - IntensityDataIOFactory_exposer_t IntensityDataIOFactory_exposer = IntensityDataIOFactory_exposer_t( "IntensityDataIOFactory", "Provides users with possibility to read and write IntensityData from/to files in different format." ); + IntensityDataIOFactory_exposer_t IntensityDataIOFactory_exposer = IntensityDataIOFactory_exposer_t( "IntensityDataIOFactory" ); bp::scope IntensityDataIOFactory_scope( IntensityDataIOFactory_exposer ); - { //::IntensityDataIOFactory::readHistogram - - typedef ::IHistogram * ( *readHistogram_function_type )( ::std::string const & ); - - IntensityDataIOFactory_exposer.def( - "readHistogram" - , readHistogram_function_type( &::IntensityDataIOFactory::readHistogram ) - , ( bp::arg("file_name") ) - , bp::return_value_policy< bp::manage_new_object >() ); - - } { //::IntensityDataIOFactory::readIntensityData typedef ::IHistogram * ( *readIntensityData_function_type )( ::std::string const & ); @@ -51,7 +40,8 @@ void register_IntensityDataIOFactory_class(){ "readIntensityData" , readIntensityData_function_type( &::IntensityDataIOFactory::readIntensityData ) , ( bp::arg("file_name") ) - , bp::return_value_policy< bp::manage_new_object >() ); + , bp::return_value_policy< bp::manage_new_object >() + , "Reads file and returns newly created Histogram object." ); } { //::IntensityDataIOFactory::readOutputData @@ -62,17 +52,8 @@ void register_IntensityDataIOFactory_class(){ "readOutputData" , readOutputData_function_type( &::IntensityDataIOFactory::readOutputData ) , ( bp::arg("file_name") ) - , bp::return_value_policy< bp::manage_new_object >() ); - - } - { //::IntensityDataIOFactory::writeHistogram - - typedef void ( *writeHistogram_function_type )( ::IHistogram const &,::std::string const & ); - - IntensityDataIOFactory_exposer.def( - "writeHistogram" - , writeHistogram_function_type( &::IntensityDataIOFactory::writeHistogram ) - , ( bp::arg("histogram"), bp::arg("file_name") ) ); + , bp::return_value_policy< bp::manage_new_object >() + , "Reads file and returns newly created OutputData object." ); } { //::IntensityDataIOFactory::writeIntensityData @@ -82,7 +63,8 @@ void register_IntensityDataIOFactory_class(){ IntensityDataIOFactory_exposer.def( "writeIntensityData" , writeIntensityData_function_type( &::IntensityDataIOFactory::writeIntensityData ) - , ( bp::arg("histogram"), bp::arg("file_name") ) ); + , ( bp::arg("histogram"), bp::arg("file_name") ) + , "Writes histogram in file." ); } { //::IntensityDataIOFactory::writeOutputData @@ -92,13 +74,12 @@ void register_IntensityDataIOFactory_class(){ IntensityDataIOFactory_exposer.def( "writeOutputData" , writeOutputData_function_type( &::IntensityDataIOFactory::writeOutputData ) - , ( bp::arg("data"), bp::arg("file_name") ) ); + , ( bp::arg("data"), bp::arg("file_name") ) + , "Writes OutputData in file." ); } - IntensityDataIOFactory_exposer.staticmethod( "readHistogram" ); IntensityDataIOFactory_exposer.staticmethod( "readIntensityData" ); IntensityDataIOFactory_exposer.staticmethod( "readOutputData" ); - IntensityDataIOFactory_exposer.staticmethod( "writeHistogram" ); IntensityDataIOFactory_exposer.staticmethod( "writeIntensityData" ); IntensityDataIOFactory_exposer.staticmethod( "writeOutputData" ); } diff --git a/Doc/Doxygen/defgroups.doc b/Doc/Doxygen/defgroups.doc index 134973e722b..7afb0a16c54 100644 --- a/Doc/Doxygen/defgroups.doc +++ b/Doc/Doxygen/defgroups.doc @@ -51,7 +51,13 @@ @brief Different tools. \defgroup tools_internal -@brief More different tools. +@brief Tools internal classes. + +\defgroup input_output Input and output +@brief Various routines for input/output. + +\defgroup input_output_internal +@brief Input/output internal classes. */ diff --git a/Doc/Doxygen/userapi.doc b/Doc/Doxygen/userapi.doc index daf004d227d..7ccd006fe41 100644 --- a/Doc/Doxygen/userapi.doc +++ b/Doc/Doxygen/userapi.doc @@ -18,6 +18,8 @@ List of implemented interference functions Additional routines <li> \ref tools "Tools" <BR> Different tools mainly to deal with intensity data +<li> \ref input_output "Input and output" <BR> +Various routines to write intensity data on disk and to import user data. <li> \ref fitting "Fitting" <BR> Fitting routines </ul> @@ -32,6 +34,7 @@ Here is a list of additional classes from internal API. <li> \ref interference_internal "Interference functions (internal)" <li> \ref algorithms_internal "Algorithms (internal)" <BR> <li> \ref tools_internal "Tools (internal)" <BR> +<li> \ref input_output_internal "Input/output (internal)" <BR> <li> \ref fitting_internal "Fitting (internal)" <BR> </ul> diff --git a/Examples/python/utils/plot_intensity_data_diff.py b/Examples/python/utils/plot_intensity_data_diff.py index 871c9daf2e4..9cdb91b59fa 100644 --- a/Examples/python/utils/plot_intensity_data_diff.py +++ b/Examples/python/utils/plot_intensity_data_diff.py @@ -4,27 +4,27 @@ import numpy import matplotlib -import pylab +from matplotlib import pyplot as plt from bornagain import * def plot_intensity_data(ref, data): - phi_min = rad2deg(ref.getAxis(0).getMin()) - phi_max = rad2deg(ref.getAxis(0).getMax()) - alpha_min = rad2deg(ref.getAxis(1).getMin()) - alpha_max = rad2deg(ref.getAxis(1).getMax()) - im = pylab.imshow(numpy.rot90(data, 1), norm=matplotlib.colors.LogNorm(), - extent=[phi_min, phi_max, alpha_min, alpha_max]) - cb = pylab.colorbar(im) + im = plt.imshow(data, + norm=matplotlib.colors.LogNorm(), + extent=[ref.getXmin()/deg, ref.getXmax()/deg, ref.getYmin()/deg, ref.getYmax()/deg], + aspect='auto') + + cb = plt.colorbar(im) cb.set_label(r'Intensity (arb. u.)', size=16) - pylab.xlabel(r'$\phi_f (^{\circ})$', fontsize=16) - pylab.ylabel(r'$\alpha_f (^{\circ})$', fontsize=16) - pylab.show() + plt.xlabel(r'$\phi_f (^{\circ})$', fontsize=16) + plt.ylabel(r'$\alpha_f (^{\circ})$', fontsize=16) + plt.show() if __name__ == '__main__': if len(sys.argv)!=3: exit("Usage: python plot_intensity_data_diff.py intensity_reference.int.gz intensity_other.int.gz") + print "xxx" intensity_ref = IntensityDataIOFactory.readIntensityData(sys.argv[1]) intensity_other = IntensityDataIOFactory.readIntensityData(sys.argv[2]) data = numpy.abs((intensity_ref.getArray() - intensity_other.getArray())/intensity_ref.getArray()) diff --git a/dev-tools/python-bindings/settings_core.py b/dev-tools/python-bindings/settings_core.py index 1e4ea74184d..319a0650af2 100644 --- a/dev-tools/python-bindings/settings_core.py +++ b/dev-tools/python-bindings/settings_core.py @@ -410,7 +410,7 @@ def ManualClassTunings(mb): cl = mb.class_("IntensityDataIOFactory") cl.member_function("readOutputData").call_policies = call_policies.return_value_policy(call_policies.manage_new_object) - cl.member_function("readHistogram").call_policies = call_policies.return_value_policy(call_policies.manage_new_object) + # cl.member_function("readHistogram").call_policies = call_policies.return_value_policy(call_policies.manage_new_object) cl.member_function("readIntensityData").call_policies = call_policies.return_value_policy(call_policies.manage_new_object) -- GitLab