@@ -104,7 +104,7 @@ def get_alms(so_map, window, niter, lmax, theta_range=None, dtype=np.complex128,
104104 return alms
105105
106106
107- def get_pure_alms (so_map , window , niter , lmax ):
107+ def get_pure_alms (so_map , window , spinned_windows , niter , lmax , theta_range = None , alm_conv = "HEALPIX" ):
108108
109109 """Compute pure alms from maps and window function
110110
@@ -116,45 +116,55 @@ def get_pure_alms(so_map, window, niter, lmax):
116116 window: so_map or tuple of so_map
117117 a so map with the window function, if the so map has 3 components
118118 (for spin0 and 2 fields) expect a tuple (window,window_pol)
119+ spinned_windows: list of so_map
120+ list of derivatives of the window function as produced by
121+ so_window.get_spinned_windows.
119122 niter: integer
120123 the number of iteration performed while computing the alm
121124 not that for CAR niter=0 should be enough
122125 lmax: integer
123126 the maximum multipole of the transform
127+ theta range: list of 2 elements
128+ for healpix pixellisation you can specify
129+ a range [theta_min,theta_max] in radian. All pixel outside this range
130+ will be assumed to be zero. WARNING: Untested, unsure it make sense for pure B modes.
131+ alm_conv: str
132+ default is HEALPIX, if IAU multiply U by -1
124133
125134 """
126135
127- w1_plus , w1_minus , w2_plus , w2_minus = so_window .get_spinned_windows (window [1 ], lmax , niter = niter )
128- p2 = np .array ([window [1 ].data * so_map .data [1 ], window [1 ].data * so_map .data [2 ]])
129- p1 = np .array ([(w1_plus .data * so_map .data [1 ] + w1_minus .data * so_map .data [2 ]), (w1_plus .data * so_map .data [2 ] - w1_minus .data * so_map .data [1 ])])
130- p0 = np .array ([(w2_plus .data * so_map .data [1 ] + w2_minus .data * so_map .data [2 ]), (w2_plus .data * so_map .data [2 ] - w2_minus .data * so_map .data [1 ])])
136+ T ,Q ,U = so_map .data [0 ], so_map .data [1 ], so_map .data [2 ]
137+ if alm_conv == "IAU" :
138+ U = - U
139+
140+ w1_plus , w1_minus , w2_plus , w2_minus = spinned_windows
141+ p2 = np .array ([window [1 ].data * Q , window [1 ].data * U ])
142+ p1 = np .array ([(w1_plus .data * Q + w1_minus .data * U ), (w1_plus .data * U - w1_minus .data * Q )])
143+ p0 = np .array ([(w2_plus .data * Q + w2_minus .data * U ), (w2_plus .data * U - w2_minus .data * Q )])
131144
132145 if so_map .pixel == "CAR" :
133- p0 = enmap .samewcs (p0 ,so_map .data )
134- p1 = enmap .samewcs (p1 ,so_map .data )
135- p2 = enmap .samewcs (p2 ,so_map .data )
146+ p0 = enmap .samewcs (p0 , so_map .data )
147+ p1 = enmap .samewcs (p1 , so_map .data )
148+ p2 = enmap .samewcs (p2 , so_map .data )
136149
137- alm = curvedsky .map2alm (so_map . data [ 0 ] * window [0 ].data , lmax = lmax )
150+ alm = curvedsky .map2alm (T * window [0 ].data , lmax = lmax )
138151 s2eblm = curvedsky .map2alm (p2 , spin = 2 , lmax = lmax )
139152 s1eblm = curvedsky .map2alm (p1 , spin = 1 , lmax = lmax )
140153 s0eblm = s1eblm .copy ()
141154 s0eblm [0 ] = curvedsky .map2alm (p0 [0 ], spin = 0 , lmax = lmax )
142155 s0eblm [1 ] = curvedsky .map2alm (p0 [1 ], spin = 0 , lmax = lmax )
143156
144157 if so_map .pixel == "HEALPIX" :
145- alm = hp .sphtfunc .map2alm (so_map .data [0 ] * window [0 ].data , lmax = lmax , iter = niter )#curvedsky.map2alm_healpix(map.data[0]*window[0].data,lmax= lmax)
146- s2eblm = curvedsky .map2alm_healpix (p2 , spin = 2 , lmax = lmax )
147- s1eblm = curvedsky .map2alm_healpix (p1 , spin = 1 , lmax = lmax )
148- if niter != 0 :
149- p2_copy = p2 .copy ()
150- p1_copy = p1 .copy ()
151- for _ in range (niter ):
152- s2eblm += curvedsky .map2alm_healpix (p2 - curvedsky .alm2map_healpix (s2eblm , p2_copy , spin = 2 ), lmax = lmax , spin = 2 )
153- s1eblm += curvedsky .map2alm_healpix (p1 - curvedsky .alm2map_healpix (s1eblm , p1_copy , spin = 1 ), lmax = lmax , spin = 1 )
158+
159+ theta_min , theta_max = theta_range if theta_range is not None else (None , None )
160+
161+ alm = curvedsky .map2alm_healpix (T * window [0 ].data , spin = 0 , lmax = lmax , niter = niter , theta_min = theta_min , theta_max = theta_max )
162+ s2eblm = curvedsky .map2alm_healpix (p2 , spin = 2 , lmax = lmax , niter = niter , theta_min = theta_min , theta_max = theta_max )
163+ s1eblm = curvedsky .map2alm_healpix (p1 , spin = 1 , lmax = lmax , niter = niter , theta_min = theta_min , theta_max = theta_max )
154164
155165 s0eblm = s1eblm .copy ()
156- s0eblm [0 ] = hp . sphtfunc . map2alm (p0 [0 ], lmax = lmax , iter = niter )
157- s0eblm [1 ] = hp . sphtfunc . map2alm (p0 [1 ], lmax = lmax , iter = niter )
166+ s0eblm [0 ] = curvedsky . map2alm_healpix (p0 [0 ], spin = 0 , lmax = lmax , niter = niter , theta_min = theta_min , theta_max = theta_max )
167+ s0eblm [1 ] = curvedsky . map2alm_healpix (p0 [1 ], spin = 0 , lmax = lmax , niter = niter , theta_min = theta_min , theta_max = theta_max )
158168
159169 ell = np .arange (lmax + 1 )
160170 filter_1 = np .zeros (lmax + 1 )
@@ -170,7 +180,7 @@ def get_pure_alms(so_map, window, niter, lmax):
170180 elm_p = s2eblm [0 ] + s1eblm [0 ] + s0eblm [0 ]
171181 blm_b = s2eblm [1 ] + s1eblm [1 ] + s0eblm [1 ]
172182
173- return np .array ([alm ,elm_p ,blm_b ])
183+ return np .array ([alm , elm_p , blm_b ])
174184
175185def show_alm_triangle (
176186 alms , lmax , vmin , vmax , real = True , cmap = "seismic" ,
0 commit comments