Commit 02078078b056a4c3309037ac47b98d69778f5f9c
1 parent
73646431
Make Python classes pickable (#1938)
Showing
52 changed files
with
873 additions
and
119 deletions
NEWS
| 1 | 1 | New Features and Important Changes in GammaLib 1.6.0 |
| 2 | 2 | |
| 3 | -22 June 2018 | |
| 3 | +25 June 2018 | |
| 4 | 4 | |
| 5 | 5 | |
| 6 | 6 | 1. Introduction |
| ... | ... | @@ -47,8 +47,10 @@ The following methods have been added: |
| 47 | 47 | - GPha::respfile() |
| 48 | 48 | - GPha::ancrfile(std::string&) |
| 49 | 49 | - GPha::ancrfile() |
| 50 | -- GFitsHeaderCard boolean constructor | |
| 50 | +- GFitsHDU::header(GFitsHeader&) | |
| 51 | 51 | - GFitsHDU::card(std::string&, bool&, std::string&) |
| 52 | +- GFitsHeaderCard general card constructor | |
| 53 | +- GFitsHeaderCard boolean constructor | |
| 52 | 54 | - GObservation::has_events() |
| 53 | 55 | - GModelSpatialPointSource::type(std::string&) |
| 54 | 56 | - GModelSpectralPlaw::type(std::string&) | ... | ... |
include/GFitsHDU.hpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsHDU.hpp - Abstract FITS extension base class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2008-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2008-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -82,8 +82,8 @@ public: |
| 82 | 82 | void extname(const std::string& extname); |
| 83 | 83 | const int& extno(void) const; |
| 84 | 84 | void extno(const int& extno); |
| 85 | - GFitsHeader& header(void); | |
| 86 | 85 | const GFitsHeader& header(void) const; |
| 86 | + void header(const GFitsHeader& header); | |
| 87 | 87 | bool has_card(const int& cardno) const; |
| 88 | 88 | bool has_card(const std::string& keyname) const; |
| 89 | 89 | GFitsHeaderCard& card(const int& cardno); |
| ... | ... | @@ -202,23 +202,24 @@ void GFitsHDU::extno(const int& extno) |
| 202 | 202 | * Returns the extension header. |
| 203 | 203 | ***************************************************************************/ |
| 204 | 204 | inline |
| 205 | -GFitsHeader& GFitsHDU::header(void) | |
| 205 | +const GFitsHeader& GFitsHDU::header(void) const | |
| 206 | 206 | { |
| 207 | 207 | return (m_header); |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | |
| 211 | 211 | /***********************************************************************//** |
| 212 | - * @brief Return extension header (const version) | |
| 212 | + * @brief Set extension header | |
| 213 | 213 | * |
| 214 | - * @return Extension header. | |
| 214 | + * @param[in] header Extension header. | |
| 215 | 215 | * |
| 216 | - * Returns the extension header. | |
| 216 | + * Sets the extension header. | |
| 217 | 217 | ***************************************************************************/ |
| 218 | 218 | inline |
| 219 | -const GFitsHeader& GFitsHDU::header(void) const | |
| 219 | +void GFitsHDU::header(const GFitsHeader& header) | |
| 220 | 220 | { |
| 221 | - return (m_header); | |
| 221 | + m_header = header; | |
| 222 | + return; | |
| 222 | 223 | } |
| 223 | 224 | |
| 224 | 225 | ... | ... |
include/GFitsHeaderCard.hpp
| ... | ... | @@ -50,6 +50,8 @@ public: |
| 50 | 50 | // Constructors & Destructors |
| 51 | 51 | GFitsHeaderCard(void); |
| 52 | 52 | GFitsHeaderCard(const std::string& keyname, const std::string& value, |
| 53 | + const std::string& unit, const std::string& comment); | |
| 54 | + GFitsHeaderCard(const std::string& keyname, const std::string& value, | |
| 53 | 55 | const std::string& comment); |
| 54 | 56 | GFitsHeaderCard(const std::string& keyname, const double& value, |
| 55 | 57 | const std::string& comment); |
| ... | ... | @@ -98,6 +100,10 @@ private: |
| 98 | 100 | void init_members(void); |
| 99 | 101 | void copy_members(const GFitsHeaderCard& card); |
| 100 | 102 | void free_members(void); |
| 103 | + void set_members(const std::string& keyname, | |
| 104 | + const std::string& value, | |
| 105 | + const std::string& unit, | |
| 106 | + const std::string& comment); | |
| 101 | 107 | void copy_dtype(const GFitsHeaderCard& card); |
| 102 | 108 | void free_dtype(void); |
| 103 | 109 | void set_dtype(const std::string& value); | ... | ... |
inst/com/src/GCOMIaq.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GCOMIaq.cpp - COMPTEL instrument response representation * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2017-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -640,22 +640,22 @@ void GCOMIaq::remove_cards(void) |
| 640 | 640 | { |
| 641 | 641 | // Remove extra header cards |
| 642 | 642 | if (m_iaq.has_card("ENERGY")) { |
| 643 | - m_iaq.header().remove("ENERGY"); | |
| 643 | + const_cast<GFitsHeader&>(m_iaq.header()).remove("ENERGY"); | |
| 644 | 644 | } |
| 645 | 645 | if (m_iaq.has_card("SPECTRUM")) { |
| 646 | - m_iaq.header().remove("SPECTRUM"); | |
| 646 | + const_cast<GFitsHeader&>(m_iaq.header()).remove("SPECTRUM"); | |
| 647 | 647 | } |
| 648 | 648 | if (m_iaq.has_card("PLAWINX")) { |
| 649 | - m_iaq.header().remove("PLAWINX"); | |
| 649 | + const_cast<GFitsHeader&>(m_iaq.header()).remove("PLAWINX"); | |
| 650 | 650 | } |
| 651 | 651 | if (m_iaq.has_card("NENG")) { |
| 652 | - m_iaq.header().remove("NENG"); | |
| 652 | + const_cast<GFitsHeader&>(m_iaq.header()).remove("NENG"); | |
| 653 | 653 | } |
| 654 | 654 | if (m_iaq.has_card("EIMIN")) { |
| 655 | - m_iaq.header().remove("EIMIN"); | |
| 655 | + const_cast<GFitsHeader&>(m_iaq.header()).remove("EIMIN"); | |
| 656 | 656 | } |
| 657 | 657 | if (m_iaq.has_card("EIMAX")) { |
| 658 | - m_iaq.header().remove("EIMAX"); | |
| 658 | + const_cast<GFitsHeader&>(m_iaq.header()).remove("EIMAX"); | |
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | // Return | ... | ... |
inst/cta/pyext/GCTAEventCube.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GCTAEventCube.i - CTA event bin container class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2011-2016 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2011-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -75,9 +75,6 @@ public: |
| 75 | 75 | * @brief GCTAEventCube class extension |
| 76 | 76 | ***************************************************************************/ |
| 77 | 77 | %extend GCTAEventCube { |
| 78 | - GCTAEventCube copy() { | |
| 79 | - return (*self); | |
| 80 | - } | |
| 81 | 78 | GCTAEventBin* __getitem__(int index) { |
| 82 | 79 | if (index >= 0 && index < self->size()) |
| 83 | 80 | return (*self)[index]; |
| ... | ... | @@ -90,4 +87,15 @@ public: |
| 90 | 87 | else |
| 91 | 88 | throw GException::out_of_range("__setitem__(int)", index, self->size()); |
| 92 | 89 | } |
| 90 | + GCTAEventCube copy() { | |
| 91 | + return (*self); | |
| 92 | + } | |
| 93 | +%pythoncode { | |
| 94 | + def __getstate__(self): | |
| 95 | + args = gammalib.GEventCube.__getstate__(self) | |
| 96 | + return args | |
| 97 | + def __setstate__(self, state): | |
| 98 | + self.__init__() | |
| 99 | + gammalib.GEventCube.__setstate__(self, state) | |
| 100 | +} | |
| 93 | 101 | }; | ... | ... |
inst/cta/pyext/GCTAEventList.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GCTAEventList.i - CTA event list class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2011-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2011-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -150,4 +150,12 @@ public: |
| 150 | 150 | GCTAEventList copy() { |
| 151 | 151 | return (*self); |
| 152 | 152 | } |
| 153 | +%pythoncode { | |
| 154 | + def __getstate__(self): | |
| 155 | + args = gammalib.GEventList.__getstate__(self) | |
| 156 | + return args | |
| 157 | + def __setstate__(self, state): | |
| 158 | + self.__init__() | |
| 159 | + gammalib.GEventList.__setstate__(self, state) | |
| 160 | +} | |
| 153 | 161 | }; | ... | ... |
inst/cta/pyext/GCTAObservation.i
| ... | ... | @@ -126,4 +126,12 @@ public: |
| 126 | 126 | GCTAObservation copy() { |
| 127 | 127 | return (*self); |
| 128 | 128 | } |
| 129 | +%pythoncode { | |
| 130 | + def __getstate__(self): | |
| 131 | + args = gammalib.GObservation.__getstate__(self) + () | |
| 132 | + return args | |
| 133 | + def __setstate__(self, state): | |
| 134 | + self.__init__() | |
| 135 | + gammalib.GObservation.__setstate__(self, state) | |
| 136 | +} | |
| 129 | 137 | }; | ... | ... |
inst/cta/test/test_CTA.py
inst/lat/src/GLATEventCube.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GLATEventCube.cpp - Fermi/LAT event cube class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2009-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2009-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -850,7 +850,7 @@ void GLATEventCube::read_gti(const GFitsTable& hdu) |
| 850 | 850 | // here the Fermi LAT time reference to circumvent the problem. |
| 851 | 851 | if (hdu.has_card("MJDREF")) { |
| 852 | 852 | if (gammalib::strip_whitespace(hdu.string("MJDREF")).empty()) { |
| 853 | - hdu_local->header().remove("MJDREF"); | |
| 853 | + const_cast<GFitsHeader&>(hdu_local->header()).remove("MJDREF"); | |
| 854 | 854 | hdu_local->card("MJDREFI", 51910, |
| 855 | 855 | "Integer part of MJD reference"); |
| 856 | 856 | hdu_local->card("MJDREFF", 0.00074287037037037, | ... | ... |
pyext/GFits.i
| ... | ... | @@ -166,4 +166,15 @@ public: |
| 166 | 166 | GFits copy() { |
| 167 | 167 | return (*self); |
| 168 | 168 | } |
| 169 | +%pythoncode { | |
| 170 | + def __getstate__(self): | |
| 171 | + state = tuple([x for x in self]), | |
| 172 | + return state | |
| 173 | + def __setstate__(self, state): | |
| 174 | + self.__init__() | |
| 175 | + size = len(state[0]) | |
| 176 | + self.reserve(size) | |
| 177 | + for x in state[0]: | |
| 178 | + self.append(x) | |
| 179 | +} | |
| 169 | 180 | } | ... | ... |
pyext/GFitsAsciiTable.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsAsciiTable.i - FITS ASCII table class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2008-2015 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2008-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -21,7 +21,7 @@ |
| 21 | 21 | /** |
| 22 | 22 | * @file GFitsAsciiTable.i |
| 23 | 23 | * @brief FITS ASCII table class definition |
| 24 | - * @author J. Knodlseder | |
| 24 | + * @author Juergen Knoedlseder | |
| 25 | 25 | */ |
| 26 | 26 | %{ |
| 27 | 27 | /* Put headers and other declarations here that are needed for compilation */ |
| ... | ... | @@ -58,4 +58,12 @@ public: |
| 58 | 58 | GFitsAsciiTable copy() { |
| 59 | 59 | return (*self); |
| 60 | 60 | } |
| 61 | +%pythoncode { | |
| 62 | + def __getstate__(self): | |
| 63 | + state = (gammalib.GFitsTable.__getstate__(self), self.nrows()) | |
| 64 | + return state | |
| 65 | + def __setstate__(self, state): | |
| 66 | + self.__init__(state[1]) | |
| 67 | + gammalib.GFitsTable.__setstate__(self, state[0]) | |
| 68 | +} | |
| 61 | 69 | } | ... | ... |
pyext/GFitsBinTable.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsBinTable.i - FITS binary table class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2008-2015 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2008-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -21,7 +21,7 @@ |
| 21 | 21 | /** |
| 22 | 22 | * @file GFitsBinTable.i |
| 23 | 23 | * @brief FITS binary table class definition |
| 24 | - * @author J. Knodlseder | |
| 24 | + * @author Juergen Knoedlseder | |
| 25 | 25 | */ |
| 26 | 26 | %{ |
| 27 | 27 | /* Put headers and other declarations here that are needed for compilation */ |
| ... | ... | @@ -58,4 +58,12 @@ public: |
| 58 | 58 | GFitsBinTable copy() { |
| 59 | 59 | return (*self); |
| 60 | 60 | } |
| 61 | +%pythoncode { | |
| 62 | + def __getstate__(self): | |
| 63 | + state = (gammalib.GFitsTable.__getstate__(self), self.nrows()) | |
| 64 | + return state | |
| 65 | + def __setstate__(self, state): | |
| 66 | + self.__init__(state[1]) | |
| 67 | + gammalib.GFitsTable.__setstate__(self, state[0]) | |
| 68 | +} | |
| 61 | 69 | } | ... | ... |
pyext/GFitsHDU.i
| ... | ... | @@ -67,7 +67,8 @@ public: |
| 67 | 67 | void extname(const std::string& extname); |
| 68 | 68 | const int& extno(void) const; |
| 69 | 69 | void extno(const int& extno); |
| 70 | - GFitsHeader& header(void); | |
| 70 | + const GFitsHeader& header(void) const; | |
| 71 | + void header(const GFitsHeader& header); | |
| 71 | 72 | bool has_card(const int& cardno) const; |
| 72 | 73 | bool has_card(const std::string& keyname) const; |
| 73 | 74 | GFitsHeaderCard& card(const int& cardno); |
| ... | ... | @@ -98,4 +99,13 @@ public: |
| 98 | 99 | * @brief GFitsHDU class SWIG extension |
| 99 | 100 | ***************************************************************************/ |
| 100 | 101 | %extend GFitsHDU { |
| 102 | +%pythoncode { | |
| 103 | + def __getstate__(self): | |
| 104 | + state = (self.extname(), self.header()) | |
| 105 | + return state | |
| 106 | + def __setstate__(self, state): | |
| 107 | + self.__init__() | |
| 108 | + self.extname(state[0]) | |
| 109 | + self.header(state[1]) | |
| 110 | +} | |
| 101 | 111 | }; | ... | ... |
pyext/GFitsHeader.i
| ... | ... | @@ -141,4 +141,15 @@ public: |
| 141 | 141 | GFitsHeader copy() { |
| 142 | 142 | return (*self); |
| 143 | 143 | } |
| 144 | +%pythoncode { | |
| 145 | + def __getstate__(self): | |
| 146 | + state = tuple([x for x in self]), | |
| 147 | + return state | |
| 148 | + def __setstate__(self, state): | |
| 149 | + self.__init__() | |
| 150 | + size = len(state[0]) | |
| 151 | + self.reserve(size) | |
| 152 | + for x in state[0]: | |
| 153 | + self.append(x) | |
| 154 | +} | |
| 144 | 155 | } | ... | ... |
pyext/GFitsHeaderCard.i
| ... | ... | @@ -26,9 +26,7 @@ |
| 26 | 26 | %{ |
| 27 | 27 | /* Put headers and other declarations here that are needed for compilation */ |
| 28 | 28 | #include "GFitsHeaderCard.hpp" |
| 29 | -#include "GTools.hpp" | |
| 30 | 29 | %} |
| 31 | -%include stl.i | |
| 32 | 30 | |
| 33 | 31 | |
| 34 | 32 | /***********************************************************************//** |
| ... | ... | @@ -46,6 +44,8 @@ public: |
| 46 | 44 | // Constructors & Destructors |
| 47 | 45 | GFitsHeaderCard(void); |
| 48 | 46 | GFitsHeaderCard(const std::string& keyname, const std::string& value, |
| 47 | + const std::string& unit, const std::string& comment); | |
| 48 | + GFitsHeaderCard(const std::string& keyname, const std::string& value, | |
| 49 | 49 | const std::string& comment); |
| 50 | 50 | GFitsHeaderCard(const std::string& keyname, const double& value, |
| 51 | 51 | const std::string& comment); |
| ... | ... | @@ -94,4 +94,11 @@ public: |
| 94 | 94 | GFitsHeaderCard copy() { |
| 95 | 95 | return (*self); |
| 96 | 96 | } |
| 97 | +%pythoncode { | |
| 98 | + def __getstate__(self): | |
| 99 | + state = (self.keyname(), self.value(), self.unit(), self.comment()) | |
| 100 | + return state | |
| 101 | + def __setstate__(self, state): | |
| 102 | + self.__init__(state[0], state[1], state[2], state[3]) | |
| 103 | +} | |
| 97 | 104 | } | ... | ... |
pyext/GFitsImage.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsImage.i - Abstract FITS image base class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2008-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2008-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -109,7 +109,6 @@ public: |
| 109 | 109 | virtual void clear(void) = 0; |
| 110 | 110 | virtual GFitsImage* clone(void) const = 0; |
| 111 | 111 | virtual std::string classname(void) const = 0; |
| 112 | - virtual void* pixels(void) = 0; | |
| 113 | 112 | virtual double pixel(const int& ix) const = 0; |
| 114 | 113 | virtual double pixel(const int& ix, const int& iy) const = 0; |
| 115 | 114 | virtual double pixel(const int& ix, const int& iy, const int& iz) const = 0; | ... | ... |
pyext/GFitsImageByte.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsImageByte.i - FITS Byte image class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -26,9 +26,35 @@ |
| 26 | 26 | %{ |
| 27 | 27 | /* Put headers and other declarations here that are needed for compilation */ |
| 28 | 28 | #include "GFitsImageByte.hpp" |
| 29 | -#include "GException.hpp" | |
| 30 | 29 | %} |
| 31 | 30 | |
| 31 | +/* __ Typemaps ___________________________________________________________ */ | |
| 32 | +%typemap(in) const unsigned char* pixels { | |
| 33 | + if (!PyList_Check($input)) { | |
| 34 | + SWIG_exception(SWIG_ValueError, "List expected"); | |
| 35 | + } | |
| 36 | + int num = PyList_Size($input); | |
| 37 | + if (num > 0) { | |
| 38 | + $1 = (unsigned char*)malloc(num*sizeof(unsigned char)); | |
| 39 | + for (int i = 0; i < num; i++) { | |
| 40 | + PyObject *s = PyList_GetItem($input,i); | |
| 41 | + if (!PyInt_Check(s)) { | |
| 42 | + free($1); | |
| 43 | + SWIG_exception(SWIG_ValueError, "List items must be integers"); | |
| 44 | + } | |
| 45 | + $1[i] = (unsigned char)PyInt_AsLong(s); | |
| 46 | + } | |
| 47 | + } | |
| 48 | +} | |
| 49 | +%typemap(typecheck, precedence=SWIG_TYPECHECK_INTEGER) const unsigned char* pixels { | |
| 50 | + $1 = PyList_Check($input) ? 1 : 0; | |
| 51 | +} | |
| 52 | +%typemap(freearg) const unsigned char* pixels { | |
| 53 | + if ($1) { | |
| 54 | + free($1); | |
| 55 | + } | |
| 56 | +} | |
| 57 | + | |
| 32 | 58 | |
| 33 | 59 | /***********************************************************************//** |
| 34 | 60 | * @class GFitsImageByte |
| ... | ... | @@ -56,7 +82,6 @@ public: |
| 56 | 82 | double pixel(const int& ix, const int& iy) const; |
| 57 | 83 | double pixel(const int& ix, const int& iy, const int& iz) const; |
| 58 | 84 | double pixel(const int& ix, const int& iy, const int& iz, const int& it) const; |
| 59 | - void* pixels(void); | |
| 60 | 85 | int type(void) const; |
| 61 | 86 | }; |
| 62 | 87 | |
| ... | ... | @@ -116,7 +141,24 @@ public: |
| 116 | 141 | GFitsImageInx[0]); |
| 117 | 142 | } |
| 118 | 143 | } |
| 144 | + PyObject* pixels(void) { | |
| 145 | + PyObject *list = PyList_New(self->npix()); | |
| 146 | + for (int i = 0; i < self->npix(); ++i) { | |
| 147 | + PyList_SetItem(list, i, PyInt_FromLong((long)(static_cast<unsigned char*>(self->pixels())[i]))); | |
| 148 | + } | |
| 149 | + return list; | |
| 150 | + } | |
| 119 | 151 | GFitsImageByte copy() { |
| 120 | 152 | return (*self); |
| 121 | 153 | } |
| 154 | +%pythoncode { | |
| 155 | + def __getstate__(self): | |
| 156 | + state = (gammalib.GFitsHDU.__getstate__(self), | |
| 157 | + [self.naxes(axis) for axis in range(self.naxis())], | |
| 158 | + self.pixels()) | |
| 159 | + return state | |
| 160 | + def __setstate__(self, state): | |
| 161 | + self.__init__(state[1], state[2]) | |
| 162 | + gammalib.GFitsHDU.__setstate__(self, state[0]) | |
| 163 | +} | |
| 122 | 164 | }; | ... | ... |
pyext/GFitsImageDouble.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsImageDouble.i - Double precision FITS image class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -26,9 +26,35 @@ |
| 26 | 26 | %{ |
| 27 | 27 | /* Put headers and other declarations here that are needed for compilation */ |
| 28 | 28 | #include "GFitsImageDouble.hpp" |
| 29 | -#include "GException.hpp" | |
| 30 | 29 | %} |
| 31 | 30 | |
| 31 | +/* __ Typemaps ___________________________________________________________ */ | |
| 32 | +%typemap(in) const double* pixels { | |
| 33 | + if (!PyList_Check($input)) { | |
| 34 | + SWIG_exception(SWIG_ValueError, "List expected"); | |
| 35 | + } | |
| 36 | + int num = PyList_Size($input); | |
| 37 | + if (num > 0) { | |
| 38 | + $1 = (double*)malloc(num*sizeof(double)); | |
| 39 | + for (int i = 0; i < num; i++) { | |
| 40 | + PyObject *s = PyList_GetItem($input,i); | |
| 41 | + if (!PyFloat_Check(s)) { | |
| 42 | + free($1); | |
| 43 | + SWIG_exception(SWIG_ValueError, "List items must be floats"); | |
| 44 | + } | |
| 45 | + $1[i] = (double)PyFloat_AsDouble(s); | |
| 46 | + } | |
| 47 | + } | |
| 48 | +} | |
| 49 | +%typemap(typecheck, precedence=SWIG_TYPECHECK_INTEGER) const double* pixels { | |
| 50 | + $1 = PyList_Check($input) ? 1 : 0; | |
| 51 | +} | |
| 52 | +%typemap(freearg) const double* pixels { | |
| 53 | + if ($1) { | |
| 54 | + free($1); | |
| 55 | + } | |
| 56 | +} | |
| 57 | + | |
| 32 | 58 | |
| 33 | 59 | /***********************************************************************//** |
| 34 | 60 | * @class GFitsImageDouble |
| ... | ... | @@ -56,7 +82,6 @@ public: |
| 56 | 82 | double pixel(const int& ix, const int& iy) const; |
| 57 | 83 | double pixel(const int& ix, const int& iy, const int& iz) const; |
| 58 | 84 | double pixel(const int& ix, const int& iy, const int& iz, const int& it) const; |
| 59 | - void* pixels(void); | |
| 60 | 85 | int type(void) const; |
| 61 | 86 | }; |
| 62 | 87 | |
| ... | ... | @@ -116,7 +141,24 @@ public: |
| 116 | 141 | GFitsImageInx[0]); |
| 117 | 142 | } |
| 118 | 143 | } |
| 144 | + PyObject* pixels(void) { | |
| 145 | + PyObject *list = PyList_New(self->npix()); | |
| 146 | + for (int i = 0; i < self->npix(); ++i) { | |
| 147 | + PyList_SetItem(list, i, PyFloat_FromDouble((static_cast<double*>(self->pixels())[i]))); | |
| 148 | + } | |
| 149 | + return list; | |
| 150 | + } | |
| 119 | 151 | GFitsImageDouble copy() { |
| 120 | 152 | return (*self); |
| 121 | 153 | } |
| 154 | +%pythoncode { | |
| 155 | + def __getstate__(self): | |
| 156 | + state = (gammalib.GFitsHDU.__getstate__(self), | |
| 157 | + [self.naxes(axis) for axis in range(self.naxis())], | |
| 158 | + self.pixels()) | |
| 159 | + return state | |
| 160 | + def __setstate__(self, state): | |
| 161 | + self.__init__(state[1], state[2]) | |
| 162 | + gammalib.GFitsHDU.__setstate__(self, state[0]) | |
| 163 | +} | |
| 122 | 164 | }; | ... | ... |
pyext/GFitsImageFloat.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsImageFloat.i - Single precision FITS image class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -26,9 +26,35 @@ |
| 26 | 26 | %{ |
| 27 | 27 | /* Put headers and other declarations here that are needed for compilation */ |
| 28 | 28 | #include "GFitsImageFloat.hpp" |
| 29 | -#include "GException.hpp" | |
| 30 | 29 | %} |
| 31 | 30 | |
| 31 | +/* __ Typemaps ___________________________________________________________ */ | |
| 32 | +%typemap(in) const float* pixels { | |
| 33 | + if (!PyList_Check($input)) { | |
| 34 | + SWIG_exception(SWIG_ValueError, "List expected"); | |
| 35 | + } | |
| 36 | + int num = PyList_Size($input); | |
| 37 | + if (num > 0) { | |
| 38 | + $1 = (float*)malloc(num*sizeof(float)); | |
| 39 | + for (int i = 0; i < num; ++i) { | |
| 40 | + PyObject *s = PyList_GetItem($input,i); | |
| 41 | + if (!PyFloat_Check(s)) { | |
| 42 | + free($1); | |
| 43 | + SWIG_exception(SWIG_ValueError, "List items must be floats"); | |
| 44 | + } | |
| 45 | + $1[i] = (float)PyFloat_AsDouble(s); | |
| 46 | + } | |
| 47 | + } | |
| 48 | +} | |
| 49 | +%typemap(typecheck, precedence=SWIG_TYPECHECK_INTEGER) const float* pixels { | |
| 50 | + $1 = PyList_Check($input) ? 1 : 0; | |
| 51 | +} | |
| 52 | +%typemap(freearg) const float* pixels { | |
| 53 | + if ($1) { | |
| 54 | + free($1); | |
| 55 | + } | |
| 56 | +} | |
| 57 | + | |
| 32 | 58 | |
| 33 | 59 | /***********************************************************************//** |
| 34 | 60 | * @class GFitsImageFloat |
| ... | ... | @@ -56,7 +82,6 @@ public: |
| 56 | 82 | double pixel(const int& ix, const int& iy) const; |
| 57 | 83 | double pixel(const int& ix, const int& iy, const int& iz) const; |
| 58 | 84 | double pixel(const int& ix, const int& iy, const int& iz, const int& it) const; |
| 59 | - void* pixels(void); | |
| 60 | 85 | int type(void) const; |
| 61 | 86 | }; |
| 62 | 87 | |
| ... | ... | @@ -116,7 +141,24 @@ public: |
| 116 | 141 | GFitsImageInx[0]); |
| 117 | 142 | } |
| 118 | 143 | } |
| 144 | + PyObject* pixels(void) { | |
| 145 | + PyObject *list = PyList_New(self->npix()); | |
| 146 | + for (int i = 0; i < self->npix(); ++i) { | |
| 147 | + PyList_SetItem(list, i, PyFloat_FromDouble((double)(static_cast<float*>(self->pixels())[i]))); | |
| 148 | + } | |
| 149 | + return list; | |
| 150 | + } | |
| 119 | 151 | GFitsImageFloat copy() { |
| 120 | 152 | return (*self); |
| 121 | 153 | } |
| 154 | +%pythoncode { | |
| 155 | + def __getstate__(self): | |
| 156 | + state = (gammalib.GFitsHDU.__getstate__(self), | |
| 157 | + [self.naxes(axis) for axis in range(self.naxis())], | |
| 158 | + self.pixels()) | |
| 159 | + return state | |
| 160 | + def __setstate__(self, state): | |
| 161 | + self.__init__(state[1], state[2]) | |
| 162 | + gammalib.GFitsHDU.__setstate__(self, state[0]) | |
| 163 | +} | |
| 122 | 164 | }; | ... | ... |
pyext/GFitsImageLong.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsImageLong.i - Long integer FITS image class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -26,9 +26,35 @@ |
| 26 | 26 | %{ |
| 27 | 27 | /* Put headers and other declarations here that are needed for compilation */ |
| 28 | 28 | #include "GFitsImageLong.hpp" |
| 29 | -#include "GException.hpp" | |
| 30 | 29 | %} |
| 31 | 30 | |
| 31 | +/* __ Typemaps ___________________________________________________________ */ | |
| 32 | +%typemap(in) const long* pixels { | |
| 33 | + if (!PyList_Check($input)) { | |
| 34 | + SWIG_exception(SWIG_ValueError, "List expected"); | |
| 35 | + } | |
| 36 | + int num = PyList_Size($input); | |
| 37 | + if (num > 0) { | |
| 38 | + $1 = (long*)malloc(num*sizeof(long)); | |
| 39 | + for (int i = 0; i < num; i++) { | |
| 40 | + PyObject *s = PyList_GetItem($input,i); | |
| 41 | + if (!PyInt_Check(s)) { | |
| 42 | + free($1); | |
| 43 | + SWIG_exception(SWIG_ValueError, "List items must be integers"); | |
| 44 | + } | |
| 45 | + $1[i] = (long)PyInt_AsLong(s); | |
| 46 | + } | |
| 47 | + } | |
| 48 | +} | |
| 49 | +%typemap(typecheck, precedence=SWIG_TYPECHECK_INTEGER) const long* pixels { | |
| 50 | + $1 = PyList_Check($input) ? 1 : 0; | |
| 51 | +} | |
| 52 | +%typemap(freearg) const long* pixels { | |
| 53 | + if ($1) { | |
| 54 | + free($1); | |
| 55 | + } | |
| 56 | +} | |
| 57 | + | |
| 32 | 58 | |
| 33 | 59 | /***********************************************************************//** |
| 34 | 60 | * @class GFitsImageLong |
| ... | ... | @@ -56,7 +82,6 @@ public: |
| 56 | 82 | double pixel(const int& ix, const int& iy) const; |
| 57 | 83 | double pixel(const int& ix, const int& iy, const int& iz) const; |
| 58 | 84 | double pixel(const int& ix, const int& iy, const int& iz, const int& it) const; |
| 59 | - void* pixels(void); | |
| 60 | 85 | int type(void) const; |
| 61 | 86 | }; |
| 62 | 87 | |
| ... | ... | @@ -116,7 +141,24 @@ public: |
| 116 | 141 | GFitsImageInx[0]); |
| 117 | 142 | } |
| 118 | 143 | } |
| 144 | + PyObject* pixels(void) { | |
| 145 | + PyObject *list = PyList_New(self->npix()); | |
| 146 | + for (int i = 0; i < self->npix(); ++i) { | |
| 147 | + PyList_SetItem(list, i, PyInt_FromLong((static_cast<long*>(self->pixels())[i]))); | |
| 148 | + } | |
| 149 | + return list; | |
| 150 | + } | |
| 119 | 151 | GFitsImageLong copy() { |
| 120 | 152 | return (*self); |
| 121 | 153 | } |
| 154 | +%pythoncode { | |
| 155 | + def __getstate__(self): | |
| 156 | + state = (gammalib.GFitsHDU.__getstate__(self), | |
| 157 | + [self.naxes(axis) for axis in range(self.naxis())], | |
| 158 | + self.pixels()) | |
| 159 | + return state | |
| 160 | + def __setstate__(self, state): | |
| 161 | + self.__init__(state[1], state[2]) | |
| 162 | + gammalib.GFitsHDU.__setstate__(self, state[0]) | |
| 163 | +} | |
| 122 | 164 | }; | ... | ... |
pyext/GFitsImageLongLong.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsImageLongLong.i - Long long integer FITS image class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -26,9 +26,35 @@ |
| 26 | 26 | %{ |
| 27 | 27 | /* Put headers and other declarations here that are needed for compilation */ |
| 28 | 28 | #include "GFitsImageLongLong.hpp" |
| 29 | -#include "GException.hpp" | |
| 30 | 29 | %} |
| 31 | 30 | |
| 31 | +/* __ Typemaps ___________________________________________________________ */ | |
| 32 | +%typemap(in) const long long* pixels { | |
| 33 | + if (!PyList_Check($input)) { | |
| 34 | + SWIG_exception(SWIG_ValueError, "List expected"); | |
| 35 | + } | |
| 36 | + int num = PyList_Size($input); | |
| 37 | + if (num > 0) { | |
| 38 | + $1 = (long long*)malloc(num*sizeof(long long)); | |
| 39 | + for (int i = 0; i < num; i++) { | |
| 40 | + PyObject *s = PyList_GetItem($input,i); | |
| 41 | + if (!PyInt_Check(s)) { | |
| 42 | + free($1); | |
| 43 | + SWIG_exception(SWIG_ValueError, "List items must be integers"); | |
| 44 | + } | |
| 45 | + $1[i] = (long long)PyInt_AsLong(s); | |
| 46 | + } | |
| 47 | + } | |
| 48 | +} | |
| 49 | +%typemap(typecheck, precedence=SWIG_TYPECHECK_INTEGER) const long long* pixels { | |
| 50 | + $1 = PyList_Check($input) ? 1 : 0; | |
| 51 | +} | |
| 52 | +%typemap(freearg) const long long* pixels { | |
| 53 | + if ($1) { | |
| 54 | + free($1); | |
| 55 | + } | |
| 56 | +} | |
| 57 | + | |
| 32 | 58 | |
| 33 | 59 | /***********************************************************************//** |
| 34 | 60 | * @class GFitsImageLongLong |
| ... | ... | @@ -56,7 +82,6 @@ public: |
| 56 | 82 | double pixel(const int& ix, const int& iy) const; |
| 57 | 83 | double pixel(const int& ix, const int& iy, const int& iz) const; |
| 58 | 84 | double pixel(const int& ix, const int& iy, const int& iz, const int& it) const; |
| 59 | - void* pixels(void); | |
| 60 | 85 | int type(void) const; |
| 61 | 86 | }; |
| 62 | 87 | |
| ... | ... | @@ -116,7 +141,24 @@ public: |
| 116 | 141 | GFitsImageInx[0]); |
| 117 | 142 | } |
| 118 | 143 | } |
| 144 | + PyObject* pixels(void) { | |
| 145 | + PyObject *list = PyList_New(self->npix()); | |
| 146 | + for (int i = 0; i < self->npix(); ++i) { | |
| 147 | + PyList_SetItem(list, i, PyInt_FromLong((static_cast<long long*>(self->pixels())[i]))); | |
| 148 | + } | |
| 149 | + return list; | |
| 150 | + } | |
| 119 | 151 | GFitsImageLongLong copy() { |
| 120 | 152 | return (*self); |
| 121 | 153 | } |
| 154 | +%pythoncode { | |
| 155 | + def __getstate__(self): | |
| 156 | + state = (gammalib.GFitsHDU.__getstate__(self), | |
| 157 | + [self.naxes(axis) for axis in range(self.naxis())], | |
| 158 | + self.pixels()) | |
| 159 | + return state | |
| 160 | + def __setstate__(self, state): | |
| 161 | + self.__init__(state[1], state[2]) | |
| 162 | + gammalib.GFitsHDU.__setstate__(self, state[0]) | |
| 163 | +} | |
| 122 | 164 | }; | ... | ... |
pyext/GFitsImageSByte.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsImageSByte.i - Signed Byte FITS image class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -26,9 +26,35 @@ |
| 26 | 26 | %{ |
| 27 | 27 | /* Put headers and other declarations here that are needed for compilation */ |
| 28 | 28 | #include "GFitsImageSByte.hpp" |
| 29 | -#include "GException.hpp" | |
| 30 | 29 | %} |
| 31 | 30 | |
| 31 | +/* __ Typemaps ___________________________________________________________ */ | |
| 32 | +%typemap(in) const char* pixels { | |
| 33 | + if (!PyList_Check($input)) { | |
| 34 | + SWIG_exception(SWIG_ValueError, "List expected"); | |
| 35 | + } | |
| 36 | + int num = PyList_Size($input); | |
| 37 | + if (num > 0) { | |
| 38 | + $1 = (char*)malloc(num*sizeof(char)); | |
| 39 | + for (int i = 0; i < num; i++) { | |
| 40 | + PyObject *s = PyList_GetItem($input,i); | |
| 41 | + if (!PyInt_Check(s)) { | |
| 42 | + free($1); | |
| 43 | + SWIG_exception(SWIG_ValueError, "List items must be integers"); | |
| 44 | + } | |
| 45 | + $1[i] = (char)PyInt_AsLong(s); | |
| 46 | + } | |
| 47 | + } | |
| 48 | +} | |
| 49 | +%typemap(typecheck, precedence=SWIG_TYPECHECK_INTEGER) const char* pixels { | |
| 50 | + $1 = PyList_Check($input) ? 1 : 0; | |
| 51 | +} | |
| 52 | +%typemap(freearg) const char* pixels { | |
| 53 | + if ($1) { | |
| 54 | + free($1); | |
| 55 | + } | |
| 56 | +} | |
| 57 | + | |
| 32 | 58 | |
| 33 | 59 | /***********************************************************************//** |
| 34 | 60 | * @class GFitsImageSByte |
| ... | ... | @@ -56,7 +82,6 @@ public: |
| 56 | 82 | double pixel(const int& ix, const int& iy) const; |
| 57 | 83 | double pixel(const int& ix, const int& iy, const int& iz) const; |
| 58 | 84 | double pixel(const int& ix, const int& iy, const int& iz, const int& it) const; |
| 59 | - void* pixels(void); | |
| 60 | 85 | int type(void) const; |
| 61 | 86 | }; |
| 62 | 87 | |
| ... | ... | @@ -116,7 +141,24 @@ public: |
| 116 | 141 | GFitsImageInx[0]); |
| 117 | 142 | } |
| 118 | 143 | } |
| 144 | + PyObject* pixels(void) { | |
| 145 | + PyObject *list = PyList_New(self->npix()); | |
| 146 | + for (int i = 0; i < self->npix(); ++i) { | |
| 147 | + PyList_SetItem(list, i, PyInt_FromLong((long)(static_cast<char*>(self->pixels())[i]))); | |
| 148 | + } | |
| 149 | + return list; | |
| 150 | + } | |
| 119 | 151 | GFitsImageSByte copy() { |
| 120 | 152 | return (*self); |
| 121 | 153 | } |
| 154 | +%pythoncode { | |
| 155 | + def __getstate__(self): | |
| 156 | + state = (gammalib.GFitsHDU.__getstate__(self), | |
| 157 | + [self.naxes(axis) for axis in range(self.naxis())], | |
| 158 | + self.pixels()) | |
| 159 | + return state | |
| 160 | + def __setstate__(self, state): | |
| 161 | + self.__init__(state[1], state[2]) | |
| 162 | + gammalib.GFitsHDU.__setstate__(self, state[0]) | |
| 163 | +} | |
| 122 | 164 | }; | ... | ... |
pyext/GFitsImageShort.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsImageShort.i - Short integer FITS image class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -26,9 +26,35 @@ |
| 26 | 26 | %{ |
| 27 | 27 | /* Put headers and other declarations here that are needed for compilation */ |
| 28 | 28 | #include "GFitsImageShort.hpp" |
| 29 | -#include "GException.hpp" | |
| 30 | 29 | %} |
| 31 | 30 | |
| 31 | +/* __ Typemaps ___________________________________________________________ */ | |
| 32 | +%typemap(in) const short* pixels { | |
| 33 | + if (!PyList_Check($input)) { | |
| 34 | + SWIG_exception(SWIG_ValueError, "List expected"); | |
| 35 | + } | |
| 36 | + int num = PyList_Size($input); | |
| 37 | + if (num > 0) { | |
| 38 | + $1 = (short*)malloc(num*sizeof(short)); | |
| 39 | + for (int i = 0; i < num; i++) { | |
| 40 | + PyObject *s = PyList_GetItem($input,i); | |
| 41 | + if (!PyInt_Check(s)) { | |
| 42 | + free($1); | |
| 43 | + SWIG_exception(SWIG_ValueError, "List items must be integers"); | |
| 44 | + } | |
| 45 | + $1[i] = (short)PyInt_AsLong(s); | |
| 46 | + } | |
| 47 | + } | |
| 48 | +} | |
| 49 | +%typemap(typecheck, precedence=SWIG_TYPECHECK_INTEGER) const short* pixels { | |
| 50 | + $1 = PyList_Check($input) ? 1 : 0; | |
| 51 | +} | |
| 52 | +%typemap(freearg) const short* pixels { | |
| 53 | + if ($1) { | |
| 54 | + free($1); | |
| 55 | + } | |
| 56 | +} | |
| 57 | + | |
| 32 | 58 | |
| 33 | 59 | /***********************************************************************//** |
| 34 | 60 | * @class GFitsImageShort |
| ... | ... | @@ -56,7 +82,6 @@ public: |
| 56 | 82 | double pixel(const int& ix, const int& iy) const; |
| 57 | 83 | double pixel(const int& ix, const int& iy, const int& iz) const; |
| 58 | 84 | double pixel(const int& ix, const int& iy, const int& iz, const int& it) const; |
| 59 | - void* pixels(void); | |
| 60 | 85 | int type(void) const; |
| 61 | 86 | }; |
| 62 | 87 | |
| ... | ... | @@ -117,7 +142,24 @@ public: |
| 117 | 142 | GFitsImageInx[0]); |
| 118 | 143 | } |
| 119 | 144 | } |
| 145 | + PyObject* pixels(void) { | |
| 146 | + PyObject *list = PyList_New(self->npix()); | |
| 147 | + for (int i = 0; i < self->npix(); ++i) { | |
| 148 | + PyList_SetItem(list, i, PyInt_FromLong((long)(static_cast<short*>(self->pixels())[i]))); | |
| 149 | + } | |
| 150 | + return list; | |
| 151 | + } | |
| 120 | 152 | GFitsImageShort copy() { |
| 121 | 153 | return (*self); |
| 122 | 154 | } |
| 155 | +%pythoncode { | |
| 156 | + def __getstate__(self): | |
| 157 | + state = (gammalib.GFitsHDU.__getstate__(self), | |
| 158 | + [self.naxes(axis) for axis in range(self.naxis())], | |
| 159 | + self.pixels()) | |
| 160 | + return state | |
| 161 | + def __setstate__(self, state): | |
| 162 | + self.__init__(state[1], state[2]) | |
| 163 | + gammalib.GFitsHDU.__setstate__(self, state[0]) | |
| 164 | +} | |
| 123 | 165 | }; | ... | ... |
pyext/GFitsImageULong.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsImageULong.i - Unsigned long image FITS class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -26,9 +26,35 @@ |
| 26 | 26 | %{ |
| 27 | 27 | /* Put headers and other declarations here that are needed for compilation */ |
| 28 | 28 | #include "GFitsImageULong.hpp" |
| 29 | -#include "GException.hpp" | |
| 30 | 29 | %} |
| 31 | 30 | |
| 31 | +/* __ Typemaps ___________________________________________________________ */ | |
| 32 | +%typemap(in) const unsigned long* pixels { | |
| 33 | + if (!PyList_Check($input)) { | |
| 34 | + SWIG_exception(SWIG_ValueError, "List expected"); | |
| 35 | + } | |
| 36 | + int num = PyList_Size($input); | |
| 37 | + if (num > 0) { | |
| 38 | + $1 = (unsigned long*)malloc(num*sizeof(unsigned long)); | |
| 39 | + for (int i = 0; i < num; i++) { | |
| 40 | + PyObject *s = PyList_GetItem($input,i); | |
| 41 | + if (!PyInt_Check(s)) { | |
| 42 | + free($1); | |
| 43 | + SWIG_exception(SWIG_ValueError, "List items must be integers"); | |
| 44 | + } | |
| 45 | + $1[i] = (unsigned long)PyInt_AsLong(s); | |
| 46 | + } | |
| 47 | + } | |
| 48 | +} | |
| 49 | +%typemap(typecheck, precedence=SWIG_TYPECHECK_INTEGER) const unsigned long* pixels { | |
| 50 | + $1 = PyList_Check($input) ? 1 : 0; | |
| 51 | +} | |
| 52 | +%typemap(freearg) const unsigned long* pixels { | |
| 53 | + if ($1) { | |
| 54 | + free($1); | |
| 55 | + } | |
| 56 | +} | |
| 57 | + | |
| 32 | 58 | |
| 33 | 59 | /***********************************************************************//** |
| 34 | 60 | * @class GFitsImageULong |
| ... | ... | @@ -56,7 +82,6 @@ public: |
| 56 | 82 | double pixel(const int& ix, const int& iy) const; |
| 57 | 83 | double pixel(const int& ix, const int& iy, const int& iz) const; |
| 58 | 84 | double pixel(const int& ix, const int& iy, const int& iz, const int& it) const; |
| 59 | - void* pixels(void); | |
| 60 | 85 | int type(void) const; |
| 61 | 86 | }; |
| 62 | 87 | |
| ... | ... | @@ -116,7 +141,24 @@ public: |
| 116 | 141 | GFitsImageInx[0]); |
| 117 | 142 | } |
| 118 | 143 | } |
| 144 | + PyObject* pixels(void) { | |
| 145 | + PyObject *list = PyList_New(self->npix()); | |
| 146 | + for (int i = 0; i < self->npix(); ++i) { | |
| 147 | + PyList_SetItem(list, i, PyInt_FromLong((long)(static_cast<unsigned long*>(self->pixels())[i]))); | |
| 148 | + } | |
| 149 | + return list; | |
| 150 | + } | |
| 119 | 151 | GFitsImageULong copy() { |
| 120 | 152 | return (*self); |
| 121 | 153 | } |
| 154 | +%pythoncode { | |
| 155 | + def __getstate__(self): | |
| 156 | + state = (gammalib.GFitsHDU.__getstate__(self), | |
| 157 | + [self.naxes(axis) for axis in range(self.naxis())], | |
| 158 | + self.pixels()) | |
| 159 | + return state | |
| 160 | + def __setstate__(self, state): | |
| 161 | + self.__init__(state[1], state[2]) | |
| 162 | + gammalib.GFitsHDU.__setstate__(self, state[0]) | |
| 163 | +} | |
| 122 | 164 | }; | ... | ... |
pyext/GFitsImageUShort.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsImageUShort.i - Unsigned short FITS image class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -26,9 +26,35 @@ |
| 26 | 26 | %{ |
| 27 | 27 | /* Put headers and other declarations here that are needed for compilation */ |
| 28 | 28 | #include "GFitsImageUShort.hpp" |
| 29 | -#include "GException.hpp" | |
| 30 | 29 | %} |
| 31 | 30 | |
| 31 | +/* __ Typemaps ___________________________________________________________ */ | |
| 32 | +%typemap(in) const unsigned short* pixels { | |
| 33 | + if (!PyList_Check($input)) { | |
| 34 | + SWIG_exception(SWIG_ValueError, "List expected"); | |
| 35 | + } | |
| 36 | + int num = PyList_Size($input); | |
| 37 | + if (num > 0) { | |
| 38 | + $1 = (unsigned short*)malloc(num*sizeof(unsigned short)); | |
| 39 | + for (int i = 0; i < num; i++) { | |
| 40 | + PyObject *s = PyList_GetItem($input,i); | |
| 41 | + if (!PyInt_Check(s)) { | |
| 42 | + free($1); | |
| 43 | + SWIG_exception(SWIG_ValueError, "List items must be integers"); | |
| 44 | + } | |
| 45 | + $1[i] = (unsigned short)PyInt_AsLong(s); | |
| 46 | + } | |
| 47 | + } | |
| 48 | +} | |
| 49 | +%typemap(typecheck, precedence=SWIG_TYPECHECK_INTEGER) const unsigned short* pixels { | |
| 50 | + $1 = PyList_Check($input) ? 1 : 0; | |
| 51 | +} | |
| 52 | +%typemap(freearg) const unsigned short* pixels { | |
| 53 | + if ($1) { | |
| 54 | + free($1); | |
| 55 | + } | |
| 56 | +} | |
| 57 | + | |
| 32 | 58 | |
| 33 | 59 | /***********************************************************************//** |
| 34 | 60 | * @class GFitsImageUShort |
| ... | ... | @@ -57,7 +83,6 @@ public: |
| 57 | 83 | double pixel(const int& ix, const int& iy) const; |
| 58 | 84 | double pixel(const int& ix, const int& iy, const int& iz) const; |
| 59 | 85 | double pixel(const int& ix, const int& iy, const int& iz, const int& it) const; |
| 60 | - void* pixels(void); | |
| 61 | 86 | int type(void) const; |
| 62 | 87 | }; |
| 63 | 88 | |
| ... | ... | @@ -117,7 +142,24 @@ public: |
| 117 | 142 | GFitsImageInx[0]); |
| 118 | 143 | } |
| 119 | 144 | } |
| 145 | + PyObject* pixels(void) { | |
| 146 | + PyObject *list = PyList_New(self->npix()); | |
| 147 | + for (int i = 0; i < self->npix(); ++i) { | |
| 148 | + PyList_SetItem(list, i, PyInt_FromLong((long)(static_cast<unsigned short*>(self->pixels())[i]))); | |
| 149 | + } | |
| 150 | + return list; | |
| 151 | + } | |
| 120 | 152 | GFitsImageUShort copy() { |
| 121 | 153 | return (*self); |
| 122 | 154 | } |
| 155 | +%pythoncode { | |
| 156 | + def __getstate__(self): | |
| 157 | + state = (gammalib.GFitsHDU.__getstate__(self), | |
| 158 | + [self.naxes(axis) for axis in range(self.naxis())], | |
| 159 | + self.pixels()) | |
| 160 | + return state | |
| 161 | + def __setstate__(self, state): | |
| 162 | + self.__init__(state[1], state[2]) | |
| 163 | + gammalib.GFitsHDU.__setstate__(self, state[0]) | |
| 164 | +} | |
| 123 | 165 | }; | ... | ... |
pyext/GFitsTable.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsTable.i - FITS abstract table base class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2008-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2008-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -26,8 +26,8 @@ |
| 26 | 26 | %{ |
| 27 | 27 | /* Put headers and other declarations here that are needed for compilation */ |
| 28 | 28 | #include "GFitsTable.hpp" |
| 29 | -#include "GTools.hpp" | |
| 30 | 29 | %} |
| 30 | + | |
| 31 | 31 | /***********************************************************************//** |
| 32 | 32 | * @brief Tuple to index conversion to provide column access. |
| 33 | 33 | * |
| ... | ... | @@ -152,4 +152,13 @@ public: |
| 152 | 152 | self->set(colname, col); |
| 153 | 153 | return; |
| 154 | 154 | } |
| 155 | +%pythoncode { | |
| 156 | + def __getstate__(self): | |
| 157 | + state = (tuple([self[i] for i in range(self.ncols())]),) | |
| 158 | + return state | |
| 159 | + def __setstate__(self, state): | |
| 160 | + self.__init__() | |
| 161 | + for x in state[0]: | |
| 162 | + self.append(x) | |
| 163 | +} | |
| 155 | 164 | }; | ... | ... |
pyext/GFitsTableBitCol.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsTableBitCol.i - FITS table bit column class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2008-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2008-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -113,4 +113,15 @@ public: |
| 113 | 113 | GFitsTableBitCol copy() { |
| 114 | 114 | return (*self); |
| 115 | 115 | } |
| 116 | +%pythoncode { | |
| 117 | + def __getstate__(self): | |
| 118 | + state = (self.name(), self.nrows(), self.number(), | |
| 119 | + [[self[row,inx] for inx in range(self.elements(row))] for row in range(self.nrows())]) | |
| 120 | + return state | |
| 121 | + def __setstate__(self, state): | |
| 122 | + self.__init__(state[0], state[1], state[2]) | |
| 123 | + for row in range(len(state[3])): | |
| 124 | + for inx in range(len(state[3][row])): | |
| 125 | + self[row,inx] = state[3][row][inx] | |
| 126 | +} | |
| 116 | 127 | }; | ... | ... |
pyext/GFitsTableBoolCol.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsTableBoolCol.i - FITS table boolean column class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2008-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2008-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -113,4 +113,15 @@ public: |
| 113 | 113 | GFitsTableBoolCol copy() { |
| 114 | 114 | return (*self); |
| 115 | 115 | } |
| 116 | +%pythoncode { | |
| 117 | + def __getstate__(self): | |
| 118 | + state = (self.name(), self.nrows(), self.number(), | |
| 119 | + [[self[row,inx] for inx in range(self.elements(row))] for row in range(self.nrows())]) | |
| 120 | + return state | |
| 121 | + def __setstate__(self, state): | |
| 122 | + self.__init__(state[0], state[1], state[2]) | |
| 123 | + for row in range(len(state[3])): | |
| 124 | + for inx in range(len(state[3][row])): | |
| 125 | + self[row,inx] = state[3][row][inx] | |
| 126 | +} | |
| 116 | 127 | }; | ... | ... |
pyext/GFitsTableByteCol.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsTableByteCol.i - FITS table Byte column class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2008-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2008-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -113,4 +113,15 @@ public: |
| 113 | 113 | GFitsTableByteCol copy() { |
| 114 | 114 | return (*self); |
| 115 | 115 | } |
| 116 | +%pythoncode { | |
| 117 | + def __getstate__(self): | |
| 118 | + state = (self.name(), self.nrows(), self.number(), | |
| 119 | + [[self[row,inx] for inx in range(self.elements(row))] for row in range(self.nrows())]) | |
| 120 | + return state | |
| 121 | + def __setstate__(self, state): | |
| 122 | + self.__init__(state[0], state[1], state[2]) | |
| 123 | + for row in range(len(state[3])): | |
| 124 | + for inx in range(len(state[3][row])): | |
| 125 | + self[row,inx] = state[3][row][inx] | |
| 126 | +} | |
| 116 | 127 | }; | ... | ... |
pyext/GFitsTableCol.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsTableCol.i - FITS abstract table column base class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2008-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2008-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -257,5 +257,4 @@ public: |
| 257 | 257 | "Column type does not support floating point setting."); |
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | - | |
| 261 | 260 | }; | ... | ... |
pyext/GFitsTableDoubleCol.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsTableDoubleCol.i - FITS table double precision column class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2008-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2008-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -113,4 +113,15 @@ public: |
| 113 | 113 | GFitsTableDoubleCol copy() { |
| 114 | 114 | return (*self); |
| 115 | 115 | } |
| 116 | +%pythoncode { | |
| 117 | + def __getstate__(self): | |
| 118 | + state = (self.name(), self.nrows(), self.number(), | |
| 119 | + [[self[row,inx] for inx in range(self.elements(row))] for row in range(self.nrows())]) | |
| 120 | + return state | |
| 121 | + def __setstate__(self, state): | |
| 122 | + self.__init__(state[0], state[1], state[2]) | |
| 123 | + for row in range(len(state[3])): | |
| 124 | + for inx in range(len(state[3][row])): | |
| 125 | + self[row,inx] = state[3][row][inx] | |
| 126 | +} | |
| 116 | 127 | }; | ... | ... |
pyext/GFitsTableFloatCol.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsTableFloatCol.i - FITS table single precision column class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2008-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2008-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -113,4 +113,15 @@ public: |
| 113 | 113 | GFitsTableFloatCol copy() { |
| 114 | 114 | return (*self); |
| 115 | 115 | } |
| 116 | +%pythoncode { | |
| 117 | + def __getstate__(self): | |
| 118 | + state = (self.name(), self.nrows(), self.number(), | |
| 119 | + [[self[row,inx] for inx in range(self.elements(row))] for row in range(self.nrows())]) | |
| 120 | + return state | |
| 121 | + def __setstate__(self, state): | |
| 122 | + self.__init__(state[0], state[1], state[2]) | |
| 123 | + for row in range(len(state[3])): | |
| 124 | + for inx in range(len(state[3][row])): | |
| 125 | + self[row,inx] = state[3][row][inx] | |
| 126 | +} | |
| 116 | 127 | }; | ... | ... |
pyext/GFitsTableLongCol.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsTableLongCol.i - FITS table long integer column class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2008-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2008-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -113,4 +113,15 @@ public: |
| 113 | 113 | GFitsTableLongCol copy() { |
| 114 | 114 | return (*self); |
| 115 | 115 | } |
| 116 | +%pythoncode { | |
| 117 | + def __getstate__(self): | |
| 118 | + state = (self.name(), self.nrows(), self.number(), | |
| 119 | + [[self[row,inx] for inx in range(self.elements(row))] for row in range(self.nrows())]) | |
| 120 | + return state | |
| 121 | + def __setstate__(self, state): | |
| 122 | + self.__init__(state[0], state[1], state[2]) | |
| 123 | + for row in range(len(state[3])): | |
| 124 | + for inx in range(len(state[3][row])): | |
| 125 | + self[row,inx] = state[3][row][inx] | |
| 126 | +} | |
| 116 | 127 | }; | ... | ... |
pyext/GFitsTableLongLongCol.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsTableLongLongCol.i - FITS table long long integer column class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2008-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2008-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -113,4 +113,15 @@ public: |
| 113 | 113 | GFitsTableLongLongCol copy() { |
| 114 | 114 | return (*self); |
| 115 | 115 | } |
| 116 | +%pythoncode { | |
| 117 | + def __getstate__(self): | |
| 118 | + state = (self.name(), self.nrows(), self.number(), | |
| 119 | + [[self[row,inx] for inx in range(self.elements(row))] for row in range(self.nrows())]) | |
| 120 | + return state | |
| 121 | + def __setstate__(self, state): | |
| 122 | + self.__init__(state[0], state[1], state[2]) | |
| 123 | + for row in range(len(state[3])): | |
| 124 | + for inx in range(len(state[3][row])): | |
| 125 | + self[row,inx] = state[3][row][inx] | |
| 126 | +} | |
| 116 | 127 | }; | ... | ... |
pyext/GFitsTableShortCol.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsTableShortCol.i - FITS table short integer column class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2008-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2008-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -113,4 +113,15 @@ public: |
| 113 | 113 | GFitsTableShortCol copy() { |
| 114 | 114 | return (*self); |
| 115 | 115 | } |
| 116 | +%pythoncode { | |
| 117 | + def __getstate__(self): | |
| 118 | + state = (self.name(), self.nrows(), self.number(), | |
| 119 | + [[self[row,inx] for inx in range(self.elements(row))] for row in range(self.nrows())]) | |
| 120 | + return state | |
| 121 | + def __setstate__(self, state): | |
| 122 | + self.__init__(state[0], state[1], state[2]) | |
| 123 | + for row in range(len(state[3])): | |
| 124 | + for inx in range(len(state[3][row])): | |
| 125 | + self[row,inx] = state[3][row][inx] | |
| 126 | +} | |
| 116 | 127 | }; | ... | ... |
pyext/GFitsTableStringCol.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsTableStringCol.i - FITS table string column class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2008-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2008-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -134,4 +134,15 @@ public: |
| 134 | 134 | GFitsTableStringCol copy() { |
| 135 | 135 | return (*self); |
| 136 | 136 | } |
| 137 | +%pythoncode { | |
| 138 | + def __getstate__(self): | |
| 139 | + state = (self.name(), self.nrows(), self.width(), self.number(), | |
| 140 | + [[self[row,inx] for inx in range(self.elements(row))] for row in range(self.nrows())]) | |
| 141 | + return state | |
| 142 | + def __setstate__(self, state): | |
| 143 | + self.__init__(state[0], state[1], state[2], state[3]) | |
| 144 | + for row in range(len(state[4])): | |
| 145 | + for inx in range(len(state[4][row])): | |
| 146 | + self[row,inx] = state[4][row][inx] | |
| 147 | +} | |
| 137 | 148 | }; | ... | ... |
pyext/GFitsTableULongCol.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsTableULongCol.i - FITS table unsigned long integer column class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -113,4 +113,15 @@ public: |
| 113 | 113 | GFitsTableULongCol copy() { |
| 114 | 114 | return (*self); |
| 115 | 115 | } |
| 116 | +%pythoncode { | |
| 117 | + def __getstate__(self): | |
| 118 | + state = (self.name(), self.nrows(), self.number(), | |
| 119 | + [[self[row,inx] for inx in range(self.elements(row))] for row in range(self.nrows())]) | |
| 120 | + return state | |
| 121 | + def __setstate__(self, state): | |
| 122 | + self.__init__(state[0], state[1], state[2]) | |
| 123 | + for row in range(len(state[3])): | |
| 124 | + for inx in range(len(state[3][row])): | |
| 125 | + self[row,inx] = state[3][row][inx] | |
| 126 | +} | |
| 116 | 127 | }; | ... | ... |
pyext/GFitsTableUShortCol.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsTableUShortCol.i - FITS table unsigned short integer column class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2008-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2008-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -113,4 +113,15 @@ public: |
| 113 | 113 | GFitsTableUShortCol copy() { |
| 114 | 114 | return (*self); |
| 115 | 115 | } |
| 116 | +%pythoncode { | |
| 117 | + def __getstate__(self): | |
| 118 | + state = (self.name(), self.nrows(), self.number(), | |
| 119 | + [[self[row,inx] for inx in range(self.elements(row))] for row in range(self.nrows())]) | |
| 120 | + return state | |
| 121 | + def __setstate__(self, state): | |
| 122 | + self.__init__(state[0], state[1], state[2]) | |
| 123 | + for row in range(len(state[3])): | |
| 124 | + for inx in range(len(state[3][row])): | |
| 125 | + self[row,inx] = state[3][row][inx] | |
| 126 | +} | |
| 116 | 127 | }; | ... | ... |
pyext/GModelSpatialDiffuseConst.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GModelSpatialDiffuseConst.i - Spatial isotropic model class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2011-2016 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2011-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -74,4 +74,13 @@ public: |
| 74 | 74 | GModelSpatialDiffuseConst copy() { |
| 75 | 75 | return (*self); |
| 76 | 76 | } |
| 77 | +%pythoncode { | |
| 78 | + def __getstate__(self): | |
| 79 | + xml = gammalib.GXmlElement() | |
| 80 | + self.write(xml) | |
| 81 | + state = xml, | |
| 82 | + return state | |
| 83 | + def __setstate__(self, state): | |
| 84 | + self.__init__(state[0]) | |
| 85 | +} | |
| 77 | 86 | }; | ... | ... |
pyext/GModelSpatialDiffuseCube.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GModelSpatialDiffuseCube.i - Spatial map cube model class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2011-2016 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2011-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * | ... | ... |
src/fits/GFitsHeaderCard.cpp
| ... | ... | @@ -75,6 +75,35 @@ GFitsHeaderCard::GFitsHeaderCard(void) |
| 75 | 75 | |
| 76 | 76 | |
| 77 | 77 | /***********************************************************************//** |
| 78 | + * @brief Card constructor | |
| 79 | + * | |
| 80 | + * @param[in] keyname Card name. | |
| 81 | + * @param[in] value Card value. | |
| 82 | + * @param[in] unit Card unit. | |
| 83 | + * @param[in] comment Card comment. | |
| 84 | + * | |
| 85 | + * Constructs a header card from @p keyname, @p value, @p unit and | |
| 86 | + * @p comment string. The card type is determined from the card value format. | |
| 87 | + ***************************************************************************/ | |
| 88 | +GFitsHeaderCard::GFitsHeaderCard(const std::string& keyname, | |
| 89 | + const std::string& value, | |
| 90 | + const std::string& unit, | |
| 91 | + const std::string& comment) | |
| 92 | +{ | |
| 93 | + // Initialise class members | |
| 94 | + init_members(); | |
| 95 | + | |
| 96 | + // Set members | |
| 97 | + set_members(keyname, value, unit, comment); | |
| 98 | + | |
| 99 | + // Return | |
| 100 | + return; | |
| 101 | +} | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | +/***********************************************************************//** | |
| 78 | 107 | * @brief Constructor for string cards |
| 79 | 108 | * |
| 80 | 109 | * @param[in] keyname Card name. |
| ... | ... | @@ -826,6 +855,35 @@ void GFitsHeaderCard::free_members(void) |
| 826 | 855 | |
| 827 | 856 | |
| 828 | 857 | /***********************************************************************//** |
| 858 | + * @brief Set card members | |
| 859 | + * | |
| 860 | + * @param[in] keyname Card name. | |
| 861 | + * @param[in] value Card value. | |
| 862 | + * @param[in] unit Card unit. | |
| 863 | + * @param[in] comment Card comment. | |
| 864 | + * | |
| 865 | + * Sets the card members from @p keyname, @p value, @p unit, and @p comment | |
| 866 | + * strings. The card type is determined from the format of the card value. | |
| 867 | + ***************************************************************************/ | |
| 868 | +void GFitsHeaderCard::set_members(const std::string& keyname, | |
| 869 | + const std::string& value, | |
| 870 | + const std::string& unit, | |
| 871 | + const std::string& comment) { | |
| 872 | + | |
| 873 | + // Store attributes | |
| 874 | + m_keyname = keyname; | |
| 875 | + m_value = value; | |
| 876 | + m_comment = comment; | |
| 877 | + | |
| 878 | + // Determine card type | |
| 879 | + set_dtype(m_value); | |
| 880 | + | |
| 881 | + // Return | |
| 882 | + return; | |
| 883 | +} | |
| 884 | + | |
| 885 | + | |
| 886 | +/***********************************************************************//** | |
| 829 | 887 | * @brief Copy dtype |
| 830 | 888 | * |
| 831 | 889 | * @param[in] card Header card. | ... | ... |
src/fits/GFitsImageByte.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsImageByte.cpp - FITS Byte image class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -166,8 +166,7 @@ GFitsImageByte::GFitsImageByte(const int& nx, const int& ny, const int& nz, |
| 166 | 166 | * @param[in] pixels Optional pointer to image pixel array |
| 167 | 167 | * |
| 168 | 168 | * Construct instance of GFitsImageByte by specifying the image dimension and |
| 169 | - * the number of pixels in each dimension. Note that this constructor does | |
| 170 | - * not allocate any memory for the actual image. | |
| 169 | + * the number of pixels in each dimension. | |
| 171 | 170 | ***************************************************************************/ |
| 172 | 171 | GFitsImageByte::GFitsImageByte(const std::vector<int>& naxes, |
| 173 | 172 | const unsigned char* pixels) : |
| ... | ... | @@ -210,7 +209,7 @@ GFitsImageByte::GFitsImageByte(const GFitsImage& image) : |
| 210 | 209 | m_bitpix = G_BITPIX; |
| 211 | 210 | |
| 212 | 211 | // Update header card |
| 213 | - header()["BITPIX"].value(G_BITPIX); | |
| 212 | + card("BITPIX").value(G_BITPIX); | |
| 214 | 213 | |
| 215 | 214 | // Return |
| 216 | 215 | return; | ... | ... |
src/fits/GFitsImageDouble.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsImageDouble.cpp - Double precision FITS image class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2008-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2008-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -166,8 +166,7 @@ GFitsImageDouble::GFitsImageDouble(const int& nx, const int& ny, const int& nz, |
| 166 | 166 | * @param[in] pixels Optional pointer to image pixel array |
| 167 | 167 | * |
| 168 | 168 | * Construct instance of GFitsImageDouble by specifying the image dimension and |
| 169 | - * the number of pixels in each dimension. Note that this constructor does | |
| 170 | - * not allocate any memory for the actual image. | |
| 169 | + * the number of pixels in each dimension. | |
| 171 | 170 | ***************************************************************************/ |
| 172 | 171 | GFitsImageDouble::GFitsImageDouble(const std::vector<int>& naxes, |
| 173 | 172 | const double* pixels) : |
| ... | ... | @@ -210,7 +209,7 @@ GFitsImageDouble::GFitsImageDouble(const GFitsImage& image) : |
| 210 | 209 | m_bitpix = G_BITPIX; |
| 211 | 210 | |
| 212 | 211 | // Update header card |
| 213 | - header()["BITPIX"].value(G_BITPIX); | |
| 212 | + card("BITPIX").value(G_BITPIX); | |
| 214 | 213 | |
| 215 | 214 | // Return |
| 216 | 215 | return; | ... | ... |
src/fits/GFitsImageFloat.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsImageFloat.cpp - Single precision FITS image class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2016 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -166,8 +166,7 @@ GFitsImageFloat::GFitsImageFloat(const int& nx, const int& ny, const int& nz, |
| 166 | 166 | * @param[in] pixels Optional pointer to image pixel array |
| 167 | 167 | * |
| 168 | 168 | * Construct instance of GFitsImageFloat by specifying the image dimension and |
| 169 | - * the number of pixels in each dimension. Note that this constructor does | |
| 170 | - * not allocate any memory for the actual image. | |
| 169 | + * the number of pixels in each dimension. | |
| 171 | 170 | ***************************************************************************/ |
| 172 | 171 | GFitsImageFloat::GFitsImageFloat(const std::vector<int>& naxes, |
| 173 | 172 | const float* pixels) : |
| ... | ... | @@ -210,7 +209,7 @@ GFitsImageFloat::GFitsImageFloat(const GFitsImage& image) : |
| 210 | 209 | m_bitpix = G_BITPIX; |
| 211 | 210 | |
| 212 | 211 | // Update header card |
| 213 | - header()["BITPIX"].value(G_BITPIX); | |
| 212 | + card("BITPIX").value(G_BITPIX); | |
| 214 | 213 | |
| 215 | 214 | // Return |
| 216 | 215 | return; | ... | ... |
src/fits/GFitsImageLong.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsImageLong.cpp - Long integer FITS image class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -165,8 +165,7 @@ GFitsImageLong::GFitsImageLong(const int& nx, const int& ny, const int& nz, |
| 165 | 165 | * @param[in] pixels Optional pointer to image pixel array |
| 166 | 166 | * |
| 167 | 167 | * Construct instance of GFitsImageLong by specifying the image dimension and |
| 168 | - * the number of pixels in each dimension. Note that this constructor does | |
| 169 | - * not allocate any memory for the actual image. | |
| 168 | + * the number of pixels in each dimension. | |
| 170 | 169 | ***************************************************************************/ |
| 171 | 170 | GFitsImageLong::GFitsImageLong(const std::vector<int>& naxes, |
| 172 | 171 | const long* pixels) : |
| ... | ... | @@ -209,7 +208,7 @@ GFitsImageLong::GFitsImageLong(const GFitsImage& image) : |
| 209 | 208 | m_bitpix = G_BITPIX; |
| 210 | 209 | |
| 211 | 210 | // Update header card |
| 212 | - header()["BITPIX"].value(G_BITPIX); | |
| 211 | + card("BITPIX").value(G_BITPIX); | |
| 213 | 212 | |
| 214 | 213 | // Return |
| 215 | 214 | return; | ... | ... |
src/fits/GFitsImageLongLong.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsImageLongLong.cpp - Long long integer FITS image class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -168,8 +168,7 @@ GFitsImageLongLong::GFitsImageLongLong(const int& nx, const int& ny, |
| 168 | 168 | * @param[in] pixels Optional pointer to image pixel array |
| 169 | 169 | * |
| 170 | 170 | * Construct instance of GFitsImageLongLong by specifying the image dimension and |
| 171 | - * the number of pixels in each dimension. Note that this constructor does | |
| 172 | - * not allocate any memory for the actual image. | |
| 171 | + * the number of pixels in each dimension. | |
| 173 | 172 | ***************************************************************************/ |
| 174 | 173 | GFitsImageLongLong::GFitsImageLongLong(const std::vector<int>& naxes, |
| 175 | 174 | const long long* pixels) : |
| ... | ... | @@ -212,7 +211,7 @@ GFitsImageLongLong::GFitsImageLongLong(const GFitsImage& image) : |
| 212 | 211 | m_bitpix = G_BITPIX; |
| 213 | 212 | |
| 214 | 213 | // Update header card |
| 215 | - header()["BITPIX"].value(G_BITPIX); | |
| 214 | + card("BITPIX").value(G_BITPIX); | |
| 216 | 215 | |
| 217 | 216 | // Return |
| 218 | 217 | return; | ... | ... |
src/fits/GFitsImageSByte.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsImageSByte.cpp - Signed Byte FITS image class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -167,8 +167,7 @@ GFitsImageSByte::GFitsImageSByte(const int& nx, const int& ny, const int& nz, |
| 167 | 167 | * @param[in] pixels Optional pointer to image pixel array |
| 168 | 168 | * |
| 169 | 169 | * Construct instance of GFitsImageSByte by specifying the image dimension and |
| 170 | - * the number of pixels in each dimension. Note that this constructor does | |
| 171 | - * not allocate any memory for the actual image. | |
| 170 | + * the number of pixels in each dimension. | |
| 172 | 171 | ***************************************************************************/ |
| 173 | 172 | GFitsImageSByte::GFitsImageSByte(const std::vector<int>& naxes, |
| 174 | 173 | const char* pixels) : |
| ... | ... | @@ -211,7 +210,7 @@ GFitsImageSByte::GFitsImageSByte(const GFitsImage& image) : |
| 211 | 210 | m_bitpix = G_BITPIX; |
| 212 | 211 | |
| 213 | 212 | // Update header card |
| 214 | - header()["BITPIX"].value(G_BITPIX); | |
| 213 | + card("BITPIX").value(G_BITPIX); | |
| 215 | 214 | |
| 216 | 215 | // Return |
| 217 | 216 | return; | ... | ... |
src/fits/GFitsImageShort.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsImageShort.cpp - Short integer FITS image class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -166,8 +166,7 @@ GFitsImageShort::GFitsImageShort(const int& nx, const int& ny, const int& nz, |
| 166 | 166 | * @param[in] pixels Optional pointer to image pixel array |
| 167 | 167 | * |
| 168 | 168 | * Construct instance of GFitsImageShort by specifying the image dimension and |
| 169 | - * the number of pixels in each dimension. Note that this constructor does | |
| 170 | - * not allocate any memory for the actual image. | |
| 169 | + * the number of pixels in each dimension. | |
| 171 | 170 | ***************************************************************************/ |
| 172 | 171 | GFitsImageShort::GFitsImageShort(const std::vector<int>& naxes, |
| 173 | 172 | const short* pixels) : |
| ... | ... | @@ -210,7 +209,7 @@ GFitsImageShort::GFitsImageShort(const GFitsImage& image) : |
| 210 | 209 | m_bitpix = G_BITPIX; |
| 211 | 210 | |
| 212 | 211 | // Update header card |
| 213 | - header()["BITPIX"].value(G_BITPIX); | |
| 212 | + card("BITPIX").value(G_BITPIX); | |
| 214 | 213 | |
| 215 | 214 | // Return |
| 216 | 215 | return; | ... | ... |
src/fits/GFitsImageULong.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsImageULong.cpp - Unsigned long image FITS class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -167,8 +167,7 @@ GFitsImageULong::GFitsImageULong(const int& nx, const int& ny, const int& nz, |
| 167 | 167 | * @param[in] pixels Optional pointer to image pixel array |
| 168 | 168 | * |
| 169 | 169 | * Construct instance of GFitsImageULong by specifying the image dimension and |
| 170 | - * the number of pixels in each dimension. Note that this constructor does | |
| 171 | - * not allocate any memory for the actual image. | |
| 170 | + * the number of pixels in each dimension. | |
| 172 | 171 | ***************************************************************************/ |
| 173 | 172 | GFitsImageULong::GFitsImageULong(const std::vector<int>& naxes, |
| 174 | 173 | const unsigned long* pixels) : |
| ... | ... | @@ -211,7 +210,7 @@ GFitsImageULong::GFitsImageULong(const GFitsImage& image) : |
| 211 | 210 | m_bitpix = G_BITPIX; |
| 212 | 211 | |
| 213 | 212 | // Update header card |
| 214 | - header()["BITPIX"].value(G_BITPIX); | |
| 213 | + card("BITPIX").value(G_BITPIX); | |
| 215 | 214 | |
| 216 | 215 | // Return |
| 217 | 216 | return; | ... | ... |
src/fits/GFitsImageUShort.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFitsImageUShort.cpp - Unsigned short FITS image class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2018 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -168,8 +168,7 @@ GFitsImageUShort::GFitsImageUShort(const int& nx, const int& ny, |
| 168 | 168 | * @param[in] pixels Optional pointer to image pixel array |
| 169 | 169 | * |
| 170 | 170 | * Construct instance of GFitsImageUShort by specifying the image dimension and |
| 171 | - * the number of pixels in each dimension. Note that this constructor does | |
| 172 | - * not allocate any memory for the actual image. | |
| 171 | + * the number of pixels in each dimension. | |
| 173 | 172 | ***************************************************************************/ |
| 174 | 173 | GFitsImageUShort::GFitsImageUShort(const std::vector<int>& naxes, |
| 175 | 174 | const unsigned short* pixels) : |
| ... | ... | @@ -212,7 +211,7 @@ GFitsImageUShort::GFitsImageUShort(const GFitsImage& image) : |
| 212 | 211 | m_bitpix = G_BITPIX; |
| 213 | 212 | |
| 214 | 213 | // Update header card |
| 215 | - header()["BITPIX"].value(G_BITPIX); | |
| 214 | + card("BITPIX").value(G_BITPIX); | |
| 216 | 215 | |
| 217 | 216 | // Return |
| 218 | 217 | return; | ... | ... |
test/test_GFits.py
| 1 | 1 | # ========================================================================== |
| 2 | 2 | # This module performs unit tests for the GammaLib FITS module. |
| 3 | 3 | # |
| 4 | -# Copyright (C) 2012-2017 Juergen Knoedlseder | |
| 4 | +# Copyright (C) 2012-2018 Juergen Knoedlseder | |
| 5 | 5 | # |
| 6 | 6 | # This program is free software: you can redistribute it and/or modify |
| 7 | 7 | # it under the terms of the GNU General Public License as published by |
| ... | ... | @@ -20,6 +20,7 @@ |
| 20 | 20 | import os |
| 21 | 21 | import math |
| 22 | 22 | import gammalib |
| 23 | +import test_support | |
| 23 | 24 | |
| 24 | 25 | |
| 25 | 26 | # =================================== # |
| ... | ... | @@ -613,6 +614,107 @@ class Test(gammalib.GPythonTestSuite): |
| 613 | 614 | # Return |
| 614 | 615 | return |
| 615 | 616 | |
| 617 | + # Test class pickeling | |
| 618 | + def _test_pickeling(self): | |
| 619 | + """ | |
| 620 | + Test class pickeling | |
| 621 | + """ | |
| 622 | + # Perform pickeling tests of empty classes | |
| 623 | + test_support._pickeling(self, gammalib.GFits()) | |
| 624 | + test_support._pickeling(self, gammalib.GFitsAsciiTable()) | |
| 625 | + test_support._pickeling(self, gammalib.GFitsBinTable()) | |
| 626 | + test_support._pickeling(self, gammalib.GFitsHeader()) | |
| 627 | + test_support._pickeling(self, gammalib.GFitsHeaderCard()) | |
| 628 | + test_support._pickeling(self, gammalib.GFitsImageByte()) | |
| 629 | + test_support._pickeling(self, gammalib.GFitsImageDouble()) | |
| 630 | + test_support._pickeling(self, gammalib.GFitsImageFloat()) | |
| 631 | + test_support._pickeling(self, gammalib.GFitsImageLong()) | |
| 632 | + test_support._pickeling(self, gammalib.GFitsImageLongLong()) | |
| 633 | + test_support._pickeling(self, gammalib.GFitsImageSByte()) | |
| 634 | + test_support._pickeling(self, gammalib.GFitsImageShort()) | |
| 635 | + test_support._pickeling(self, gammalib.GFitsImageULong()) | |
| 636 | + test_support._pickeling(self, gammalib.GFitsImageUShort()) | |
| 637 | + test_support._pickeling(self, gammalib.GFitsTableBitCol()) | |
| 638 | + test_support._pickeling(self, gammalib.GFitsTableBoolCol()) | |
| 639 | + test_support._pickeling(self, gammalib.GFitsTableByteCol()) | |
| 640 | + #test_support._pickeling(self, gammalib.GFitsTableCDoubleCol()) | |
| 641 | + #test_support._pickeling(self, gammalib.GFitsTableCFloatCol()) | |
| 642 | + test_support._pickeling(self, gammalib.GFitsTableDoubleCol()) | |
| 643 | + test_support._pickeling(self, gammalib.GFitsTableFloatCol()) | |
| 644 | + test_support._pickeling(self, gammalib.GFitsTableLongCol()) | |
| 645 | + test_support._pickeling(self, gammalib.GFitsTableLongLongCol()) | |
| 646 | + test_support._pickeling(self, gammalib.GFitsTableShortCol()) | |
| 647 | + test_support._pickeling(self, gammalib.GFitsTableStringCol()) | |
| 648 | + test_support._pickeling(self, gammalib.GFitsTableULongCol()) | |
| 649 | + test_support._pickeling(self, gammalib.GFitsTableUShortCol()) | |
| 650 | + | |
| 651 | + # Setup for tests | |
| 652 | + fits = gammalib.GFits(os.environ['TEST_DATA']+'/test_cube.fits') | |
| 653 | + header = gammalib.GFitsHeader() | |
| 654 | + header.append(gammalib.GFitsHeaderCard('key1','"string"','deg','test1')) | |
| 655 | + header.append(gammalib.GFitsHeaderCard('key2','1.0','deg','test2')) | |
| 656 | + col_bit = gammalib.GFitsTableBitCol('a',2,3) | |
| 657 | + col_bool = gammalib.GFitsTableBoolCol('a',2,3) | |
| 658 | + col_byte = gammalib.GFitsTableByteCol('a',2,3) | |
| 659 | + col_double = gammalib.GFitsTableDoubleCol('a',2,3) | |
| 660 | + col_float = gammalib.GFitsTableFloatCol('a',2,3) | |
| 661 | + col_long = gammalib.GFitsTableLongCol('a',2,3) | |
| 662 | + col_llong = gammalib.GFitsTableLongLongCol('a',2,3) | |
| 663 | + col_short = gammalib.GFitsTableShortCol('a',2,3) | |
| 664 | + col_ulong = gammalib.GFitsTableULongCol('a',2,3) | |
| 665 | + col_ushort = gammalib.GFitsTableUShortCol('a',2,3) | |
| 666 | + col_string = gammalib.GFitsTableStringCol('a',2,10,3) | |
| 667 | + bit = False | |
| 668 | + for row in range(2): | |
| 669 | + for col in range(3): | |
| 670 | + if bit: | |
| 671 | + bit = False | |
| 672 | + else: | |
| 673 | + bit = True | |
| 674 | + col_bit[row,col] = bit | |
| 675 | + col_bool[row,col] = not bit | |
| 676 | + col_byte[row,col] = row*10+col | |
| 677 | + col_double[row,col] = row*10+col | |
| 678 | + col_float[row,col] = row*10+col | |
| 679 | + col_long[row,col] = row*10+col | |
| 680 | + col_llong[row,col] = row*10+col | |
| 681 | + col_short[row,col] = row*10+col | |
| 682 | + col_ulong[row,col] = row*10+col | |
| 683 | + col_ushort[row,col] = row*10+col | |
| 684 | + col_string[row,col] = str(row*10+col) | |
| 685 | + | |
| 686 | + # Perform pickeling tests of filled classes | |
| 687 | + test_support._pickeling(self, gammalib.GFits(fits)) | |
| 688 | + test_support._pickeling(self, gammalib.GFitsAsciiTable(3)) | |
| 689 | + test_support._pickeling(self, gammalib.GFitsBinTable(4)) | |
| 690 | + test_support._pickeling(self, gammalib.GFitsHeader(header)) | |
| 691 | + test_support._pickeling(self, gammalib.GFitsHeaderCard('key','value','deg','test')) | |
| 692 | + test_support._pickeling(self, gammalib.GFitsImageByte(2,2,[1,2,3,4])) | |
| 693 | + test_support._pickeling(self, gammalib.GFitsImageDouble(2,2,[1.0,2.0,3.0,4.0])) | |
| 694 | + test_support._pickeling(self, gammalib.GFitsImageFloat(2,2,[1.0,2.0,3.0,4.0])) | |
| 695 | + test_support._pickeling(self, gammalib.GFitsImageLong(2,2,[1,2,3,4])) | |
| 696 | + test_support._pickeling(self, gammalib.GFitsImageLongLong(2,2,[1,2,3,4])) | |
| 697 | + test_support._pickeling(self, gammalib.GFitsImageSByte(2,2,[1,2,3,4])) | |
| 698 | + test_support._pickeling(self, gammalib.GFitsImageShort([2,2],[1,2,3,4])) | |
| 699 | + test_support._pickeling(self, gammalib.GFitsImageULong(2,2,1,[1,2,3,4])) | |
| 700 | + test_support._pickeling(self, gammalib.GFitsImageUShort(3,[1,2,3])) | |
| 701 | + test_support._pickeling(self, gammalib.GFitsTableBitCol(col_bit)) | |
| 702 | + test_support._pickeling(self, gammalib.GFitsTableBoolCol(col_bool)) | |
| 703 | + test_support._pickeling(self, gammalib.GFitsTableByteCol(col_byte)) | |
| 704 | + #test_support._pickeling(self, gammalib.GFitsTableCDoubleCol()) | |
| 705 | + #test_support._pickeling(self, gammalib.GFitsTableCFloatCol()) | |
| 706 | + test_support._pickeling(self, gammalib.GFitsTableDoubleCol(col_double)) | |
| 707 | + test_support._pickeling(self, gammalib.GFitsTableFloatCol(col_float)) | |
| 708 | + test_support._pickeling(self, gammalib.GFitsTableLongCol(col_long)) | |
| 709 | + test_support._pickeling(self, gammalib.GFitsTableLongLongCol(col_llong)) | |
| 710 | + test_support._pickeling(self, gammalib.GFitsTableShortCol(col_short)) | |
| 711 | + test_support._pickeling(self, gammalib.GFitsTableStringCol(col_string)) | |
| 712 | + test_support._pickeling(self, gammalib.GFitsTableULongCol(col_ulong)) | |
| 713 | + test_support._pickeling(self, gammalib.GFitsTableUShortCol(col_ushort)) | |
| 714 | + | |
| 715 | + # Return | |
| 716 | + return | |
| 717 | + | |
| 616 | 718 | # Set test functions |
| 617 | 719 | def set(self): |
| 618 | 720 | """ |
| ... | ... | @@ -623,13 +725,14 @@ class Test(gammalib.GPythonTestSuite): |
| 623 | 725 | |
| 624 | 726 | # Append tests |
| 625 | 727 | self.append(self._test_fits, 'Test GFits') |
| 626 | - self.append(self._test_fits_access, 'Test GFits parameter access') | |
| 728 | + self.append(self._test_fits_access, 'Test GFits member access') | |
| 627 | 729 | self.append(self._test_fits_slicing, 'Test GFits slicing') |
| 628 | - self.append(self._test_header_access, 'Test GFitsHeader parameter access') | |
| 730 | + self.append(self._test_header_access, 'Test GFitsHeader member access') | |
| 629 | 731 | self.append(self._test_header_slicing, 'Test GFitsHeader slicing') |
| 630 | 732 | self.append(self._test_fits_image, 'Test GFitsImage') |
| 631 | 733 | self.append(self._test_fits_table, 'Test GFitsTable') |
| 632 | 734 | self.append(self._test_fits_table_columns, 'Test GFitsTableCol') |
| 735 | + self.append(self._test_pickeling, 'Test pickeling of "fits" classes') | |
| 633 | 736 | |
| 634 | 737 | # Return |
| 635 | 738 | return | ... | ... |
test/test_GModel.py
| ... | ... | @@ -117,7 +117,7 @@ class Test(gammalib.GPythonTestSuite): |
| 117 | 117 | test_support._pickeling(self, gammalib.GModels()) |
| 118 | 118 | test_support._pickeling(self, gammalib.GModelSky()) |
| 119 | 119 | test_support._pickeling(self, gammalib.GModelSpatialComposite()) |
| 120 | - #test_support._pickeling(self, gammalib.GModelSpatialDiffuseConst()) | |
| 120 | + test_support._pickeling(self, gammalib.GModelSpatialDiffuseConst()) | |
| 121 | 121 | #test_support._pickeling(self, gammalib.GModelSpatialDiffuseCube()) |
| 122 | 122 | #test_support._pickeling(self, gammalib.GModelSpatialDiffuseMap()) |
| 123 | 123 | #test_support._pickeling(self, gammalib.GModelSpatialEllipticalDisk()) |
| ... | ... | @@ -176,7 +176,7 @@ class Test(gammalib.GPythonTestSuite): |
| 176 | 176 | test_support._pickeling(self, gammalib.GModels(self._setup_models())) |
| 177 | 177 | test_support._pickeling(self, gammalib.GModelSky(sky)) |
| 178 | 178 | test_support._pickeling(self, gammalib.GModelSpatialComposite(spacom)) |
| 179 | - #test_support._pickeling(self, gammalib.GModelSpatialDiffuseConst()) | |
| 179 | + test_support._pickeling(self, gammalib.GModelSpatialDiffuseConst(2.0)) | |
| 180 | 180 | #test_support._pickeling(self, gammalib.GModelSpatialDiffuseCube()) |
| 181 | 181 | #test_support._pickeling(self, gammalib.GModelSpatialDiffuseMap()) |
| 182 | 182 | #test_support._pickeling(self, gammalib.GModelSpatialEllipticalDisk()) | ... | ... |