Skip to content

Cube

cube

EmissivityCube

Bases: Module

Generate an emissivity cube

Source code in src/cube.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class EmissivityCube(hk.Module):
    """
    Generate an emissivity cube
    """

    def __init__(self, spatial_grid, exposure = 125e3):
        """
        Initialize

        Parameters:
            spatial_grid (class): 3D Spatial grid
            exposure (float): Exposure time in seconds

        """ 
        super(EmissivityCube, self).__init__()
        self.power_spectrum = KolmogorovPowerSpectrum()
        self.spatial_grid = spatial_grid
        self.exposure = exposure #exposure in seconds
        pixsize_cm = self.spatial_grid.pixsize * u.kiloparsec.to(u.cm)

        model = XrayEmissivity()
        self.lam = model(self.spatial_grid.R) * pixsize_cm**3 * self.exposure



    def __call__(self):
        """
        Returns:
            field_spatial (jnp.array): Random realization of emissivity cube

        """

        key = hk.next_rng_key()


        field_spatial = np.random.poisson(
                                       lam  = self.lam, 
                                       size = self.spatial_grid.shape)
        return field_spatial

__call__()

Returns:

Name Type Description
field_spatial array

Random realization of emissivity cube

Source code in src/cube.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
def __call__(self):
    """
    Returns:
        field_spatial (jnp.array): Random realization of emissivity cube

    """

    key = hk.next_rng_key()


    field_spatial = np.random.poisson(
                                   lam  = self.lam, 
                                   size = self.spatial_grid.shape)
    return field_spatial

__init__(spatial_grid, exposure=125000.0)

Initialize

Parameters:

Name Type Description Default
spatial_grid class

3D Spatial grid

required
exposure float

Exposure time in seconds

125000.0
Source code in src/cube.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
def __init__(self, spatial_grid, exposure = 125e3):
    """
    Initialize

    Parameters:
        spatial_grid (class): 3D Spatial grid
        exposure (float): Exposure time in seconds

    """ 
    super(EmissivityCube, self).__init__()
    self.power_spectrum = KolmogorovPowerSpectrum()
    self.spatial_grid = spatial_grid
    self.exposure = exposure #exposure in seconds
    pixsize_cm = self.spatial_grid.pixsize * u.kiloparsec.to(u.cm)

    model = XrayEmissivity()
    self.lam = model(self.spatial_grid.R) * pixsize_cm**3 * self.exposure

FluctuationCube

Bases: Module

Generate a fluctuation cube as seen from https://garrettgoon.com/gaussian-fields/

Source code in src/cube.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
class FluctuationCube(hk.Module):
    """
    Generate a fluctuation cube as seen from https://garrettgoon.com/gaussian-fields/
    """


    def __init__(self, spatial_grid):
        """
        Initialize. The power spectrum is implicitly defined from the Kolmogorov power spectrum

        Parameters:
            spatial_grid (class): 3D Spatial grid
            exposure (float): Exposure time in seconds

        """ 

        super(FluctuationCube, self).__init__()
        self.power_spectrum = KolmogorovPowerSpectrum()
        self.spatial_grid = spatial_grid
        self.fourier_grid = FourierGrid3D(self.spatial_grid)
        self.K = self.fourier_grid.K.astype(np.float64)

    def __call__(self):
        """
        Returns:
            field_spatial (jnp.array): Random realization of GRF

        """

        key = hk.next_rng_key()

        #Dont mind the rfft, it is here to gain memory
        field_spatial = random.normal(key, shape=self.spatial_grid.shape)
        field_fourier = fft.rfftn(field_spatial)*jnp.sqrt(self.power_spectrum(self.K)/self.spatial_grid.pixsize**3)
        field_spatial = fft.irfftn(field_fourier, s=self.spatial_grid.shape)

        return field_spatial

__call__()

Returns:

Name Type Description
field_spatial array

Random realization of GRF

Source code in src/cube.py
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
def __call__(self):
    """
    Returns:
        field_spatial (jnp.array): Random realization of GRF

    """

    key = hk.next_rng_key()

    #Dont mind the rfft, it is here to gain memory
    field_spatial = random.normal(key, shape=self.spatial_grid.shape)
    field_fourier = fft.rfftn(field_spatial)*jnp.sqrt(self.power_spectrum(self.K)/self.spatial_grid.pixsize**3)
    field_spatial = fft.irfftn(field_fourier, s=self.spatial_grid.shape)

    return field_spatial

__init__(spatial_grid)

Initialize. The power spectrum is implicitly defined from the Kolmogorov power spectrum

Parameters:

Name Type Description Default
spatial_grid class

3D Spatial grid

required
exposure float

Exposure time in seconds

required
Source code in src/cube.py
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
def __init__(self, spatial_grid):
    """
    Initialize. The power spectrum is implicitly defined from the Kolmogorov power spectrum

    Parameters:
        spatial_grid (class): 3D Spatial grid
        exposure (float): Exposure time in seconds

    """ 

    super(FluctuationCube, self).__init__()
    self.power_spectrum = KolmogorovPowerSpectrum()
    self.spatial_grid = spatial_grid
    self.fourier_grid = FourierGrid3D(self.spatial_grid)
    self.K = self.fourier_grid.K.astype(np.float64)