Skip to content

Commit

Permalink
Image simulation (#16)
Browse files Browse the repository at this point in the history
* Added dark frame generation to Camera, moved other astroimsim code

* Initial implementations of image simulation methods

* Docs build fix

* Remove now redundant astroimsim.py

* Memory use reduction (no longer creates huge temporary arrays)

* Fix off-by-one, array vs Quantity & floating point stopping bugs

* Fix axis 18 (#20)

* Axis order changed

* Camera.py docstring improved

* clipping below zero pixel values

* Correcting test_psf.py

* camera.py docstring improved

* below zero assert added

* below zero and infinit asserts added

* combining pairs

* `@pytest.mark.parameterize` implemented

* Some problems with ...

* something that works for now

* Crval not set as per Issue #17 (#25)

* use centre to always set CRVAL first thing

See issue: #17

* created get_pixel_coords method for Imager

* remove centre for get_pixel_coords & check for CRVAL

* add :skip: InvalidTransformError to docs/index.rst

* added test of get_pixel_coords

* fix unit=deg problems in SkyCoord

* also unit=deg fix

* another unit=deg fix

* split test and make scope function

* make_noiseless_image unit=deg

* kwargs docstrings & split star_ & centre_ kwargs

* @bazkiaei
trying to parametrize as it has been advised

* @bazkiaei
trying to parametrize as it has been advised

* Revert "Merge remote-tracking branch 'upstream/image_sim' into improve-pytest-#26"

This reverts commit 308168f.

* Revert "Merge remote-tracking branch 'upstream/image_sim' into improve-pytest-#26"

This reverts commit 4b4bc04.

* Revert "Revert "Merge remote-tracking branch 'upstream/image_sim' into improve-pytest-#26""

This reverts commit 25a4c04.

* Revert "@bazkiaei"

This reverts commit 94273a2.

* Revert "@bazkiaei"

This reverts commit c811d41.

* Revert "Merge remote-tracking branch 'upstream/image_sim' into improve-pytest-#26"

This reverts commit 308168f.

* Revert "Revert "Merge remote-tracking branch 'upstream/image_sim' into improve-pytest-#26""

This reverts commit 9eb810c.

* Improving psf_pytest.py  #26 (#28)

The `test_psf.py` parametrised and decorated.

* auto pep8

* fix pixellated call

* add notimplemented error for analytical psf

* fix real image generator bug

* rename ZWO QE
  • Loading branch information
AnthonyHorton authored and lspitler committed Nov 25, 2019
1 parent 0f82a51 commit 029692b
Show file tree
Hide file tree
Showing 11 changed files with 571 additions and 318 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ matrix:
EVENT_TYPE='pull_request push cron'
#- os: linux
# env: PYTHON_VERSION=2.7 ASTROPY_VERSION=lts
- os: linux
env: ASTROPY_VERSION=lts
# - os: linux
# env: ASTROPY_VERSION=lts

# Try all python versions and Numpy versions. Since we can assume that
# the Numpy developers have taken care of testing Numpy with different
Expand Down
4 changes: 3 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,13 @@ Reference/API
:skip: PSF
:skip: Sky
:skip: Simple
:skip: Table
:skip: MoffatPSF
:skip: ZodiacalLight
:skip: WCS
:skip: SkyCoord
:skip: CCDData
:skip: interp1d
:skip: InvalidTransformError
:no-inheritance-diagram:

.. automodapi:: gunagala.optic
Expand Down
213 changes: 0 additions & 213 deletions gunagala/astroimsim.py

This file was deleted.

70 changes: 67 additions & 3 deletions gunagala/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Cameras (stricly the image sensor subsystem, not including optics, optical filters, etc)
"""
import os
import numpy as np

from astropy import units as u
from astropy.table import Table
Expand Down Expand Up @@ -37,7 +38,8 @@ class Camera:
Pixel pitch. Square pixels are assumed.
Resolution : astropy.units.Quantity
Two element Quantity containing the number of pixels across
the image sensor in both horizontal & vertical directions.
the image sensor in both vertical & horizontal directions.
(y, x)
read_noise astropy.units.Quantity
Intrinsic noise of image sensor and readout electronics, in
electrons/pixel units.
Expand All @@ -55,6 +57,13 @@ class Camera:
minimum_exposure : astropy.units.Quantity
Length of the shortest exposure that the camera is able to
take.
dark_current_dist : scipy.stats.rv_continuous, optional
A 'frozen' continuous random variable object that describes the distribution
of dark currents for the pixels in the image sensor. Used to create a `dark frame`
of uncorrelated dark current values. If not given no dark frame is created.
dark_current_seed: int, optional
Seed used to initialise the random number generator before creating the dark
frame. Set to a fixed value if you need to repeatedly generate the same dark frame.
Attributes
----------
Expand Down Expand Up @@ -86,9 +95,23 @@ class Camera:
Sequence of wavelengths from the QE data
QE : astropy.units.Quantity
Sequence of quantum efficiency values from the QE data.
dark_frame: astropy.units.Quantity or None
Array containing the dark current values for the pixels of the image sensor
"""
def __init__(self, bit_depth, full_well, gain, bias, readout_time, pixel_size, resolution,
read_noise, dark_current, QE, minimum_exposure):
def __init__(self,
bit_depth,
full_well,
gain,
bias,
readout_time,
pixel_size,
resolution,
read_noise,
dark_current,
QE,
minimum_exposure,
dark_current_dist=None,
dark_current_seed=None):

self.bit_depth = int(bit_depth)
self.full_well = ensure_unit(full_well, u.electron / u.pixel)
Expand All @@ -112,3 +135,44 @@ def __init__(self, bit_depth, full_well, gain, bias, readout_time, pixel_size, r
self.wavelengths, self.QE = get_table_data(QE,
column_names=('Wavelength', 'QE'),
column_units=(u.nm, u.electron / u.photon))

# Generate dark frame
if dark_current_dist is not None:
try:
dark_current_dist.rvs
except AttributeError:
raise ValueError("dark_current_dist ({}) has no rvs() method!".format(dark_current_dist))
self.dark_frame = self._make_dark_frame(dark_current_dist, dark_current_seed)
else:
self.dark_frame = None

def _make_dark_frame(self, distribution, seed=None):
"""
Function to create a dark current 'image' in electrons per second per pixel.
Creates an array of random, uncorrelated dark current values drawn from the
statistical distribution defined by the `distribution` parameter and returns
it as an astropy.units.Quantity.
Parameters
----------
distribution : scipy.stats.rv_continuous
A 'frozen' continuous random variable object that describes the distribution
of dark current values for the pixels in the image sensor.
seed: int
Seed used to initialise the random number generator before creating the dark
frame. Set to a fixed value if you need to repeatedly generate the same dark
frame.
"""
if seed is not None:
# Initialise RNG
np.random.seed(seed)

dark_frame = distribution.rvs(size=self.resolution.value.astype(int))
dark_frame = dark_frame * u.electron / (u.second * u.pixel)\

if seed is not None:
# Re-initialise RNG with random seed
np.random.seed()

return dark_frame
2 changes: 1 addition & 1 deletion gunagala/data/performance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ cameras:
resolution: 4656, 3520 # pixel
read_noise: 2.5 # electron / pixel
dark_current: 0.008 # electron / (second * pixel)
QE: ZWO_QE.csv
QE: ZWO_QE_asi1600.csv
minimum_exposure: 0.000032 # second

cis115: # e2v CIS115 'Sirius' back side illuminated CMOS image sensor
Expand Down
File renamed without changes.
Loading

0 comments on commit 029692b

Please sign in to comment.