Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ distribute-*.tar.gz
.project
.pydevproject
.settings
.pytest_cache*

# Mac OSX
.DS_Store
11 changes: 5 additions & 6 deletions gunagala/imager.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,8 @@ def extended_source_signal_noise(self, surface_brightness, filter_name, total_ex
# Sky counts already included in _is_saturated, need to avoid counting them twice
saturated = self._is_saturated(
0 * u.electron / (u.pixel * u.second), sub_exp_time, filter_name)
signal = np.where(saturated, 0 * u.electron / u.pixel, signal)
noise = np.where(saturated, 0 * u.electron / u.pixel, noise)
signal = np.where(saturated, 0, signal) * u.electron / u.pixel
noise = np.where(saturated, 0, noise) * u.electron / u.pixel

# Totals per (binned) pixel for all imagers.
signal = signal * self.num_imagers * binning
Expand Down Expand Up @@ -1001,8 +1001,8 @@ def point_source_signal_noise(self, brightness, filter_name, total_exp_time, sub
# in a single sub exposure, and check against saturation_level.
if saturation_check:
saturated = self._is_saturated(rate * self.psf.peak, sub_exp_time, filter_name)
signal = np.where(saturated, 0.0 * u.electron, signal)
noise = np.where(saturated, 0.0 * u.electron , noise)
signal = np.where(saturated, 0.0, signal) * u.electron
noise = np.where(saturated, 0.0, noise) * u.electron

return signal, noise

Expand Down Expand Up @@ -1086,13 +1086,12 @@ def point_source_etc(self, brightness, filter_name, snr_target, sub_exp_time, sa

total_exp_time = self.extended_source_etc(rate / self.psf.n_pix, filter_name, snr_target, sub_exp_time,
saturation_check=False, binning=self.psf.n_pix / u.pixel)

# Saturation check. For point sources need to know maximum fraction of total electrons that will end up
# in a single pixel, this is available as psf.peak. Can use this to calculate maximum electrons per pixel
# in a single sub exposure, and check against saturation_level.
if saturation_check:
saturated = self._is_saturated(rate * self.psf.peak, sub_exp_time, filter_name)
total_exp_time = np.where(saturated, 0.0 * u.second, total_exp_time)
total_exp_time = np.where(saturated, 0.0, total_exp_time) * u.second

return total_exp_time

Expand Down
70 changes: 39 additions & 31 deletions gunagala/tests/test_psf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,15 @@

from gunagala.psf import PSF, MoffatPSF, PixellatedPSF


@pytest.fixture(scope='module')
def psf_moffat():
return make_moffat()


def make_moffat():
def make_psf_moffat():
psf = MoffatPSF(FWHM=1 / 30 * u.arcminute, shape=4.7)
return psf


@pytest.fixture(scope='module')
def psf_pixellated():
return make_pixellated()

def psf_moffat():
return(make_psf_moffat())

def make_pixellated():
def make_psf_pixellated():
psf_data = np.array([[0.0, 0.0, 0.1, 0.0, 0.0],
[0.0, 0.3, 0.7, 0.4, 0.0],
[0.1, 0.8, 1.0, 0.6, 0.1],
Expand All @@ -33,6 +25,9 @@ def make_pixellated():
pixel_scale=(2 / 3) * u.arcsecond / u.pixel)
return psf

@pytest.fixture(scope='module')
def psf_pixellated():
return(make_psf_pixellated())

def test_base():
with pytest.raises(TypeError):
Expand All @@ -41,8 +36,8 @@ def test_base():


@pytest.mark.parametrize("psf, type", [
(make_moffat(), MoffatPSF),
(make_pixellated(), PixellatedPSF)],
(make_psf_moffat(), MoffatPSF),
(make_psf_pixellated(), PixellatedPSF)],
ids=["moffat", "pixellated"]
)
def test_instance(psf, type):
Expand All @@ -64,14 +59,27 @@ def test_FWHM(psf_moffat):
psf_moffat.FWHM = 2 * u.arcsecond


def test_pixel_scale(psf_moffat):
psf.pixel_scale = 2.85 * u.arcsecond / u.pixel
assert psf.pixel_scale == 2.85 * u.arcsecond / u.pixel


def test_pixel_scale_pix(psf_pixellated):
psf_pixellated.pixel_scale = (1 / 3) * u.arcsecond / u.pixel
assert psf_pixellated.pixel_scale == (1 / 3) * u.arcsecond / u.pixel
psf_pixellated.pixel_scale = (2 / 3) * u.arcsecond / u.pixel


def test_n_pix(psf_moffat):
assert psf.n_pix == 4.25754067000986 * u.pixel


def test_n_pix_pix(psf_pixellated):
assert psf_pixellated.n_pix.to(u.pixel).value == pytest.approx(21.0699454)
assert psf_pixellated.n_pix.to(u.pixel).value == pytest.approx(21.01351017, 0.1)


def test_peak(psf_moffat):
assert psf.peak == 0.7134084656751443 / u.pixel


def test_peak_pix(psf_pixellated):
Expand All @@ -88,8 +96,8 @@ def test_shape(psf_moffat):


@pytest.mark.parametrize("psf, t_pixel_scale, pixel_scale", [
(make_moffat(), 2.85, 2.85),
(make_pixellated(), (1 / 3), (2 / 3))],
(make_psf_moffat(), 2.85, 2.85),
(make_psf_pixellated(), (1 / 3), (2 / 3))],
ids=["moffat", "pixellated"]
)
def test_pixel_scale(psf, t_pixel_scale, pixel_scale):
Expand All @@ -99,8 +107,8 @@ def test_pixel_scale(psf, t_pixel_scale, pixel_scale):


@pytest.mark.parametrize("psf, expected_n_pix, pixel_scale", [
(make_moffat(), 4.25754067000986, 2.85),
(make_pixellated(), 21.06994544, (2 / 3))],
(make_psf_moffat(), 4.25754067000986, 2.85),
(make_psf_pixellated(), 21.06994544, (2 / 3))],
ids=["moffat", "pixellated"]
)
def test_n_pix(psf, expected_n_pix, pixel_scale):
Expand All @@ -109,8 +117,8 @@ def test_n_pix(psf, expected_n_pix, pixel_scale):


@pytest.mark.parametrize("psf, expected_peak, pixel_scale", [
(make_moffat(), 0.7134084656751443, 2.85),
(make_pixellated(), 0.08073066, (2 / 3))],
(make_psf_moffat(), 0.7134084656751443, 2.85),
(make_psf_pixellated(), 0.08073066, (2 / 3))],
ids=["moffat", "pixellated"]
)
def test_peak(psf, expected_peak, pixel_scale):
Expand All @@ -119,10 +127,10 @@ def test_peak(psf, expected_peak, pixel_scale):


@pytest.mark.parametrize("psf, image_size", [
(make_moffat(), (21, 21)),
(make_pixellated(), (21, 21)),
(make_moffat(), (7, 9)),
(make_pixellated(), (7, 9))],
(make_psf_moffat(), (21, 21)),
(make_psf_pixellated(), (21, 21)),
(make_psf_moffat(), (7, 9)),
(make_psf_pixellated(), (7, 9))],
ids=["moffat_square",
"pixellated_square",
"moffat_rectangle",
Expand All @@ -141,10 +149,10 @@ def test_pixellated_dimension(psf, image_size):


@pytest.mark.parametrize("psf, offset", [
(make_moffat(), (0.0, 0.0)),
(make_pixellated(), (0.0, 0.0)),
(make_moffat(), (0.3, -0.7)),
(make_pixellated(), (0.3, -0.7))],
(make_psf_moffat(), (0.0, 0.0)),
(make_psf_pixellated(), (0.0, 0.0)),
(make_psf_moffat(), (0.3, -0.7)),
(make_psf_pixellated(), (0.3, -0.7))],
ids=["moffat_centre_offsets",
"pixellated_centre_offsets",
"moffat_noncentre_offsets",
Expand All @@ -158,8 +166,8 @@ def test_offsets(psf, offset):


@pytest.mark.parametrize("psf, test_size", [
(make_moffat(), (1.3, -1.3)),
(make_pixellated(), (-1.3, 1.3))],
(make_psf_moffat(), (1.3, -1.3)),
(make_psf_pixellated(), (-1.3, 1.3))],
ids=["moffat", "pixellated"]
)
def test_pixellated_invalid_size(psf, test_size):
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ edit_on_github = False
github_project = AstroHuntsman/gunagala
# install_requires should be formatted as a comma-separated list, e.g.:
# install_requires = astropy, scipy, matplotlib
install_requires = astropy, pyYAML, numpy, scipy, matplotlib
install_requires = astropy>=4.0.2, pyYAML, numpy, scipy, matplotlib
# version should be PEP386 compatible (http://www.python.org/dev/peps/pep-0386)
version = 0.1.dev0

Expand Down