Skip to content

Commit

Permalink
Revert "Merge remote-tracking branch 'upstream/image_sim' into improv…
Browse files Browse the repository at this point in the history
…e-pytest-#26"

This reverts commit 308168f.
  • Loading branch information
bazkiaei committed Oct 9, 2018
1 parent 94273a2 commit 25a4c04
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 74 deletions.
1 change: 0 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ Reference/API
:skip: SkyCoord
:skip: CCDData
:skip: interp1d
:skip: InvalidTransformError
:no-inheritance-diagram:

.. automodapi:: gunagala.optic
Expand Down
71 changes: 21 additions & 50 deletions gunagala/imager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from astropy import constants as c
from astropy import units as u
from astropy.wcs import WCS, InvalidTransformError
from astropy.wcs import WCS
from astropy.coordinates import SkyCoord
from astropy.nddata import CCDData

Expand Down Expand Up @@ -254,7 +254,6 @@ def __init__(self, optic, camera, filters, psf, sky, num_imagers=1, num_per_comp
self.wcs.wcs.cdelt = [self.pixel_scale.to(u.degree / u.pixel).value,
self.pixel_scale.to(u.degree / u.pixel).value]
self.wcs.wcs.ctype = ['RA---TAN', 'DEC--TAN']
self.wcs.wcs.crval = [None, None]

# Calculate end to end efficiencies, etc.
self._efficiencies()
Expand Down Expand Up @@ -284,29 +283,6 @@ def __init__(self, optic, camera, filters, psf, sky, num_imagers=1, num_per_comp
# Not a callable, should be a Simple sky model which just returns AB magnitudes per square arcsecond
self.sky_rate[filter_name] = self.SB_to_rate(sb, filter_name)


def set_WCS_centre(self, centre, *args, **kwargs):
"""
Set the WCS CRVALs of the Imager instance to centre.
Parameters
----------
centre : astropy.coordinates.SkyCoord or str
Sky coordinates of the image centre. Must be either a SkyCoord object or convertible
to one by the constructor of SkyCoord.
unit : str (optional)
Unit is the same as for the astropy.coordinates.SkyCoord(), e.g.
SkyCoord(RAdec[0], RAdec[1], unit='deg')
"""

# Ensure centre is a SkyCoord (this allows entering centre as a string)
if not isinstance(centre, SkyCoord):
centre = SkyCoord(centre, **kwargs)

# Set field centre coordinates in internal WCS
self.wcs.wcs.crval = [centre.icrs.ra.value, centre.icrs.dec.value]


def extended_source_signal_noise(self, surface_brightness, filter_name, total_exp_time, sub_exp_time,
calc_type='per pixel', saturation_check=True, binning=1):
"""
Expand Down Expand Up @@ -1535,52 +1511,48 @@ def snr_vs_ABmag(self, exp_times, filter_name, magnitude_interval=0.02 * u.ABmag

return magnitudes.to(u.ABmag), snrs.to(u.dimensionless_unscaled)

def get_pixel_coords(self):
def get_pixel_coords(self, centre):
"""
Utility function to return a SkyCoord array containing the on sky position
of the centre of all the pixels in the image.
of the centre of all the pixels in the image, given a SkyCoord for the
field centre
"""
# Ensure centre is a SkyCoord (this allows entering centre as a string)
if not isinstance(centre, SkyCoord):
centre = SkyCoord(centre)

# Set field centre coordinates in internal WCS
self.wcs.wcs.crval = [centre.icrs.ra.value, centre.icrs.dec.value]

# Arrays of pixel coordinates
XY = np.meshgrid(np.arange(self.wcs._naxis1), np.arange(self.wcs._naxis2))

# Convert to arrays of RA, dec (ICRS, decimal degrees)
try:
RAdec = self.wcs.all_pix2world(XY[0], XY[1], 0)
except InvalidTransformError:
raise ValueError("CRVAL not set! Must call set_WCS_centre before get_pixel_coords")
RAdec = self.wcs.all_pix2world(XY[0], XY[1], 0)

return SkyCoord(RAdec[0], RAdec[1], unit='deg')

def make_noiseless_image(self,
centre,
obs_time,
filter_name,
centre_kwargs={},
stars=None,
star_kwargs={}):
stars=None):
"""
Creates a noiseless simulated image for a given image centre and
observation time.
Creates a noiseless simulated image for a given image centre and observation time.
Parameters
----------
centre : astropy.coordinates.SkyCoord or str
Sky coordinates of the image centre. Must be either a SkyCoord
object or convertible to one by the constructor of SkyCoord.
Sky coordinates of the image centre. Must be either a SkyCoord object or convertible
to one by the constructor of SkyCoord.
obs_time : astropy.time.Time or str
Time of the obseration. This can be relevant when calculating the
sky background and source positions. Must be either a Time object
or convertible to one by the constructor of Time.
Time of the obseration. This can be relevant when calculating the sky background
and source positions. Must be either a Time object or convertible to one by the
constructor of Time.
filter_name : str
Name of the optical filter to use.
stars : sequence, optional
Sequence containing
centre_kwargs : dict (optional)
kwargs for centre kwargs to send to astropy.coordinates.SkyCoord(),
e.g. SkyCoord(centre, unit='deg')
star_kwargs : dict (optional)
kwargs for star kwargs to send to astropy.coordinates.SkyCoord(),
e.g. SkyCoord(coords, unit='deg')
Returns
-------
Expand All @@ -1589,19 +1561,18 @@ def make_noiseless_image(self,
"""
electrons = np.zeros((self.wcs._naxis2,
self.wcs._naxis1)) * u.electron / (u.second * u.pixel)
self.set_WCS_centre(centre, **centre_kwargs)

# Calculate observed sky background
sky_rate = self.sky_rate[filter_name]
if hasattr(self.sky, 'relative_brightness'):
pixel_coords = self.get_pixel_coords()
pixel_coords = self.get_pixel_coords(centre)
relative_sky = self.sky.relative_brightness(pixel_coords, obs_time)
sky_rate = sky_rate * relative_sky
electrons = electrons + sky_rate

if stars is not None:
for (coords, magnitude) in stars:
coords = SkyCoord(coords, **star_kwargs)
coords = SkyCoord(coords)
pixel_coords = self.wcs.all_world2pix(((coords.ra.degree, coords.dec.degree),), 0) \
- self.wcs.wcs.crpix
star_rate = self.ABmag_to_rate(magnitude, filter_name)
Expand Down
23 changes: 0 additions & 23 deletions gunagala/tests/test_imager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import numpy as np
import astropy.units as u
import astropy.constants as c
from astropy.coordinates import SkyCoord

from gunagala.optic import Optic
from gunagala.optical_filter import Filter
Expand Down Expand Up @@ -78,12 +77,6 @@ def imager(lens, ccd, filters, psf, sky):
return imager


@pytest.fixture(scope='function')
def imager_function_scope(lens, ccd, filters, psf, sky):
imager = Imager(optic=lens, camera=ccd, filters=filters, psf=psf, sky=sky, num_imagers=5, num_per_computer=5)
return imager


def test_init(imager):
assert isinstance(imager, Imager)
assert imager.pixel_scale == (5.4 * u.micron / (391 * u.mm * u.pixel)).to(u.arcsecond / u.pixel,
Expand Down Expand Up @@ -742,22 +735,6 @@ def test_snr_vs_mag(imager, filter_name, tmpdir):
assert mags3[-1].value == pytest.approx(mags[-1].value - 2.5, abs=0.1)


def test_get_pixel_coords_no_WCS_call_first(imager_function_scope):
# test if get_pixel_coords is called without first running set_WCS_centre
with pytest.raises(ValueError):
imager_function_scope.get_pixel_coords()


def test_get_pixel_coords_with_WCS_call_first(imager_function_scope):
test_coord_string = "189.9976325 -11.6230544"

# now set WCS centre first, then try and get_pixel_coords
imager_function_scope.set_WCS_centre(test_coord_string, unit='deg')
centre_field_pixels = imager_function_scope.get_pixel_coords()
assert imager_function_scope.wcs._naxis1 == centre_field_pixels.shape[1]
assert imager_function_scope.wcs._naxis2 == centre_field_pixels.shape[0]


def test_create_imagers():
imagers = create_imagers()
assert isinstance(imagers, dict)
Expand Down

0 comments on commit 25a4c04

Please sign in to comment.