def __init__(self, mask, maps, templates=None, beam=None, purify_e=False, purify_b=False, n_iter_mask_purify=3, tol_pinv=1E-10): self.fl = None pure_e = 0 if (purify_e): pure_e = 1 pure_b = 0 if (purify_b): pure_b = 1 nside = 2 while (12 * nside * nside != len(mask)): nside *= 2 if (nside > 65536): raise ValueError("Something is wrong with your input arrays") if ((len(maps) != 1) and (len(maps) != 2)): raise ValueError("Must supply 1 or 2 maps per field") if (len(maps[0]) != len(mask)): raise ValueError("All maps must have the same resolution") if isinstance(templates, (list, tuple, np.ndarray)): if ((len(templates[0]) != 1) and (len(templates[0]) != 2)): raise ValueError("Must supply 1 or 2 maps per field") if (len(templates[0][0]) != len(mask)): raise ValueError("All maps must have the same resolution") else: if (templates is not None): raise ValueError( "Input templates can only be an array or None\n") if isinstance(beam, (list, tuple, np.ndarray)): if (len(beam) != 3 * nside): raise ValueError("Input beam must have 3*nside elements") beam_use = beam else: if (beam is None): beam_use = np.ones(3 * nside) else: raise ValueError("Input beam can only be an array or None\n") if isinstance(templates, (list, tuple, np.ndarray)): self.fl = lib.field_alloc_new(mask, maps, templates, beam_use, pure_e, pure_b, n_iter_mask_purify, tol_pinv) else: self.fl = lib.field_alloc_new_notemp(mask, maps, beam_use, pure_e, pure_b, n_iter_mask_purify)
def __init__(self, mask, maps, spin=None, templates=None, beam=None, purify_e=False, purify_b=False, n_iter_mask_purify=3, tol_pinv=1E-10, wcs=None, n_iter=3, lmax_sht=-1, masked_on_input=False, lite=False): self.fl = None pure_e = 0 if purify_e: pure_e = 1 pure_b = 0 if purify_b: pure_b = 1 masked_input = 0 if masked_on_input: masked_input = 1 wt = NmtWCSTranslator(wcs, mask.shape) if wt.is_healpix == 0: if wt.flip_th: mask = mask[::-1, :] if wt.flip_ph: mask = mask[:, ::-1] mask = mask.reshape(wt.npix) if maps is None: mask_only = True if spin is None: raise ValueError("Please supply field spin") lite = True else: mask_only = False if (len(maps) != 1) and (len(maps) != 2): raise ValueError("Must supply 1 or 2 maps per field") if spin is None: if len(maps) == 1: spin = 0 else: spin = 2 else: if (((spin != 0) and len(maps) == 1) or ((spin == 0) and len(maps) != 1)): raise ValueError("Spin-zero fields are " "associated with a single map") if wt.is_healpix and (len(maps[0]) != len(mask)): raise ValueError("All maps must have the same resolution") if (pure_e or pure_b) and spin != 2: raise ValueError("Purification only implemented for spin-2 fields") # Flatten if 2D maps if (not mask_only) and (wt.is_healpix == 0): try: maps = np.array(maps) if wt.flip_th: maps = maps[:, ::-1, :] if wt.flip_ph: maps = maps[:, :, ::-1] maps = maps.reshape([len(maps), wt.npix]) except: raise ValueError("Input maps have the wrong shape") if isinstance(templates, (list, tuple, np.ndarray)): ntemp = len(templates) if (len(templates[0]) != 1) and (len(templates[0]) != 2): raise ValueError("Must supply 1 or 2 maps per field") if wt.is_healpix == 0: # Flatten if 2D maps try: templates = np.array(templates) if wt.flip_th: templates = templates[:, :, ::-1, :] if wt.flip_ph: templates = templates[:, :, :, ::-1] templates = templates.reshape([ntemp, len(maps), wt.npix]) except: raise ValueError("Input templates have the wrong shape") if len(templates[0][0]) != len(mask): raise ValueError("All maps must have the same resolution") else: if templates is not None: raise ValueError("Input templates can only be an array " "or None\n") if lmax_sht > 0: lmax = lmax_sht else: lmax = wt.get_lmax() if isinstance(beam, (list, tuple, np.ndarray)): if len(beam) <= lmax: raise ValueError("Input beam must have at least %d elements " "given the input map resolution" % (lmax)) beam_use = beam else: if beam is None: beam_use = np.ones(lmax + 1) else: raise ValueError("Input beam can only be an array or None\n") if mask_only: self.fl = lib.field_alloc_empty(wt.is_healpix, wt.nside, lmax_sht, wt.nx, wt.ny, wt.d_phi, wt.d_theta, wt.phi0, wt.theta_max, spin, mask, beam_use, pure_e, pure_b, n_iter_mask_purify) else: if isinstance(templates, (list, tuple, np.ndarray)): self.fl = lib.field_alloc_new( wt.is_healpix, wt.nside, lmax_sht, wt.nx, wt.ny, wt.d_phi, wt.d_theta, wt.phi0, wt.theta_max, spin, mask, maps, templates, beam_use, pure_e, pure_b, n_iter_mask_purify, tol_pinv, n_iter, masked_input, int(lite)) else: self.fl = lib.field_alloc_new_notemp( wt.is_healpix, wt.nside, lmax_sht, wt.nx, wt.ny, wt.d_phi, wt.d_theta, wt.phi0, wt.theta_max, spin, mask, maps, beam_use, pure_e, pure_b, n_iter_mask_purify, n_iter, masked_input, int(lite)) self.lite = lite
def __init__(self, mask, maps, templates=None, beam=None, purify_e=False, purify_b=False, n_iter_mask_purify=3, tol_pinv=1E-10, wcs=None, n_iter=3): self.fl = None pure_e = 0 if purify_e: pure_e = 1 pure_b = 0 if purify_b: pure_b = 1 wt = NmtWCSTranslator(wcs, mask.shape) if wt.is_healpix == 0: if wt.flip_th: mask = mask[::-1, :] if wt.flip_ph: mask = mask[:, ::-1] mask = mask.reshape(wt.npix) if (len(maps) != 1) and (len(maps) != 2): raise ValueError("Must supply 1 or 2 maps per field") if wt.is_healpix == 0: #Flatten if 2D maps try: maps = np.array(maps) if wt.flip_th: maps = maps[:, ::-1, :] if wt.flip_ph: maps = maps[:, :, ::-1] maps = maps.reshape([len(maps), wt.npix]) except: raise ValueError("Input maps have the wrong shape") if len(maps[0]) != len(mask): raise ValueError("All maps must have the same resolution") if isinstance(templates, (list, tuple, np.ndarray)): ntemp = len(templates) if (len(templates[0]) != 1) and (len(templates[0]) != 2): raise ValueError("Must supply 1 or 2 maps per field") if wt.is_healpix == 0: #Flatten if 2D maps try: templates = np.array(templates) if wt.flip_th: templates = templates[:, :, ::-1, :] if wt.flip_ph: templates = templates[:, :, :, ::-1] templates = templates.reshape([ntemp, len(maps), wt.npix]) except: raise ValueError("Input templates have the wrong shape") if len(templates[0][0]) != len(mask): raise ValueError("All maps must have the same resolution") else: if templates is not None: raise ValueError( "Input templates can only be an array or None\n") lmax = wt.get_lmax() if isinstance(beam, (list, tuple, np.ndarray)): if len(beam) <= lmax: raise ValueError( "Input beam must have at least %d elements given the input map resolution" % (lmax)) beam_use = beam else: if beam is None: beam_use = np.ones(lmax + 1) else: raise ValueError("Input beam can only be an array or None\n") if isinstance(templates, (list, tuple, np.ndarray)): self.fl = lib.field_alloc_new(wt.is_healpix, wt.nside, wt.nx, wt.ny, wt.d_phi, wt.d_theta, wt.phi0, wt.theta_max, mask, maps, templates, beam_use, pure_e, pure_b, n_iter_mask_purify, tol_pinv, n_iter) else: self.fl = lib.field_alloc_new_notemp(wt.is_healpix, wt.nside, wt.nx, wt.ny, wt.d_phi, wt.d_theta, wt.phi0, wt.theta_max, mask, maps, beam_use, pure_e, pure_b, n_iter_mask_purify, n_iter)