# Path: cora/core/maps.py
# class Map2d(object):
# class Map3d(Map2d):
# class Sky3d(Map3d):
#     def like_map(cls, mapobj, *args, **kwargs):
#     def _width_array(self):
#     def _num_array(self):
#     def x_pixels(self):
#     def y_pixels(self):
#     def nside(self):
#     def nside(self, value):
#     def like_map(cls, mapobj, *args, **kwargs):
#     def _width_array(self):
#     def _num_array(self):
#     def nu_num(self):
#     def nu_num(self, num):
#     def frequencies(self):
#     def frequencies(self, freq):
#     def like_kiyo_map(cls, mapobj, *args, **kwargs):
#     def angular_powerspectrum(self, l, nu1, nu2):
#     def mean_nu(self, freq):
#     def getfield(self):
#     def getsky(self):
#     def getpolsky(self):
#     def getalms(self, lmax):
# 
# Path: cora/util/fftutil.py
# def rfftfreqn(n, d=None):
# def rfftn(arr):
# def irfftn(arr):
# 
# Path: cora/util/units.py
# G = 6.6742e-11


import numpy as np
import math
from cora.core import maps
from cora.util import fftutil, units
        from cora.util.cubicspline import LogInterpolater
            from os.path import dirname, join
class Cmb(RandomFieldA2):
    r"""Simulate a patch of the CMB."""

    def __init__(self, psfile=None, cambnorm=True):
        """Initialise the CMB field class."""


        if psfile == None:

            psfile = join(dirname(__file__), "ps_cmb2.dat")
        if cambnorm:
            a = np.loadtxt(psfile)
            l = a[:, 0]
            tt = (2 * math.pi) * a[:, 1] / (l * (l + 1.0))
            self._powerspectrum_int = LogInterpolater(np.vstack((l, tt)).T)
        else:
            self._powerspectrum_int = LogInterpolater.fromfile(psfile)

    def powerspectrum(self, karray):
        return np.vectorize(self._powerspectrum_int.value)(
            (karray ** 2).sum(axis=2) ** 0.5
        )


class TestF(RandomFieldA2F):
    def powerspectrum(self, karray):

        return np.exp(-0.5 * (karray[..., 0] / (2 * math.pi / 250.0)) ** 2) * np.exp(
            -0.5
            * (karray[..., 1:3] ** 2).sum(axis=3)

# Path: cora/core/maps.py
# class Map2d(object):
# class Map3d(Map2d):
# class Sky3d(Map3d):
#     def like_map(cls, mapobj, *args, **kwargs):
#     def _width_array(self):
#     def _num_array(self):
#     def x_pixels(self):
#     def y_pixels(self):
#     def nside(self):
#     def nside(self, value):
#     def like_map(cls, mapobj, *args, **kwargs):
#     def _width_array(self):
#     def _num_array(self):
#     def nu_num(self):
#     def nu_num(self, num):
#     def frequencies(self):
#     def frequencies(self, freq):
#     def like_kiyo_map(cls, mapobj, *args, **kwargs):
#     def angular_powerspectrum(self, l, nu1, nu2):
#     def mean_nu(self, freq):
#     def getfield(self):
#     def getsky(self):
#     def getpolsky(self):
#     def getalms(self, lmax):
# 
# Path: cora/util/fftutil.py
# def rfftfreqn(n, d=None):
# def rfftn(arr):
# def irfftn(arr):
# 
# Path: cora/util/units.py
# G = 6.6742e-11


# Path: cora/core/gaussianfield.py
import numpy as np
import math
from cora.core import maps
from cora.util import fftutil, units
        from cora.util.cubicspline import LogInterpolater
            from os.path import dirname, join

class Cmb(RandomFieldA2):
    r"""Simulate a patch of the CMB."""

    def __init__(self, psfile=None, cambnorm=True):
        """Initialise the CMB field class."""


        if psfile == None:

            psfile = join(dirname(__file__), "ps_cmb2.dat")
        if cambnorm:
            a = np.loadtxt(psfile)
            l = a[:, 0]
            tt = (2 * math.pi) * a[:, 1] / (l * (l + 1.0))
            self._powerspectrum_int = LogInterpolater(np.vstack((l, tt)).T)
        else:
            self._powerspectrum_int = LogInterpolater.fromfile(psfile)

    def powerspectrum(self, karray):
        return np.vectorize(self._powerspectrum_int.value)(
            (karray ** 2).sum(axis=2) ** 0.5
        )


class TestF(RandomFieldA2F):
    def powerspectrum(self, karray):

        return np.exp(-0.5 * (karray[..., 0] / (2 * math.pi / 250.0)) ** 2) * np.exp(
            -0.5
            * (karray[..., 1:3] ** 2).sum(axis=3)

            / (2 * math.pi / (1.0 * units.degree)) ** 2