コード例 #1
0
    def setUp(self):
        baseDir = os.path.join(getPackageDir('sims_GalSimInterface'),
                               'tests', 'cameraData')

        self.camera = ReturnCamera(baseDir)

        ra = 145.0
        dec = -73.0
        self.epoch = 2000.0
        mjd = 49250.0
        rotSkyPos = 45.0
        self.obs = ObservationMetaData(unrefractedRA=ra,
                                       unrefractedDec=dec,
                                       boundType='circle',
                                       boundLength=1.0,
                                       mjd=mjd,
                                       rotSkyPos=rotSkyPos)

        raPointing, \
        decPointing = _observedFromICRS(numpy.array([numpy.radians(ra)]),
                                       numpy.array([numpy.radians(dec)]),
                                       obs_metadata=self.obs,
                                       epoch=self.epoch)

        self.ra = raPointing[0]
        self.dec = decPointing[0]
コード例 #2
0
ファイル: moObs.py プロジェクト: moeyensj/MafSSO
 def ssoInFov(self, interpfuncs, simdata, rFov=np.radians(1.75),
              useCamera=True,
              simdataRaCol = 'fieldRA', simdataDecCol='fieldDec'):
     """
     Return the indexes of the simdata observations where the object was inside the fov.
     """
     # See if the object is within 'rFov' of the center of the boresight.
     raSso = np.radians(interpfuncs['ra'](simdata['expMJD']))
     decSso = np.radians(interpfuncs['dec'](simdata['expMJD']))
     sep = haversine(raSso, decSso, simdata[simdataRaCol], simdata[simdataDecCol])
     if not useCamera:
         idxObsRough = np.where(sep<rFov)[0]
         return idxObsRough
     # Or go on and use the camera footprint.
     try:
         self.camera
     except AttributeError:
         self._setupCamera()
     idxObs = []
     idxObsRough = np.where(sep<self.cameraFov)[0]
     for idx in idxObsRough:
         mjd = simdata[idx]['expMJD']
         obs_metadata = ObservationMetaData(unrefractedRA=np.degrees(simdata[idx][simdataRaCol]),
                                            unrefractedDec=np.degrees(simdata[idx][simdataDecCol]),
                                            rotSkyPos=np.degrees(simdata[idx]['rotSkyPos']),
                                            mjd=simdata[idx]['expMJD'])
         raObj = np.radians(np.array([interpfuncs['ra'](simdata[idx]['expMJD'])]))
         decObj = np.radians(np.array([interpfuncs['dec'](simdata[idx]['expMJD'])]))
         raObj, decObj = _observedFromICRS(raObj, decObj, obs_metadata=obs_metadata, epoch=self.epoch)
         chipNames = _chipNameFromRaDec(ra=raObj,dec=decObj, epoch=self.epoch, camera=self.camera, obs_metadata=obs_metadata)
         if chipNames != [None]:
             idxObs.append(idx)
     idxObs = np.array(idxObs)
     return idxObs
コード例 #3
0
    def setUp(self):
        baseDir = os.path.join(getPackageDir('sims_GalSimInterface'), 'tests', 'cameraData')
        self.camera = ReturnCamera(baseDir)
        self.obs = ObservationMetaData(unrefractedRA=25.0, unrefractedDec=-10.0,
                                       boundType='circle', boundLength=1.0,
                                       mjd=49250.0, rotSkyPos=0.0)
        self.epoch = 2000.0

        self.raPointing, self.decPointing = _observedFromICRS(numpy.array([self.obs._unrefractedRA]),
                                                             numpy.array([self.obs._unrefractedDec]),
                                                             obs_metadata=self.obs,
                                                             epoch=self.epoch)
コード例 #4
0
 def ssoInFov(self,
              interpfuncs,
              simdata,
              rFov=np.radians(1.75),
              useCamera=True,
              simdataRaCol='fieldRA',
              simdataDecCol='fieldDec'):
     """
     Return the indexes of the simdata observations where the object was inside the fov.
     """
     # See if the object is within 'rFov' of the center of the boresight.
     raSso = np.radians(interpfuncs['ra'](simdata['expMJD']))
     decSso = np.radians(interpfuncs['dec'](simdata['expMJD']))
     sep = haversine(raSso, decSso, simdata[simdataRaCol],
                     simdata[simdataDecCol])
     if not useCamera:
         idxObsRough = np.where(sep < rFov)[0]
         return idxObsRough
     # Or go on and use the camera footprint.
     try:
         self.camera
     except AttributeError:
         self._setupCamera()
     idxObs = []
     idxObsRough = np.where(sep < self.cameraFov)[0]
     for idx in idxObsRough:
         mjd = simdata[idx]['expMJD']
         obs_metadata = ObservationMetaData(
             unrefractedRA=np.degrees(simdata[idx][simdataRaCol]),
             unrefractedDec=np.degrees(simdata[idx][simdataDecCol]),
             rotSkyPos=np.degrees(simdata[idx]['rotSkyPos']),
             mjd=simdata[idx]['expMJD'])
         raObj = np.radians(
             np.array([interpfuncs['ra'](simdata[idx]['expMJD'])]))
         decObj = np.radians(
             np.array([interpfuncs['dec'](simdata[idx]['expMJD'])]))
         raObj, decObj = _observedFromICRS(raObj,
                                           decObj,
                                           obs_metadata=obs_metadata,
                                           epoch=self.epoch)
         chipNames = _chipNameFromRaDec(ra=raObj,
                                        dec=decObj,
                                        epoch=self.epoch,
                                        camera=self.camera,
                                        obs_metadata=obs_metadata)
         if chipNames != [None]:
             idxObs.append(idx)
     idxObs = np.array(idxObs)
     return idxObs
コード例 #5
0
def tanWcsFromDetector(afwDetector, afwCamera, obs_metadata, epoch):
    """
    Take an afw.cameraGeom detector and return a WCS which approximates
    the focal plane as perfectly flat (i.e. it ignores optical distortions
    that the telescope may impose on the image)

    @param [in] afwDetector is an instantiation of afw.cameraGeom's Detector
    class which characterizes the detector for which you wish to return th
    WCS

    @param [in] afwCamera is an instantiation of afw.cameraGeom's Camera
    class which characterizes the camera containing afwDetector

    @param [in] obs_metadata is an instantiation of ObservationMetaData
    characterizing the telescope's current pointing

    @param [in] epoch is the epoch in Julian years of the equinox against
    which RA and Dec are measured

    @param [out] tanWcs is an instantiation of afw.image's TanWcs class
    representing the WCS of the detector as if there were no optical
    distortions imposed by the telescope.
    """

    xTanPixMin, xTanPixMax, \
    yTanPixMin, yTanPixMax = _getTanPixelBounds(afwDetector, afwCamera)


    xPixList = []
    yPixList = []
    nameList = []

    #dx and dy are set somewhat heuristically
    #setting them eqal to 0.1(max-min) lead to errors
    #on the order of 0.7 arcsec in the WCS

    dx = 0.5*(xTanPixMax-xTanPixMin)
    dy = 0.5*(yTanPixMax-yTanPixMin)
    for xx in numpy.arange(xTanPixMin, xTanPixMax+0.5*dx, dx):
        for yy in numpy.arange(yTanPixMin, yTanPixMax+0.5*dx, dx):
            xPixList.append(xx)
            yPixList.append(yy)
            nameList.append(afwDetector.getName())


    raList, decList = _raDecFromPixelCoords(numpy.array(xPixList),
                                            numpy.array(yPixList),
                                            nameList,
                                            camera=afwCamera,
                                            obs_metadata=obs_metadata,
                                            epoch=epoch,
                                            includeDistortion=False)

    raPointing, decPointing = _observedFromICRS(numpy.array([obs_metadata._unrefractedRA]),
                                               numpy.array([obs_metadata._unrefractedDec]),
                                               obs_metadata=obs_metadata, epoch=epoch)

    crPix1, crPix2 = _pixelCoordsFromRaDec(raPointing, decPointing,
                                           chipNames=[afwDetector.getName()], camera=afwCamera,
                                           obs_metadata=obs_metadata, epoch=epoch,
                                           includeDistortion=False)

    lonList, latList = _nativeLonLatFromRaDec(raList, decList, raPointing[0], decPointing[0])

    #convert from native longitude and latitude to intermediate world coordinates
    #according to equations (12), (13), (54) and (55) of
    #
    #Calabretta and Greisen (2002), A&A 395, p. 1077
    #
    radiusList = 180.0/(numpy.tan(latList)*numpy.pi)
    uList = radiusList*numpy.sin(lonList)
    vList = -radiusList*numpy.cos(lonList)

    delta_xList = xPixList - crPix1[0]
    delta_yList = yPixList - crPix2[0]

    bVector = numpy.array([
                          (delta_xList*uList).sum(),
                          (delta_yList*uList).sum(),
                          (delta_xList*vList).sum(),
                          (delta_yList*vList).sum()
                          ])

    offDiag = (delta_yList*delta_xList).sum()
    xsq = numpy.power(delta_xList,2).sum()
    ysq = numpy.power(delta_yList,2).sum()

    aMatrix = numpy.array([
                          [xsq, offDiag, 0.0, 0.0],
                          [offDiag, ysq, 0.0, 0.0],
                          [0.0, 0.0, xsq, offDiag],
                          [0.0, 0.0, offDiag, ysq]
                          ])

    coeffs = numpy.linalg.solve(aMatrix, bVector)

    crValPoint = afwGeom.Point2D(numpy.degrees(raPointing[0]), numpy.degrees(decPointing[0]))
    crPixPoint = afwGeom.Point2D(crPix1[0], crPix2[0])

    fitsHeader = dafBase.PropertyList()
    fitsHeader.set("RADESYS", "ICRS")
    fitsHeader.set("EQUINOX", epoch)
    fitsHeader.set("CRVAL1", numpy.degrees(raPointing[0]))
    fitsHeader.set("CRVAL2", numpy.degrees(decPointing[0]))
    fitsHeader.set("CRPIX1", crPix1[0]+1) # the +1 is because LSST uses 0-indexed images
    fitsHeader.set("CRPIX2", crPix2[0]+1) # FITS files use 1-indexed images
    fitsHeader.set("CTYPE1", "RA---TAN")
    fitsHeader.set("CTYPE2", "DEC--TAN")
    fitsHeader.setDouble("CD1_1", coeffs[0])
    fitsHeader.setDouble("CD1_2", coeffs[1])
    fitsHeader.setDouble("CD2_1", coeffs[2])
    fitsHeader.setDouble("CD2_2", coeffs[3])
    tanWcs = afwImage.cast_TanWcs(afwImage.makeWcs(fitsHeader))

    return tanWcs