Skip to content

Commit

Permalink
Merge pull request #253 from mwcraig/more-camera-settings
Browse files Browse the repository at this point in the history
Tidy up Camera-related tests and add a name property
  • Loading branch information
mwcraig authored Jan 13, 2024
2 parents a217b4d + 792fc4d commit 61b6ef6
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 166 deletions.
79 changes: 31 additions & 48 deletions stellarphot/photometry/tests/test_photometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,28 @@

SHIFT_TOLERANCE = 6
FWHM_ESTIMATE = 5

# A camera with not unreasonable settings
FAKE_CAMERA = Camera(
data_unit=u.adu,
gain=1.0 * u.electron / u.adu,
name="test camera",
read_noise=0 * u.electron,
dark_current=0.1 * u.electron / u.second,
pixel_scale=1 * u.arcsec / u.pixel,
max_data_value=40000 * u.adu,
)

# Camera with no read noise or dark currnet
ZERO_CAMERA = Camera(
data_unit=u.adu,
gain=1.0 * u.electron / u.adu,
name="test camera",
read_noise=0 * u.electron,
dark_current=0.0 * u.electron / u.second,
pixel_scale=1 * u.arcsec / u.pixel,
max_data_value=40000 * u.adu,
)
FAKE_OBS = EarthLocation(lat=0 * u.deg, lon=0 * u.deg, height=0 * u.m)
COORDS2USE = "pixel"

Expand All @@ -57,14 +71,8 @@ def test_calc_noise_source_only(gain, aperture_area):
expected = np.sqrt(gain * counts)

# Create camera instance
camera = Camera(
data_unit=u.adu,
gain=gain * u.electron / u.adu,
read_noise=0 * u.electron,
dark_current=0 * u.electron / u.second,
pixel_scale=1 * u.arcsec / u.pixel,
max_data_value=40000 * u.adu,
)
camera = ZERO_CAMERA.copy()
camera.gain = gain * camera.gain.unit

np.testing.assert_allclose(
calculate_noise(camera, counts=counts, aperture_area=aperture_area), expected
Expand All @@ -80,14 +88,10 @@ def test_calc_noise_dark_only(gain, aperture_area):
exposure = 20

# Create camera instance
camera = Camera(
data_unit=u.adu,
gain=gain * u.electron / u.adu,
read_noise=0 * u.electron,
dark_current=dark_current * u.electron / u.second,
pixel_scale=1 * u.arcsec / u.pixel,
max_data_value=40000 * u.adu,
)
camera = ZERO_CAMERA.copy()
# Set gain and dark current to values for test
camera.dark_current = dark_current * camera.dark_current.unit
camera.gain = gain * camera.gain.unit

expected = np.sqrt(dark_current * aperture_area * exposure)

Expand All @@ -106,14 +110,9 @@ def test_calc_read_noise_only(gain, aperture_area):
expected = np.sqrt(aperture_area * read_noise**2)

# Create camera instance
camera = Camera(
data_unit=u.adu,
gain=gain * u.electron / u.adu,
read_noise=read_noise * u.electron,
dark_current=0 * u.electron / u.second,
pixel_scale=1 * u.arcsec / u.pixel,
max_data_value=40000 * u.adu,
)
camera = ZERO_CAMERA.copy()
camera.read_noise = read_noise * camera.read_noise.unit
camera.gain = gain * camera.gain.unit

np.testing.assert_allclose(
calculate_noise(camera, aperture_area=aperture_area), expected
Expand All @@ -128,14 +127,8 @@ def test_calc_sky_only(gain, aperture_area):
expected = np.sqrt(gain * aperture_area * sky)

# Create camera instance
camera = Camera(
data_unit=u.adu,
gain=gain * u.electron / u.adu,
read_noise=0 * u.electron,
dark_current=0 * u.electron / u.second,
pixel_scale=1 * u.arcsec / u.pixel,
max_data_value=40000 * u.adu,
)
camera = ZERO_CAMERA.copy()
camera.gain = gain * camera.gain.unit

np.testing.assert_allclose(
calculate_noise(camera, aperture_area=aperture_area, sky_per_pix=sky), expected
Expand All @@ -153,14 +146,8 @@ def test_annulus_area_term():
expected = np.sqrt(gain * aperture_area * (1 + aperture_area / annulus_area) * sky)

# Create camera instance
camera = Camera(
data_unit=u.adu,
gain=gain * u.electron / u.adu,
read_noise=0 * u.electron,
dark_current=0 * u.electron / u.second,
pixel_scale=1 * u.arcsec / u.pixel,
max_data_value=40000 * u.adu,
)
camera = ZERO_CAMERA.copy()
camera.gain = gain * camera.gain.unit

np.testing.assert_allclose(
calculate_noise(
Expand Down Expand Up @@ -189,14 +176,10 @@ def test_calc_noise_messy_case(digit, expected):
read_noise = 12

# Create camera instance
camera = Camera(
data_unit=u.adu,
gain=gain * u.electron / u.adu,
read_noise=read_noise * u.electron,
dark_current=dark_current * u.electron / u.second,
pixel_scale=1 * u.arcsec / u.pixel,
max_data_value=40000 * u.adu,
)
camera = ZERO_CAMERA.copy()
camera.gain = gain * camera.gain.unit
camera.dark_current = dark_current * camera.dark_current.unit
camera.read_noise = read_noise * camera.read_noise.unit

np.testing.assert_allclose(
calculate_noise(
Expand Down
12 changes: 12 additions & 0 deletions stellarphot/settings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class Camera(BaseModel):
The gain of the camera in units such the product of `gain`
times the image data has units equal to that of the `read_noise`.
name : str
The name of the camera; can be anything that helps the user identify
the camera.
read_noise : `astropy.units.Quantity`
The read noise of the camera with units.
Expand All @@ -53,6 +57,10 @@ class Camera(BaseModel):
The gain of the camera in units such the product of `gain`
times the image data has units equal to that of the `read_noise`.
name : str
The name of the camera; can be anything that helps the user identify
the camera.
read_noise : `astropy.units.Quantity`
The read noise of the camera with units.
Expand All @@ -78,6 +86,7 @@ class Camera(BaseModel):
>>> from stellarphot.settings import Camera
>>> camera = Camera(data_unit="adu",
... gain=1.0 * u.electron / u.adu,
... name="test camera",
... read_noise=1.0 * u.electron,
... dark_current=0.01 * u.electron / u.second,
... pixel_scale=0.563 * u.arcsec / u.pixel,
Expand All @@ -86,6 +95,8 @@ class Camera(BaseModel):
Unit("adu")
>>> camera.gain
<Quantity 1. electron / adu>
>>> camera.name
'test camera'
>>> camera.read_noise
<Quantity 1. electron>
>>> camera.dark_current
Expand All @@ -103,6 +114,7 @@ class Camera(BaseModel):
description="unit should be consistent with data and read noise",
examples=["1.0 electron / adu"],
)
name: str
read_noise: QuantityType = Field(
description="unit should be consistent with dark current",
examples=["10.0 electron"],
Expand Down
Loading

0 comments on commit 61b6ef6

Please sign in to comment.