Exemple #1
0
 def __init__(self, power_1, power_2, comoving):#, mu_1, mu_2):
     self.comoving = comoving
     self.domain = UniformGrid(self.comoving)
     self.fourier = FourierTransform(self.domain, centered=True)
     self.frqs = self.domain.frequencies(centered=True)
     self.power_1 = power_1(np.abs(self.frqs))
     self.power_2 = power_2(np.abs(self.frqs))
     self.biasing = np.sqrt(self.power_2/self.power_1).transpose()[:,0]
     self.biasing[np.asarray(self.biasing.shape)//2] = 1
Exemple #2
0
    def __init__(self, domain, radius, nmeas, nforward=64):
        assert isinstance(domain, StarTrigDiscr)
        self.radius = radius
        """The measurement radius."""
        self.nforward = nforward
        """The Fourier order of the forward solver."""

        super().__init__(
            domain=domain,
            codomain=UniformGrid(np.linspace(0, 2 * np.pi, nmeas, endpoint=False))
        )

        k = 1 + np.arange(self.nforward)
        k_t = np.outer(k, np.linspace(0, 2 * np.pi, self.nforward, endpoint=False))
        k_tfl = np.outer(k, self.codomain.coords[0])
        self.cosin = np.cos(k_t)
        self.sinus = np.sin(k_t)
        self.cos_fl = np.cos(k_tfl)
        self.sin_fl = np.sin(k_tfl)
Exemple #3
0
class Biasing():
    def __init__(self, power_1, power_2, comoving):#, mu_1, mu_2):
        self.comoving = comoving
        self.domain = UniformGrid(self.comoving)
        self.fourier = FourierTransform(self.domain, centered=True)
        self.frqs = self.domain.frequencies(centered=True)
        self.power_1 = power_1(np.abs(self.frqs))
        self.power_2 = power_2(np.abs(self.frqs))
        self.biasing = np.sqrt(self.power_2/self.power_1).transpose()[:,0]
        self.biasing[np.asarray(self.biasing.shape)//2] = 1
        #self.mu_1 = mu_1
        #self.mu_2 = mu_2

    def __call__(self, delta):
        delta_lin = np.log(delta)# - self.mu_1
        gaussian = self.fourier(delta_lin)
        gaussian *= self.biasing
        toret = self.fourier.inverse(gaussian)
        return np.exp(toret)#+self.mu_2)
Exemple #4
0
#For simplicity we assume vanishing peculiar velocities. Needs just to be commented out if peculiar velocities should be taken into account
vel_baryon = 0 * vel_baryon
####################################################################################################################################################################
'''
Compute Ly-alpha forest flux from computed overdensities. More explained in the file synthetic_data/....
'''
#Which lines of sights to select from the box
array = 10 + 20 * np.linspace(0, 4, 5)

#Number of lines of sights
Nr_LOS = array.shape[0]**2

#Define domain and codomain for forward operator
#Domain and codomain are defined on a uniform grid
coords = np.linspace(1, parameters_box['nr_pix'], parameters_box['nr_pix'])
domain = UniformGrid(coords, dtype=float)

coords = np.linspace(1, parameters_box['nr_pix'], parameters_box['nr_pix'])
codomain = UniformGrid(coords, dtype=float)

#parameters describing the forward operator
#->redshift_back: redshift of box
#->width: length of line of sight in [h^{-1}Mpc]
#->n_pix: (size domain, size codomain)
#->beta, t_med, tilde_c: three parameters describing the forward problem
parameters_forward = {
    "redshift_back": parameters_box['redshift'],
    "width": parameters_box['width'],
    "sampling": (parameters_box['nr_pix'], parameters_box['nr_pix']),
    "beta": parameters_igm['beta'],
    "t_med": parameters_igm['t_med'],
Exemple #5
0
import logging
from functools import partial

import matplotlib.pyplot as plt
import numpy as np

from regpy.mcmc import RandomWalk, StateHistory, adaptive_stepsize
from regpy.operators.volterra import Volterra
from regpy.hilbert import L2, Sobolev
from regpy.discrs import UniformGrid

logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s %(levelname)s %(name)-40s :: %(message)s')

op = Volterra(UniformGrid((0, 2 * np.pi, 200)))

# Simulate data
exact_solution = np.sin(op.domain.coords[0])
exact_data = op(exact_solution)
data = exact_data + 0.03 * op.domain.randn()

# Compute log probability functional as negative Tikhonov functional with Sobolev regularizer

regpar = 1e-1
temperature = 1e-3

prior = regpar * Sobolev(op.domain).norm_functional
likelihood = L2(op.codomain).norm_functional * (op - data)
logpdf = -(likelihood + prior) / temperature
Exemple #6
0
import matplotlib.pyplot as plt
import numpy as np

import regpy.stoprules as rules
from regpy.operators.volterra import Volterra
from regpy.solvers import HilbertSpaceSetting
from regpy.solvers.landweber import Landweber
from regpy.hilbert import L2, Sobolev
from regpy.discrs import UniformGrid

logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s %(levelname)s %(name)-20s :: %(message)s'
)

grid = UniformGrid(np.linspace(0, 2 * np.pi, 200))
op = Volterra(grid, exponent=3)

exact_solution = np.sin(grid.coords[0])
exact_data = op(exact_solution)
noise = 0.03 * op.domain.randn()
data = exact_data + noise
init = op.domain.ones()

setting = HilbertSpaceSetting(op=op, Hdomain=Sobolev, Hcodomain=L2)

landweber = Landweber(setting, data, init, stepsize=0.01)
stoprule = (
    # Landweber is slow, so need to use large number of iterations
    rules.CountIterations(max_iterations=100000) +
    rules.Discrepancy(
Exemple #7
0
from regpy.operators.volterra import Volterra
from regpy.hilbert import L2
from regpy.discrs import UniformGrid
from regpy.solvers import HilbertSpaceSetting
from regpy.solvers.tikhonov import TikhonovCG
import regpy.stoprules as rules

import numpy as np
import logging
import matplotlib.pyplot as plt

logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s %(levelname)s %(name)-20s :: %(message)s')

grid = UniformGrid((0, 2 * np.pi, 200))
op = Volterra(grid)

exact_solution = np.sin(grid.coords[0])
exact_data = op(exact_solution)
noise = 0.03 * op.domain.randn()
data = exact_data + noise
init = op.domain.ones()

setting = HilbertSpaceSetting(op=op, Hdomain=L2, Hcodomain=L2)

solver = TikhonovCG(setting, data, regpar=0.01)
stoprule = (rules.CountIterations(1000) +
            rules.Discrepancy(setting.Hcodomain.norm,
                              data,
                              noiselevel=setting.Hcodomain.norm(noise),
from regpy.hilbert import L2
from regpy.discrs import UniformGrid
from regpy.solvers import HilbertSpaceSetting
from regpy.solvers.newton import NewtonSemiSmooth
import regpy.stoprules as rules

import numpy as np
import logging
import matplotlib.pyplot as plt

logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s %(levelname)s %(name)-20s :: %(message)s'
)

grid = UniformGrid(np.linspace(0, 2*np.pi, 200))
op = Volterra(grid)

exact_solution = np.sin(grid.coords[0])
exact_data = op(exact_solution)
noise = 0.03 * op.domain.randn()
data = exact_data + noise
init = grid.zeros()

setting = HilbertSpaceSetting(op=op, Hdomain=L2, Hcodomain=L2)

# Run the solver with a `-1 <= reco <= 1` constraint. For illustration, you can also try a
# constraint which is violated by the exact solution.
newton = NewtonSemiSmooth(setting, data, init, alpha=0.1, psi_minus=-1, psi_plus=1)
stoprule = (
    rules.CountIterations(1000) +
Exemple #9
0
import numpy as np
from scipy.misc import ascent
import logging
import matplotlib.pyplot as plt

logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s %(levelname)s %(name)-20s :: %(message)s')

# Example parameters
fresnelNumber = 5e-4  # Fresnel-number of the simulated imaging system, associated with the unit-lengthscale
# in grid (i.e. with the size of one pixel for the above choice of grid)
noise_level = 0.01  # Noise level in the simulated data

# Uniform grid of unit-spacing
grid = UniformGrid(np.arange(1024), np.arange(1024))

# Forward operator
op = xray_phase_contrast(grid, fresnelNumber)

# Create phantom phase-image (= padded example-image)
exact_solution = ascent().astype(np.float64)
exact_solution /= exact_solution.max()
pad_amount = tuple([(grid.shape[0] - exact_solution.shape[0]) // 2,
                    (grid.shape[1] - exact_solution.shape[1]) // 2])
exact_solution = np.pad(exact_solution,
                        pad_amount,
                        'constant',
                        constant_values=0)

# Create exact and noisy data
Exemple #10
0
import numpy as np

import regpy.stoprules as rules
import regpy.util as util
from regpy.operators.mri import cartesian_sampling, normalize, parallel_mri, sobolev_smoother
from regpy.solvers import HilbertSpaceSetting
from regpy.solvers.irgnm import IrgnmCG
from regpy.discrs import UniformGrid
from regpy.hilbert import L2

logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s %(levelname)s %(name)-40s :: %(message)s')

# TODO dtype=complex?
grid = UniformGrid((-1, 1, 100), (-1, 1, 100))

sobolev_index = 30
noiselevel = 0.05

# In real applications with data known before constructing the operator, estimate_sampling_pattern
# can be used to determine the mask.
mask = grid.zeros(dtype=bool)
mask[::2] = True
mask[:10] = True
mask[-10:] = True

full_mri_op = parallel_mri(grid=grid, ncoils=10)
sampling = cartesian_sampling(full_mri_op.codomain, mask=mask)
mri_op = sampling * full_mri_op