def test_plot_metrics(omnical_data): plt = pytest.importorskip("matplotlib.pyplot") # test execution full_metrics = omnical_data.OM.run_metrics(fcfiles=omnical_data.fc_file) metrics = full_metrics['XX'] basename = utils.strip_extension(omnical_data.OM.filename) fname1 = os.path.join(omnical_data.OM.filedir, basename + '.chisq_std.png') fname2 = os.path.join(omnical_data.OM.filedir, basename + '.phs_std.png') fname3 = os.path.join(omnical_data.OM.filedir, basename + '.phs_ft.png') for f in [fname1, fname2, fname3]: if os.path.isfile(f) is True: os.remove(f) omnical_data.OM.plot_metrics(metrics) assert os.path.isfile(fname1) assert os.path.isfile(fname2) assert os.path.isfile(fname3) os.remove(fname1) os.remove(fname2) os.remove(fname3) plt.close('all')
def test_plot_chisq_metrics(omnical_data): plt = pytest.importorskip("matplotlib.pyplot") full_metrics = omnical_data.OM.run_metrics(fcfiles=omnical_data.fc_file) metrics = full_metrics['XX'] fname = os.path.join(omnical_data.OM.filedir, 'chisq.png') if os.path.isfile(fname): os.remove(fname) # plot w/ fname omnical_metrics.plot_chisq_metric(metrics, fname=fname, save=True) assert os.path.isfile(fname) os.remove(fname) plt.close('all') # plot w/ fname and outpath omnical_metrics.plot_chisq_metric(metrics, fname=fname, save=True, outpath=omnical_data.OM.filedir) assert os.path.isfile(fname) os.remove(fname) plt.close('all') # plot w/o fname fname = os.path.join( omnical_data.OM.filedir, utils.strip_extension(omnical_data.OM.filename) + '.chisq_std.png') omnical_metrics.plot_chisq_metric(metrics, save=True) assert os.path.isfile(fname) os.remove(fname) plt.close('all') # plot feeding ax object fig, ax = plt.subplots() omnical_metrics.plot_chisq_metric(metrics, ax=ax) plt.close('all') # check return figs fig = omnical_metrics.plot_chisq_metric(metrics) assert fig is not None plt.close('all')
def test_strip_extension_return_ext_extension(): path = 'goo/foo.boo/hoo/woo.two' root, ext = utils.strip_extension(path, return_ext=True) assert ext == path[-3:]
def test_strip_extension_return_ext_basename(): path = 'goo/foo.boo/hoo/woo.two' root, ext = utils.strip_extension(path, return_ext=True) assert root == path[:-4]
def test_strip_extension(): path = 'goo/foo.boo/hoo/woo.two' root = utils.strip_extension(path) assert root == path[:-4]
def test_firstcal_metrics_run(omnicalrun_data): pytest.importorskip('matplotlib.pyplot') # get arg parse a = utils.get_metrics_ArgumentParser('omnical_metrics') if DATA_PATH not in sys.path: sys.path.append(DATA_PATH) # test w/ no file arguments = '' cmd = ' '.join([arguments, '']) args = a.parse_args(cmd.split()) history = cmd pytest.raises(AssertionError, omnical_metrics.omnical_metrics_run, args.files, args, history) # test w/ no fc_file arguments = '' cmd = ' '.join([arguments, omnicalrun_data.oc_file]) args = a.parse_args(cmd.split()) history = cmd outfile = utils.strip_extension( omnicalrun_data.oc_file) + '.omni_metrics.json' if os.path.isfile(outfile): os.remove(outfile) omnical_metrics.omnical_metrics_run(args.files, args, history) assert os.path.isfile(outfile) os.remove(outfile) # test w/ extension arguments = '--extension=.omni.json' cmd = ' '.join([arguments, omnicalrun_data.oc_file]) args = a.parse_args(cmd.split()) history = cmd outfile = utils.strip_extension(omnicalrun_data.oc_file) + '.omni.json' if os.path.isfile(outfile): os.remove(outfile) omnical_metrics.omnical_metrics_run(args.files, args, history) assert os.path.isfile(outfile) os.remove(outfile) # test w/ metrics_path arguments = '--metrics_path={}'.format(omnicalrun_data.out_dir) cmd = ' '.join([arguments, omnicalrun_data.oc_file]) args = a.parse_args(cmd.split()) history = cmd outfile = os.path.join( omnicalrun_data.out_dir, utils.strip_extension(omnicalrun_data.oc_basename) + '.omni_metrics.json') if os.path.isfile(outfile): os.remove(outfile) omnical_metrics.omnical_metrics_run(args.files, args, history) assert os.path.isfile(outfile) os.remove(outfile) # test w/ options arguments = '--fc_files={0} --no_bandcut --phs_std_cut=0.5 --chisq_std_zscore_cut=4.0'.format( omnicalrun_data.fc_file) cmd = ' '.join([arguments, omnicalrun_data.oc_file]) args = a.parse_args(cmd.split()) history = cmd outfile = utils.strip_extension( omnicalrun_data.oc_file) + '.omni_metrics.json' if os.path.isfile(outfile): os.remove(outfile) omnical_metrics.omnical_metrics_run(args.files, args, history) assert os.path.isfile(outfile) os.remove(outfile) # test make plots arguments = '--fc_files={0} --make_plots'.format(omnicalrun_data.fc_file) cmd = ' '.join([arguments, omnicalrun_data.oc_file]) args = a.parse_args(cmd.split()) history = cmd omnical_metrics.omnical_metrics_run(args.files, args, history) basename = utils.strip_extension(omnicalrun_data.oc_file) outfile = basename + '.omni_metrics.json' outpng1 = basename + '.chisq_std.png' outpng2 = basename + '.phs_std.png' outpng3 = basename + '.phs_ft.png' outpng4 = basename + '.phs_hist.png' assert os.path.isfile(outfile) assert os.path.isfile(outpng1) assert os.path.isfile(outpng2) assert os.path.isfile(outpng3) assert os.path.isfile(outpng4) os.remove(outfile) os.remove(outpng1) os.remove(outpng2) os.remove(outpng3) os.remove(outpng4)
def test_plot_gains(omnical_data): plt = pytest.importorskip("matplotlib.pyplot") omnical_data.OM.run_metrics(fcfiles=omnical_data.fc_file) fname = os.path.join(omnical_data.OM.filedir, 'gains.png') if os.path.isfile(fname): os.remove(fname) # plot w/ fname omnical_data.OM.plot_gains(plot_type='phs', fname=fname, save=True) assert os.path.isfile(fname) os.remove(fname) omnical_data.OM.plot_gains(plot_type='amp', fname=fname, save=True) assert os.path.isfile(fname) os.remove(fname) plt.close('all') # divide_fc = True omnical_data.OM.plot_gains(plot_type='phs', fname=fname, save=True, divide_fc=True) assert os.path.isfile(fname) os.remove(fname) omnical_data.OM.plot_gains(plot_type='amp', fname=fname, save=True, divide_fc=True) assert os.path.isfile(fname) os.remove(fname) plt.close('all') # plot w/ fname and outpath omnical_data.OM.plot_gains(plot_type='phs', fname=fname, save=True, outpath=omnical_data.OM.filedir) assert os.path.isfile(fname) os.remove(fname) plt.close('all') # plot w/o fname fname = os.path.join( omnical_data.OM.filedir, utils.strip_extension(omnical_data.OM.filename) + '.gain_phs.png') omnical_data.OM.plot_gains(plot_type='phs', save=True) assert os.path.isfile(fname) os.remove(fname) plt.close('all') fname = os.path.join( omnical_data.OM.filedir, utils.strip_extension(omnical_data.OM.filename) + '.gain_amp.png') omnical_data.OM.plot_gains(plot_type='amp', save=True) assert os.path.isfile(fname) os.remove(fname) plt.close('all') # plot feeding ax object fig, ax = plt.subplots() omnical_data.OM.plot_gains(ax=ax) plt.close('all') # plot feeding ants fname = os.path.join(omnical_data.OM.filedir, 'gains.png') omnical_data.OM.plot_gains(ants=omnical_data.OM.ant_array[:2], fname=fname, save=True) assert os.path.isfile(fname) os.remove(fname) plt.close('all') # check return figs fig = omnical_data.OM.plot_gains() assert fig is not None plt.close('all')
def test_plot_phs_metrics(omnical_data): plt = pytest.importorskip("matplotlib.pyplot") # run metrics w/ fc file full_metrics = omnical_data.OM.run_metrics(fcfiles=omnical_data.fc_file) metrics = full_metrics['XX'] # plot w/ fname, w/o outpath fname = os.path.join(omnical_data.OM.filedir, 'phs.png') if os.path.isfile(fname): os.remove(fname) omnical_metrics.plot_phs_metric(metrics, plot_type='std', fname=fname, save=True) assert os.path.isfile(fname) os.remove(fname) omnical_metrics.plot_phs_metric(metrics, plot_type='ft', fname=fname, save=True) assert os.path.isfile(fname) os.remove(fname) omnical_metrics.plot_phs_metric(metrics, plot_type='hist', fname=fname, save=True) assert os.path.isfile(fname) os.remove(fname) plt.close('all') # plot w/ fname and outpath omnical_metrics.plot_phs_metric(metrics, plot_type='std', fname=fname, save=True, outpath=omnical_data.OM.filedir) assert os.path.isfile(fname) os.remove(fname) omnical_metrics.plot_phs_metric(metrics, plot_type='hist', fname=fname, save=True, outpath=omnical_data.OM.filedir) assert os.path.isfile(fname) os.remove(fname) omnical_metrics.plot_phs_metric(metrics, plot_type='ft', fname=fname, save=True, outpath=omnical_data.OM.filedir) assert os.path.isfile(fname) os.remove(fname) plt.close('all') # plot w/o fname basename = utils.strip_extension(omnical_data.OM.filename) fname = os.path.join(omnical_data.OM.filedir, basename + '.phs_std.png') if os.path.isfile(fname): os.remove(fname) omnical_metrics.plot_phs_metric(metrics, plot_type='std', save=True) assert os.path.isfile(fname) os.remove(fname) fname = os.path.join(omnical_data.OM.filedir, basename + '.phs_ft.png') if os.path.isfile(fname): os.remove(fname) omnical_metrics.plot_phs_metric(metrics, plot_type='ft', save=True) assert os.path.isfile(fname) os.remove(fname) fname = os.path.join(omnical_data.OM.filedir, basename + '.phs_hist.png') if os.path.isfile(fname): os.remove(fname) omnical_metrics.plot_phs_metric(metrics, plot_type='hist', save=True) assert os.path.isfile(fname) os.remove(fname) plt.close('all') # plot feeding ax object fig, ax = plt.subplots() fname = os.path.join(omnical_data.OM.filedir, 'phs.png') if os.path.isfile(fname): os.remove(fname) omnical_metrics.plot_phs_metric(metrics, fname='phs.png', ax=ax, save=True) assert os.path.isfile(fname) os.remove(fname) plt.close('all') # exception del omnical_data.OM.omni_gains pytest.raises(Exception, omnical_data.OM.plot_gains) omnical_data.OM.run_metrics() # check return figs fig = omnical_metrics.plot_phs_metric(metrics) assert fig is not None plt.close('all')