Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. import pyfits
  2. import healpy as hp
  3. import numpy as np
  4. import time
  5. import pymp
  6. from math import sqrt
  7.  
  8. start_time = time.time()
  9. print('Starting')
  10.  
  11. threads=16
  12. lmax=2002
  13. lmax=int(lmax+1)
  14.  
  15. ########## IMPORTING DATA ##########
  16. alm=pyfits.open('alm.fits')
  17. almimag=np.array(alm[1].data['IMAG'])
  18. almreal=np.array(alm[1].data['REAL'])
  19. almreal=list(almreal)
  20. almimag=list(almimag)
  21. cl=np.array((pyfits.open('cl.fits'))[1].data['TEMPERATURE'],dtype='float64')
  22. #mastermatrix=1;
  23. #gaussianbeam
  24. #noise
  25. #<f>ab,<f>dopp e <f>abdopp==<f>ab+<f>dopp (import or generate)
  26.  
  27. ########## DEFINING FUNCTIONS ##########
  28.  
  29. def almf( l, m ):
  30. ellement=almlist[(l*(l+1))+m]
  31. return ellement;
  32. def almfconjugate( l, m ):
  33. ellement=almlistconjugate[(l*(l+1))+m]
  34. return ellement;
  35. def cps0factor( l, m):
  36. return sqrt(((l+1+m)*(l+1-m))/((4*(l+1)*(l+1)-1)))
  37. def cms0factor( l, m):
  38. return -1*sqrt(((l+m)*(l-m))/(4*l*l-1))
  39. def cps1factor( l, m):
  40. return -1*sqrt(((l+2+m)*(l+m+1))/((4*(l+1)*(l+1)-1)*(2)))
  41. def cms1factor( l, m):
  42. return -1*sqrt(((l+m-1)*(l+m))/((4*l*l-1)*(2)))
  43.  
  44. ########## CALCULATING c+ AND c- ##########
  45.  
  46. cps0abfactorlist=pymp.shared.array((hp.Alm.getsize(lmax=lmaxalm)*2-lmaxalm,), dtype='float64')
  47. cms0abfactorlist=pymp.shared.array((hp.Alm.getsize(lmax=lmaxalm)*2-lmaxalm,), dtype='float64')
  48. cps0doppfactorlist=pymp.shared.array((hp.Alm.getsize(lmax=lmaxalm)*2-lmaxalm,), dtype='float64')
  49. cms0doppfactorlist=pymp.shared.array((hp.Alm.getsize(lmax=lmaxalm)*2-lmaxalm,), dtype='float64')
  50. with pymp.Parallel(threads) as p:
  51. for l in p.range(lmaxalm+1):
  52. idxl=l*(l+1)
  53. for m in range(-l,l+1):
  54. idxlm=idxl+m
  55. cps0=cps0factor( l, m)
  56. cms0=cms0factor( l, m)
  57. cps0abfactorlist[idxlm]=(l+2)*cps0
  58. cms0abfactorlist[idxlm]=(l-1)*cms0
  59. cps0doppfactorlist[idxlm]=-cps0
  60. cms0doppfactorlist[idxlm]=cms0
  61.  
  62. elapsed_time = time.time() - start_time
  63. print('cp and cm generated')
  64. print(elapsed_time,'secs')
  65.  
  66. ########## CALCULATING <f> AND <g> (h) ##########
  67.  
  68. symarraysize=hp.Alm.getsize(lmax=lmax)*2-lmax-2
  69. notsymarraysize=hp.Alm.getsize(lmax=lmax)
  70.  
  71. hs0ablist=pymp.shared.array((hp.Alm.getsize(lmax=lmax),), dtype='float64')
  72. hs0dopplist=pymp.shared.array((hp.Alm.getsize(lmax=lmax),), dtype='float64')
  73. hs02ablist=pymp.shared.array((hp.Alm.getsize(lmax=lmax),), dtype='float64')
  74. hs02dopplist=pymp.shared.array((hp.Alm.getsize(lmax=lmax),), dtype='float64')
  75.  
  76. with pymp.Parallel(threads) as p:
  77. for l in p.range(lmax+1):
  78. idxl=l*(l+1);idxlp1=(l+1)*(l+2);
  79. for m in range(1,l):
  80. idxlm=idxl+m;idxlp1m=idxlp1+m;
  81. abcoef=(cms0abfactorlist[idxlp1m]*cl[l]+cps0abfactorlist[idxlm]*cl[l+1])
  82. doppcoef=(cms0doppfactorlist[idxlp1m]*cl[l]+cps0doppfactorlist[idxlm]*cl[l+1])
  83. hs0ablist[int((idxl/2)+m)]=abcoef
  84. hs02ablist[int((idxl/2)+m)]=2*abcoef
  85. hs0dopplist[int((idxl/2)+m)]=doppcoef
  86. hs02dopplist[int((idxl/2)+m)]=2*doppcoef
  87. for m in [l]:
  88. idxlm=idxl+m;idxlp1m=idxlp1+m;
  89. abcoef=(cms0abfactorlist[idxlp1m]*cl[l]+cps0abfactorlist[idxlm]*cl[l+1])
  90. doppcoef=(cms0doppfactorlist[idxlp1m]*cl[l]+cps0doppfactorlist[idxlm]*cl[l+1])
  91. hs0ablist[int((idxl/2)+m)]=abcoef
  92. hs02ablist[int((idxl/2)+m)]=2*abcoef
  93. hs0dopplist[int((idxl/2)+m)]=doppcoef
  94. hs02dopplist[int((idxl/2)+m)]=2*doppcoef
  95. for m in [0]:
  96. idxlm=idxl+m;idxlp1m=idxlp1+m;
  97. hs0ablist[int((idxl/2)+m)]=(cms0abfactorlist[idxlp1m]*cl[l]+cps0abfactorlist[idxlm]*cl[l+1])
  98. hs02ablist[int((idxl/2)+m)]=(cms0abfactorlist[idxlp1m]*cl[l]+cps0abfactorlist[idxlm]*cl[l+1])
  99. hs0dopplist[int((idxl/2)+m)]=(cms0doppfactorlist[idxlp1m]*cl[l]+cps0doppfactorlist[idxlm]*cl[l+1])
  100. hs02dopplist[int((idxl/2)+m)]=(cms0doppfactorlist[idxlp1m]*cl[l]+cps0doppfactorlist[idxlm]*cl[l+1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement