diff --git a/python/lsst/sims/GalSimInterface/galSimCameraWrapper.py b/python/lsst/sims/GalSimInterface/galSimCameraWrapper.py index 7e8ec76..15f317c 100644 --- a/python/lsst/sims/GalSimInterface/galSimCameraWrapper.py +++ b/python/lsst/sims/GalSimInterface/galSimCameraWrapper.py @@ -56,6 +56,7 @@ class that inherits from GalSimCameraWrapper. This class will """ import numpy as np +import lsst.obs.lsst.phosim as obs_lsst_phosim from lsst.afw.cameraGeom import FOCAL_PLANE, PIXELS, TAN_PIXELS from lsst.afw.cameraGeom import FIELD_ANGLE import lsst.geom as LsstGeom @@ -483,6 +484,11 @@ def pixelCoordsFromRaDec(self, ra, dec, pm_ra=None, pm_dec=None, parallax=None, class LSSTCameraWrapper(coordUtils.DMtoCameraPixelTransformer, GalSimCameraWrapper): + def __init__(self): + self._camera = obs_lsst_phosim.PhosimMapper().camera + + + def getTanPixelBounds(self, detector_name): """ Return the min and max pixel values of a detector, assuming @@ -544,10 +550,10 @@ def pixelCoordsFromPupilCoords(self, xPupil, yPupil, chipName, obs_metadata, are defined in the Camera team system, rather than the DM system. """ (dm_x_pix, - dm_y_pix) = coordUtils.pixelCoordsFromPupilCoordsLSST(xPupil, yPupil, - chipName=chipName, - band=obs_metadata.bandpass, - includeDistortion=includeDistortion) + dm_y_pix) = coordUtils.pixelCoordsFromPupilCoords(xPupil, yPupil, + chipName=chipName, + camera=self.camera, + includeDistortion=includeDistortion) cam_y_pix = dm_x_pix if isinstance(chipName, list) or isinstance(chipName, np.ndarray): @@ -609,9 +615,9 @@ def pupilCoordsFromPixelCoords(self, xPix, yPix, chipName, obs_metadata, else: cam_center_pix = self.getCenterPixel(chipName) dm_yPix = 2.0*cam_center_pix.getX()-xPix - return coordUtils.pupilCoordsFromPixelCoordsLSST(dm_xPix, dm_yPix, chipName, - band=obs_metadata.bandpass, - includeDistortion=includeDistortion) + return coordUtils.pupilCoordsFromPixelCoords(dm_xPix, dm_yPix, chipName, + camera=self.camera, + includeDistortion=includeDistortion) def _raDecFromPixelCoords(self, xPix, yPix, chipName, obs_metadata, epoch=2000.0, includeDistortion=True): @@ -666,11 +672,11 @@ def _raDecFromPixelCoords(self, xPix, yPix, chipName, obs_metadata, cam_center_pix = self.getCenterPixel(chipName) dm_yPix = 2.0*cam_center_pix.getX() - xPix - return coordUtils._raDecFromPixelCoordsLSST(dm_xPix, dm_yPix, chipName, - obs_metadata=obs_metadata, - band=obs_metadata.bandpass, - epoch=epoch, - includeDistortion=includeDistortion) + return coordUtils._raDecFromPixelCoords(dm_xPix, dm_yPix, chipName, + obs_metadata=obs_metadata, + camera=self.camera, + epoch=epoch, + includeDistortion=includeDistortion) def raDecFromPixelCoords(self, xPix, yPix, chipName, obs_metadata, epoch=2000.0, includeDistortion=True): @@ -775,14 +781,14 @@ def _pixelCoordsFromRaDec(self, ra, dec, pm_ra=None, pm_dec=None, parallax=None, are defined in the Camera team system, rather than the DM system. """ - dm_xPix, dm_yPix = coordUtils._pixelCoordsFromRaDecLSST(ra, dec, - pm_ra=pm_ra, pm_dec=pm_dec, - parallax=parallax, v_rad=v_rad, - obs_metadata=obs_metadata, - chipName=chipName, - band=obs_metadata.bandpass, - epoch=epoch, - includeDistortion=includeDistortion) + dm_xPix, dm_yPix = coordUtils._pixelCoordsFromRaDec(ra, dec, + pm_ra=pm_ra, pm_dec=pm_dec, + parallax=parallax, v_rad=v_rad, + obs_metadata=obs_metadata, + chipName=chipName, + camera=self.camera, + epoch=epoch, + includeDistortion=includeDistortion) return self.cameraPixFromDMPix(dm_xPix, dm_yPix, chipName) diff --git a/python/lsst/sims/GalSimInterface/galSimDetector.py b/python/lsst/sims/GalSimInterface/galSimDetector.py index 6d22940..6e20617 100644 --- a/python/lsst/sims/GalSimInterface/galSimDetector.py +++ b/python/lsst/sims/GalSimInterface/galSimDetector.py @@ -10,9 +10,9 @@ import galsim import numpy as np import lsst.geom as LsstGeom +import lsst.obs.lsst.translators.lsst from lsst.afw.cameraGeom import FIELD_ANGLE, PIXELS, FOCAL_PLANE from lsst.afw.cameraGeom import WAVEFRONT, GUIDER -from lsst.obs.lsstSim import LsstSimMapper from lsst.sims.utils import arcsecFromRadians from lsst.sims.GalSimInterface.wcsUtils import tanSipWcsFromDetector from lsst.sims.GalSimInterface import GalSimCameraWrapper @@ -116,13 +116,12 @@ def __init__(self, detectorName, cameraWrapper, obs_metadata, epoch, photParams= self.fitsHeader.set('SIMULATE', True) self.fitsHeader.set('ORIGIN', 'IMSIM') observatory = LsstObservatory() - self.fitsHeader.set('OBS-LONG', observatory.getLongitude().asDegrees()) - self.fitsHeader.set('OBS-LAT', observatory.getLongitude().asDegrees()) - self.fitsHeader.set('OBS-ELEV', observatory.getElevation()) - obs_location = observatory.getLocation() - self.fitsHeader.set('OBSGEO-X', obs_location.geocentric[0].value) - self.fitsHeader.set('OBSGEO-Y', obs_location.geocentric[1].value) - self.fitsHeader.set('OBSGEO-Z', obs_location.geocentric[2].value) + self.fitsHeader.set('OBS-LONG', observatory.lon.degree) + self.fitsHeader.set('OBS-LAT', observatory.lat.degree) + self.fitsHeader.set('OBS-ELEV', observatory.height.value) + self.fitsHeader.set('OBSGEO-X', observatory.geocentric[0].value) + self.fitsHeader.set('OBSGEO-Y', observatory.geocentric[1].value) + self.fitsHeader.set('OBSGEO-Z', observatory.geocentric[2].value) self.crpix1 = self.fitsHeader.getScalar("CRPIX1") self.crpix2 = self.fitsHeader.getScalar("CRPIX2") @@ -688,7 +687,8 @@ class LsstObservatory: observatory location information. """ def __init__(self): - self.observatory = LsstSimMapper().MakeRawVisitInfoClass().observatory + self.observatory = lsst.obs.lsst.translators.lsst.LSST_LOCATION + self.geocentric = self.observatory.to_geocentric() def getLocation(self): """ @@ -698,10 +698,7 @@ def getLocation(self): ------- astropy.coordinates.earth.EarthLocation """ - return astropy.coordinates.EarthLocation.from_geodetic( - self.observatory.getLongitude().asDegrees(), - self.observatory.getLatitude().asDegrees(), - self.observatory.getElevation()) + return self.observatory def __getattr__(self, attr): if hasattr(self.observatory, attr): diff --git a/python/lsst/sims/GalSimInterface/galSimInterpreter.py b/python/lsst/sims/GalSimInterface/galSimInterpreter.py index c0a95c4..c4ce044 100644 --- a/python/lsst/sims/GalSimInterface/galSimInterpreter.py +++ b/python/lsst/sims/GalSimInterface/galSimInterpreter.py @@ -770,7 +770,7 @@ def __init__(self, obs_metadata=None, detectors=None, bandpassDict=None, self.local_hour_angle \ = self.getHourAngle(self.obs_metadata.mjd.TAI, self.obs_metadata.pointingRA)*galsim.degrees - self.obs_latitude = self.observatory.getLatitude().asDegrees()*galsim.degrees + self.obs_latitude = self.observatory.lat.degree*galsim.degrees # Make a trivial SED to use for faint things. blue_limit = np.min([bp.blue_limit for bp in self.gs_bandpass_dict.values()]) diff --git a/tests/testFitsHeaders.py b/tests/testFitsHeaders.py index c5a7221..8063cab 100644 --- a/tests/testFitsHeaders.py +++ b/tests/testFitsHeaders.py @@ -23,7 +23,6 @@ from testUtils import create_text_catalog -from lsst.sims.coordUtils import clean_up_lsst_camera ROOT = os.path.abspath(os.path.dirname(__file__)) @@ -67,7 +66,6 @@ class FitsHeaderTest(unittest.TestCase): @classmethod def tearDownClass(cls): sims_clean_up() - clean_up_lsst_camera() def testFitsHeader(self): """ diff --git a/tests/testGalSimCameraWrapper.py b/tests/testGalSimCameraWrapper.py index 9ad574a..7f1a257 100644 --- a/tests/testGalSimCameraWrapper.py +++ b/tests/testGalSimCameraWrapper.py @@ -2,6 +2,8 @@ import numpy as np import lsst.utils.tests +import lsst.obs.lsst.phosim as obs_lsst_phosim + from lsst.sims.utils import ObservationMetaData from lsst.sims.utils import raDecFromAltAz from lsst.sims.coordUtils import pixelCoordsFromRaDec @@ -13,21 +15,11 @@ from lsst.sims.GalSimInterface import GalSimCameraWrapper from lsst.sims.GalSimInterface import LSSTCameraWrapper -from lsst.sims.coordUtils import lsst_camera import lsst.afw.cameraGeom.testUtils as camTestUtils from lsst.afw.cameraGeom import FOCAL_PLANE from lsst.afw.cameraGeom import TAN_PIXELS, FIELD_ANGLE, PIXELS -from lsst.sims.coordUtils import chipNameFromPupilCoordsLSST -from lsst.sims.coordUtils import focalPlaneCoordsFromPupilCoordsLSST -from lsst.sims.coordUtils import pupilCoordsFromFocalPlaneCoordsLSST -from lsst.sims.coordUtils import pupilCoordsFromPixelCoordsLSST -from lsst.sims.coordUtils import pixelCoordsFromPupilCoordsLSST -from lsst.sims.coordUtils import raDecFromPixelCoordsLSST -from lsst.sims.coordUtils import lsst_camera - -from lsst.sims.coordUtils import clean_up_lsst_camera def setup_module(module): lsst.utils.tests.init() @@ -37,10 +29,6 @@ class Camera_Wrapper_Test_Class(unittest.TestCase): longMessage = True - @classmethod - def tearDownClass(cls): - clean_up_lsst_camera() - def test_generic_camera_wrapper(self): """ Test that GalSimCameraWrapper wraps its methods as expected. @@ -209,7 +197,7 @@ def test_LSST_camera_wrapper(self): Camera +y = DM +x Camera +x = DM -y """ - camera = lsst_camera() + camera = obs_lsst_phosim.PhosimMapper().camera camera_wrapper = LSSTCameraWrapper() obs_mjd = ObservationMetaData(mjd=60000.0) @@ -290,8 +278,8 @@ def test_LSST_camera_wrapper(self): # is as expected x_pup = rng.random_sample(10)*0.005-0.01 y_pup = rng.random_sample(10)*0.005-0.01 - x_pix, y_pix = pixelCoordsFromPupilCoordsLSST(x_pup, y_pup, chipName=name, - band=obs.bandpass) + x_pix, y_pix = pixelCoordsFromPupilCoords(x_pup, y_pup, chipName=name, + camera=camera) (x_pix_wrapper, y_pix_wrapper) = camera_wrapper.pixelCoordsFromPupilCoords(x_pup, y_pup, @@ -324,8 +312,8 @@ def test_LSST_camera_wrapper(self): x_pix = bbox.getMinX() + rng.random_sample(10)*(bbox.getMaxX()-bbox.getMinX()) y_pix = bbox.getMinY() + rng.random_sample(10)*(bbox.getMaxY()-bbox.getMinY()) - ra, dec = raDecFromPixelCoordsLSST(x_pix, y_pix, name, obs_metadata=obs, - band=obs.bandpass) + ra, dec = raDecFromPixelCoords(x_pix, y_pix, name, obs_metadata=obs, + camera=camera) (ra_wrapper, dec_wrapper) = camera_wrapper.raDecFromPixelCoords(2.0*center_pix.getY()-y_pix, @@ -370,14 +358,13 @@ def test_LSST_camera_wrapper(self): del camera del camera_wrapper - del lsst_camera._lsst_camera def test_dmPixFromCameraPix(self): """ Test that the method to return DM pixel coordinates from Camera Team pixel coordinates works. """ - camera = lsst_camera() + camera = obs_lsst_phosim.PhosimMapper().camera camera_wrapper = LSSTCameraWrapper() obs = ObservationMetaData(bandpassName='u') @@ -391,10 +378,10 @@ def test_dmPixFromCameraPix(self): chip_name_list = rng.choice(name_list, size=npts) (xPup_list, - yPup_list) = pupilCoordsFromPixelCoordsLSST(dm_x_pix_list, - dm_y_pix_list, - chipName=chip_name_list, - band=obs.bandpass) + yPup_list) = pupilCoordsFromPixelCoords(dm_x_pix_list, + dm_y_pix_list, + chipName=chip_name_list, + camera=camera) (cam_x_pix_list, cam_y_pix_list) = camera_wrapper.pixelCoordsFromPupilCoords(xPup_list, @@ -425,10 +412,10 @@ def test_dmPixFromCameraPix(self): chip_name = chip_name_list[10] (xPup_list, - yPup_list) = pupilCoordsFromPixelCoordsLSST(dm_x_pix_list, - dm_y_pix_list, - chipName=chip_name, - band=obs.bandpass) + yPup_list) = pupilCoordsFromPixelCoords(dm_x_pix_list, + dm_y_pix_list, + chipName=chip_name, + camera=camera) (cam_x_pix_list, cam_y_pix_list) = camera_wrapper.pixelCoordsFromPupilCoords(xPup_list, @@ -448,7 +435,6 @@ def test_dmPixFromCameraPix(self): del camera del camera_wrapper - del lsst_camera._lsst_camera def test_camPixFromDMpix(self): """ @@ -459,12 +445,11 @@ def test_camPixFromDMpix(self): npts = 200 cam_x_in = rng.random_sample(npts)*4000.0 cam_y_in = rng.random_sample(npts)*4000.0 - dm_x, dm_y = camera_wrapper.dmPixFromCameraPix(cam_x_in, cam_y_in, 'R:1,1 S:2,2') - cam_x, cam_y = camera_wrapper.cameraPixFromDMPix(dm_x, dm_y, 'R:1,1 S:2,2') + dm_x, dm_y = camera_wrapper.dmPixFromCameraPix(cam_x_in, cam_y_in, 'R11_S22') + cam_x, cam_y = camera_wrapper.cameraPixFromDMPix(dm_x, dm_y, 'R11_S22') np.testing.assert_array_almost_equal(cam_x_in, cam_x, decimal=10) np.testing.assert_array_almost_equal(cam_y_in, cam_y, decimal=10) del camera_wrapper - del lsst_camera._lsst_camera class MemoryTestClass(lsst.utils.tests.MemoryTestCase): diff --git a/tests/testGalSimInterface.py b/tests/testGalSimInterface.py index 3725ce0..807f91c 100644 --- a/tests/testGalSimInterface.py +++ b/tests/testGalSimInterface.py @@ -34,7 +34,6 @@ from lsst.sims.catUtils.utils import (calcADUwrapper, testGalaxyBulgeDBObj, testGalaxyDiskDBObj, testGalaxyAgnDBObj, testStarsDBObj) import lsst.afw.image as afwImage -from lsst.sims.coordUtils import clean_up_lsst_camera # Tell astropy not to download this file again, even if it's out of date. from astropy.utils import iers @@ -1121,7 +1120,6 @@ def setUp(self): self.db_name = os.path.join(self.scratch_dir, 'galsim_test_db') def tearDown(self): - clean_up_lsst_camera() if os.path.exists(self.db_name): os.remove(self.db_name) if os.path.exists(self.scratch_dir): @@ -1143,7 +1141,7 @@ def test_getStampBounds(self): obs_md.OpsimMetaData['altitude'] = altitude obs_md.OpsimMetaData['rawSeeing'] = seeing camera_wrapper = LSSTCameraWrapper() - detector = make_galsim_detector(camera_wrapper, 'R:2,2 S:1,1', + detector = make_galsim_detector(camera_wrapper, 'R22_S11', PhotometricParameters(), obs_md) gs_interpreter = make_gs_interpreter(obs_md, [detector], BandpassDict.loadTotalBandpassesFromFiles(), diff --git a/tests/testLSSTPlacement.py b/tests/testLSSTPlacement.py index 3fc005f..52c718a 100644 --- a/tests/testLSSTPlacement.py +++ b/tests/testLSSTPlacement.py @@ -15,6 +15,7 @@ import os from lsst.utils import getPackageDir import lsst.afw.image as afwImage +import lsst.obs.lsst.phosim as obs_lsst_phosim from lsst.sims.utils.CodeUtilities import sims_clean_up from lsst.sims.catUtils.utils import ObservationMetaDataGenerator from lsst.sims.catalogs.db import fileDBObject @@ -24,12 +25,7 @@ from lsst.sims.coordUtils import pixelCoordsFromRaDec from lsst.sims.coordUtils import DMtoCameraPixelTransformer -from lsst.sims.coordUtils import raDecFromPixelCoordsLSST -from lsst.sims.coordUtils import pixelCoordsFromRaDecLSST -from lsst.sims.coordUtils import chipNameFromPupilCoordsLSST -from lsst.sims.coordUtils import pupilCoordsFromFocalPlaneCoordsLSST -from lsst.sims.coordUtils import focalPlaneCoordsFromPupilCoordsLSST -from lsst.sims.coordUtils import lsst_camera +from lsst.sims.coordUtils import raDecFromPixelCoords ROOT = os.path.abspath(os.path.dirname(__file__)) @@ -71,17 +67,10 @@ class GalSimPlacementTest(unittest.TestCase): @classmethod def tearDownClass(cls): sims_clean_up() - if hasattr(chipNameFromPupilCoordsLSST, '_detector_arr'): - del chipNameFromPupilCoordsLSST._detector_arr - if hasattr(focalPlaneCoordsFromPupilCoordsLSST, '_z_fitter'): - del focalPlaneCoordsFromPupilCoordsLSST._z_fitter - if hasattr(pupilCoordsFromFocalPlaneCoordsLSST, '_z_fitter'): - del pupilCoordsFromFocalPlaneCoordsLSST._z_fitter - if hasattr(lsst_camera, '_lsst_camera'): - del lsst_camera._lsst_camera @classmethod def setUpClass(cls): + cls.camera = obs_lsst_phosim.PhosimMapper().camera opsimdb = os.path.join(getPackageDir('sims_data'), 'OpSimData', 'opsimblitz1_1133_sqlite.db') obs_gen = ObservationMetaDataGenerator(opsimdb) @@ -104,7 +93,7 @@ def testObjectPlacement(self): shutil.rmtree(scratchDir) os.mkdir(scratchDir) - detector = lsst_camera()['R:0,3 S:2,2'] + detector = self.camera['R03_S22'] det_name = 'R03_S22' magNorm = 19.0 @@ -121,10 +110,10 @@ def testObjectPlacement(self): imageName = '%s_%s_%s.fits' % (imageRoot, det_name, obs.bandpass) - ra_c, dec_c = raDecFromPixelCoordsLSST(2000.0, 2000.0, - detector.getName(), - band=obs.bandpass, - obs_metadata=obs) + ra_c, dec_c = raDecFromPixelCoords(2000.0, 2000.0, + detector.getName(), + camera=self.camera, + obs_metadata=obs) nSamples = 3 rng = np.random.RandomState(42) @@ -137,21 +126,15 @@ def testObjectPlacement(self): ra_obj = ra_c + rng.random_sample()*0.2 - 0.1 dec_obj = dec_c + rng.random_sample()*0.2 - 0.1 - dmx_wrong, dmy_wrong = pixelCoordsFromRaDec(ra_obj, dec_obj, - chipName=detector.getName(), - obs_metadata=obs, - camera=lsst_camera()) - dmx_pix, dmy_pix = pixelCoordsFromRaDecLSST(ra_obj, dec_obj, - chipName=detector.getName(), - obs_metadata=obs, - band=obs.bandpass) + dmx_pix, dmy_pix = pixelCoordsFromRaDec(ra_obj, dec_obj, + chipName=detector.getName(), + obs_metadata=obs, + camera=self.camera) x_pix, y_pix = pixel_transformer.cameraPixFromDMPix(dmx_pix, dmy_pix, detector.getName()) - x_pix_wrong, y_pix_wrong = pixel_transformer.cameraPixFromDMPix(dmx_wrong, dmy_wrong, - detector.getName()) d_ra = 3600.0*(ra_obj - obs.pointingRA) # in arcseconds d_dec = 3600.0*(dec_obj - obs.pointingDec) @@ -178,11 +161,6 @@ def testObjectPlacement(self): dd = np.sqrt((x_pix-x_centroid)**2 + (y_pix-y_centroid)**2) self.assertLess(dd, 0.5*fwhm) - dd_wrong = np.sqrt((x_pix_wrong-x_centroid)**2 + - (y_pix_wrong-y_centroid)**2) - - self.assertLess(dd, dd_wrong) - if os.path.exists(dbFileName): os.unlink(dbFileName) if os.path.exists(catName): diff --git a/tests/testWcsUtils.py b/tests/testWcsUtils.py index 06c2619..fd40079 100644 --- a/tests/testWcsUtils.py +++ b/tests/testWcsUtils.py @@ -28,7 +28,7 @@ class WcsTest(unittest.TestCase): def setUpClass(cls): cls.camera_wrapper = LSSTCameraWrapper() - cls.detector = cls.camera_wrapper.camera['R:1,1 S:2,2'] + cls.detector = cls.camera_wrapper.camera['R11_S22'] cls.obs = ObservationMetaData(pointingRA=25.0, pointingDec=-10.0, boundType='circle', boundLength=1.0, diff --git a/ups/sims_GalSimInterface.table b/ups/sims_GalSimInterface.table index 2a89d35..01c804b 100644 --- a/ups/sims_GalSimInterface.table +++ b/ups/sims_GalSimInterface.table @@ -8,7 +8,7 @@ setupRequired(sims_coordUtils) setupRequired(sims_catalogs) setupRequired(sims_catUtils) -setupOptional(obs_lsstSim) +setupOptional(obs_lsst) #This is needed by the mssql python module envPrepend(TDSVER, 7.0)