Пример #1
0
def main():

    p = OptionParser()
    
    p.set_usage('%prog [options]')
    p.set_description(__doc__)
    p.add_option('-v', '--verbosity', dest='verbosity',type='int', default=1,
        help='Verbosity level. Default: 1')
    p.add_option('-p', '--skip_prog', dest='prog_fpga',action='store_false', default=True,
        help='Skip FPGA programming (assumes already programmed).  Default: program the FPGAs')     
    p.add_option('-r', '--roach', dest='roach',type='str', default='srbsr2-1',
        help='ROACH IP address or hostname. Default: srbsr2-1')
    p.add_option('-z', '--zdok', dest='zdok', type='int', default=2,
        help='ZDOK, 0 or 1, if input is 2, then refers to both. Default = 2')
    p.add_option('-t', '--types', dest='types', type='str', default='all',
        help='Which type of calibrations to load: [all, ogp, inl]')
    p.add_option('-l', '--caldir', dest='caldir', type='str', default=None,
        help='What directory to find the calibration files in')
    p.add_option('-f', '--file', dest='file', type='str', default=None,
        help='What specific file to use? -type & -zdok options must be used as well')
    p.add_option('-b', '--boffile', dest='boffile',type='str', default='h1k_ver105_2013_Dec_02_1551.bof',
        help='Boffile to program. Default: h1k_ver105_2013_Dec_02_1551.bof')
    p.add_option('-g', '--gpibaddr', dest='gpibaddr', type='str', default='10.16.96.174',
        help='IP Address of the GPIB.  Current default is set to tape room machine. Default = 10.16.96.174')
    p.add_option('-d', '--directory', dest='dir', type='str', default='.',    
        help='name of directory to put all files')
    p.add_option('-u', '--use_conifg', dest='use_conifg', action='store_true', default=False,
        help='Load calibrations found in <roachname>-adc.conf file?')
    p.add_option('-c', '--clockrate', dest='clockrate', type='float', default=1500.0,
        help='Clock rate in MHz; must be specified if --use_config option is specified')

    opts, args = p.parse_args(sys.argv[1:])

    # setup log file name:
    current_time = datetime.datetime.now().strftime('%Y-%m%d-%H%M%S')
    timestamp = "_%s_z%d_%s"%(opts.roach, opts.zdok, current_time)
    AdcCalLoggingFileHandler.timestamp = timestamp

    # load log config file
    var = "YGOR_TELESCOPE"
    confdir = '.' if not os.environ.has_key(var) else  os.path.join(os.environ[var], "etc/config")
    conffile = "%s/%s" % (confdir, 'adc_cal_logging.conf')
    if not os.path.isfile(conffile):
        print "Cannot find config file for logging: %s" % conffile
        sys.exit(0)

    logging.config.fileConfig(conffile)
    logger = logging.getLogger('adc5gLogging')
    logger.info("Started")
    
    if not opts.verbosity:
        logger.setLevel(logging.INFO)       

    logger.info("opts :\n\t" + str(opts))
    logger.info("args :\n\t" + str(args))
    logger.info("log file name:\n\t" + AdcCalLoggingFileHandler.logfilename)

    tmsg = 'Connecting to %s'%opts.roach
    logger.info(tmsg)
    r = corr.katcp_wrapper.FpgaClient(opts.roach)
    time.sleep(0.2)
    tmsg = 'ROACH is connected? ' +  str(r.is_connected())
    logger.info(tmsg)

    if opts.prog_fpga:
        tmsg = 'Programming ROACH with boffile %s'%opts.boffile
        r.progdev(opts.boffile)
        time.sleep(0.5)
        logger.info(tmsg)   

    # Time to make our worker class
    cal = ADCCalibrate(dir = opts.dir 
                     , gpib_addr = opts.gpibaddr
                     , roach_name = opts.roach
                     , roach = r)

    # First, check out the noise before we load
    logger.info("Checking initial state of spectrum.")
    fn = cal.get_check_filename("inital_spec", opts.zdok)
    cal.check_spec(opts.zdok, filename = fn)
        

    # TBF: we have to do this, or some subset, after the roach has
    # has been rebooted.  WHY?
    if opts.prog_fpga:
        cal.do_mmcm(opts.zdok)

    logger.info("Checking of spectrum after MMCM calibration.")
    fn = cal.get_check_filename("after_mmcm_spec", opts.zdok)
    cal.check_spec(opts.zdok, filename = fn)

    if opts.types == 'all':
        types = None
    else:
        types = [opts.types]

    if opts.file is not None:
        if opts.types is 'all':
            raise Exception, "Must specify --types when specifiying --file"
        if opts.zdok == 2:
            raise Exception, "Must specify --zdok as 0 or 1 when specifiying --file"
        if opts.types == 'ogp':
            cal.ogp.load_from_file(opts.file)
            logger.info("Loading calibration file %s" % opts.file)
        elif opts.types == 'inl':
            cal.inl.load_from_file(opts.file)
            logger.info("Loading calibration file %s" % opts.file)
        else:
            msg = "--type value unsupported (all, ogp, inl): ", opts.types
            logger.debug(msg)
            raise Exception, msg 
    else:
        cal.load_calibrations(indir = opts.caldir
                            , use_conf = opts.use_conf
                            , freq = opts.clockrate
                            , zdoks = opts.zdok
                            , types = types)

    # Finally, check out the noise
    logger.info("Checking final state of spectrum.")
    fn = cal.get_check_filename("after_load_cals_spec", opts.zdok)
    cal.check_spec(opts.zdok, filename = fn)
Пример #2
0
def main():

    p = OptionParser()
    
    p.set_usage('%prog [options]')
    p.set_description(__doc__)
    p.add_option('-v', '--verbosity', dest='verbosity',type='int', default=1,
        help='Verbosity level. Default: 1')
    p.add_option('-r', '--roach', dest='roach',type='str', default='srbsr2-1',
        help='ROACH IP address or hostname. Default: srbsr2-1')
    p.add_option('-z', '--zdok', dest='zdok', type='int', default=2,
        help='ZDOK, 0 or 1, if input is 2, then refers to both. Default = 2')
    p.add_option('-d', '--directory', dest='dir', type='str', default='.',    
        help='name of directory to put all files')
    p.add_option('-o', '--read_ogp', dest='read_ogp', action='store_true', default=False,
        help='Read the OGP values from the hardware') 
    p.add_option('-i', '--read_inl', dest='read_inl', action='store_true', default=False,
        help='Read the INL values from the hardware') 
    opts, args = p.parse_args(sys.argv[1:])

    # setup log file name:
    current_time = datetime.datetime.now().strftime('%Y-%m%d-%H%M%S')
    timestamp = "_%s_z%d_%s"%(opts.roach, opts.zdok, current_time)
    AdcCalLoggingFileHandler.timestamp = timestamp

    # load log config file
    import os
    var = "YGOR_TELESCOPE"
    confdir = '.' if not os.environ.has_key(var) else  os.path.join(os.environ[var], "etc/config")
    conffile = "%s/%s" % (confdir, 'adc_cal_logging.conf')
    if not os.path.isfile(conffile):
        print "Cannot find config file for logging: %s" % conffile
        sys.exit(0)

    logging.config.fileConfig(conffile)
    logger = logging.getLogger('adc5gLogging')
    logger.info("Started")
    
    if not opts.verbosity:
        logger.setLevel(logging.INFO)       

    logger.info("opts :\n\t" + str(opts))
    logger.info("args :\n\t" + str(args))
    logger.info("log file name:\n\t" + AdcCalLoggingFileHandler.logfilename)

    tmsg = 'Connecting to %s'%opts.roach
    logger.info(tmsg)
    r = corr.katcp_wrapper.FpgaClient(opts.roach)
    time.sleep(0.2)
    tmsg = 'ROACH is connected? ' +  str(r.is_connected())
    logger.info(tmsg)

    # Time to make our worker class
    cal = ADCCalibrate(dir = opts.dir 
                     , gpib_addr = None #opts.gpibaddr
                     , roach_name = opts.roach
                     , roach = r)

    zdoks = [opts.zdok] if opts.zdok != 2 else [0,1]

    # What are the currently loaded OGP values in the Card?
    chs = range(1,5)
    if opts.read_ogp:
        for z in zdoks:
            cal.set_zdok(z)
            os = [cal.spi.get_offset(c) for c in chs]
            gs = [cal.spi.get_gain(c)   for c in chs]
            ps = [cal.spi.get_phase(c)  for c in chs]
            logger.info("OGPs for zdok %s" % z)
            logger.info("Offsets: %s" % os)
            logger.info("Gains: %s" % gs)
            logger.info("Phases: %s" % ps)

    if opts.read_inl:
        for z in zdoks:
            cal.set_zdok(z)
            logger.info("INLs for zdok %s" % z)
            a = cal.inl.get_inl_array()
            logger.debug( "lvl  A     B     C     D")
            for level in range(17):
                logger.debug( "%3d %5.2f %5.2f %5.2f %5.2f" % tuple(a[level]))

    i = 0
    while cal.user_input("Check ADC output?"):
        fn = cal.get_check_filename("raw_%d" % i, opts.zdok)
        cal.check_raw(opts.zdok, filename = fn)
        fn = cal.get_check_filename("spec_%d" % i, opts.zdok)
        cal.check_spec(opts.zdok, filename = fn)
        i += 1
Пример #3
0
class ADCCalibrateTest(unittest.TestCase):
    "Unit tests for ."

    def setUp(self):
        # setup this class for unit tests
        now = datetime(2014, 4, 24, 9, 8, 38)
        self.adc = ADCCalibrate(dir="testdata", now=now, roach_name="noroach", test=True)

        # Uncomment this code if you want the logs to stdout
        # logging.config.fileConfig('adc5g_logging_config.conf')
        # logger = logging.getLogger('adc5gLogging')
        # logger.info("Started")

    def tearDown(self):

        # clean up all the generated files
        files = []
        basename = "%s/snapshot_raw_%s_z%d_%s.dat.%s"
        exts = ["fit", "ogp", "a", "b", "c", "d", "res"]
        for zdok in [0, 1]:
            for i in range(10):
                for ext in exts:
                    e = "%d.%s" % (i, ext)
                    f = basename % (self.adc.dir, self.adc.roach_name, zdok, self.adc.current_time, e)
                    files.append(f)
        for f in files:
            if os.path.isfile(f):
                os.remove(f)

        # clean up .png's
        fs = os.listdir(self.adc.dir)

    def test_load_calibrations(self):

        indir = "testdata"
        self.adc.load_calibrations(indir=indir)

        # did we load the right files?
        exp = ["%s/ogp_noroach_z%d_2014-04-24-090838" % (indir, i) for i in range(2)]
        exp.extend(["%s/inl_noroach_z%d_2014-04-24-090838.meas" % (indir, i) for i in range(2)])
        self.assertEquals(exp, self.adc.loaded_files)

        # probe the lower level objects to make sure commands were sent
        self.assertEqual(138, len(self.adc.spi.regs))

        # test filters
        self.adc.load_calibrations(indir=indir, zdoks=1, types=["ogp"])
        exp = ["%s/ogp_noroach_z%d_2014-04-24-090838" % (indir, 1)]
        self.assertEquals(exp, self.adc.loaded_files)

    def test_load_calibrations_2(self):

        indir = "testdata"
        self.adc.load_calibrations(indir=indir, use_conf=True, freq=1500.0)

        self.assertEquals([], self.adc.loaded_files)

        # probe the lower level objects to make sure commands were sent
        self.assertEqual(138, len(self.adc.spi.regs))

    # *************** The below tests are using dummy input data, so checking their
    # results is of limited value.  Here we basically make sure theres no failures.

    def test_check_ramp(self):

        # setup
        zdok = 0
        fn1 = self.adc.get_check_filename(self.adc.post_mmcm_ramp_check_name, zdok) + ".png"
        fn2 = self.adc.get_check_filename(self.adc.post_ramp_check_raw_name, zdok) + ".png"
        for f in [fn1, fn2]:
            if os.path.isfile(f):
                os.remove(f)

        self.adc.check_ramp(zdok, save=True, view=False)

        # test & cleanup
        for f in [fn1, fn2]:
            self.assertTrue(os.path.isfile(f))
            if os.path.isfile(f):
                os.remove(f)

    def test_check_raw(self):

        # setup
        zdok = 0
        fn = self.adc.get_check_filename(self.adc.raw_startup_name, zdok) + ".png"
        if os.path.isfile(fn):
            os.remove(fn)

        self.adc.check_raw(zdok, save=True, view=False)

        self.assertTrue(os.path.isfile(fn))
        if os.path.isfile(fn):
            os.remove(fn)

    # skipping this for now ...
    def skip_test_check_spec(self):

        # setup
        zdok = 0
        fn = self.adc.get_check_filename("spec", zdok) + ".png"
        if os.path.isfile(fn):
            os.remove(fn)

        self.adc.gpib.set_freq(1.0)
        self.adc.gpib.set_ampl(1.0)

        # not saving because the FFT causes NaN's, which the figure has
        # problems with
        self.adc.check_spec(zdok, save=False, view=False)

        self.assertTrue(not os.path.isfile(fn))
        if os.path.isfile(fn):
            os.remove(fn)
def main():

    p = OptionParser()

    p.set_usage('%prog [options]')
    p.set_description(__doc__)
    p.add_option('-v',
                 '--verbosity',
                 dest='verbosity',
                 type='int',
                 default=1,
                 help='Verbosity level. Default: 1')
    p.add_option('-r',
                 '--roach',
                 dest='roach',
                 type='str',
                 default='srbsr2-1',
                 help='ROACH IP address or hostname. Default: srbsr2-1')
    p.add_option(
        '-z',
        '--zdok',
        dest='zdok',
        type='int',
        default=2,
        help='ZDOK, 0 or 1, if input is 2, then refers to both. Default = 2')
    p.add_option('-d',
                 '--directory',
                 dest='dir',
                 type='str',
                 default='.',
                 help='name of directory to put all files')
    p.add_option('-o',
                 '--read_ogp',
                 dest='read_ogp',
                 action='store_true',
                 default=False,
                 help='Read the OGP values from the hardware')
    p.add_option('-i',
                 '--read_inl',
                 dest='read_inl',
                 action='store_true',
                 default=False,
                 help='Read the INL values from the hardware')
    opts, args = p.parse_args(sys.argv[1:])

    # setup log file name:
    current_time = datetime.datetime.now().strftime('%Y-%m%d-%H%M%S')
    timestamp = "_%s_z%d_%s" % (opts.roach, opts.zdok, current_time)
    AdcCalLoggingFileHandler.timestamp = timestamp

    # load log config file
    import os
    var = "YGOR_TELESCOPE"
    confdir = '.' if not os.environ.has_key(var) else os.path.join(
        os.environ[var], "etc/config")
    conffile = "%s/%s" % (confdir, 'adc_cal_logging.conf')
    if not os.path.isfile(conffile):
        print "Cannot find config file for logging: %s" % conffile
        sys.exit(0)

    logging.config.fileConfig(conffile)
    logger = logging.getLogger('adc5gLogging')
    logger.info("Started")

    if not opts.verbosity:
        logger.setLevel(logging.INFO)

    logger.info("opts :\n\t" + str(opts))
    logger.info("args :\n\t" + str(args))
    logger.info("log file name:\n\t" + AdcCalLoggingFileHandler.logfilename)

    tmsg = 'Connecting to %s' % opts.roach
    logger.info(tmsg)
    r = corr.katcp_wrapper.FpgaClient(opts.roach)
    time.sleep(0.2)
    tmsg = 'ROACH is connected? ' + str(r.is_connected())
    logger.info(tmsg)

    # Time to make our worker class
    cal = ADCCalibrate(
        dir=opts.dir,
        gpib_addr=None  #opts.gpibaddr
        ,
        roach_name=opts.roach,
        roach=r)

    zdoks = [opts.zdok] if opts.zdok != 2 else [0, 1]

    # What are the currently loaded OGP values in the Card?
    chs = range(1, 5)
    if opts.read_ogp:
        for z in zdoks:
            cal.set_zdok(z)
            os = [cal.spi.get_offset(c) for c in chs]
            gs = [cal.spi.get_gain(c) for c in chs]
            ps = [cal.spi.get_phase(c) for c in chs]
            logger.info("OGPs for zdok %s" % z)
            logger.info("Offsets: %s" % os)
            logger.info("Gains: %s" % gs)
            logger.info("Phases: %s" % ps)

    if opts.read_inl:
        for z in zdoks:
            cal.set_zdok(z)
            logger.info("INLs for zdok %s" % z)
            a = cal.inl.get_inl_array()
            logger.debug("lvl  A     B     C     D")
            for level in range(17):
                logger.debug("%3d %5.2f %5.2f %5.2f %5.2f" % tuple(a[level]))

    i = 0
    while cal.user_input("Check ADC output?"):
        fn = cal.get_check_filename("raw_%d" % i, opts.zdok)
        cal.check_raw(opts.zdok, filename=fn)
        fn = cal.get_check_filename("spec_%d" % i, opts.zdok)
        cal.check_spec(opts.zdok, filename=fn)
        i += 1
Пример #5
0
def main():

    p = OptionParser()
    
    p.set_usage('%prog [options]')
    p.set_description(__doc__)
    p.add_option('-p', '--skip_prog', dest='prog_fpga',action='store_false', default=True,
        help='Skip FPGA programming (assumes already programmed).  Default: program the FPGAs')
    p.add_option('-v', '--verbosity', dest='verbosity',type='int', default=1,
        help='Verbosity level. Default: 1')
    p.add_option('-r', '--roach', dest='roach',type='str', default='srbsr2-1',
        help='ROACH IP address or hostname. Default: srbsr2-1')
    p.add_option('-b', '--boffile', dest='boffile',type='str', default='h1k_ver105_2013_Dec_02_1551.bof',
        help='Boffile to program. Default: h1k_ver105_2013_Dec_02_1551.bof')
    p.add_option('-N', '--n_trials', dest='n_trials',type='int', default=10,
        help='Number of snap/fit trials. Default: 10')
    p.add_option('-c', '--clockrate', dest='clockrate', type='float', default=1500.0,
        help='Clock rate in MHz, for use when plotting frequency axes. If none is given, rate will be estimated from FPGA clock')
    p.add_option('-f', '--testfreq', dest='testfreq', type='float', default=18.3105,
        help='sine wave test frequency input in MHz. Default = 18.3105')
    p.add_option('-l', '--ampl', dest='ampl', type='float', default=3.0,
        help='Power level of test tone input in dBm. Default = 3.0')
    p.add_option('-g', '--gpibaddr', dest='gpibaddr', type='str', default='10.16.96.174',
        help='IP Address of the GPIB.  Current default is set to tape room machine. Default = 10.16.96.174')
    p.add_option('-s', '--snapname', dest='snapname', type='str', default='adcsnap',
        help='snapname. Default = adcsnap')
    p.add_option('-z', '--zdok', dest='zdok', type='int', default=2,
        help='ZDOK, 0 or 1, if input is 2, then refers to both. Default = 2')
    p.add_option('-d', '--directory', dest='dir', type='str', default='.',    
        help='name of directory to put all files')
    p.add_option('-o', '--ogp', dest='do_ogp', type='int', default=1,
        help='Do OGP calibration? Default = 1')
    p.add_option('-i', '--inl', dest='do_inl', type='int', default=1,
        help='Do INL calibration (OGP must be completed first)? Default = 1')
    p.add_option('-t', '--test', dest='test', type='int', default=1,
        help='Test after calibration is completed. Default=1')
    p.add_option('-m', '--manual', dest='manual', type='int', default=1,
        help='Manual control of the calibration process. Default=1')
    p.add_option('-S', '--save', dest='save', type='int', default=1,
        help='To save the plots. Default=1 (save)')
    p.add_option('-V', '--view', dest='view', type='int', default=1,
        help='To show the plots interactively (will be forced to 0 if manual is off). Default=1 (show)')
    p.add_option('-u', '--update_conf', dest='update_conf', action='store_false', default=True,
        help='Update the <roach_name>-adc.conf file?')

    opts, args = p.parse_args(sys.argv[1:])

    # setup log file name:
    current_time = datetime.datetime.now().strftime('%Y-%m%d-%H%M%S')
    timestamp = "_%s_z%d_%s"%(opts.roach, opts.zdok, current_time)
    AdcCalLoggingFileHandler.timestamp = timestamp

    # load log config file
    var = "YGOR_TELESCOPE"
    confdir = '.' if not os.environ.has_key(var) else  os.path.join(os.environ[var], "etc/config")
    conffile = "%s/%s" % (confdir, 'adc_cal_logging.conf')
    if not os.path.isfile(conffile):
        print "Cannot find config file for logging: %s" % conffile
        sys.exit(0)

    logging.config.fileConfig(conffile)
    logger = logging.getLogger('adc5gLogging')
    logger.info("Started")
    
    if not opts.verbosity:
        logger.setLevel(logging.INFO)

    logger.info("opts :\n\t" + str(opts))
    logger.info("args :\n\t" + str(args))
    logger.info("log file name:\n\t" + AdcCalLoggingFileHandler.logfilename)

    tmsg = 'Connecting to %s'%opts.roach
    logger.info(tmsg)
    r = corr.katcp_wrapper.FpgaClient(opts.roach)
    time.sleep(0.2)
    tmsg = 'ROACH is connected? ' +  str(r.is_connected())
    logger.info(tmsg)

    if opts.prog_fpga:
        tmsg = 'Programming ROACH with boffile %s'%opts.boffile
        r.progdev(opts.boffile)
        time.sleep(0.5)
        logger.info(tmsg)

    tmsg = 'Estimating clock speed...'
    logger.info(tmsg)
    clk_est = r.est_brd_clk()
    tmsg = 'Clock estimated speed is %d MHz'%clk_est
    logger.info(tmsg)

    if opts.clockrate is None:
        clkrate = clk_est*16
        print "SETTING clkrate to: ", clkrate
    else:
        clkrate = opts.clockrate

    # Before progressing furth, check that the Valon Synth
    # is actually set to the clkrate.
    # ValonKATCP is not a worker class belonging to ADCCalibrate
    # since ADCCalibrate is inherited code, while Valon is ours.
    valonSerial = "/dev/ttyS1" # this should never change
    valonSynth = 0 # neither should this (0: A, 8: B)
    v = ValonKATCP(r, valonSerial) 
    current_clkrate = v.get_frequency(valonSynth)
    tmsg = "Valon Synth set to frequency: %f MHz" % current_clkrate
    logger.info(tmsg)
    if abs(current_clkrate - clkrate) > 0.001:
        v.set_frequency(valonSynth, clkrate)
        time.sleep(1)
        current_clkrate = v.get_frequency(valonSynth)
        tmsg = "Valon Synth changed to frequency: %f MHz" % current_clkrate
        logger.info(tmsg)

    # Time to make our worker class
    cal = ADCCalibrate(dir = opts.dir 
                     , roach_name = opts.roach
                     , gpib_addr = opts.gpibaddr
                     , clockrate = clkrate
                     , bof = opts.boffile
                     , config = opts.update_conf
                     , roach = r)

    cal.set_freq(opts.testfreq)
    cal.set_ampl(opts.ampl)

    if opts.prog_fpga:
        tmsg = 'Calibrating ADCs (MMCM)'
        logger.info(tmsg)
        cal.do_mmcm(opts.zdok)
        if opts.manual:
            if cal.user_input("Check the test ramps now?"):
                cal.check_ramp(opts.zdok, save=opts.save, view=opts.view) #, filename = fn)


    if opts.do_ogp or opts.test:
        if  cal.gpib_test(opts.zdok, opts.testfreq, opts.ampl, manual=opts.manual): 
            tmsg = 'Current test tone power level: %.4f'%opts.ampl
            logger.debug(tmsg)
            tmsg ='Current test tone frequency: %.4f'%opts.testfreq
            logger.debug(tmsg)
            cal.check_raw(opts.zdok, save=opts.save, view=(opts.manual and opts.view))
            if opts.manual:
                if cal.user_input("Adjust power level now?"):
                    cal.ampl_setup(opts.zdok, manual = True)
        else:
            tmsg = "Problem with synthesizer, aborting OGP calibration & testing..."
            logger.warning(tmsg)
            opts.do_ogp = 0
            opts.test = 0


    if opts.do_ogp:
        cal.do_ogp(opts.zdok, opts.testfreq, opts.n_trials)
        if opts.do_inl:
            cal.do_inl(opts.zdok) 

    if opts.test:
        if opts.manual:
            logger.info("Startinging manual testing...")
            check_spec = cal.user_input("Check spectrum?")
            while(check_spec):
                cal.freq_setup(opts.zdok, manual=True)
                cal.ampl_setup(opts.zdok, manual=True)
                fn = cal.get_check_filename("post_adjustment_test_%.4fMHz" % cal.gpib.freq, opts.zdok) 
                cal.check_spec(opts.zdok, save=opts.save, view=opts.view, filename=fn) #, filename=fn)
                check_spec = cal.user_input("Check spectrum?")
            if cal.user_input("Do frequency scan?"):
                cal.freq_scan(save=opts.save, view=opts.view) #, filename=fn)
        else:
            logger.info("Starting automatic testing...")
            for i in range(0, 5):
                test_freq = random.random()*cal.clockrate
                cal.freq_setup(manual=False, freq = test_freq)
                fn = "post_adjustment_test_%.4fMHz"%cal.gpib.freq + cal.file_label
                cal.check_spec(save=opts.save, view=False, filename=fn)
            fn = 'freq_scan' + cal.file_label #timestamp
            cal.freq_scan(save=opts.save, view=False, filename=fn)
Пример #6
0
def main():

    p = OptionParser()

    p.set_usage('%prog [options]')
    p.set_description(__doc__)
    p.add_option(
        '-p',
        '--skip_prog',
        dest='prog_fpga',
        action='store_false',
        default=True,
        help=
        'Skip FPGA programming (assumes already programmed).  Default: program the FPGAs'
    )
    p.add_option('-v',
                 '--verbosity',
                 dest='verbosity',
                 type='int',
                 default=1,
                 help='Verbosity level. Default: 1')
    p.add_option('-r',
                 '--roach',
                 dest='roach',
                 type='str',
                 default='srbsr2-1',
                 help='ROACH IP address or hostname. Default: srbsr2-1')
    p.add_option(
        '-b',
        '--boffile',
        dest='boffile',
        type='str',
        default='h1k_ver105_2013_Dec_02_1551.bof',
        help='Boffile to program. Default: h1k_ver105_2013_Dec_02_1551.bof')
    p.add_option('-N',
                 '--n_trials',
                 dest='n_trials',
                 type='int',
                 default=10,
                 help='Number of snap/fit trials. Default: 10')
    p.add_option(
        '-c',
        '--clockrate',
        dest='clockrate',
        type='float',
        default=1500.0,
        help=
        'Clock rate in MHz, for use when plotting frequency axes. If none is given, rate will be estimated from FPGA clock'
    )
    p.add_option(
        '-f',
        '--testfreq',
        dest='testfreq',
        type='float',
        default=18.3105,
        help='sine wave test frequency input in MHz. Default = 18.3105')
    p.add_option('-l',
                 '--ampl',
                 dest='ampl',
                 type='float',
                 default=3.0,
                 help='Power level of test tone input in dBm. Default = 3.0')
    p.add_option(
        '-g',
        '--gpibaddr',
        dest='gpibaddr',
        type='str',
        default='10.16.96.174',
        help=
        'IP Address of the GPIB.  Current default is set to tape room machine. Default = 10.16.96.174'
    )
    p.add_option('-s',
                 '--snapname',
                 dest='snapname',
                 type='str',
                 default='adcsnap',
                 help='snapname. Default = adcsnap')
    p.add_option(
        '-z',
        '--zdok',
        dest='zdok',
        type='int',
        default=2,
        help='ZDOK, 0 or 1, if input is 2, then refers to both. Default = 2')
    p.add_option('-d',
                 '--directory',
                 dest='dir',
                 type='str',
                 default='.',
                 help='name of directory to put all files')
    p.add_option('-o',
                 '--ogp',
                 dest='do_ogp',
                 type='int',
                 default=1,
                 help='Do OGP calibration? Default = 1')
    p.add_option(
        '-i',
        '--inl',
        dest='do_inl',
        type='int',
        default=1,
        help='Do INL calibration (OGP must be completed first)? Default = 1')
    p.add_option('-t',
                 '--test',
                 dest='test',
                 type='int',
                 default=1,
                 help='Test after calibration is completed. Default=1')
    p.add_option('-m',
                 '--manual',
                 dest='manual',
                 type='int',
                 default=1,
                 help='Manual control of the calibration process. Default=1')
    p.add_option('-S',
                 '--save',
                 dest='save',
                 type='int',
                 default=1,
                 help='To save the plots. Default=1 (save)')
    p.add_option(
        '-V',
        '--view',
        dest='view',
        type='int',
        default=1,
        help=
        'To show the plots interactively (will be forced to 0 if manual is off). Default=1 (show)'
    )
    p.add_option('-u',
                 '--update_conf',
                 dest='update_conf',
                 action='store_false',
                 default=True,
                 help='Update the <roach_name>-adc.conf file?')

    opts, args = p.parse_args(sys.argv[1:])

    # setup log file name:
    current_time = datetime.datetime.now().strftime('%Y-%m%d-%H%M%S')
    timestamp = "_%s_z%d_%s" % (opts.roach, opts.zdok, current_time)
    AdcCalLoggingFileHandler.timestamp = timestamp

    # load log config file
    var = "YGOR_TELESCOPE"
    confdir = '.' if not os.environ.has_key(var) else os.path.join(
        os.environ[var], "etc/config")
    conffile = "%s/%s" % (confdir, 'adc_cal_logging.conf')
    if not os.path.isfile(conffile):
        print "Cannot find config file for logging: %s" % conffile
        sys.exit(0)

    logging.config.fileConfig(conffile)
    logger = logging.getLogger('adc5gLogging')
    logger.info("Started")

    if not opts.verbosity:
        logger.setLevel(logging.INFO)

    logger.info("opts :\n\t" + str(opts))
    logger.info("args :\n\t" + str(args))
    logger.info("log file name:\n\t" + AdcCalLoggingFileHandler.logfilename)

    tmsg = 'Connecting to %s' % opts.roach
    logger.info(tmsg)
    r = corr.katcp_wrapper.FpgaClient(opts.roach)
    time.sleep(0.2)
    tmsg = 'ROACH is connected? ' + str(r.is_connected())
    logger.info(tmsg)

    if opts.prog_fpga:
        tmsg = 'Programming ROACH with boffile %s' % opts.boffile
        r.progdev(opts.boffile)
        time.sleep(0.5)
        logger.info(tmsg)

    tmsg = 'Estimating clock speed...'
    logger.info(tmsg)
    clk_est = r.est_brd_clk()
    tmsg = 'Clock estimated speed is %d MHz' % clk_est
    logger.info(tmsg)

    if opts.clockrate is None:
        clkrate = clk_est * 16
        print "SETTING clkrate to: ", clkrate
    else:
        clkrate = opts.clockrate

    # Before progressing furth, check that the Valon Synth
    # is actually set to the clkrate.
    # ValonKATCP is not a worker class belonging to ADCCalibrate
    # since ADCCalibrate is inherited code, while Valon is ours.
    valonSerial = "/dev/ttyS1"  # this should never change
    valonSynth = 0  # neither should this (0: A, 8: B)
    v = ValonKATCP(r, valonSerial)
    current_clkrate = v.get_frequency(valonSynth)
    tmsg = "Valon Synth set to frequency: %f MHz" % current_clkrate
    logger.info(tmsg)
    if abs(current_clkrate - clkrate) > 0.001:
        v.set_frequency(valonSynth, clkrate)
        time.sleep(1)
        current_clkrate = v.get_frequency(valonSynth)
        tmsg = "Valon Synth changed to frequency: %f MHz" % current_clkrate
        logger.info(tmsg)

    # Time to make our worker class
    cal = ADCCalibrate(dir=opts.dir,
                       roach_name=opts.roach,
                       gpib_addr=opts.gpibaddr,
                       clockrate=clkrate,
                       bof=opts.boffile,
                       config=opts.update_conf,
                       roach=r)

    cal.set_freq(opts.testfreq)
    cal.set_ampl(opts.ampl)

    if opts.prog_fpga:
        tmsg = 'Calibrating ADCs (MMCM)'
        logger.info(tmsg)
        cal.do_mmcm(opts.zdok)
        if opts.manual:
            if cal.user_input("Check the test ramps now?"):
                cal.check_ramp(opts.zdok, save=opts.save,
                               view=opts.view)  #, filename = fn)

    if opts.do_ogp or opts.test:
        if cal.gpib_test(opts.zdok,
                         opts.testfreq,
                         opts.ampl,
                         manual=opts.manual):
            tmsg = 'Current test tone power level: %.4f' % opts.ampl
            logger.debug(tmsg)
            tmsg = 'Current test tone frequency: %.4f' % opts.testfreq
            logger.debug(tmsg)
            cal.check_raw(opts.zdok,
                          save=opts.save,
                          view=(opts.manual and opts.view))
            if opts.manual:
                if cal.user_input("Adjust power level now?"):
                    cal.ampl_setup(opts.zdok, manual=True)
        else:
            tmsg = "Problem with synthesizer, aborting OGP calibration & testing..."
            logger.warning(tmsg)
            opts.do_ogp = 0
            opts.test = 0

    if opts.do_ogp:
        cal.do_ogp(opts.zdok, opts.testfreq, opts.n_trials)
        if opts.do_inl:
            cal.do_inl(opts.zdok)

    if opts.test:
        if opts.manual:
            logger.info("Startinging manual testing...")
            check_spec = cal.user_input("Check spectrum?")
            while (check_spec):
                cal.freq_setup(opts.zdok, manual=True)
                cal.ampl_setup(opts.zdok, manual=True)
                fn = cal.get_check_filename(
                    "post_adjustment_test_%.4fMHz" % cal.gpib.freq, opts.zdok)
                cal.check_spec(opts.zdok,
                               save=opts.save,
                               view=opts.view,
                               filename=fn)  #, filename=fn)
                check_spec = cal.user_input("Check spectrum?")
            if cal.user_input("Do frequency scan?"):
                cal.freq_scan(save=opts.save, view=opts.view)  #, filename=fn)
        else:
            logger.info("Starting automatic testing...")
            for i in range(0, 5):
                test_freq = random.random() * cal.clockrate
                cal.freq_setup(manual=False, freq=test_freq)
                fn = "post_adjustment_test_%.4fMHz" % cal.gpib.freq + cal.file_label
                cal.check_spec(save=opts.save, view=False, filename=fn)
            fn = 'freq_scan' + cal.file_label  #timestamp
            cal.freq_scan(save=opts.save, view=False, filename=fn)