Commit 9a18f090eabb256f78bdafca3086f597fd4bcb23

Authored by Jürgen Knödlseder
1 parent 28bd0159

Fix GSkyMap::publish() bug for empty sky maps (#1835)

ChangeLog
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 * Version 1.2.0 released 3 * Version 1.2.0 released
4 ========================= 4 =========================
5 5
  6 + Fix GSkyMap::publish() bug for empty sky maps (#1835)
6 Fix loss of application name and version (#1835) 7 Fix loss of application name and version (#1835)
7 Add methods for logging in applications (#1828) 8 Add methods for logging in applications (#1828)
8 Fix removal of Python wrappers after make clean (#1826) 9 Fix removal of Python wrappers after make clean (#1826)
@@ -38,7 +38,7 @@ The parameters for the following methods have been changed: @@ -38,7 +38,7 @@ The parameters for the following methods have been changed:
38 - GApplication::log_parameters() now has a mandatory GChatter argument 38 - GApplication::log_parameters() now has a mandatory GChatter argument
39 39
40 The return value of the following methods has been changed: 40 The return value of the following methods has been changed:
41 -- ... 41 +- GSkyMap::write() now returns a pointer to GFitsHDU instead of void
42 42
43 43
44 3. Configuration 44 3. Configuration
@@ -109,7 +109,10 @@ None @@ -109,7 +109,10 @@ None
109 109
110 12. Sky module 110 12. Sky module
111 -------------- 111 --------------
112 -None 112 +The GSkyMap::write() method now returns a pointer to the written GFitsHDU
  113 +object. In case that no sky map is written, for example because none has been
  114 +defined so far, the method returns NONE. The GSkyMap::publish() method will
  115 +detect the NONE value and will do nothing if no sky map exists (#1835).
113 116
114 117
115 13. Support module 118 13. Support module
include/GSkyMap.hpp
@@ -163,7 +163,7 @@ public: @@ -163,7 +163,7 @@ public:
163 void save(const GFilename& filename, 163 void save(const GFilename& filename,
164 const bool& clobber = false) const; 164 const bool& clobber = false) const;
165 void read(const GFitsHDU& hdu); 165 void read(const GFitsHDU& hdu);
166 - void write(GFits& file, 166 + GFitsHDU* write(GFits& file,
167 const std::string& extname = "") const; 167 const std::string& extname = "") const;
168 void publish(const std::string& name = "") const; 168 void publish(const std::string& name = "") const;
169 std::string print(const GChatter& chatter = NORMAL) const; 169 std::string print(const GChatter& chatter = NORMAL) const;
pyext/GSkyMap.i
@@ -178,7 +178,7 @@ public: @@ -178,7 +178,7 @@ public:
178 void save(const GFilename& filename, 178 void save(const GFilename& filename,
179 const bool& clobber = false) const; 179 const bool& clobber = false) const;
180 void read(const GFitsHDU& hdu); 180 void read(const GFitsHDU& hdu);
181 - void write(GFits& file, 181 + GFitsHDU* write(GFits& file,
182 const std::string& extname = "") const; 182 const std::string& extname = "") const;
183 void publish(const std::string& name = "") const; 183 void publish(const std::string& name = "") const;
184 }; 184 };
src/sky/GSkyMap.cpp
@@ -2072,16 +2072,22 @@ void GSkyMap::read(const GFitsHDU& hdu) @@ -2072,16 +2072,22 @@ void GSkyMap::read(const GFitsHDU& hdu)
2072 * 2072 *
2073 * @param[in] file FITS file pointer. 2073 * @param[in] file FITS file pointer.
2074 * @param[in] extname Sky map extension name. 2074 * @param[in] extname Sky map extension name.
  2075 + * @return Pointer to written HDU.
2075 * 2076 *
2076 * Write the sky map into a FITS file. Optionally, the extension name of 2077 * Write the sky map into a FITS file. Optionally, the extension name of
2077 - * the FITS HDU can be specified using the @p extname parameter. 2078 + * the FITS HDU can be specified using the @p extname parameter. The method
  2079 + * returns a pointer to the appended HDU. If no HDU has been appended, for
  2080 + * example because the sky map is empty, the method will return NULL.
2078 ***************************************************************************/ 2081 ***************************************************************************/
2079 -void GSkyMap::write(GFits& file, const std::string& extname) const 2082 +GFitsHDU* GSkyMap::write(GFits& file, const std::string& extname) const
2080 { 2083 {
  2084 + // Initialise pointer to appended HDU
  2085 + GFitsHDU* hdu_appended = NULL;
  2086 +
2081 // Continue only if we have data to save 2087 // Continue only if we have data to save
2082 if (m_proj != NULL) { 2088 if (m_proj != NULL) {
2083 2089
2084 - // Initialise HDU pointer 2090 + // Initialise local HDU pointer
2085 GFitsHDU* hdu = NULL; 2091 GFitsHDU* hdu = NULL;
2086 2092
2087 // Case A: Skymap is Healpix 2093 // Case A: Skymap is Healpix
@@ -2102,8 +2108,8 @@ void GSkyMap::write(GFits& file, const std::string& extname) const @@ -2102,8 +2108,8 @@ void GSkyMap::write(GFits& file, const std::string& extname) const
2102 hdu->extname(extname); 2108 hdu->extname(extname);
2103 } 2109 }
2104 2110
2105 - // Append HDU  
2106 - file.append(*hdu); 2111 + // Append HDU and recover the pointer to the appended HDU
  2112 + hdu_appended = file.append(*hdu);
2107 2113
2108 // Delete HDU 2114 // Delete HDU
2109 if (hdu != NULL) delete hdu; 2115 if (hdu != NULL) delete hdu;
@@ -2112,8 +2118,8 @@ void GSkyMap::write(GFits& file, const std::string& extname) const @@ -2112,8 +2118,8 @@ void GSkyMap::write(GFits& file, const std::string& extname) const
2112 2118
2113 } // endif: we had data to save 2119 } // endif: we had data to save
2114 2120
2115 - // Return  
2116 - return; 2121 + // Return pointer to appended HDU
  2122 + return hdu_appended;
2117 } 2123 }
2118 2124
2119 2125
@@ -2123,27 +2129,34 @@ void GSkyMap::write(GFits& file, const std::string& extname) const @@ -2123,27 +2129,34 @@ void GSkyMap::write(GFits& file, const std::string& extname) const
2123 * @param[in] name Name of sky map. 2129 * @param[in] name Name of sky map.
2124 * 2130 *
2125 * Publishes the sky map on a Virtual Observatory Hub. If no Hub is currently 2131 * Publishes the sky map on a Virtual Observatory Hub. If no Hub is currently
2126 - * active, the method will start a new Hub. 2132 + * active, the method will start a new Hub. If on sky map has been allocated
  2133 + * the method does nothing.
2127 ***************************************************************************/ 2134 ***************************************************************************/
2128 -void GSkyMap::publish(const std::string& name) const 2135 +void GSkyMap::publish(const std::string& name) const
2129 { 2136 {
2130 // Create FITS file containing the sky map 2137 // Create FITS file containing the sky map
2131 GFits fits; 2138 GFits fits;
2132 - write(fits);  
2133 2139
2134 - // Get last FITS HDU  
2135 - GFitsHDU* hdu = fits[fits.size()-1]; 2140 + // Write sky map into FITS file and return a pointer to the written HDU.
  2141 + // This method returns a NULL pointer if no sky map projection exists,
  2142 + // which typically is true for empty sky maps.
  2143 + GFitsHDU* hdu = write(fits);
2136 2144
2137 - // Optionally set extension name  
2138 - if (!name.empty()) {  
2139 - hdu->extname(name);  
2140 - } 2145 + // Continue only if HDU pointer is valid
  2146 + if (hdu != NULL) {
  2147 +
  2148 + // Optionally set extension name
  2149 + if (!name.empty()) {
  2150 + hdu->extname(name);
  2151 + }
  2152 +
  2153 + // Create VO Client
  2154 + GVOClient client;
2141 2155
2142 - // Create VO Client  
2143 - GVOClient client; 2156 + // Publish map using VO client
  2157 + client.publish(*hdu);
2144 2158
2145 - // Publish map using VO client  
2146 - client.publish(*hdu); 2159 + } // endif: HDU pointer was valid
2147 2160
2148 // Return 2161 // Return
2149 return; 2162 return;
@@ -2153,7 +2166,7 @@ void GSkyMap::publish(const std::string& name) const @@ -2153,7 +2166,7 @@ void GSkyMap::publish(const std::string& name) const
2153 /***********************************************************************//** 2166 /***********************************************************************//**
2154 * @brief Print sky map 2167 * @brief Print sky map
2155 * 2168 *
2156 - * @param[in] chatter Chattiness (defaults to NORMAL). 2169 + * @param[in] chatter Chattiness.
2157 * @return String containing sky map information. 2170 * @return String containing sky map information.
2158 ***************************************************************************/ 2171 ***************************************************************************/
2159 std::string GSkyMap::print(const GChatter& chatter) const 2172 std::string GSkyMap::print(const GChatter& chatter) const