Пример #1
0
class TestEnvironment(unittest.TestCase):

    def tearDown(self):
        pass

    def setUp(self):
        self.rt = Configuration(logger=logger)
        self.rt.readConfiguration(fileName='./rts2saf-bootes-2.cfg')

    def test_expandToTmp(self):
        logger.info('== {} =='.format(self._testMethodName))
        ev=Environment(debug=False, rt=self.rt, logger=logger)
        res=ev.expandToTmp(fn='fn')
        self.assertEqual(res,'{}/fn'.format(self.rt.cfg['TEMP_DIRECTORY']),'return value:{}'.format(res))

    def test_expandToPlotFileName(self):
        logger.info('== {} =='.format(self._testMethodName))
        ev=Environment(debug=False, rt=self.rt, logger=logger)
        res=ev.expandToPlotFileName()
        self.assertEqual(res, 'myPlot-{}.png'.format(ev.startTime[0:19]),'return value:{}'.format(res))

    def test_expandToAcquisitionBasePath(self):
        logger.info('== {} =='.format(self._testMethodName))
        ev=Environment(debug=False, rt=self.rt, logger=logger)
        res=ev.expandToAcquisitionBasePath()
        tst='{}/{}'.format(self.rt.cfg['BASE_DIRECTORY'], ev.startTime)
        self.assertEqual( res, '{}/{}/'.format(self.rt.cfg['BASE_DIRECTORY'], ev.startTime),'return value:{}, {}'.format(res, tst))

    #@unittest.skip('feature not yet implemented')
    def test_createAcquisitionBasePath(self):
        logger.info('== {} =='.format(self._testMethodName))
        ev=Environment(debug=False, rt=self.rt, logger=logger)
        res=ev.createAcquisitionBasePath()
        self.assertTrue(res,'return value:{}'.format(res))
Пример #2
0
class TestEnvironment(unittest.TestCase):
    def tearDown(self):
        pass

    def setUp(self):
        self.rt = Configuration(logger=logger)
        self.rt.readConfiguration(fileName="./rts2saf-bootes-2.cfg")

    def test_expandToTmp(self):
        logger.info("== {} ==".format(self._testMethodName))
        ev = Environment(debug=False, rt=self.rt, logger=logger)
        res = ev.expandToTmp(fn="fn")
        self.assertEqual(res, "{}/fn".format(self.rt.cfg["TEMP_DIRECTORY"]), "return value:{}".format(res))

    def test_expandToPlotFileName(self):
        logger.info("== {} ==".format(self._testMethodName))
        ev = Environment(debug=False, rt=self.rt, logger=logger)
        res = ev.expandToPlotFileName()
        self.assertEqual(res, "myPlot-{}.png".format(ev.startTime[0:19]), "return value:{}".format(res))

    def test_expandToAcquisitionBasePath(self):
        logger.info("== {} ==".format(self._testMethodName))
        ev = Environment(debug=False, rt=self.rt, logger=logger)
        res = ev.expandToAcquisitionBasePath()
        tst = "{}/{}".format(self.rt.cfg["BASE_DIRECTORY"], ev.startTime)
        self.assertEqual(
            res, "{}/{}/".format(self.rt.cfg["BASE_DIRECTORY"], ev.startTime), "return value:{}, {}".format(res, tst)
        )

    # @unittest.skip('feature not yet implemented')
    def test_createAcquisitionBasePath(self):
        logger.info("== {} ==".format(self._testMethodName))
        ev = Environment(debug=False, rt=self.rt, logger=logger)
        res = ev.createAcquisitionBasePath()
        self.assertTrue(res, "return value:{}".format(res))
Пример #3
0
 def test_sextract(self):
     logger.info('== {} =='.format(self._testMethodName))
     rt = Configuration(logger=logger)
     rt.readConfiguration(fileName='./rts2saf-no-filter-wheel.cfg')
     sx = Sextract(debug=False, rt=rt, logger=logger)
     fitsFn='../samples/20071205025911-725-RA.fits'
     dSx=sx.sextract(fitsFn=fitsFn)
     self.assertIs(type(dSx), DataSxtr, 'return object of type: '.format(type(dSx)))
     self.assertEqual(fitsFn, dSx.fitsFn, 'install sample FITS from wget http://azug.minpet.unibas.ch/~wildi/rts2saf-test-focus-2013-09-14.tgz')
Пример #4
0
 def test_sextractFlux(self):
     logger.info('== {} =='.format(self._testMethodName))
     rt = Configuration(logger=logger)
     rt.readConfiguration(fileName='./rts2saf-flux.cfg')
     sx = Sextract(debug=False, rt=rt, logger=logger)
     fitsFn='../samples/20071205025911-725-RA.fits'
     sx.appendFluxFields()
     dSx=sx.sextract(fitsFn=fitsFn)
     self.assertEqual(dSx.fields[12], 'FLUXERR_APER', 'return value: {}'.format(dSx.fields[12]))
Пример #5
0
 def test_sextractFlux(self):
     logger.info('== {} =='.format(self._testMethodName))
     rt = Configuration(logger=logger)
     rt.readConfiguration(fileName='./rts2saf-flux.cfg')
     sx = Sextract(debug=False, rt=rt, logger=logger)
     fitsFn = '../samples/20071205025911-725-RA.fits'
     sx.appendFluxFields()
     dSx = sx.sextract(fitsFn=fitsFn)
     self.assertEqual(dSx.fields[12], 'FLUXERR_APER',
                      'return value: {}'.format(dSx.fields[12]))
Пример #6
0
 def test_sextract(self):
     logger.info('== {} =='.format(self._testMethodName))
     rt = Configuration(logger=logger)
     rt.readConfiguration(fileName='./rts2saf-no-filter-wheel.cfg')
     sx = Sextract(debug=False, rt=rt, logger=logger)
     fitsFn = '../samples/20071205025911-725-RA.fits'
     dSx = sx.sextract(fitsFn=fitsFn)
     self.assertIs(type(dSx), DataSxtr,
                   'return object of type: '.format(type(dSx)))
     self.assertEqual(
         fitsFn, dSx.fitsFn,
         'install sample FITS from wget http://azug.minpet.unibas.ch/~wildi/rts2saf-test-focus-2013-09-14.tgz'
     )
Пример #7
0
class TestConfigurationBootes2(unittest.TestCase):

    def tearDown(self):
        pass

    def setUp(self):
        self.rt = Configuration(logger=logger)
        self.fileName='./rts2saf-bootes-2.cfg'
        self.success=self.rt.readConfiguration(fileName=self.fileName)
        self.args=Args()
        self.args.associate = True
        self.args.flux=True

    #@unittest.skip('feature not yet implemented')
    def test_readConfiguration(self):
        logger.info('== {} =='.format(self._testMethodName))
        self.assertTrue(self.success, 'config file: {} faulty or not found'.format(self.fileName))
        self.assertIs(type(self.rt), Configuration)

    def test_checkConfiguration(self):
        logger.info('== {} =='.format(self._testMethodName))
        self.assertTrue(self.success, 'config file: {} faulty or not found'.format(self.fileName))
        result = self.rt.checkConfiguration(args=self.args)
        self.assertTrue(result)

    def test_filterWheelInUse(self):
        logger.info('== {} =='.format(self._testMethodName))
        self.assertEqual(self.rt.cfg['inuse'][0], 'COLWFLT', 'return value: {}'.format(self.rt.cfg['inuse'][0]))

    def test_writeDefaultConfiguration(self):
        logger.info('== {} =='.format(self._testMethodName))
        cfn='./rts2saf-default.cfg'
        result=self.rt.writeDefaultConfiguration(cfn=cfn)
        self.assertEqual(cfn, result, 'return value: {}'.format(result))
Пример #8
0
class TestCreateOneFilterWheel(unittest.TestCase):
    """
    This test creates a filter wheel with no empty slots.
    """
    def tearDown(self):
        pass

    def setUp(self):
        self.rt = Configuration(logger=logger)
        self.fileName = './rts2saf-one-filter-wheel.cfg'
        self.success = self.rt.readConfiguration(fileName=self.fileName)

    #@unittest.skip('feature not yet implemented')
    def test_createFTW(self):
        logger.info('== {} =='.format(self._testMethodName))
        fts = CreateFilters(debug=False, rt=self.rt, logger=logger).create()
        foc = CreateFocuser(debug=False, rt=self.rt,
                            logger=logger).create(focDef=0)
        # no connection to real device
        foc.focDef = 0
        cftw = CreateFilterWheels(debug=False,
                                  rt=self.rt,
                                  logger=logger,
                                  filters=fts,
                                  foc=foc)
        ftw = cftw.create()
        self.assertEqual(ftw[0].name, 'W0')
        self.assertEqual(ftw[0].filters[0].name, 'R')
Пример #9
0
class TestSimpleAnalysis(unittest.TestCase):
    def tearDown(self):
        pass

    def setUp(self):
        self.rt = Configuration(logger=logger)
        self.fileName = './rts2saf-flux.cfg'
        self.success = self.rt.readConfiguration(fileName=self.fileName)
        self.ev = Environment(debug=False, rt=self.rt, logger=logger)

    #@unittest.skip('feature not yet implemented')
    def test_readConfiguration(self):
        logger.info('== {} =='.format(self._testMethodName))
        self.assertTrue(
            self.success,
            'config file: {} faulty or not found, return value: {}'.format(
                self.fileName, self.success))

    def test_fitsInBasepath(self):
        logger.info('== {} =='.format(self._testMethodName))
        fitsFns = glob.glob('{0}/{1}'.format('../samples',
                                             self.rt.cfg['FILE_GLOB']))
        self.assertEqual(len(fitsFns), 14,
                         'return value: {}'.format(len(fitsFns)))

    def test_analyze(self):
        logger.info('== {} =='.format(self._testMethodName))
        fitsFns = glob.glob('{0}/{1}'.format('../samples',
                                             self.rt.cfg['FILE_GLOB']))
        dataSxtr = list()
        for k, fitsFn in enumerate(fitsFns):

            logger.info('analyze: processing fits file: {0}'.format(fitsFn))
            sxtr = Sextract(debug=False, rt=self.rt, logger=logger)
            dSx = sxtr.sextract(fitsFn=fitsFn)

            if dSx:
                dataSxtr.append(dSx)

        self.assertEqual(len(dataSxtr), 14,
                         'return value: {}'.format(len(dataSxtr)))

        an = SimpleAnalysis(debug=False,
                            dataSxtr=dataSxtr,
                            Ds9Display=False,
                            FitDisplay=False,
                            focRes=float(self.rt.cfg['FOCUSER_RESOLUTION']),
                            ev=self.ev,
                            rt=self.rt,
                            logger=logger)
        resultFitFwhm, resultMeansFwhm, resultFitFlux, resultMeansFlux = an.analyze(
        )
        self.assertAlmostEqual(resultFitFwhm.extrFitVal,
                               2.2175214358,
                               places=2,
                               msg='return value: {}'.format(
                                   resultFitFwhm.extrFitVal))

        an.display()
Пример #10
0
class TestDs9Region(unittest.TestCase):
    def tearDown(self):
        pass

    def setUp(self):
        self.rt = Configuration(logger=logger)
        self.rt.readConfiguration(fileName='./rts2saf-no-filter-wheel.cfg')
        self.dSx = Sextract(debug=False, rt=self.rt, logger=logger).sextract(
            fitsFn='../samples/20071205025911-725-RA.fits')
        print self.dSx.fitsFn

    @unittest.skip('test not yet meaningful')
    def test_displayWithRegion(self):
        logger.info('== {} =='.format(self._testMethodName))
        ds9r = Ds9DisplayThread(dataSxtr=self.dSx, logger=logger)

        self.assertTrue(ds9r, 'return value: '.format(type(DataSxtr)))
Пример #11
0
class TestDs9Region(unittest.TestCase):
    def tearDown(self):
        pass

    def setUp(self):
        self.rt = Configuration(logger=logger)
        self.rt.readConfiguration(fileName="./rts2saf-no-filter-wheel.cfg")
        self.dSx = Sextract(debug=False, rt=self.rt, logger=logger).sextract(
            fitsFn="../samples/20071205025911-725-RA.fits"
        )
        print self.dSx.fitsFn

    @unittest.skip("test not yet meaningful")
    def test_displayWithRegion(self):
        logger.info("== {} ==".format(self._testMethodName))
        ds9r = Ds9DisplayThread(dataSxtr=self.dSx, logger=logger)

        self.assertTrue(ds9r, "return value: ".format(type(DataSxtr)))
Пример #12
0
class TestCatalogAnalysis(unittest.TestCase):
    def tearDown(self):
        pass

    def setUp(self):
        self.rt = Configuration(logger=logger)
        self.fileName = "./rts2saf-no-filter-wheel.cfg"
        self.success = self.rt.readConfiguration(fileName=self.fileName)
        self.ev = Environment(debug=False, rt=self.rt, logger=logger)

    def test_readConfiguration(self):
        logger.info("== {} ==".format(self._testMethodName))
        self.assertTrue(
            self.success, "config file: {} faulty or not found, return value: {}".format(self.fileName, self.success)
        )

    def test_fitsInBasepath(self):
        logger.info("== {} ==".format(self._testMethodName))
        fitsFns = glob.glob("{0}/{1}".format("../samples", self.rt.cfg["FILE_GLOB"]))
        self.assertEqual(len(fitsFns), 14, "return value: {}".format(len(fitsFns)))

    # @unittest.skip('feature not yet implemented')
    def test_selectAndAnalyze(self):
        logger.info("== {} ==".format(self._testMethodName))
        fitsFns = glob.glob("{0}/{1}".format("../samples", self.rt.cfg["FILE_GLOB"]))
        dataSxtr = list()
        for k, fitsFn in enumerate(fitsFns):

            logger.info("analyze: processing fits file: {0}".format(fitsFn))
            sxtr = Sextract(debug=False, rt=self.rt, logger=logger)
            dSx = sxtr.sextract(fitsFn=fitsFn)

            if dSx:
                dataSxtr.append(dSx)

        self.assertEqual(len(dataSxtr), 14, "return value: {}".format(len(dataSxtr)))
        an = CatalogAnalysis(
            debug=False,
            dataSxtr=dataSxtr,
            Ds9Display=False,
            FitDisplay=False,
            focRes=float(self.rt.cfg["FOCUSER_RESOLUTION"]),
            moduleName="rts2saf.criteria_radius",
            ev=self.ev,
            rt=self.rt,
            logger=logger,
        )
        accRFt, rejRFt, allrFt, accRMns, recRMns, allRMns = an.selectAndAnalyze()
        self.assertAlmostEqual(
            allrFt.extrFitVal, 2.2175214358, delta=0.1, msg="return value: {}".format(allrFt.extrFitVal)
        )
        self.assertAlmostEqual(
            accRFt.extrFitVal, 2.24000979001, delta=0.1, msg="return value: {}".format(allrFt.extrFitVal)
        )
Пример #13
0
class TestCreateDevices(unittest.TestCase):
    def tearDown(self):
        pass

    def setUp(self):
        self.rt = Configuration(logger=logger)
        self.fileName = './rts2saf-no-filter-wheel.cfg'
        self.success = self.rt.readConfiguration(fileName=self.fileName)

    #@unittest.skip('feature not yet implemented')
    def test_createFTs(self):
        logger.info('== {} =='.format(self._testMethodName))
        fts = CreateFilters(debug=False, rt=self.rt, logger=logger).create()
        self.assertIsNotNone(fts)
        self.assertEqual(fts[0].name, 'FAKE_FT')

    #@unittest.skip('feature not yet implemented')
    def test_createFOC(self):
        logger.info('== {} =='.format(self._testMethodName))
        cfoc = CreateFocuser(debug=False, rt=self.rt, logger=logger)
        foc = cfoc.create(focDef=0)
        self.assertEqual(foc.name, 'F0')

    #@unittest.skip('feature not yet implemented')
    def test_createFTWs(self):
        logger.info('== {} =='.format(self._testMethodName))
        fts = CreateFilters(debug=False, rt=self.rt, logger=logger).create()
        foc = CreateFocuser(debug=False, rt=self.rt,
                            logger=logger).create(focDef=0)
        # no connection to real device
        foc.focDef = 0
        cftw = CreateFilterWheels(debug=False,
                                  rt=self.rt,
                                  logger=logger,
                                  filters=fts,
                                  foc=foc)
        ftw = cftw.create()
        self.assertEqual(ftw[0].name, 'FAKE_FTW')

    #@unittest.skip('feature not yet implemented')
    def test_createCCD(self):
        logger.info('== {} =='.format(self._testMethodName))
        fts = CreateFilters(debug=False, rt=self.rt, logger=logger).create()
        foc = CreateFocuser(debug=False, rt=self.rt,
                            logger=logger).create(focDef=0)
        CreateFilterWheels(debug=False,
                           rt=self.rt,
                           logger=logger,
                           filters=fts,
                           foc=foc)
        cccd = CreateCCD(debug=False, rt=self.rt, logger=logger, ftws=fts)
        ccd = cccd.create()
        self.assertEqual(ccd.name, 'C0')
Пример #14
0
class TestSimpleAnalysis(unittest.TestCase):
    def tearDown(self):
        pass

    def setUp(self):
        self.rt = Configuration(logger=logger)
        self.fileName = "./rts2saf-flux.cfg"
        self.success = self.rt.readConfiguration(fileName=self.fileName)
        self.ev = Environment(debug=False, rt=self.rt, logger=logger)

    # @unittest.skip('feature not yet implemented')
    def test_readConfiguration(self):
        logger.info("== {} ==".format(self._testMethodName))
        self.assertTrue(
            self.success, "config file: {} faulty or not found, return value: {}".format(self.fileName, self.success)
        )

    def test_fitsInBasepath(self):
        logger.info("== {} ==".format(self._testMethodName))
        fitsFns = glob.glob("{0}/{1}".format("../samples", self.rt.cfg["FILE_GLOB"]))
        self.assertEqual(len(fitsFns), 14, "return value: {}".format(len(fitsFns)))

    def test_analyze(self):
        logger.info("== {} ==".format(self._testMethodName))
        fitsFns = glob.glob("{0}/{1}".format("../samples", self.rt.cfg["FILE_GLOB"]))
        dataSxtr = list()
        for k, fitsFn in enumerate(fitsFns):

            logger.info("analyze: processing fits file: {0}".format(fitsFn))
            sxtr = Sextract(debug=False, rt=self.rt, logger=logger)
            dSx = sxtr.sextract(fitsFn=fitsFn)

            if dSx:
                dataSxtr.append(dSx)

        self.assertEqual(len(dataSxtr), 14, "return value: {}".format(len(dataSxtr)))

        an = SimpleAnalysis(
            debug=False,
            dataSxtr=dataSxtr,
            Ds9Display=False,
            FitDisplay=False,
            focRes=float(self.rt.cfg["FOCUSER_RESOLUTION"]),
            ev=self.ev,
            rt=self.rt,
            logger=logger,
        )
        resultFitFwhm, resultMeansFwhm, resultFitFlux, resultMeansFlux = an.analyze()
        self.assertAlmostEqual(
            resultFitFwhm.extrFitVal, 2.2175214358, places=2, msg="return value: {}".format(resultFitFwhm.extrFitVal)
        )

        an.display()
Пример #15
0
class TestAnalyzeRuns(unittest.TestCase):
    def tearDown(self):
        pass

    def setUp(self):
        self.rt = Configuration(logger=logger)
        self.fileName = './rts2saf-flux.cfg'
        self.success = self.rt.readConfiguration(fileName=self.fileName)
        self.ev = Environment(debug=False, rt=self.rt, logger=logger)
        self.args = Args()
        self.args.catalogAnalysis = True
        self.args.Ds9Display = False
        self.args.FitDisplay = False
        self.args.criteria = 'rts2saf.criteria_radius'
        self.args.basePath = '../samples'
        self.args.filterNames = None
        self.args.sxDebug = False
        self.args.flux = True
        self.args.fractObjs = 0.5

    #@unittest.skip('feature not yet implemented')
    def test_analyze_runs(self):
        logger.info('== {} =='.format(self._testMethodName))
        self.args.associate = False
        aRs = AnalyzeRuns(basePath=self.args.basePath,
                          args=self.args,
                          rt=self.rt,
                          ev=self.ev,
                          logger=logger)
        aRs.aggregateRuns()
        rFfFwhm, rFfFlux = aRs.analyzeRuns()
        # ToDo expand to Flux
        self.assertEqual(type(rFfFwhm[0]), ResultFit,
                         'return value: {}'.format(type(rFfFwhm[0])))

    #@unittest.skip('feature not yet implemented')
    def test_analyze_runs_assoc(self):
        logger.info('== {} =='.format(self._testMethodName))
        self.args.associate = True
        aRs = AnalyzeRuns(basePath=self.args.basePath,
                          args=self.args,
                          rt=self.rt,
                          ev=self.ev,
                          logger=logger)
        aRs.aggregateRuns()
        rFfFwhm, rFfFlux = aRs.analyzeRuns()
        # ToDo expand to Flux
        self.assertEqual(type(rFfFwhm[0]), ResultFit,
                         'return value: {}'.format(type(rFfFwhm[0])))
Пример #16
0
class TestConfigurationNoFilterWheel(unittest.TestCase):

    def tearDown(self):
        pass

    def setUp(self):
        self.rt = Configuration(logger=logger)
        self.fileName='./rts2saf-no-filter-wheel.cfg'
        self.success=self.rt.readConfiguration(fileName=self.fileName)

    #@unittest.skip('feature not yet implemented')
    def test_readConfiguration(self):
        logger.info('== {} =='.format(self._testMethodName))
        self.assertTrue(self.success, 'config file: {} faulty or not found'.format(self.fileName))
        self.assertIs(type(self.rt), Configuration)
Пример #17
0
class TestConfigurationFlux(unittest.TestCase):

    def tearDown(self):
        pass

    def setUp(self):
        self.rt = Configuration(logger=logger)
        self.fileName='./rts2saf-flux.cfg'
        self.success=self.rt.readConfiguration(fileName=self.fileName)

    #@unittest.skip('feature not yet implemented')
    def test_readConfiguration(self):
        logger.info('== {} =='.format(self._testMethodName))        
        self.assertEqual(self.rt.cfg[ 'MINIMUM_FOCUSER_POSITIONS'], 5, 'return value: {}, config file: {} faulty or not found'.format(self.rt.cfg[ 'MINIMUM_FOCUSER_POSITIONS'], self.fileName))
        self.assertTrue(self.success, 'config file: {} faulty or not found'.format(self.fileName))
        self.assertIs(type(self.rt), Configuration)
Пример #18
0
class TestCheckDevices(unittest.TestCase):

    def tearDown(self):
        pass

    def setUp(self):
        self.rt = Configuration(logger=logger)
        self.fileName='./rts2saf-bootes-2.cfg'
        self.success=self.rt.readConfiguration(fileName=self.fileName)
        self.proxy=JSONProxy(url=self.rt.cfg['URL'],username=self.rt.cfg['USERNAME'],password=self.rt.cfg['PASSWORD'])
        self.rts2safFoc= CheckDevices(debug=False, proxy=self.proxy, blind=None, verbose=None, ccd=None, ftws=None, foc=None, logger=logger)



    @unittest.skip('these tests are done in test_focus')
    def test_checkDevices(self):
        logger.info('== {} =='.format(self._testMethodName))
Пример #19
0
class TestCreateDevices(unittest.TestCase):

    def tearDown(self):
        pass

    def setUp(self):
        self.rt = Configuration(logger=logger)
        self.fileName='./rts2saf-no-filter-wheel.cfg'
        self.success=self.rt.readConfiguration(fileName=self.fileName)

    #@unittest.skip('feature not yet implemented')
    def test_createFTs(self):
        logger.info('== {} =='.format(self._testMethodName))
        fts=CreateFilters(debug=False, rt=self.rt, logger=logger).create()
        self.assertIsNotNone(fts)
        self.assertEqual(fts[0].name, 'FAKE_FT')

    #@unittest.skip('feature not yet implemented')
    def test_createFOC(self):
        logger.info('== {} =='.format(self._testMethodName))
        cfoc= CreateFocuser(debug=False, rt=self.rt, logger=logger)
        foc=cfoc.create(focDef=0)
        self.assertEqual(foc.name, 'F0')

    #@unittest.skip('feature not yet implemented')
    def test_createFTWs(self):
        logger.info('== {} =='.format(self._testMethodName))
        fts=CreateFilters(debug=False, rt=self.rt, logger=logger).create()
        foc=CreateFocuser(debug=False, rt=self.rt, logger=logger).create(focDef=0)
        # no connection to real device
        foc.focDef=0
        cftw= CreateFilterWheels(debug=False, rt=self.rt, logger=logger, filters=fts, foc=foc)
        ftw=cftw.create()
        self.assertEqual(ftw[0].name, 'FAKE_FTW')

    #@unittest.skip('feature not yet implemented')
    def test_createCCD(self):
        logger.info('== {} =='.format(self._testMethodName))
        fts=CreateFilters(debug=False, rt=self.rt, logger=logger).create()
        foc=CreateFocuser(debug=False, rt=self.rt, logger=logger).create(focDef=0)
        CreateFilterWheels(debug=False, rt=self.rt, logger=logger, filters=fts, foc=foc)
        cccd= CreateCCD(debug=False, rt=self.rt, logger=logger, ftws=fts)
        ccd=cccd.create()
        self.assertEqual(ccd.name, 'C0')
Пример #20
0
class TestAnalyzeRuns(unittest.TestCase):

    def tearDown(self):
        pass

    def setUp(self):
        self.rt = Configuration(logger=logger)
        self.fileName='./rts2saf-flux.cfg'
        self.success=self.rt.readConfiguration(fileName=self.fileName)
        self.ev=Environment(debug=False, rt=self.rt,logger=logger)
        self.args=Args()
        self.args.catalogAnalysis = True
        self.args.Ds9Display = False
        self.args.FitDisplay = False
        self.args.criteria = 'rts2saf.criteria_radius'
        self.args.basePath = '../samples'
        self.args.filterNames = None
        self.args.sxDebug=False
        self.args.flux=True
        self.args.fractObjs=0.5

    #@unittest.skip('feature not yet implemented')
    def test_analyze_runs(self):
        logger.info('== {} =='.format(self._testMethodName))
        self.args.associate = False
        aRs = AnalyzeRuns(basePath = self.args.basePath, args = self.args, rt = self.rt, ev = self.ev, logger = logger)
        aRs.aggregateRuns()
        rFfFwhm, rFfFlux = aRs.analyzeRuns()
        # ToDo expand to Flux
        self.assertEqual(type(rFfFwhm[0]), ResultFit, 'return value: {}'.format(type(rFfFwhm[0])))

    #@unittest.skip('feature not yet implemented')
    def test_analyze_runs_assoc(self):
        logger.info('== {} =='.format(self._testMethodName))
        self.args.associate = True
        aRs = AnalyzeRuns(basePath = self.args.basePath, args = self.args, rt = self.rt, ev = self.ev, logger = logger)
        aRs.aggregateRuns()
        rFfFwhm, rFfFlux = aRs.analyzeRuns()
        # ToDo expand to Flux
        self.assertEqual(type(rFfFwhm[0]), ResultFit, 'return value: {}'.format(type(rFfFwhm[0])))
Пример #21
0
class TestCatalogAnalysis(unittest.TestCase):

    def tearDown(self):
        pass

    def setUp(self):
        self.rt = Configuration(logger=logger)
        self.fileName='./rts2saf-no-filter-wheel.cfg'
        self.success=self.rt.readConfiguration(fileName=self.fileName)
        self.ev=Environment(debug=False, rt=self.rt,logger=logger)

    def test_readConfiguration(self):
        logger.info('== {} =='.format(self._testMethodName))
        self.assertTrue(self.success, 'config file: {} faulty or not found, return value: {}'.format(self.fileName, self.success))

    def test_fitsInBasepath(self):
        logger.info('== {} =='.format(self._testMethodName))
        fitsFns=glob.glob('{0}/{1}'.format('../samples', self.rt.cfg['FILE_GLOB']))
        self.assertEqual(len(fitsFns), 14, 'return value: {}'.format(len(fitsFns)))

    #@unittest.skip('feature not yet implemented')
    def test_selectAndAnalyze(self):
        logger.info('== {} =='.format(self._testMethodName))
        fitsFns=glob.glob('{0}/{1}'.format('../samples', self.rt.cfg['FILE_GLOB']))
        dataSxtr=list()
        for k, fitsFn in enumerate(fitsFns):
        
            logger.info('analyze: processing fits file: {0}'.format(fitsFn))
            sxtr= Sextract(debug=False, rt=self.rt, logger=logger)
            dSx=sxtr.sextract(fitsFn=fitsFn)

            if dSx:
                dataSxtr.append(dSx)

        self.assertEqual(len(dataSxtr), 14, 'return value: {}'.format(len(dataSxtr)))
        an=CatalogAnalysis(debug=False, dataSxtr=dataSxtr, Ds9Display=False, FitDisplay=False, focRes=float(self.rt.cfg['FOCUSER_RESOLUTION']), moduleName='rts2saf.criteria_radius', ev=self.ev, rt=self.rt, logger=logger)
        accRFt, rejRFt, allrFt, accRMns, recRMns, allRMns=an.selectAndAnalyze()
        self.assertAlmostEqual(allrFt.extrFitVal, 2.2175214358, delta=0.1, msg='return value: {}'.format(allrFt.extrFitVal))
        self.assertAlmostEqual(accRFt.extrFitVal, 2.24000979001, delta=0.1, msg='return value: {}'.format(allrFt.extrFitVal))
Пример #22
0
class TestCheckDevices(unittest.TestCase):
    def tearDown(self):
        pass

    def setUp(self):
        self.rt = Configuration(logger=logger)
        self.fileName = './rts2saf-bootes-2.cfg'
        self.success = self.rt.readConfiguration(fileName=self.fileName)
        self.proxy = JSONProxy(url=self.rt.cfg['URL'],
                               username=self.rt.cfg['RTS2_HTTPD_USERNAME'],
                               password=self.rt.cfg['PASSWORD'])
        self.rts2safFoc = CheckDevices(debug=False,
                                       proxy=self.proxy,
                                       blind=None,
                                       verbose=None,
                                       ccd=None,
                                       ftws=None,
                                       foc=None,
                                       logger=logger)

    @unittest.skip('these tests are done in test_focus')
    def test_checkDevices(self):
        logger.info('== {} =='.format(self._testMethodName))
Пример #23
0
class TestCreateOneFilterWheel(unittest.TestCase):
    """
    This test creates a filter wheel with no empty slots.
    """

    def tearDown(self):
        pass

    def setUp(self):
        self.rt = Configuration(logger=logger)
        self.fileName='./rts2saf-one-filter-wheel.cfg'
        self.success=self.rt.readConfiguration(fileName=self.fileName)

    #@unittest.skip('feature not yet implemented')
    def test_createFTW(self):
        logger.info('== {} =='.format(self._testMethodName))
        fts=CreateFilters(debug=False, rt=self.rt, logger=logger).create()
        foc=CreateFocuser(debug=False, rt=self.rt, logger=logger).create(focDef=0)
        # no connection to real device
        foc.focDef=0
        cftw= CreateFilterWheels(debug=False, rt=self.rt, logger=logger, filters=fts, foc=foc)
        ftw=cftw.create()
        self.assertEqual(ftw[0].name, 'W0')
        self.assertEqual(ftw[0].filters[0].name, 'R')
Пример #24
0
class RTS2Environment(unittest.TestCase):

    def tearDown(self):
        processes=['rts2-centrald','rts2-executor', 'rts2-xmlrpcd','rts2-focusd-dummy','rts2-filterd-dummy', 'rts2-camd-dummy']
        p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
        out, err = p.communicate()

        for line in out.splitlines():
            # wildi     7432  0.0  0.1  24692  5192 pts/1    S    17:34   0:01 /usr/local/bin/rts2-centrald 
            itms= line.split()
            exe= itms[10].split('/')[-1]
            if self.uid in itms[0] and exe in processes:
                pid = int(itms[1])
                os.kill(pid, signal.SIGTERM)

        # reove th lock files
        for fn in glob.glob(self.lockPrefix):
            os.unlink (fn)

    def setUp(self):
        # by name
        self.uid=pwd.getpwuid(os.getuid())[0]
        self.gid= grp.getgrgid(os.getgid())[0]
        # lock prefix
        self.lockPrefix = '/tmp/rts2_{}'.format(self.uid)
        # sometimes they are present
        self.tearDown()
        # set up rts2saf
        # read configuration
        self.rt = Configuration(logger=logger)
        self.ev=Environment(debug=False, rt=self.rt,logger=logger)
        self.fileName='./rts2saf-bootes-2-autonomous.cfg'
        self.success=self.rt.readConfiguration(fileName=self.fileName)
        # set up RTS2
        # rts2-centrald
        cmd=[ '/usr/local/bin/rts2-centrald', 
              '--run-as', '{}.{}'.format(self.uid,self.gid), 
              '--local-port', '1617', 
              '--logfile', '/tmp/rts2saf_log/rts2-debug', 
              '--lock-prefix', self.lockPrefix, 
              '--config', './rts2-unittest.ini'
        ]
        self.p_centrald= subprocess.Popen(cmd)

        # rts2-executor
        cmd=[ '/usr/local/bin/rts2-executor', 
              '--run-as', '{}.{}'.format(self.uid,self.gid), 
              '--lock-prefix', self.lockPrefix, 
              '--config', './rts2-unittest.ini',
              '--server', '127.0.0.1:1617', 
              '--noauth'
        ]
        self.p_exec= subprocess.Popen(cmd)

        # rts2-xmlrpcd
        cmd=[ '/usr/local/bin/rts2-xmlrpcd', 
              '--run-as', '{}.{}'.format(self.uid,self.gid), 
              '--lock-prefix', self.lockPrefix, 
              '--config', './rts2-unittest.ini',
              '--server', '127.0.0.1:1617', 
              '-p', '9999', 
              '--noauth'
        ]
        self.p_xmlrpcd= subprocess.Popen(cmd)

        # rts2-focusd-dummy
        focName=self.rt.cfg['FOCUSER_NAME']
        cmd=[ '/usr/local/bin/rts2-focusd-dummy', 
              '--run-as', '{}.{}'.format(self.uid,self.gid), 
              '--lock-prefix', self.lockPrefix, 
              '--server', '127.0.0.1:1617', 
              '-d', focName, 
              '--modefile', './f0.modefile'
        ]
        self.p_focusd_dummy= subprocess.Popen(cmd)

        # rts2-filterd-dummy
        ftwns=list()
        for ftwn in self.rt.cfg['inuse']:
            ftwns.append(ftwn)
            cmd=[ '/usr/local/bin/rts2-filterd-dummy', 
                  '--run-as', '{}.{}'.format(self.uid,self.gid), 
                  '--lock-prefix', self.lockPrefix, 
                  '--server', '127.0.0.1:1617', 
                  '-d', ftwn 
            ]
            ftnames=str()

            for ftn in self.rt.cfg['FILTER WHEEL DEFINITIONS'][ftwn]:
                ftnames += '{}:'.format(ftn)

            if len(ftnames)>0:
                cmd.append('-F')
                cmd.append(ftnames)

            self.p_filterd_dummy= subprocess.Popen(cmd)
        
        # rts2-camd-dummy
        name=self.rt.cfg['CCD_NAME']
        # '--wheeldev', 'COLWSLT',  '--filter-offsets', '1:2:3:4:5:6:7:8'
        cmd=[ '/usr/local/bin/rts2-camd-dummy', 
              '--run-as', '{}.{}'.format(self.uid,self.gid), 
              '--lock-prefix', self.lockPrefix, 
              '--server', '127.0.0.1:1617', 
              '-d', name,  
              '--focdev', focName
        ]
        for nm in ftwns:
            cmd.append('--wheeldev')
            cmd.append(nm)
            if nm in self.rt.cfg['inuse'][0]:
                cmd.append('--filter-offsets')
                cmd.append('1:2:3:4:5:6:7:8')

        self.p_camd_dummy= subprocess.Popen(cmd)
        # 
        time.sleep(20)

    def setupDevices(self, blind=False):
        # setup rts2saf
        # fake arguments
        self.args=Args()
        self.args.sxDebug=False
        self.args.blind=blind
        self.args.verbose=False
        self.args.check=True
        self.args.fetchOffsets=True
        self.args.exposure= 1.887
        self.args.catalogAnalysis=False
        self.args.Ds9Display=False
        self.args.FitDisplay=False
        self.args.flux=True
        self.args.dryFitsFiles='../samples_bootes2'
        # JSON
        self.proxy=JSONProxy(url=self.rt.cfg['URL'],username=self.rt.cfg['USERNAME'],password=self.rt.cfg['PASSWORD'])
        # create Focuser 
        self.foc= CreateFocuser(debug=False, proxy=self.proxy, check=self.args.check, rt=self.rt, logger=logger).create()
        # create filters
        fts=CreateFilters(debug=False, proxy=self.proxy, check=self.args.check, rt=self.rt, logger=logger).create()
        # create filter wheels
        ftwc= CreateFilterWheels(debug=False, proxy=self.proxy, check=self.args.check, rt=self.rt, logger=logger, filters=fts, foc=self.foc)
        ftws=ftwc.create()
        if not ftwc.checkBounds():
            logger.error('setupDevice: filter focus ranges out of bounds, exiting')
            sys.exit(1)

        # create ccd
        ccd= CreateCCD(debug=False, proxy=self.proxy, check=self.args.check, rt=self.rt, logger=logger, ftws=ftws, fetchOffsets=self.args.fetchOffsets).create()
        
        cdv= CheckDevices(debug=False, proxy=self.proxy, blind=self.args.blind, verbose=self.args.verbose, ccd=ccd, ftws=ftws, foc=self.foc, logger=logger)
        cdv.summaryDevices()
        cdv.printProperties()
        cdv.deviceWriteAccess()
        dryFitsFiles=None
        if self.args.dryFitsFiles:
            dryFitsFiles=glob.glob('{0}/{1}'.format(self.args.dryFitsFiles, self.rt.cfg['FILE_GLOB']))
            if len(dryFitsFiles)==0:
                logger.error('setupDevice: no FITS files found in:{}'.format(self.args.dryFitsFiles))
                logger.info('setupDevice: download a sample from wget http://azug.minpet.unibas.ch/~wildi/rts2saf-test-focus-2013-09-14.tgz')
                sys.exit(1)

        # ok evrything is there
        self.rts2safFoc= Focus(debug=False, proxy=self.proxy, args=self.args, dryFitsFiles=dryFitsFiles, ccd=ccd, foc=self.foc, ftws=ftws, rt=self.rt, ev=self.ev, logger=logger)
Пример #25
0
    #
    if args.verbose:
        args.debug = True
        args.level = 'DEBUG'
        args.toconsole = True

    if args.checkConfig:
        args.toconsole = True

    # logger
    logger = Logger(
        debug=args.debug,
        args=args).logger  # if you need to chage the log format do it here
    # read the run time configuration
    rt = Configuration(logger=logger)
    if not rt.readConfiguration(fileName=args.config):
        logger.error(
            'rts2saf_focus: exiting, wrong syntax, check the configuration file: {0}'
            .format(args.config))
        sys.exit(1)

    if not rt.checkConfiguration(args=args):
        logger.error(
            'rts2saf_focus: exiting, check the configuration file: {0}'.format(
                args.config))
        sys.exit(1)

    # overwrite config defaults
    rt.cfg['ANALYZE_FLUX'] = args.flux
    rt.cfg['ANALYZE_ASSOC'] = args.associate
    rt.cfg['ANALYZE_ASSOC_FRACTION'] = args.fractObjs
Пример #26
0
    # if you need it
    #args.dryFitsFiles='YOUR/HOME/rts-2/scripts/rts2saf/samples'
    #
    if args.verbose:
        args.debug=True
        args.level='DEBUG'
        args.toconsole=True
        
    if args.checkConfig:
        args.toconsole=True

    # logger
    logger= Logger(debug=args.debug, args=args).logger # if you need to chage the log format do it here
    # read the run time configuration
    rt=Configuration(logger=logger)
    if not rt.readConfiguration(fileName=args.config):
        logger.error('rts2saf_focus: exiting, wrong syntax, check the configuration file: {0}'.format(args.config))
        sys.exit(1)
        
    if not rt.checkConfiguration(args=args):
        logger.error('rts2saf_focus: exiting, check the configuration file: {0}'.format(args.config))
        sys.exit(1)

    # overwrite config defaults
    rt.cfg['ANALYZE_FLUX'] = args.flux  
    rt.cfg['ANALYZE_ASSOC'] = args.associate
    rt.cfg['ANALYZE_ASSOC_FRACTION'] = args.fractObjs

    if args.FitDisplay:
        rt.cfg['WITH_MATHPLOTLIB'] = True
Пример #27
0
class RTS2Environment(unittest.TestCase):
    def tearDown(self):
        processes = [
            'rts2-centrald', 'rts2-executor', 'rts2-xmlrpcd',
            'rts2-focusd-dummy', 'rts2-filterd-dummy', 'rts2-camd-dummy'
        ]
        p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
        out, err = p.communicate()

        for line in out.splitlines():
            # wildi     7432  0.0  0.1  24692  5192 pts/1    S    17:34   0:01 /usr/local/bin/rts2-centrald
            itms = line.split()
            exe = itms[10].split('/')[-1]
            if self.uid in itms[0] and exe in processes:
                pid = int(itms[1])
                os.kill(pid, signal.SIGTERM)

        # reove th lock files
        for fn in glob.glob(self.lockPrefix):
            os.unlink(fn)

    def setUp(self):
        # by name
        self.uid = pwd.getpwuid(os.getuid())[0]
        self.gid = grp.getgrgid(os.getgid())[0]
        # lock prefix
        self.lockPrefix = '/tmp/rts2_{}'.format(self.uid)
        # sometimes they are present
        self.tearDown()
        # set up rts2saf
        # read configuration
        self.rt = Configuration(logger=logger)
        self.ev = Environment(debug=False, rt=self.rt, logger=logger)
        self.fileName = './rts2saf-bootes-2-autonomous.cfg'
        self.success = self.rt.readConfiguration(fileName=self.fileName)
        # set up RTS2
        # rts2-centrald
        cmd = [
            '/usr/local/bin/rts2-centrald', '--run-as',
            '{}.{}'.format(self.uid, self.gid), '--local-port', '1617',
            '--logfile', '/tmp/rts2saf_log/rts2-debug', '--lock-prefix',
            self.lockPrefix, '--config', './rts2-unittest.ini'
        ]
        self.p_centrald = subprocess.Popen(cmd)

        # rts2-executor
        cmd = [
            '/usr/local/bin/rts2-executor', '--run-as',
            '{}.{}'.format(self.uid, self.gid), '--lock-prefix',
            self.lockPrefix, '--config', './rts2-unittest.ini', '--server',
            '127.0.0.1:1617', '--noauth'
        ]
        self.p_exec = subprocess.Popen(cmd)

        # rts2-xmlrpcd
        cmd = [
            '/usr/local/bin/rts2-xmlrpcd', '--run-as',
            '{}.{}'.format(self.uid, self.gid), '--lock-prefix',
            self.lockPrefix, '--config', './rts2-unittest.ini', '--server',
            '127.0.0.1:1617', '-p', '9999', '--noauth'
        ]
        self.p_xmlrpcd = subprocess.Popen(cmd)

        # rts2-focusd-dummy
        focName = self.rt.cfg['FOCUSER_NAME']
        cmd = [
            '/usr/local/bin/rts2-focusd-dummy', '--run-as',
            '{}.{}'.format(self.uid, self.gid), '--lock-prefix',
            self.lockPrefix, '--server', '127.0.0.1:1617', '-d', focName,
            '--modefile', './f0.modefile'
        ]
        self.p_focusd_dummy = subprocess.Popen(cmd)

        # rts2-filterd-dummy
        ftwns = list()
        for ftwn in self.rt.cfg['inuse']:
            ftwns.append(ftwn)
            cmd = [
                '/usr/local/bin/rts2-filterd-dummy', '--run-as',
                '{}.{}'.format(self.uid, self.gid), '--lock-prefix',
                self.lockPrefix, '--server', '127.0.0.1:1617', '-d', ftwn
            ]
            ftnames = str()

            for ftn in self.rt.cfg['FILTER WHEEL DEFINITIONS'][ftwn]:
                ftnames += '{}:'.format(ftn)

            if len(ftnames) > 0:
                cmd.append('-F')
                cmd.append(ftnames)

            self.p_filterd_dummy = subprocess.Popen(cmd)

        # rts2-camd-dummy
        name = self.rt.cfg['CCD_NAME']
        # '--wheeldev', 'COLWSLT',  '--filter-offsets', '1:2:3:4:5:6:7:8'
        cmd = [
            '/usr/local/bin/rts2-camd-dummy', '--run-as',
            '{}.{}'.format(self.uid,
                           self.gid), '--lock-prefix', self.lockPrefix,
            '--server', '127.0.0.1:1617', '-d', name, '--focdev', focName
        ]
        for nm in ftwns:
            cmd.append('--wheeldev')
            cmd.append(nm)
            if nm in self.rt.cfg['inuse'][0]:
                cmd.append('--filter-offsets')
                cmd.append('1:2:3:4:5:6:7:8')

        self.p_camd_dummy = subprocess.Popen(cmd)
        #
        time.sleep(20)

    def setupDevices(self, blind=False):
        # setup rts2saf
        # fake arguments
        self.args = Args()
        self.args.sxDebug = False
        self.args.blind = blind
        self.args.verbose = False
        self.args.check = True
        self.args.fetchOffsets = True
        self.args.exposure = 1.887
        self.args.catalogAnalysis = False
        self.args.Ds9Display = False
        self.args.FitDisplay = False
        self.args.flux = True
        self.args.dryFitsFiles = '../samples_bootes2'
        # JSON
        self.proxy = JSONProxy(url=self.rt.cfg['URL'],
                               username=self.rt.cfg['USERNAME'],
                               password=self.rt.cfg['PASSWORD'])
        # create Focuser
        self.foc = CreateFocuser(debug=False,
                                 proxy=self.proxy,
                                 check=self.args.check,
                                 rt=self.rt,
                                 logger=logger).create()
        # create filters
        fts = CreateFilters(debug=False,
                            proxy=self.proxy,
                            check=self.args.check,
                            rt=self.rt,
                            logger=logger).create()
        # create filter wheels
        ftwc = CreateFilterWheels(debug=False,
                                  proxy=self.proxy,
                                  check=self.args.check,
                                  rt=self.rt,
                                  logger=logger,
                                  filters=fts,
                                  foc=self.foc)
        ftws = ftwc.create()
        if not ftwc.checkBounds():
            logger.error(
                'setupDevice: filter focus ranges out of bounds, exiting')
            sys.exit(1)

        # create ccd
        ccd = CreateCCD(debug=False,
                        proxy=self.proxy,
                        check=self.args.check,
                        rt=self.rt,
                        logger=logger,
                        ftws=ftws,
                        fetchOffsets=self.args.fetchOffsets).create()

        cdv = CheckDevices(debug=False,
                           proxy=self.proxy,
                           blind=self.args.blind,
                           verbose=self.args.verbose,
                           ccd=ccd,
                           ftws=ftws,
                           foc=self.foc,
                           logger=logger)
        cdv.summaryDevices()
        cdv.printProperties()
        cdv.deviceWriteAccess()
        dryFitsFiles = None
        if self.args.dryFitsFiles:
            dryFitsFiles = glob.glob('{0}/{1}'.format(
                self.args.dryFitsFiles, self.rt.cfg['FILE_GLOB']))
            if len(dryFitsFiles) == 0:
                logger.error('setupDevice: no FITS files found in:{}'.format(
                    self.args.dryFitsFiles))
                logger.info(
                    'setupDevice: download a sample from wget http://azug.minpet.unibas.ch/~wildi/rts2saf-test-focus-2013-09-14.tgz'
                )
                sys.exit(1)

        # ok evrything is there
        self.rts2safFoc = Focus(debug=False,
                                proxy=self.proxy,
                                args=self.args,
                                dryFitsFiles=dryFitsFiles,
                                ccd=ccd,
                                foc=self.foc,
                                ftws=ftws,
                                rt=self.rt,
                                ev=self.ev,
                                logger=logger)