def test_psf_type(self): assert self.data_adu._psf_type == 'GAUSSIAN' kwargs_observations = { 'exposure_time': 1, 'sky_brightness': 1, 'magnitude_zero_point': self.magnitude_zero_point, 'num_exposures': 1, 'seeing': 1, 'psf_type': 'PIXEL' } kwargs_data = util.merge_dicts(self.kwargs_instrument, kwargs_observations) data_pixel = SingleBand(data_count_unit='ADU', **kwargs_data) assert data_pixel._psf_type == 'PIXEL' kwargs_observations = { 'exposure_time': 1, 'sky_brightness': 1, 'magnitude_zero_point': self.magnitude_zero_point, 'num_exposures': 1, 'seeing': 1, 'psf_type': 'NONE' } kwargs_data = util.merge_dicts(self.kwargs_instrument, kwargs_observations) data_pixel = SingleBand(data_count_unit='ADU', **kwargs_data) assert data_pixel._psf_type == 'NONE'
def setUp(self): self.g = LSST() # default is g_band self.r = LSST(band='r') self.i = LSST(band='i') kwargs_g_band = self.g.kwargs_single_band() kwargs_r_band = self.r.kwargs_single_band() kwargs_i_band = self.i.kwargs_single_band() self.g_band = SingleBand(**kwargs_g_band) self.r_band = SingleBand(**kwargs_r_band) self.i_band = SingleBand(**kwargs_i_band) # dictionaries mapping LSST kwargs to SingleBand kwargs self.camera_settings = {'read_noise': '_read_noise', 'pixel_scale': 'pixel_scale', 'ccd_gain': 'ccd_gain'} self.obs_settings = {'exposure_time': '_exposure_time', 'sky_brightness': '_sky_brightness_', 'magnitude_zero_point': '_magnitude_zero_point', 'num_exposures': '_num_exposures', 'seeing': '_seeing', 'psf_type': '_psf_type'} self.instrument = Instrument(**self.g.camera)
def setup(self): self.ccd_gain = 4. pixel_scale = 0.13 self.read_noise = 10. self.kwargs_instrument = { 'read_noise': self.read_noise, 'pixel_scale': pixel_scale, 'ccd_gain': self.ccd_gain } exposure_time = 100 sky_brightness = 20. self.magnitude_zero_point = 21. num_exposures = 2 seeing = 0.9 kwargs_observations = { 'exposure_time': exposure_time, 'sky_brightness': sky_brightness, 'magnitude_zero_point': self.magnitude_zero_point, 'num_exposures': num_exposures, 'seeing': seeing, 'psf_type': 'GAUSSIAN' } self.kwargs_data = util.merge_dicts(self.kwargs_instrument, kwargs_observations) self.data_adu = SingleBand(data_count_unit='ADU', **self.kwargs_data) self.data_e_ = SingleBand(data_count_unit='e-', **self.kwargs_data)
def test_raise(self): self.ccd_gain = 4. pixel_scale = 0.13 self.read_noise = 10. kwargs_instrument = {'read_noise': self.read_noise, 'pixel_scale': pixel_scale, 'ccd_gain': self.ccd_gain} exposure_time = 100 sky_brightness = 20. self.magnitude_zero_point = 21. num_exposures = 2 seeing = 0.9 kwargs_observations = {'exposure_time': exposure_time, 'sky_brightness': sky_brightness, 'magnitude_zero_point': self.magnitude_zero_point, 'num_exposures': num_exposures, 'seeing': seeing, 'psf_type': 'GAUSSIAN'} self.kwargs_data = util.merge_dicts(kwargs_instrument, kwargs_observations) with self.assertRaises(ValueError): SingleBand(data_count_unit='wrong', **self.kwargs_data) with self.assertRaises(ValueError): band = SingleBand(pixel_scale=1, exposure_time=1, magnitude_zero_point=1, read_noise=None, ccd_gain=None, sky_brightness=None, seeing=None, num_exposures=1, psf_type='GAUSSIAN', kernel_point_source=None, data_count_unit='ADU', background_noise=None) out = band.sky_brightness with self.assertRaises(ValueError): band = SingleBand(pixel_scale=1, exposure_time=1, magnitude_zero_point=1, read_noise=None, ccd_gain=None, sky_brightness=None, seeing=None, num_exposures=1, psf_type='GAUSSIAN', kernel_point_source=None, data_count_unit='ADU', background_noise=None) out = band.read_noise with self.assertRaises(ValueError): band = SingleBand(pixel_scale=1, exposure_time=1, magnitude_zero_point=1, read_noise=None, ccd_gain=None, sky_brightness=None, seeing=None, num_exposures=1, psf_type='GAUSSIAN', kernel_point_source=None, data_count_unit='ADU', background_noise=None) out = band.background_noise
def setUp(self): self.TDLMC_F160W = HST() # default is TDLMC_F160W self.F160W = HST(band='F160W') self.F160W2 = HST(band='F160W', psf_type='GAUSSIAN') kwargs_TDLMC_F160W = self.TDLMC_F160W.kwargs_single_band() kwargs_F160W = self.F160W.kwargs_single_band() kwargs_F160W2 = self.F160W2.kwargs_single_band() self.TDLMC_F160W_band = SingleBand(**kwargs_TDLMC_F160W) self.F160W_band = SingleBand(**kwargs_F160W) self.F160W2_band = SingleBand(**kwargs_F160W2) # dictionaries mapping HST kwargs to SingleBand kwargs self.camera_settings = {'read_noise': '_read_noise', 'pixel_scale': 'pixel_scale', 'ccd_gain': 'ccd_gain'} self.obs_settings = {'exposure_time': '_exposure_time', 'sky_brightness': '_sky_brightness_', 'magnitude_zero_point': '_magnitude_zero_point', 'num_exposures': '_num_exposures', 'seeing': '_seeing', 'psf_type': '_psf_type'} self.instrument = Instrument(**self.TDLMC_F160W.camera)
def __init__(self, numpix, **kwargs_single_band): """ :param numpix: number of pixels per axis in the simulation to be modelled :param kwargs_single_band: keyword arguments used to create instance of SingleBand class """ self.numpix = numpix SingleBand.__init__(self, **kwargs_single_band)
def add_noise(image, kwargs_band, background_noise=True, poisson_noise=True): """ :param image: 2d numpy array of a simlulated image without noise :param kwargs_band: keyword arguments containing the noise estimates :return: noisy image """ single_band = SingleBand(**kwargs_band) noise = single_band.noise_for_model(model=image, background_noise=background_noise, poisson_noise=poisson_noise) return image + noise
def get_noise_sigma2_lenstronomy(img, pixel_scale, exposure_time, magnitude_zero_point, read_noise=None, ccd_gain=None, sky_brightness=None, seeing=None, num_exposures=1, psf_type='GAUSSIAN', kernel_point_source=None, truncation=5, data_count_unit='ADU', background_noise=None): """Get the variance of sky, readout, and Poisson flux noise sources using lenstronomy Parameters ---------- img : 2D numpy array image on which the noise will be evaluated pixel_scale : float pixel scale in arcsec/pixel exposure_time : float exposure time per image in seconds magnitude_zero_point : float magnitude at which 1 count per second per arcsecond square is registered read_noise : float std of noise generated by readout (in units of electrons) ccd_gain : float electrons/ADU (analog-to-digital unit). A gain of 8 means that the camera digitizes the CCD signal so that each ADU corresponds to 8 photoelectrons sky_brightness : float sky brightness (in magnitude per square arcsec) seeing : float fwhm of PSF num_exposures : float number of exposures that are combined psf_type : str type of PSF ('GAUSSIAN' and 'PIXEL' supported) kernel_point_source : 2d numpy array model of PSF centered with odd number of pixels per axis(optional when psf_type='PIXEL' is chosen) truncation : float Gaussian truncation (in units of sigma), only required for 'GAUSSIAN' model data_count_unit : str unit of the data (and other properties), 'e-': (electrons assumed to be IID), 'ADU': (analog-to-digital unit) background_noise : float sqrt(variance of background) as a total contribution from read noise, sky brightness, etc. in units of the data_count_units If you set this parameter, it will override read_noise, sky_brightness. Default: None Returns ------- dict variance in the poisson, sky, and readout noise sources """ single_band = SingleBand(pixel_scale, exposure_time, magnitude_zero_point, read_noise=read_noise, ccd_gain=ccd_gain, sky_brightness=sky_brightness, seeing=seeing, num_exposures=num_exposures, psf_type=psf_type, kernel_point_source=kernel_point_source, truncation=truncation, data_count_unit=data_count_unit, background_noise=background_noise) noise_sigma2 = {} noise_sigma2['poisson'] = single_band.flux_noise(img)**2.0 exposure_time_tot = single_band._num_exposures * single_band._exposure_time readout_noise_tot = single_band._num_exposures * single_band.read_noise**2.0 sky_per_pixel = single_band.sky_brightness * single_band.pixel_scale ** 2 noise_sigma2['sky'] = sky_per_pixel**2.0/exposure_time_tot noise_sigma2['readout'] = readout_noise_tot / exposure_time_tot**2.0 return noise_sigma2
def test_raise(self): self.ccd_gain = 4. pixel_scale = 0.13 self.read_noise = 10. kwargs_instrument = { 'read_noise': self.read_noise, 'pixel_scale': pixel_scale, 'ccd_gain': self.ccd_gain } exposure_time = 100 sky_brightness = 20. self.magnitude_zero_point = 21. num_exposures = 2 seeing = 0.9 kwargs_observations = { 'exposure_time': exposure_time, 'sky_brightness': sky_brightness, 'magnitude_zero_point': self.magnitude_zero_point, 'num_exposures': num_exposures, 'seeing': seeing, 'psf_type': 'GAUSSIAN' } self.kwargs_data = util.merge_dicts(kwargs_instrument, kwargs_observations) with self.assertRaises(ValueError): SingleBand(data_count_unit='wrong', **self.kwargs_data)
def add_arc(image, kwargs_band, kwargs_params, kwargs_model, kwargs_numerics={}): """ routine to add lensed arc to existing image :param image: 2d square numpy array of original image :param kwargs_band: keyword arguments specifying the observation to be simulated according to lenstronomy.SimulationAPI :param kwargs_model: keyword arguments of model configurations. All possibilities available at lenstronom.Util.class_creator :param kwargs_params: keyword arguments of the different model components. Supports 'kwargs_lens', 'kwargs_source_mag', 'kwargs_lens_light_mag', 'kwargs_ps_mag' :param kwargs_numerics: keyword arguments describing the numerical setting of lenstronomy as outlined in lenstronomy.ImSim.Numerics :return: 2d numpy array """ numpix = len(image) arc = _arc_model(numpix, kwargs_band, kwargs_model, kwargs_numerics=kwargs_numerics, **kwargs_params) band = SingleBand(**kwargs_band) noisy_arc = arc + band.flux_noise(arc) return image + noisy_arc
def __init__(self, numpix, kwargs_pixel_grid=None, **kwargs_single_band): """ :param numpix: number of pixels per axis in the simulation to be modelled :param kwargs_pixel_grid: if None, uses default pixel grid option if defined, must contain keyword arguments PixelGrid() class :param kwargs_single_band: keyword arguments used to create instance of SingleBand class """ self.numpix = numpix if kwargs_pixel_grid is not None: required_keys = [ 'ra_at_xy_0', 'dec_at_xy_0', 'transform_pix2angle' ] if not all(k in kwargs_pixel_grid for k in required_keys): raise ValueError('Missing 1 or more required' + 'kwargs_pixel_grid parameters') self._kwargs_pixel_grid = kwargs_pixel_grid SingleBand.__init__(self, **kwargs_single_band)
def setUp(self): self.F062 = Roman() # default is F062 self.F087 = Roman(band='F087', survey_mode='microlensing') self.F106 = Roman(band='F106', psf_type='GAUSSIAN') self.F129 = Roman(band='F129', psf_type='GAUSSIAN') self.F158 = Roman(band='F158', psf_type='GAUSSIAN') self.F184 = Roman(band='F184', psf_type='GAUSSIAN') self.F146 = Roman(band='F146', survey_mode='microlensing', psf_type='GAUSSIAN') kwargs_F062 = self.F062.kwargs_single_band() kwargs_F087 = self.F087.kwargs_single_band() kwargs_F106 = self.F106.kwargs_single_band() kwargs_F129 = self.F129.kwargs_single_band() kwargs_F158 = self.F158.kwargs_single_band() kwargs_F184 = self.F184.kwargs_single_band() kwargs_F146 = self.F146.kwargs_single_band() self.F062_band = SingleBand(**kwargs_F062) self.F087_band = SingleBand(**kwargs_F087) self.F106_band = SingleBand(**kwargs_F106) self.F129_band = SingleBand(**kwargs_F129) self.F158_band = SingleBand(**kwargs_F158) self.F184_band = SingleBand(**kwargs_F184) self.F146_band = SingleBand(**kwargs_F146) # dictionaries mapping Roman kwargs to SingleBand kwargs self.camera_settings = { 'read_noise': '_read_noise', 'pixel_scale': 'pixel_scale', 'ccd_gain': 'ccd_gain' } self.obs_settings = { 'exposure_time': '_exposure_time', 'sky_brightness': '_sky_brightness_', 'magnitude_zero_point': '_magnitude_zero_point', 'num_exposures': '_num_exposures', 'seeing': '_seeing', 'psf_type': '_psf_type' } self.instrument = Instrument(**self.F062.camera)
def setUp(self): self.VIS = Euclid() kwargs_VIS = self.VIS.kwargs_single_band() self.VIS_band = SingleBand(**kwargs_VIS) # dictionaries mapping Euclid kwargs to SingleBand kwargs self.camera_settings = { 'read_noise': '_read_noise', 'pixel_scale': 'pixel_scale', 'ccd_gain': 'ccd_gain' } self.obs_settings = { 'exposure_time': '_exposure_time', 'sky_brightness': '_sky_brightness_', 'magnitude_zero_point': '_magnitude_zero_point', 'num_exposures': '_num_exposures', 'seeing': '_seeing', 'psf_type': '_psf_type' } self.instrument = Instrument(**self.VIS.camera)
class TestData(object): def setup(self): self.ccd_gain = 4. pixel_scale = 0.13 self.read_noise = 10. self.kwargs_instrument = { 'read_noise': self.read_noise, 'pixel_scale': pixel_scale, 'ccd_gain': self.ccd_gain } exposure_time = 100 sky_brightness = 20. self.magnitude_zero_point = 21. num_exposures = 2 seeing = 0.9 kwargs_observations = { 'exposure_time': exposure_time, 'sky_brightness': sky_brightness, 'magnitude_zero_point': self.magnitude_zero_point, 'num_exposures': num_exposures, 'seeing': seeing, 'psf_type': 'GAUSSIAN' } self.kwargs_data = util.merge_dicts(self.kwargs_instrument, kwargs_observations) self.data_adu = SingleBand(data_count_unit='ADU', **self.kwargs_data) self.data_e_ = SingleBand(data_count_unit='e-', **self.kwargs_data) def test_sky_brightness(self): sky_adu = self.data_adu.sky_brightness sky_e_ = self.data_e_.sky_brightness assert sky_e_ == sky_adu * self.ccd_gain npt.assert_almost_equal(sky_adu, 0.627971607877395, decimal=6) def test_background_noise(self): bkg_adu = self.data_adu.background_noise bkg_e_ = self.data_e_.background_noise assert bkg_adu == bkg_e_ / self.ccd_gain self.data_adu._background_noise = 1 bkg = self.data_adu.background_noise assert bkg == 1 def test_flux_noise(self): flux_iid = 50. flux_adu = flux_iid / self.ccd_gain noise_adu = self.data_adu.flux_noise(flux_adu) noise_e_ = self.data_e_.flux_noise(flux_iid) assert noise_e_ == 100. / 200. assert noise_e_ == noise_adu * self.ccd_gain def test_noise_for_model(self): model_adu = np.ones((10, 10)) model_e_ = model_adu * self.ccd_gain noise_adu = self.data_adu.noise_for_model(model_adu, background_noise=True, poisson_noise=True, seed=42) noise_adu_2 = self.data_adu.noise_for_model(model_adu, background_noise=True, poisson_noise=True, seed=42) npt.assert_almost_equal(noise_adu, noise_adu_2, decimal=10) noise_e_ = self.data_e_.noise_for_model(model_e_, background_noise=True, poisson_noise=True, seed=42) npt.assert_almost_equal(noise_adu, noise_e_ / self.ccd_gain, decimal=10) noise_e_ = self.data_e_.noise_for_model(model_e_, background_noise=True, poisson_noise=True, seed=None) def test_estimate_noise(self): image_adu = np.ones((10, 10)) image_e_ = image_adu * self.ccd_gain noise_adu = self.data_adu.estimate_noise(image_adu) noise_e_ = self.data_e_.estimate_noise(image_e_) npt.assert_almost_equal(noise_e_, noise_adu * self.ccd_gain) def test_magnitude2cps(self): mag_0 = self.data_adu.magnitude2cps( magnitude=self.magnitude_zero_point) npt.assert_almost_equal(mag_0, 1. / self.ccd_gain, decimal=10) mag_0_e_ = self.data_e_.magnitude2cps( magnitude=self.magnitude_zero_point) npt.assert_almost_equal(mag_0_e_, 1, decimal=10) mag_0 = self.data_adu.magnitude2cps( magnitude=self.magnitude_zero_point + 1) npt.assert_almost_equal(mag_0, 0.0995267926383743, decimal=10) mag_0 = self.data_adu.magnitude2cps( magnitude=self.magnitude_zero_point - 1) npt.assert_almost_equal(mag_0, 0.627971607877395, decimal=10) def test_flux_iid(self): flux_iid_adu = self.data_adu.flux_iid(flux_per_second=1) flux_iid_e = self.data_e_.flux_iid(flux_per_second=1) npt.assert_almost_equal(flux_iid_e, flux_iid_adu / self.ccd_gain, decimal=6) flux_adu = 10 flux_e_ = flux_adu * self.ccd_gain noise_e_ = self.data_e_.flux_noise(flux_e_) noise_adu = self.data_adu.flux_noise(flux_adu) npt.assert_almost_equal(noise_e_ / self.ccd_gain, noise_adu, decimal=8) def test_psf_type(self): assert self.data_adu._psf_type == 'GAUSSIAN' kwargs_observations = { 'exposure_time': 1, 'sky_brightness': 1, 'magnitude_zero_point': self.magnitude_zero_point, 'num_exposures': 1, 'seeing': 1, 'psf_type': 'PIXEL' } kwargs_data = util.merge_dicts(self.kwargs_instrument, kwargs_observations) data_pixel = SingleBand(data_count_unit='ADU', **kwargs_data) assert data_pixel._psf_type == 'PIXEL' kwargs_observations = { 'exposure_time': 1, 'sky_brightness': 1, 'magnitude_zero_point': self.magnitude_zero_point, 'num_exposures': 1, 'seeing': 1, 'psf_type': 'NONE' } kwargs_data = util.merge_dicts(self.kwargs_instrument, kwargs_observations) data_pixel = SingleBand(data_count_unit='ADU', **kwargs_data) assert data_pixel._psf_type == 'NONE'