Skip to content

Commit

Permalink
Merge pull request #77 from Jammy2211/feature/simulator_refactor
Browse files Browse the repository at this point in the history
Feature/simulator refactor
  • Loading branch information
Jammy2211 authored Dec 1, 2023
2 parents 3a6c75c + af1b1ec commit a433b99
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 27 deletions.
4 changes: 2 additions & 2 deletions autoarray/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
from .dataset.abstract.settings import AbstractSettingsDataset
from .dataset.abstract.w_tilde import AbstractWTilde
from .dataset.imaging.settings import SettingsImaging
from .dataset.imaging.imaging import Imaging
from .dataset.imaging.dataset import Imaging
from .dataset.imaging.simulator import SimulatorImaging
from .dataset.imaging.w_tilde import WTildeImaging
from .dataset.interferometer.interferometer import Interferometer
from .dataset.interferometer.dataset import Interferometer
from .dataset.interferometer.settings import SettingsInterferometer
from .dataset.interferometer.simulator import SimulatorInterferometer
from .dataset.interferometer.w_tilde import WTildeInterferometer
Expand Down
File renamed without changes.
38 changes: 25 additions & 13 deletions autoarray/dataset/imaging/simulator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import numpy as np

from autoarray.dataset.imaging.imaging import Imaging
from autoarray.dataset.imaging.dataset import Imaging
from autoarray.structures.arrays.uniform_2d import Array2D
from autoarray.structures.arrays.kernel_2d import Kernel2D
from autoarray.mask.mask_2d import Mask2D
Expand All @@ -19,28 +19,38 @@ def __init__(
background_sky_level: float = 0.0,
psf: Kernel2D = None,
normalize_psf: bool = True,
read_noise: float = None,
add_poisson_noise: bool = True,
noise_if_add_noise_false: float = 0.1,
noise_seed: int = -1,
):
"""
A class representing a Imaging observation, using the shape of the image, the pixel scale,
psf, exposure time, etc.
Simulations observations of imaging data, including simulation of the image, noise-map, PSF, etc. as
an `Imaging` object.
The simulation of an `Imaging` dataset uses the following steps:
1) Receive as input the raw image which is simulated via the steps below.
2) Convolve the image with the Point Spread Function of the simulated dataset.
3) Use input values of the background sky level in every pixel of the image to add the background sky to
the PSF convolved image.
4) Add Poisson noise to the image, which represents noise due to whether photons hits the CCD and are converted
to photo-electrons which are succcessfully detected by the CCD and converted to counts.
5) Subtract the background sky from the image, so that the returned simulated dataset is background sky
subtracted.
The inputs of the `SimulatorImaging` object can toggle these steps on and off, for example if `psf=None` the
PSF convolution step is omitted.
Parameters
----------
psf : Kernel2D
An arrays describing the PSF kernel of the image.
exposure_time
The exposure time of the simulated imaging.
background_sky_level
The level of the background sky of the simulated imaging.
psf
An array describing the PSF kernel of the image.
normalize_psf
If `True`, the PSF kernel is normalized so all values sum to 1.0.
read_noise
The level of read-noise added to the simulated imaging by drawing from a Gaussian distribution with
sigma equal to the value `read_noise`.
add_poisson_noise
Whether Poisson noise corresponding to photon count statistics on the imaging observation is added.
noise_if_add_noise_false
Expand All @@ -60,19 +70,21 @@ def __init__(
self.exposure_time = exposure_time
self.background_sky_level = background_sky_level

self.read_noise = read_noise
self.add_poisson_noise = add_poisson_noise
self.noise_if_add_noise_false = noise_if_add_noise_false
self.noise_seed = noise_seed

def via_image_from(self, image: Array2D):
def via_image_from(self, image: Array2D) -> Imaging:
"""
Returns a realistic simulated image by applying effects to a plain simulated image.
Simulate an `Imaging` dataset from an input image.
The steps of the `SimulatorImaging` simulation process (e.g. PSF convolution, noise addition) are
described in the `SimulatorImaging` `__init__` method docstring.
Parameters
----------
image
The image before simulating which has noise added, PSF convolution, etc performed to it.
The 2D image from which the Imaging dataset is simulated.
"""

exposure_time_map = Array2D.full(
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion autoarray/dataset/interferometer/simulator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

from autoarray.dataset.interferometer.interferometer import Interferometer
from autoarray.dataset.interferometer.dataset import Interferometer
from autoarray.operators.transformer import TransformerDFT
from autoarray.structures.visibilities import VisibilitiesNoiseMap

Expand Down
2 changes: 1 addition & 1 deletion autoarray/dataset/plot/imaging_plotters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from autoarray.plot.mat_plot.two_d import MatPlot2D
from autoarray.plot.auto_labels import AutoLabels
from autoarray.plot.abstract_plotters import Plotter
from autoarray.dataset.imaging.imaging import Imaging
from autoarray.dataset.imaging.dataset import Imaging


class ImagingPlotterMeta(Plotter):
Expand Down
2 changes: 1 addition & 1 deletion autoarray/dataset/plot/interferometer_plotters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from autoarray.plot.mat_plot.one_d import MatPlot1D
from autoarray.plot.mat_plot.two_d import MatPlot2D
from autoarray.plot.auto_labels import AutoLabels
from autoarray.dataset.interferometer.interferometer import Interferometer
from autoarray.dataset.interferometer.dataset import Interferometer
from autoarray.structures.grids.irregular_2d import Grid2DIrregular


Expand Down
2 changes: 1 addition & 1 deletion autoarray/fit/fit_imaging.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Dict, Optional

from autoarray.dataset.imaging.imaging import Imaging
from autoarray.dataset.imaging.dataset import Imaging
from autoarray.fit.fit_dataset import FitDataset
from autoarray.mask.mask_2d import Mask2D
from autoarray.structures.arrays.uniform_2d import Array2D
Expand Down
2 changes: 1 addition & 1 deletion autoarray/fit/fit_interferometer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
from typing import Dict, Optional, Union

from autoarray.dataset.interferometer.interferometer import Interferometer
from autoarray.dataset.interferometer.dataset import Interferometer
from autoarray.structures.arrays.uniform_2d import Array2D
from autoarray.structures.visibilities import Visibilities
from autoarray.fit.fit_dataset import FitDataset
Expand Down
2 changes: 1 addition & 1 deletion autoarray/inversion/inversion/factory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Dict, List, Optional, Union

from autoarray.dataset.imaging.imaging import Imaging
from autoarray.dataset.imaging.dataset import Imaging
from autoarray.dataset.imaging.w_tilde import WTildeImaging
from autoarray.dataset.interferometer.w_tilde import WTildeInterferometer
from autoarray.structures.arrays.uniform_2d import Array2D
Expand Down
5 changes: 1 addition & 4 deletions autoarray/plot/wrap/base/ticks.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,7 @@ def set(
)

if is_log10:
if not is_log10:
plt.ylim(min_value, max_value)
else:
plt.ylim(max(min_value, 1e-3), max_value)
plt.ylim(max(min_value, 1e-3), max_value)

if not is_for_1d_plot and not units.use_scaled:
labels = reversed(labels)
Expand Down
5 changes: 3 additions & 2 deletions autoarray/plot/wrap/one_d/yx_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ def plot_y_vs_x(
# ls=ls_errorbar,
**self.config_dict
)
if y_extra is not None:
plt.plot(x, y_extra, c="r")
if plot_axis_type == "errorbar_logy":
plt.yscale("log")
else:
raise exc.PlottingException(
"The plot_axis_type supplied to the plotter is not a valid string (must be linear "
"{semilogy, loglog})"
)

if y_extra is not None:
plt.plot(x, y_extra, c="r")

0 comments on commit a433b99

Please sign in to comment.