Skip to content

Commit

Permalink
Fix psf tests that I apparently only half finished
Browse files Browse the repository at this point in the history
  • Loading branch information
rmjarvis committed Nov 5, 2021
1 parent cb0493d commit 9e58487
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 15 deletions.
8 changes: 5 additions & 3 deletions imsim/atmPSF.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import numpy as np
from scipy.optimize import bisect

import pickle
import galsim

from .optical_system import OpticalZernikes, mock_deviations
Expand Down Expand Up @@ -328,6 +329,7 @@ def __init__(self, airmass, rawSeeing, band, boresight, rng,
# Instead, the user can choose to convolve this by a Gaussian in the config file.
self.atm = AtmosphericPSF(airmass, rawSeeing, band, rng,
t0=t0, exptime=exptime, kcrit=kcrit, gaussianFWHM=0.,
screen_size=screen_size, screen_scale=screen_scale,
doOpt=doOpt, logger=logger, nproc=nproc)
# The other change is that we need the boresight to do image_pos -> field_pos
# I think it makes sense to take that as an input here rather than in the
Expand Down Expand Up @@ -387,10 +389,10 @@ def BuildDoubleGaussianPSF(config, base, ignore, gsparams, logger):

eff_pixel_sigma_sq = pixel_scale*pixel_scale/12.0

sigma = numpy.sqrt(alpha*alpha - eff_pixel_sigma_sq)
sigma = np.sqrt(alpha*alpha - eff_pixel_sigma_sq)
gaussian1 = galsim.Gaussian(sigma=sigma, gsparams=gsparams)

sigma = numpy.sqrt(4.0*alpha*alpha - eff_pixel_sigma_sq)
sigma = np.sqrt(4.0*alpha*alpha - eff_pixel_sigma_sq)
gaussian2 = galsim.Gaussian(sigma=sigma, gsparams=gsparams)

psf = 0.909*(gaussian1 + 0.1*gaussian2)
Expand Down Expand Up @@ -439,7 +441,7 @@ def BuildKolmogorovPSF(config, base, ignore, gsparams, logger):
FWHMatm = rawSeeing*(wlen_eff/500.)**-0.3*airmass**0.6
# From LSST-20160 eqn (4.1)

FWHMsys = numpy.sqrt(0.25**2 + 0.3**2 + 0.08**2)*airmass**0.6
FWHMsys = np.sqrt(0.25**2 + 0.3**2 + 0.08**2)*airmass**0.6
# From LSST-20160 eqn (4.2)

atm = galsim.Kolmogorov(fwhm=FWHMatm, gsparams=gsparams)
Expand Down
54 changes: 42 additions & 12 deletions tests/test_psf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def setUp(self):
self.test_dir = 'psf_tests_dir'
instcat = 'tiny_instcat.txt'
self.obs_md = imsim.OpsimMetaDict(instcat)
os.makedirs(self.test_dir)
if not os.path.exists(self.test_dir):
os.makedirs(self.test_dir)

def tearDown(self):
for item in glob.glob(os.path.join(self.test_dir, '*')):
Expand Down Expand Up @@ -51,15 +52,30 @@ def test_save_and_load_psf(self):
'airmass': self.obs_md['airmass'],
'rawSeeing': self.obs_md['rawSeeing'],
'band': self.obs_md['band'],
'screen_scale': 6.4,
'boresight': {
'type': 'RADec',
'ra': { 'type': 'Degrees', 'theta': self.obs_md['rightascension'], },
'dec': { 'type': 'Degrees', 'theta': self.obs_md['declination'], }
}
}
},
'image_pos': galsim.PositionD(0,0), # This would get set appropriately during
# normal config processing.
'image' : {
'wcs': {
'type' : 'Tan',
'dudx' : 0.2,
'dudy' : 0.,
'dvdx' : 0.,
'dvdy' : 0.2,
'ra' : '@input.atm_psf.boresight.ra',
'dec' : '@input.atm_psf.boresight.dec',
}
}
}
}
galsim.config.ProcessInput(config)
config['wcs'] = galsim.config.BuildWCS(config['image'], 'wcs', config)
for psf_name in ("DoubleGaussian", "Kolmogorov", "Atmospheric"):
psf = galsim.config.BuildGSObject(config, psf_name)
psf_file = os.path.join(self.test_dir, '{}.pkl'.format(psf_name))
Expand All @@ -76,9 +92,7 @@ def test_atm_psf_config(self):
'psf': {
'type': 'Convolve',
'items': [
{ 'type': 'AtmosphericPSF',
'screen_scale': 6.4,
},
{ 'type': 'AtmosphericPSF' },
{ 'type': 'Gaussian', 'fwhm': 0.3 },
],
},
Expand All @@ -87,25 +101,41 @@ def test_atm_psf_config(self):
'airmass': self.obs_md['airmass'],
'rawSeeing': self.obs_md['rawSeeing'],
'band': self.obs_md['band'],
'screen_scale': 6.4,
'boresight': {
'type': 'RADec',
'ra': { 'type': 'Degrees', 'theta': self.obs_md['rightascension'], },
'dec': { 'type': 'Degrees', 'theta': self.obs_md['declination'], }
}
}
},
'image_pos': galsim.PositionD(0,0), # This would get set appropriately during
# normal config processing.
'image' : {
'wcs': {
'type' : 'Tan',
'dudx' : 0.2,
'dudy' : 0.,
'dvdx' : 0.,
'dvdy' : 0.2,
'ra' : '@input.atm_psf.boresight.ra',
'dec' : '@input.atm_psf.boresight.dec',
}
}
}
galsim.config.ProcessInput(config)
config1 = galsin.config.CopyConfig(config)
# PSF with gaussianFWHM explicitly set to zero.
config1['psf']['items'][1]['fwhm'] = 0.
psf_0 = galsim.config.BuildGSObject(config1, 'psf')
config['wcs'] = galsim.config.BuildWCS(config['image'], 'wcs', config)

# PSF without gaussian
config1 = galsim.config.CopyConfig(config)
del config1['psf']['items'][1]
psf_0 = galsim.config.BuildGSObject(config1, 'psf')[0]

# PSF with gaussianFWHM explicitly set to config file value.
psf_c = galsim.config.BuildGSObject(config, 'psf')
# PSF with gaussian
psf_c = galsim.config.BuildGSObject(config, 'psf')[0]

# PSF made manually convolving Atm with Gaussian.
psf_a = galsim.config.BuildGSObject(config['psf']['items'], 0, config)
psf_a = galsim.config.BuildGSObject(config['psf']['items'], 0, config)[0]
psf = galsim.Convolve(psf_a, galsim.Gaussian(fwhm=0.3))

self.assertEqual(psf, psf_c)
Expand Down

0 comments on commit 9e58487

Please sign in to comment.