Beispiel #1
0
def get_opd_ra_dec(instrument, raField, decField, rotskypos):
    ''' Provide phoSim with ra,dec locations to evaluate OPD.
    The OPD expects field location, not sky location.
    '''
    if instrument == 'comCam':
        sensorNames, xCenter, yCenter = get_all_sensor_names_xy(
            LsstComCam().getCamera())

    elif instrument == 'lsstCam':
        sensorNames, xCenter, yCenter = get_all_sensor_names_xy(
            LsstCam().getCamera())

    elif instrument == 'wfs':
        sensorNames, xCenter, yCenter = get_wfs_sensor_names_xy()

    # Declare the SkySim()
    skySim = SkySim()

    # Set the observation information
    skySim.setObservationMetaData(raField, decField, rotskypos)

    xPx = xCenter
    yPx = yCenter
    starMag = 15

    starId = 0
    # we have only one x,y point per sensor
    for i in range(len(sensorNames)):
        skySim.addStarByChipPos(sensorNames[i], starId, xCenter[i], yCenter[i],
                                starMag)
        starId += 1

    raList, decList = skySim.getRaDecInDeg()

    # Note:  ra for phosim is (0 <= ra <= 360). But the
    # field position might be < 0 (-180 <= field_ra <= 180).
    # So here I change
    # the (0,360) range to (-180,180) range:
    m = raList > 180
    raList[m] = raList[m] - 360

    mags = skySim.getStarMag()
    coords = Table(data=[raList, decList, xCenter, yCenter, mags],
                   names=['ra', 'dec', 'xPx', 'yPx', 'r'])

    # add a column with object id
    coords['objid'] = np.arange(len(coords))

    panda_cat = coords.to_pandas()

    return panda_cat
Beispiel #2
0
class TestSkySim(unittest.TestCase):
    """ Test the SkySim class."""
    def setUp(self):

        self.skySim = SkySim()

    def testGetStarId(self):

        starId = self.skySim.getStarId()
        self.assertEqual(len(starId), 0)
        self.assertTrue(isinstance(starId, np.ndarray))

    def testGetRaDecInDeg(self):

        ra, decl = self.skySim.getRaDecInDeg()

        self.assertEqual(len(ra), 0)
        self.assertTrue(isinstance(ra, np.ndarray))

        self.assertEqual(len(decl), 0)
        self.assertTrue(isinstance(decl, np.ndarray))

    def testGetStarMag(self):

        mag = self.skySim.getStarMag()
        self.assertEqual(len(mag), 0)
        self.assertTrue(isinstance(mag, np.ndarray))

    def testAddStarByRaDecInDeg(self):

        self.skySim.addStarByRaDecInDeg(1, 2, 3, 4)
        self.assertEqual(len(self.skySim.getStarId()), 1)

        self.skySim.addStarByRaDecInDeg(2, 2.1, 3, 4)
        starId = self.skySim.getStarId()
        self.assertEqual(len(starId), 2)
        self.assertEqual(starId[0], 1)
        self.assertEqual(starId[1], 2)

        # Try to add the same star Id again
        self.skySim.addStarByRaDecInDeg(2, 2.1, 3, 4)
        self.assertEqual(len(self.skySim.getStarId()), 2)

    def testResetSky(self):

        self.skySim.addStarByRaDecInDeg(1, 2, 3, 4)
        self.skySim.resetSky()
        self.assertEqual(len(self.skySim.getStarId()), 0)

    def testSetStarRaDecInDeg(self):

        self.skySim.setStarRaDecInDeg(np.array([0]), np.array([1]),
                                      np.array([2]), np.array([3]))
        self.assertEqual(len(self.skySim.getStarId()), 1)

    def testAddStarByFile(self):

        self._addStarByFile("wfsStar.txt")

        self.assertEqual(len(self.skySim.getStarId()), 8)

        ra, decl = self.skySim.getRaDecInDeg()
        self.assertEqual(ra[2], -1.176)
        self.assertEqual(decl[2], 1.196)

        self.assertEqual(self.skySim.getStarMag()[2], 17.0)

    def _addStarByFile(self, skyFileName):

        skyFile = os.path.join(getModulePath(), "tests", "testData", "sky",
                               skyFileName)
        self.skySim.addStarByFile(skyFile)

    def testAddStarByFileWithSglStar(self):

        self._addStarByFile("wfsSglStar.txt")

        self.assertEqual(len(self.skySim.getStarId()), 1)

        ra, decl = self.skySim.getRaDecInDeg()
        self.assertEqual(ra[0], 1.196)
        self.assertEqual(decl[0], 1.176)

        self.assertEqual(self.skySim.getStarMag()[0], 17.0)

    def testExportSkyToFile(self):

        self._addStarByFile("wfsStar.txt")
        outputFilePath = os.path.join(getModulePath(), "output",
                                      "testSkyOutput.txt")

        self.skySim.exportSkyToFile(outputFilePath)
        self.assertTrue(os.path.isfile(outputFilePath))
        os.remove(outputFilePath)

    def testAddStarByChipPos(self):

        self._setObservationMetaData()

        # Add the star
        sensorName = "R22_S11"
        starId = 0
        xInpixelInCam = 2000
        yInPixelInCam = 2036
        starMag = 17
        self.skySim.addStarByChipPos(sensorName, starId, xInpixelInCam,
                                     yInPixelInCam, starMag)

        # Test the result
        ra, decl = self.skySim.getRaDecInDeg()
        self.assertAlmostEqual(ra[0], 359.99971038)
        self.assertAlmostEqual(decl[0], 0.0001889)

    def _setObservationMetaData(self):

        ra = 0
        decl = 0
        rotSkyPos = 0
        mjd = 59580.0
        self.skySim.setObservationMetaData(ra, decl, rotSkyPos, mjd)