Commit 857b0c9803e0b9e3e8801360d544f98e5f5a5e8d
1 parent
f438e519
Add stamp() methods to GApplication (#3662)
Showing
8 changed files
with
118 additions
and
7 deletions
ChangeLog
NEWS
| 1 | 1 | New Features and Important Changes in GammaLib 2.0.0 |
| 2 | 2 | |
| 3 | -30 April 2021 | |
| 3 | +8 May 2021 | |
| 4 | 4 | |
| 5 | 5 | |
| 6 | 6 | 1. Introduction |
| ... | ... | @@ -31,6 +31,9 @@ The following classes have been renamed: |
| 31 | 31 | |
| 32 | 32 | The following methods have been added: |
| 33 | 33 | - GApplication::eCO2() |
| 34 | +- GApplication::stamp(GFitsHdu&) | |
| 35 | +- GApplication::stamp(GFits&) | |
| 36 | +- GApplication::stamp(GFilename&) | |
| 34 | 37 | - GFitsTableCol::tscale() |
| 35 | 38 | - GResponse::convolve(GModelSky&, GObservation&, GMatrixSparse*) |
| 36 | 39 | - GResponse::irf_spatial(GModelSky&, GObservation&, GMatrix*) |
| ... | ... | @@ -132,6 +135,10 @@ Add Astrophysics Source Code Library (ASCL) shield to "About" page (#3630) |
| 132 | 135 | |
| 133 | 136 | 5. Application module |
| 134 | 137 | --------------------- |
| 138 | +Add GApplication::stamp() methods to write provenance information into a FITS | |
| 139 | +HDU, a FITS object or a FITS file. So far the only provenance information that | |
| 140 | +is written is the CREATOR keyword (#3662). | |
| 141 | + | |
| 135 | 142 | Add GApplication::eCO2() method to estimate the carbon footprint if the elapsed |
| 136 | 143 | CPU time. The carbon footprint estimation is also added to the trailer text of |
| 137 | 144 | an application to raise awareness (#3592). | ... | ... |
README.md
| 1 | 1 | GammaLib information |
| 2 | 2 | ==================== |
| 3 | -* Version: 2.0.0.dev (30 April 2021) | |
| 3 | +* Version: 2.0.0.dev (5 May 2021) | |
| 4 | 4 | |
| 5 | 5 | [](https://cta-jenkins.irap.omp.eu/job/gammalib-integrate-os/) |
| 6 | 6 | ... | ... |
doc/source/admin/release_history/2.0.rst
| 1 | 1 | .. _2.0: |
| 2 | 2 | |
| 3 | -GammaLib 2.0 release (30 April 2021) | |
| 4 | -==================================== | |
| 3 | +GammaLib 2.0 release (8 May 2021) | |
| 4 | +================================= | |
| 5 | 5 | |
| 6 | 6 | Overview |
| 7 | 7 | -------- |
| ... | ... | @@ -33,6 +33,8 @@ Bug fixes |
| 33 | 33 | Improvements |
| 34 | 34 | ------------ |
| 35 | 35 | |
| 36 | +* [`3662 <https://cta-redmine.irap.omp.eu/issues/3662>`_] - | |
| 37 | + Add ``stamp()`` methods to ``GApplication`` | |
| 36 | 38 | * [`3630 <https://cta-redmine.irap.omp.eu/issues/3630>`_] - |
| 37 | 39 | Add ASCL shield to **About** page |
| 38 | 40 | * [`3626 <https://cta-redmine.irap.omp.eu/issues/3626>`_] - | ... | ... |
include/GApplication.hpp
| ... | ... | @@ -35,6 +35,11 @@ |
| 35 | 35 | #include "GLog.hpp" |
| 36 | 36 | #include "GApplicationPars.hpp" |
| 37 | 37 | |
| 38 | +/* __ Forward declarations _______________________________________________ */ | |
| 39 | +class GFitsHDU; | |
| 40 | +class GFits; | |
| 41 | +class GFilename; | |
| 42 | + | |
| 38 | 43 | |
| 39 | 44 | /***********************************************************************//** |
| 40 | 45 | * @class GApplication |
| ... | ... | @@ -115,6 +120,9 @@ public: |
| 115 | 120 | const GApplicationPars& pars(void) const; |
| 116 | 121 | void pars(const GApplicationPars& pars); |
| 117 | 122 | const std::vector<std::string>& args(void) const; |
| 123 | + void stamp(GFitsHDU& hdu) const; | |
| 124 | + void stamp(GFits& fits) const; | |
| 125 | + void stamp(const GFilename& filename) const; | |
| 118 | 126 | std::string print(const GChatter& chatter = NORMAL) const; |
| 119 | 127 | |
| 120 | 128 | // Public members | ... | ... |
pyext/GApplication.i
| ... | ... | @@ -83,6 +83,7 @@ public: |
| 83 | 83 | %rename(_log_trailer) log_trailer; |
| 84 | 84 | %rename(_need_help) need_help; |
| 85 | 85 | %rename(_args) args; |
| 86 | + %rename(_stamp) stamp; | |
| 86 | 87 | %rename(_log) log; |
| 87 | 88 | |
| 88 | 89 | // Methods |
| ... | ... | @@ -105,6 +106,9 @@ public: |
| 105 | 106 | const bool& need_help(void) const; |
| 106 | 107 | const GApplicationPars& pars(void) const; |
| 107 | 108 | void pars(const GApplicationPars& pars); |
| 109 | + void stamp(GFitsHDU& hdu) const; | |
| 110 | + void stamp(GFits& fits) const; | |
| 111 | + void stamp(const GFilename& filename) const; | |
| 108 | 112 | const std::vector<std::string>& args(void) const; |
| 109 | 113 | |
| 110 | 114 | // Public members | ... | ... |
src/app/GApplication.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GApplication.cpp - GammaLib application base class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2020 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2021 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -30,6 +30,9 @@ |
| 30 | 30 | #endif |
| 31 | 31 | #include "GApplication.hpp" |
| 32 | 32 | #include "GTools.hpp" |
| 33 | +#include "GFits.hpp" | |
| 34 | +#include "GFitsHDU.hpp" | |
| 35 | +#include "GFilename.hpp" | |
| 33 | 36 | |
| 34 | 37 | /* __ OpenMP section _____________________________________________________ */ |
| 35 | 38 | #ifdef _OPENMP |
| ... | ... | @@ -893,6 +896,68 @@ void GApplication::log_parameters(const GChatter& chatter) |
| 893 | 896 | |
| 894 | 897 | |
| 895 | 898 | /***********************************************************************//** |
| 899 | + * @brief Stamp FITS header with provenance information | |
| 900 | + * | |
| 901 | + * @param[in] hdu FITS header. | |
| 902 | + * | |
| 903 | + * Write provenance information into a FITS header. | |
| 904 | + ***************************************************************************/ | |
| 905 | +void GApplication::stamp(GFitsHDU& hdu) const | |
| 906 | +{ | |
| 907 | + // Set provenance information | |
| 908 | + std::string creator = name() + " v" + version(); | |
| 909 | + | |
| 910 | + // Write provenance information | |
| 911 | + hdu.card("CREATOR", creator, "Program which created the file"); | |
| 912 | + | |
| 913 | + // Return | |
| 914 | + return; | |
| 915 | +} | |
| 916 | + | |
| 917 | + | |
| 918 | +/***********************************************************************//** | |
| 919 | + * @brief Stamp all headers in FITS object with provenance information | |
| 920 | + * | |
| 921 | + * @param[in] fits FITS object. | |
| 922 | + * | |
| 923 | + * Write provenance information into all headers of FITS object. | |
| 924 | + ***************************************************************************/ | |
| 925 | +void GApplication::stamp(GFits& fits) const | |
| 926 | +{ | |
| 927 | + // Loop over FITS headers | |
| 928 | + for (int i = 0; i < fits.size(); ++i) { | |
| 929 | + stamp(*fits[i]); | |
| 930 | + } | |
| 931 | + | |
| 932 | + // Return | |
| 933 | + return; | |
| 934 | +} | |
| 935 | + | |
| 936 | + | |
| 937 | +/***********************************************************************//** | |
| 938 | + * @brief Stamp all headers in FITS file with provenance information | |
| 939 | + * | |
| 940 | + * @param[in] filename FITS file name. | |
| 941 | + * | |
| 942 | + * Write provenance information into all headers of FITS file. | |
| 943 | + ***************************************************************************/ | |
| 944 | +void GApplication::stamp(const GFilename& filename) const | |
| 945 | +{ | |
| 946 | + // Open FITS file | |
| 947 | + GFits fits(filename); | |
| 948 | + | |
| 949 | + // Stamp headers | |
| 950 | + stamp(fits); | |
| 951 | + | |
| 952 | + // Save FITS file | |
| 953 | + fits.save(true); | |
| 954 | + | |
| 955 | + // Return | |
| 956 | + return; | |
| 957 | +} | |
| 958 | + | |
| 959 | + | |
| 960 | +/***********************************************************************//** | |
| 896 | 961 | * @brief Print application |
| 897 | 962 | * |
| 898 | 963 | * @param[in] chatter Chattiness. | ... | ... |
test/test_GApplication.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * test_GApplication.cpp - test GApplication classes * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2012-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2012-2021 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -673,6 +673,30 @@ void TestGApplication::test_GApplication(void) |
| 673 | 673 | |
| 674 | 674 | } // endif: log file existed |
| 675 | 675 | |
| 676 | + // Check stamping of FITS HDU | |
| 677 | + GFitsBinTable table1; | |
| 678 | + app1.stamp(table1); | |
| 679 | + test_value(table1.string("CREATOR"), "test_GApplication v1.0.0", | |
| 680 | + "Check stamping of FITS HDU"); | |
| 681 | + | |
| 682 | + // Check stamping of FITS object | |
| 683 | + GFits fits1; | |
| 684 | + GFitsBinTable table2; | |
| 685 | + fits1.append(table2); | |
| 686 | + app1.stamp(fits1); | |
| 687 | + test_value(fits1[0]->string("CREATOR"), "test_GApplication v1.0.0", | |
| 688 | + "Check stamping of FITS object"); | |
| 689 | + | |
| 690 | + // Check stamping of FITS file | |
| 691 | + GFits fits2; | |
| 692 | + GFitsBinTable table3; | |
| 693 | + fits2.append(table3); | |
| 694 | + fits2.saveto("test_application.fits", true); | |
| 695 | + app1.stamp("test_application.fits"); | |
| 696 | + GFits fits3("test_application.fits"); | |
| 697 | + test_value(fits3[0]->string("CREATOR"), "test_GApplication v1.0.0", | |
| 698 | + "Check stamping of FITS file"); | |
| 699 | + | |
| 676 | 700 | // Return |
| 677 | 701 | return; |
| 678 | 702 | } | ... | ... |