[843] | 1 | #ifndef SPHEREHEALPIX_SEEN
|
---|
| 2 | #define SPHEREHEALPIX_SEEN
|
---|
| 3 |
|
---|
| 4 | #include "sphericalmap.h"
|
---|
| 5 | #include "tvector.h"
|
---|
| 6 | #include "ndatablock.h"
|
---|
| 7 |
|
---|
| 8 | #include "anydataobj.h"
|
---|
| 9 | #include "ppersist.h"
|
---|
| 10 |
|
---|
[1196] | 11 | #include "HEALPixUtils.h"
|
---|
[843] | 12 |
|
---|
| 13 | namespace SOPHYA {
|
---|
| 14 |
|
---|
| 15 |
|
---|
[853] | 16 | // ***************** CLASSE SphereHEALPix *****************************
|
---|
[843] | 17 |
|
---|
[1217] | 18 | /*! Class SphereHEALPix */
|
---|
[843] | 19 |
|
---|
| 20 |
|
---|
| 21 | template<class T>
|
---|
[853] | 22 | class FIO_SphereHEALPix;
|
---|
[843] | 23 |
|
---|
| 24 | template<class T>
|
---|
[853] | 25 | class FITS_SphereHEALPix;
|
---|
[843] | 26 |
|
---|
| 27 | template<class T>
|
---|
[853] | 28 | class SphereHEALPix : public SphericalMap<T>
|
---|
[843] | 29 | {
|
---|
[1196] | 30 | public :
|
---|
| 31 | // Static Methods to ease the use of HEALPix index <> angle conversion methods
|
---|
[843] | 32 |
|
---|
[1196] | 33 | static inline int_4 nest2ring(int_4 nside,int_4 ipnest)
|
---|
| 34 | { return HEALPix::nest2ring(nside, ipnest); }
|
---|
| 35 | static inline int_4 ring2nest(int_4 nside,int_4 ipring)
|
---|
| 36 | { return HEALPix::ring2nest(nside, ipring); }
|
---|
| 37 | static inline int_4 ang2pix_ring(int_4 nside,double theta,double phi)
|
---|
| 38 | { return HEALPix::ang2pix_ring(nside, theta, phi); }
|
---|
| 39 | static inline int_4 ang2pix_nest(int_4 nside,double theta,double phi)
|
---|
| 40 | { return HEALPix::ang2pix_nest(nside, theta, phi); }
|
---|
| 41 | static inline void pix2ang_ring(int_4 nside,int_4 ipix,double& theta,double& phi)
|
---|
| 42 | { HEALPix::pix2ang_ring(nside, ipix, theta, phi); }
|
---|
| 43 | static inline void pix2ang_nest(int_4 nside,int_4 ipix,double& theta,double& phi)
|
---|
| 44 | { HEALPix::pix2ang_nest(nside, ipix, theta, phi); }
|
---|
[843] | 45 |
|
---|
[853] | 46 | SphereHEALPix();
|
---|
| 47 | SphereHEALPix(int_4 m);
|
---|
[906] | 48 | SphereHEALPix(const SphereHEALPix<T>& s, bool share);
|
---|
| 49 | SphereHEALPix(const SphereHEALPix<T>& s);
|
---|
[853] | 50 | virtual ~SphereHEALPix();
|
---|
[843] | 51 |
|
---|
[908] | 52 | inline virtual bool IsTemp(void) const {
|
---|
| 53 |
|
---|
| 54 | if (sliceBeginIndex_.IsTemp() != pixels_.IsTemp() || sliceLenght_.IsTemp() != pixels_.IsTemp() )
|
---|
| 55 | throw PException(" l'etat 'temporaire' de la spherehealpix est incoherent");
|
---|
| 56 | return pixels_.IsTemp();
|
---|
| 57 | }
|
---|
[1217] | 58 |
|
---|
[843] | 59 | inline virtual void SetTemp(bool temp=false) const
|
---|
| 60 | {
|
---|
| 61 | pixels_.SetTemp(temp);
|
---|
| 62 | sliceBeginIndex_.SetTemp(temp);
|
---|
| 63 | sliceLenght_.SetTemp(temp);
|
---|
| 64 | };
|
---|
| 65 | // ------------------ Definition of PixelMap abstract methods
|
---|
| 66 |
|
---|
| 67 | virtual int_4 NbPixels() const;
|
---|
| 68 |
|
---|
| 69 | virtual T& PixVal(int_4 k);
|
---|
| 70 | virtual T const& PixVal(int_4 k) const;
|
---|
| 71 |
|
---|
[2968] | 72 | virtual uint_4 NbThetaSlices() const;
|
---|
| 73 | virtual r_8 ThetaOfSlice(int_4 index) const;
|
---|
[843] | 74 | virtual void GetThetaSlice(int_4 index,r_8& theta,TVector<r_8>& phi,TVector<T>& value) const;
|
---|
| 75 | virtual void GetThetaSlice(int_4 sliceIndex,r_8& theta, r_8& phi0, TVector<int_4>& pixelIndices,TVector<T>& value) const ;
|
---|
| 76 |
|
---|
| 77 | virtual bool ContainsSph(double theta, double phi) const;
|
---|
| 78 | virtual int_4 PixIndexSph(double theta,double phi) const;
|
---|
| 79 |
|
---|
| 80 | virtual void PixThetaPhi(int_4 k,double& theta,double& phi) const;
|
---|
| 81 |
|
---|
| 82 | virtual T SetPixels(T v);
|
---|
| 83 |
|
---|
[1217] | 84 | /*! Pixel Solid angle (steradians)
|
---|
[843] | 85 |
|
---|
| 86 | All the pixels have the same solid angle. The dummy argument is
|
---|
| 87 | for compatibility with eventual pixelizations which would not
|
---|
| 88 | fulfil this requirement.
|
---|
| 89 | */
|
---|
[1217] | 90 | inline virtual double PixSolAngle(int_4 dummy=0) const {return omeg_;}
|
---|
[843] | 91 |
|
---|
| 92 | /* Acces to the DataBlock */
|
---|
| 93 | inline NDataBlock<T>& DataBlock() {return pixels_;}
|
---|
| 94 | inline const NDataBlock<T>& DataBlock() const {return pixels_;}
|
---|
| 95 |
|
---|
| 96 | // --------------- Specific methods
|
---|
| 97 |
|
---|
[1217] | 98 | virtual void Resize(int_4 m);
|
---|
[843] | 99 |
|
---|
[1217] | 100 | /*!
|
---|
[843] | 101 |
|
---|
[1217] | 102 | \return type of storage of the map : RING or NESTED
|
---|
| 103 |
|
---|
| 104 | at the moment, always RING
|
---|
[843] | 105 | */
|
---|
[2290] | 106 | inline virtual string TypeOfMap() const {return string("RING");};
|
---|
[843] | 107 |
|
---|
| 108 |
|
---|
| 109 | virtual T& PixValNest(int_4 k);
|
---|
| 110 | virtual T const& PixValNest(int_4 k) const;
|
---|
| 111 |
|
---|
| 112 | virtual int_4 PixIndexSphNest(double theta,double phi) const;
|
---|
| 113 |
|
---|
| 114 | virtual void PixThetaPhiNest(int_4 k,double& theta,double& phi) const;
|
---|
| 115 |
|
---|
| 116 | void Pixelize(int_4);
|
---|
| 117 |
|
---|
| 118 | int_4 NestToRing(int_4) const;
|
---|
| 119 |
|
---|
| 120 | int_4 RingToNest(int_4) const;
|
---|
| 121 |
|
---|
| 122 |
|
---|
[1217] | 123 | /*! \return value of healpix nside */
|
---|
[843] | 124 | inline virtual int_4 SizeIndex() const {return(nSide_);}
|
---|
| 125 |
|
---|
| 126 | void print(ostream& os) const;
|
---|
[892] | 127 |
|
---|
| 128 |
|
---|
| 129 |
|
---|
[1419] | 130 |
|
---|
| 131 |
|
---|
| 132 |
|
---|
| 133 |
|
---|
| 134 |
|
---|
| 135 | // Operations diverses = , +=, ...
|
---|
| 136 |
|
---|
| 137 |
|
---|
| 138 | SphereHEALPix<T>& Set(const SphereHEALPix<T>& a);
|
---|
[892] | 139 | inline SphereHEALPix<T>& operator = (const SphereHEALPix<T>& a)
|
---|
[980] | 140 | {return Set(a);}
|
---|
[1195] | 141 |
|
---|
[1419] | 142 | // A += -= *= /= x (ajoute, soustrait, ... x a tous les elements)
|
---|
| 143 |
|
---|
| 144 | //! Fill SphereHEALPix with all elements equal to \b x
|
---|
| 145 | virtual SphereHEALPix<T>& SetT(T a);
|
---|
| 146 | inline SphereHEALPix<T>& operator = (T a) {return SetT(a);}
|
---|
| 147 |
|
---|
| 148 | //! Add \b x to all elements
|
---|
| 149 | virtual SphereHEALPix<T>& Add(T a);
|
---|
[2290] | 150 | inline SphereHEALPix<T>& operator += (T x) { pixels_ += x; return *this; }
|
---|
[1419] | 151 | //! Substract \b x to all elements
|
---|
[1624] | 152 | virtual SphereHEALPix<T>& Sub(T a,bool fginv=false);
|
---|
[2290] | 153 | inline SphereHEALPix<T>& operator -= (T x) { pixels_ -= x; return *this; }
|
---|
[1419] | 154 | //! Multiply all elements by \b x
|
---|
| 155 | virtual SphereHEALPix<T>& Mul(T a);
|
---|
[2290] | 156 | inline SphereHEALPix<T>& operator *= (T x) {pixels_ *= x; return *this; }
|
---|
[1419] | 157 | //! Divide all elements by \b x
|
---|
| 158 | virtual SphereHEALPix<T>& Div(T a);
|
---|
[2290] | 159 | inline SphereHEALPix<T>& operator /= (T x) {pixels_ /= x; return *this; }
|
---|
[1419] | 160 |
|
---|
| 161 | // A += -= (ajoute, soustrait element par element les deux spheres )
|
---|
| 162 | //! Operator SphereHEALPix += SphereHEALPix
|
---|
| 163 | virtual SphereHEALPix<T>& AddElt(const SphereHEALPix<T>& a);
|
---|
| 164 | inline SphereHEALPix<T>& operator += (const SphereHEALPix<T>& a) { return AddElt(a); }
|
---|
| 165 |
|
---|
| 166 |
|
---|
| 167 |
|
---|
| 168 | virtual SphereHEALPix<T>& SubElt(const SphereHEALPix<T>& a);
|
---|
| 169 | //! Operator SphereHEALPix -= SphereHEALPix
|
---|
| 170 | inline SphereHEALPix<T>& operator -= (const SphereHEALPix<T>& a) { return SubElt(a); }
|
---|
| 171 | // Multiplication, division element par element les deux SphereHEALPix
|
---|
| 172 | virtual SphereHEALPix<T>& MulElt(const SphereHEALPix<T>& a);
|
---|
| 173 | inline SphereHEALPix<T>& operator *= (const SphereHEALPix<T>& a) { return MulElt(a); }
|
---|
[1551] | 174 | virtual SphereHEALPix<T>& DivElt(const SphereHEALPix<T>& a);
|
---|
| 175 | inline SphereHEALPix<T>& operator /= (const SphereHEALPix<T>& a) { return DivElt(a); }
|
---|
[1419] | 176 |
|
---|
| 177 |
|
---|
[1196] | 178 | void CloneOrShare(const SphereHEALPix<T>& a);
|
---|
[1419] | 179 | void Share(const SphereHEALPix<T>& a);
|
---|
[1196] | 180 | SphereHEALPix<T>& CopyElt(const SphereHEALPix<T>& a);
|
---|
| 181 |
|
---|
| 182 |
|
---|
| 183 | // friend declaration for classes which handle persistence and FITS IO
|
---|
| 184 | friend class FIO_SphereHEALPix<T>;
|
---|
| 185 | friend class FITS_SphereHEALPix<T>;
|
---|
[1195] | 186 |
|
---|
[1196] | 187 | protected :
|
---|
[843] | 188 |
|
---|
| 189 | // ------------- méthodes internes ----------------------
|
---|
| 190 | void InitNul();
|
---|
| 191 | void SetThetaSlices();
|
---|
| 192 |
|
---|
| 193 | inline void setParameters(int_4 nside, int_4 nbpixels, double solangle)
|
---|
| 194 | {
|
---|
| 195 | nSide_= nside;
|
---|
| 196 | nPix_= nbpixels;
|
---|
| 197 | omeg_= solangle;
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | // ------------- variables internes -----------------------
|
---|
| 201 |
|
---|
| 202 | int_4 nSide_;
|
---|
| 203 | int_4 nPix_;
|
---|
| 204 | double omeg_;
|
---|
| 205 |
|
---|
| 206 | NDataBlock<T> pixels_;
|
---|
[1217] | 207 | NDataBlock<int_4> sliceBeginIndex_; // Rationalisation Mac. D.Y.
|
---|
[1145] | 208 | NDataBlock<int_4> sliceLenght_;
|
---|
[843] | 209 |
|
---|
| 210 | };
|
---|
| 211 |
|
---|
[1419] | 212 | ////////////////////////////////////////////////////////////////
|
---|
| 213 | // Surcharge d'operateurs A (+,-,*,/) (T) x
|
---|
[1423] | 214 | /*! \ingroup SkyMap \fn operator+(const SphereHEALPix<T>&,T)
|
---|
[1419] | 215 | \brief Operator SphereHEALPix = SphereHEALPix + constant */
|
---|
| 216 | template <class T> inline SphereHEALPix<T> operator + (const SphereHEALPix<T>& a, T b)
|
---|
| 217 | {SphereHEALPix<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 218 | result.Add(b); return result;}
|
---|
[1423] | 219 | /*! \ingroup SkyMap \fn operator+(T,const SphereHEALPix<T>&)
|
---|
[1419] | 220 | \brief Operator SphereHEALPix = constant + SphereHEALPix */
|
---|
| 221 | template <class T> inline SphereHEALPix<T> operator + (T b,const SphereHEALPix<T>& a)
|
---|
| 222 | {SphereHEALPix<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 223 | result.Add(b); return result;}
|
---|
[843] | 224 |
|
---|
| 225 |
|
---|
[1419] | 226 | /*! \ingroup SphereHEALPix\fn operator-(const SphereHEALPix<T>&,T)
|
---|
| 227 | \brief Operator SphereHEALPix = SphereHEALPix - constant */
|
---|
| 228 | template <class T> inline SphereHEALPix<T> operator - (const SphereHEALPix<T>& a, T b)
|
---|
| 229 | {SphereHEALPix<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 230 | result.Sub(b); return result;}
|
---|
| 231 |
|
---|
| 232 | /*! \ingroup \fn operator-(T,const SphereHEALPix<T>&)
|
---|
| 233 | \brief Operator SphereHEALPix = constant - SphereHEALPix */
|
---|
| 234 | template <class T> inline SphereHEALPix<T> operator - (T b,const SphereHEALPix<T>& a)
|
---|
| 235 | {SphereHEALPix<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 236 | result.Sub(b,true); return result;}
|
---|
| 237 |
|
---|
[1423] | 238 | /*! \ingroup SkyMap \fn operator*(const SphereHEALPix<T>&,T)
|
---|
[1419] | 239 | \brief Operator SphereHEALPix = SphereHEALPix * constant */
|
---|
| 240 | template <class T> inline SphereHEALPix<T> operator * (const SphereHEALPix<T>& a, T b)
|
---|
| 241 | {SphereHEALPix<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 242 | result.Mul(b); return result;}
|
---|
| 243 |
|
---|
[1423] | 244 | /*! \ingroup SkyMap \fn operator*(T,const SphereHEALPix<T>&)
|
---|
[1419] | 245 | \brief Operator SphereHEALPix = constant * SphereHEALPix */
|
---|
| 246 | template <class T> inline SphereHEALPix<T> operator * (T b,const SphereHEALPix<T>& a)
|
---|
| 247 | {SphereHEALPix<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 248 | result.Mul(b); return result;}
|
---|
| 249 |
|
---|
[1423] | 250 | /*! \ingroup SkyMap \fn operator/(const SphereHEALPix<T>&,T)
|
---|
[1419] | 251 | \brief Operator SphereHEALPix = SphereHEALPix / constant */
|
---|
| 252 | template <class T> inline SphereHEALPix<T> operator / (const SphereHEALPix<T>& a, T b)
|
---|
| 253 | {SphereHEALPix<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 254 | result.Div(b); return result;}
|
---|
| 255 |
|
---|
[1423] | 256 | /*! \ingroup SkyMap \fn operator/(T,const SphereHEALPix<T>&)
|
---|
[1419] | 257 | \brief Operator SphereHEALPix = constant / SphereHEALPix */
|
---|
| 258 | template <class T> inline SphereHEALPix<T> operator / (T b, const SphereHEALPix<T>& a)
|
---|
| 259 | {SphereHEALPix<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 260 | result.Div(b, true); return result;}
|
---|
| 261 |
|
---|
| 262 | ////////////////////////////////////////////////////////////////
|
---|
| 263 | // Surcharge d'operateurs C = A (+,-) B
|
---|
| 264 |
|
---|
[1423] | 265 | /*! \ingroup SkyMap \fn operator+(const SphereHEALPix<T>&,const SphereHEALPix<T>&)
|
---|
[1419] | 266 | \brief Operator SphereHEALPix = SphereHEALPix + SphereHEALPix */
|
---|
| 267 | template <class T>
|
---|
| 268 | inline SphereHEALPix<T> operator + (const SphereHEALPix<T>& a,const SphereHEALPix<T>& b)
|
---|
| 269 | { SphereHEALPix<T> result; result.SetTemp(true);
|
---|
| 270 | if (b.IsTemp()) { result.Share(b); result.AddElt(a); }
|
---|
| 271 | else { result.CloneOrShare(a); result.AddElt(b); }
|
---|
| 272 | return result; }
|
---|
| 273 |
|
---|
[1423] | 274 | /*! \ingroup SkyMap \fn operator-(const SphereHEALPix<T>&,const SphereHEALPix<T>&)
|
---|
[1419] | 275 | \brief Operator SphereHEALPix = SphereHEALPix - SphereHEALPix */
|
---|
| 276 | template <class T>
|
---|
| 277 | inline SphereHEALPix<T> operator - (const SphereHEALPix<T>& a,const SphereHEALPix<T>& b)
|
---|
| 278 | { SphereHEALPix<T> result; result.SetTemp(true);
|
---|
[2965] | 279 | result.CloneOrShare(a); result.SubElt(b);
|
---|
[1419] | 280 | return result; }
|
---|
| 281 |
|
---|
[1551] | 282 | ////////////////////////////////////////////////////////////////
|
---|
| 283 | // Surcharge d'operateurs C = A (*,/) B
|
---|
| 284 |
|
---|
| 285 | /*! \ingroup SkyMap \fn operator*(const SphereHEALPix<T>&,const SphereHEALPix<T>&)
|
---|
| 286 | \brief Operator SphereHEALPix = SphereHEALPix * SphereHEALPix (pixel by pixel multiply) */
|
---|
| 287 | template <class T>
|
---|
| 288 | inline SphereHEALPix<T> operator * (const SphereHEALPix<T>& a,const SphereHEALPix<T>& b)
|
---|
| 289 | { SphereHEALPix<T> result; result.SetTemp(true);
|
---|
| 290 | if (b.IsTemp()) { result.Share(b); result.MulElt(a); }
|
---|
| 291 | else { result.CloneOrShare(a); result.MulElt(b); }
|
---|
| 292 | return result; }
|
---|
| 293 |
|
---|
| 294 | /*! \ingroup SkyMap \fn operator/(const SphereHEALPix<T>&,const SphereHEALPix<T>&)
|
---|
| 295 | \brief Operator SphereHEALPix = SphereHEALPix / SphereHEALPix (pixel by pixel divide) */
|
---|
| 296 | template <class T>
|
---|
| 297 | inline SphereHEALPix<T> operator / (const SphereHEALPix<T>& a,const SphereHEALPix<T>& b)
|
---|
| 298 | { SphereHEALPix<T> result; result.SetTemp(true);
|
---|
[2433] | 299 | result.CloneOrShare(a); result.DivElt(b);
|
---|
[1551] | 300 | return result; }
|
---|
| 301 |
|
---|
[843] | 302 | } // Fin du namespace
|
---|
| 303 |
|
---|
| 304 | #endif
|
---|