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