def test_run_setup(): """ Test the setup script """ # Remove .setup if needed sfiles = glob.glob('*.setups') for sfile in sfiles: os.remove(sfile) # droot = data_path('b') pargs = setup.parser([ '-r', droot, '-s', 'shane_kast_blue', '-c=all', '--extension=fits.gz', '--output_path={:s}'.format(data_path('')) ]) setup.main(pargs) ''' setup_file = glob.glob(data_path('setup_files/shane_kast_blue*.setups'))[0] # Load with open(setup_file, 'r') as infile: setup_dict = yaml.load(infile) # Test assert '01' in setup_dict['A'].keys() assert setup_dict['A']['--']['disperser']['name'] == '600/4310' ''' # Failures pargs2 = setup.parser([ '-r', droot, '-s', 'shane_kast_blu', '-c=all', '--extension=fits.gz', '--output_path={:s}'.format(data_path('')) ]) with pytest.raises(ValueError): setup.main(pargs2)
def test_trace_edges(): # Define the output directories (HARDCODED!!) setupdir = os.path.join(os.getcwd(), 'setup_files') outdir = os.path.join(os.getcwd(), 'shane_kast_blue_A') # Remove them if they already exist if os.path.isdir(setupdir): shutil.rmtree(setupdir) if os.path.isdir(outdir): shutil.rmtree(outdir) # Perform the setup droot = os.path.join(os.environ['PYPEIT_DEV'], 'RAW_DATA/shane_kast_blue/600_4310_d55') droot += '/' setup.main(setup.parser(['-r', droot, '-s', 'shane_kast_blue', '-c', 'all'])) # Define the pypeit file (HARDCODED!!) pypeit_file = os.path.join(outdir, 'shane_kast_blue_A.pypeit') # Run the tracing trace_edges.main(trace_edges.parser(['-f', pypeit_file])) # Define the edges master file (HARDCODED!!) trace_file = os.path.join(outdir, 'Masters', 'MasterEdges_A_1_01.fits.gz') # Check that the correct number of traces were found edges = edgetrace.EdgeTraceSet.from_file(trace_file) assert edges.ntrace == 2, 'Did not find the expected number of traces.' # Clean up shutil.rmtree(setupdir) shutil.rmtree(outdir)
def test_setup_not_alfosc(): droot = os.path.join(os.environ['PYPEIT_DEV'], 'RAW_DATA/not_alfosc/grism4') droot += '/ALD' pargs = setup.parse_args(['-r', droot, '-s', 'not_alfosc']) setup.main(pargs) cwd = os.getcwd() setup_dir = os.path.join(cwd, 'setup_files') assert os.path.isdir(setup_dir), 'No setup_files directory created' files = glob.glob(os.path.join(setup_dir, 'not_alfosc*')) ext = [f.split('.')[-1] for f in files] expected = expected_file_extensions() assert np.all([e in ext for e in expected]), \ 'Did not find all setup file extensions: {0}'.format(expected) # Build a PypeIt file pargs = setup.parse_args(['-r', droot, '-s', 'not_alfosc', '-c', 'A', '-d', data_path('')]) setup.main(pargs) pypeit_file = data_path('not_alfosc_A/not_alfosc_A.pypeit') # TODO: Why is this using pypeit.PypeIt and not pypeitsetup.PypeItSetup? pypeIt = pypeit.PypeIt(pypeit_file, calib_only=True) # Clean-up shutil.rmtree(setup_dir) shutil.rmtree(data_path('not_alfosc_A'))
def make_example_pypeit_file(): oroot = os.path.join( os.path.split(os.path.abspath(resource_filename('pypeit', '')))[0], 'doc', 'include') droot = os.path.join(os.getenv('PYPEIT_DEV'), 'RAW_DATA/shane_kast_blue/600_4310_d55') droot += '/' pargs = setup.parse_args( ['-r', droot, '-s', 'shane_kast_blue', '-c', 'all', '-d', oroot]) setup.main(pargs) shutil.rmtree(os.path.join(oroot, 'setup_files')) ofile = os.path.join(oroot, 'shane_kast_blue_A.pypeit.rst') with open(ofile, 'w') as f: with open( os.path.join(oroot, 'shane_kast_blue_A', 'shane_kast_blue_A.pypeit'), 'r') as p: lines = p.readlines() f.write('.. code-block:: console\n') f.write('\n') for l in lines: f.write(' ' + l) f.write('\n\n') shutil.rmtree(os.path.join(oroot, 'shane_kast_blue_A'))
def test_run_pypeit(): # Get the directories rawdir = os.path.join(os.environ['PYPEIT_DEV'], 'RAW_DATA', 'Shane_Kast_blue', '600_4310_d55') assert os.path.isdir(rawdir), 'Incorrect raw directory' # Just get a few files testrawdir = os.path.join(rawdir, 'TEST') if os.path.isdir(testrawdir): shutil.rmtree(testrawdir) os.makedirs(testrawdir) files = [ 'b21.fits.gz', 'b22.fits.gz', 'b23.fits.gz', 'b27.fits.gz', 'b1.fits.gz', 'b11.fits.gz', 'b12.fits.gz', 'b13.fits.gz' ] for f in files: shutil.copy(os.path.join(rawdir, f), os.path.join(testrawdir, f)) outdir = os.path.join(os.getenv('PYPEIT_DEV'), 'REDUX_OUT_TEST') # For previously failed tests if os.path.isdir(outdir): shutil.rmtree(outdir) # Run the setup sargs = setup.parser([ '-r', testrawdir, '-s', 'shane_kast_blue', '-c all', '-o', '--output_path', outdir ]) setup.main(sargs) # Change to the configuration directory and set the pypeit file configdir = os.path.join(outdir, 'shane_kast_blue_A') pyp_file = os.path.join(configdir, 'shane_kast_blue_A.pypeit') assert os.path.isfile(pyp_file), 'PypeIt file not written.' # Perform the original reductions pargs = run_pypeit.parser([pyp_file, '-o']) run_pypeit.main(pargs) # Now try to reuse the old masters pargs = run_pypeit.parser([pyp_file, '-o', '-m']) run_pypeit.main(pargs) # Now try not overwriting and using the old masters pargs = run_pypeit.parser([pyp_file, '-m']) run_pypeit.main(pargs) # Clean-up shutil.rmtree(outdir) shutil.rmtree(testrawdir)
def test_read_combid(): # ------------------------------------------------------------------ # In case of failed tests setup_dir = data_path('setup_files') if os.path.isdir(setup_dir): shutil.rmtree(setup_dir) config_dir = data_path('shane_kast_blue_A') if os.path.isdir(config_dir): shutil.rmtree(config_dir) # ------------------------------------------------------------------ # Generate the pypeit file with the comb_id droot = data_path('b') pargs = setup.parse_args([ '-r', droot, '-s', 'shane_kast_blue', '-c=all', '-b', '--extension=fits.gz', '--output_path={:s}'.format(data_path('')) ]) setup.main(pargs) shutil.rmtree(setup_dir) pypeit_file = os.path.join(config_dir, 'shane_kast_blue_A.pypeit') cfg_lines, data_files, frametype, usrdata, setups = parse_pypeit_file( pypeit_file) # Get the spectrograph spectrograph = None for l in cfg_lines: if 'spectrograph' in l: spectrograph = load_spectrograph(l.split(' ')[-1]) break assert spectrograph is not None, 'Did not appropriately read spectrograph' # Set the metadata pmd = PypeItMetaData(spectrograph, spectrograph.default_pypeit_par(), files=data_files, usrdata=usrdata, strict=False) indx = pmd['filename'] == 'b27.fits.gz' assert pmd['comb_id'][indx] == [1], 'Incorrect combination group ID' assert pmd['comb_id'][~indx] == [-1], 'Incorrect combination group ID' shutil.rmtree(config_dir)
def test_setup_keck_lris_red(): droot = os.path.join(os.environ['PYPEIT_DEV'], 'RAW_DATA/Keck_LRIS_red/multi_400_8500_d560') droot += '/' pargs = setup.parser(['-r', droot, '-s', 'keck_lris_red']) setup.main(pargs) cwd = os.getcwd() setup_dir = os.path.join(cwd, 'setup_files') assert os.path.isdir(setup_dir), 'No setup_files directory created' files = glob.glob(os.path.join(setup_dir, 'keck_lris_red*')) ext = [f.split('.')[-1] for f in files] assert np.all([e in ext for e in expected]), \ 'Did not find all setup file extensions: {0}'.format(expected) # Clean-up shutil.rmtree(setup_dir)
def test_setup_vlt_xshooter_nir(): droot = os.path.join(os.environ['PYPEIT_DEV'], 'RAW_DATA/VLT_XSHOOTER/NIR') droot += '/XSHO' pargs = setup.parser(['-r', droot, '-s', 'vlt_xshooter_nir']) setup.main(pargs) cwd = os.getcwd() setup_dir = os.path.join(cwd, 'setup_files') assert os.path.isdir(setup_dir), 'No setup_files directory created' files = glob.glob(os.path.join(setup_dir, 'vlt_xshooter_nir*')) ext = [f.split('.')[-1] for f in files] #expected = ['lst', 'pypeit', 'setups', 'sorted'] assert np.all([e in ext for e in expected]), \ 'Did not find all setup file extensions: {0}'.format(expected) # Clean-up shutil.rmtree(setup_dir)
def test_setup_gemini_gnirs(): droot = os.path.join(os.environ['PYPEIT_DEV'], 'RAW_DATA/gemini_gnirs/32_SB_SXD/') droot += '/cN' pargs = setup.parse_args(['-r', droot, '-s', 'gemini_gnirs']) setup.main(pargs) cwd = os.getcwd() setup_dir = os.path.join(cwd, 'setup_files') assert os.path.isdir(setup_dir), 'No setup_files directory created' files = glob.glob(os.path.join(setup_dir, 'gemini_gnirs*')) ext = [f.split('.')[-1] for f in files] expected = expected_file_extensions() assert np.all([e in ext for e in expected]), \ 'Did not find all setup file extensions: {0}'.format(expected) # Clean-up shutil.rmtree(setup_dir)
def test_setup_wht_isis_blue(): droot = os.path.join(os.environ['PYPEIT_DEV'], 'RAW_DATA/wht_isis_blue/long_R300B_d5300') droot += '/' pargs = setup.parse_args(['-r', droot, '-s', 'wht_isis_blue', '--extension', '.fit']) setup.main(pargs) cwd = os.getcwd() setup_dir = os.path.join(cwd, 'setup_files') assert os.path.isdir(setup_dir), 'No setup_files directory created' files = glob.glob(os.path.join(setup_dir, 'wht_isis_blue*')) ext = [f.split('.')[-1] for f in files] expected = expected_file_extensions() assert np.all([e in ext for e in expected]), \ 'Did not find all setup file extensions: {0}'.format(expected) # Clean-up shutil.rmtree(setup_dir)
def test_setup_shane_kast_blue(): droot = os.path.join(os.environ['PYPEIT_DEV'], 'RAW_DATA/Shane_Kast_blue/600_4310_d55') droot += '/' pargs = setup.parser(['-r', droot, '-s', 'shane_kast_blue']) setup.main(pargs) cwd = os.getcwd() setup_dir = os.path.join(cwd, 'setup_files') assert os.path.isdir(setup_dir), 'No setup_files directory created' files = glob.glob(os.path.join(setup_dir, 'shane_kast_blue*')) ext = [f.split('.')[-1] for f in files] #expected = ['lst', 'pypeit', 'setups', 'sorted'] assert np.all([e in ext for e in expected]), \ 'Did not find all setup file extensions: {0}'.format(expected) # Clean-up shutil.rmtree(setup_dir)
def test_setup_keck_nirspec(): droot = os.path.join(os.environ['PYPEIT_DEV'], 'RAW_DATA/keck_nirspec/LOW_NIRSPEC-1') droot += '/' pargs = setup.parse_args(['-r', droot, '-s', 'keck_nirspec_low']) setup.main(pargs) cwd = os.getcwd() setup_dir = os.path.join(cwd, 'setup_files') assert os.path.isdir(setup_dir), 'No setup_files directory created' files = glob.glob(os.path.join(setup_dir, 'keck_nirspec*')) ext = [f.split('.')[-1] for f in files] #expected = ['lst', 'pypeit', 'setups', 'sorted'] assert np.all([e in ext for e in expected]), \ 'Did not find all setup file extensions: {0}'.format(expected) # Clean-up shutil.rmtree(setup_dir)
def test_setup_vlt_fors2(): droot = os.path.join(os.environ['PYPEIT_DEV'], 'RAW_DATA/vlt_fors2/300I/') droot += '/FORS2' pargs = setup.parse_args(['-r', droot, '-s', 'vlt_fors2']) setup.main(pargs) cwd = os.getcwd() setup_dir = os.path.join(cwd, 'setup_files') assert os.path.isdir(setup_dir), 'No setup_files directory created' files = glob.glob(os.path.join(setup_dir, 'vlt_fors2*')) ext = [f.split('.')[-1] for f in files] expected = expected_file_extensions() assert np.all([e in ext for e in expected]), \ 'Did not find all setup file extensions: {0}'.format(expected) # Clean-up shutil.rmtree(setup_dir) # Now chk calib pargs = chk_for_calibs.parse_args([droot, '-s', 'vlt_fors2']) answers, ps = chk_for_calibs.main(pargs) assert answers['pass'][0], 'A must pass!'
def test_run_pypeit_calib_only(): # Get the directories rawdir = os.path.join(os.environ['PYPEIT_DEV'], 'RAW_DATA', 'shane_kast_blue', '600_4310_d55') assert os.path.isdir(rawdir), 'Incorrect raw directory' # File list all_files = { 'arcs': ['b1.fits.gz'], 'flats': ['b11.fits.gz', 'b12.fits.gz', 'b13.fits.gz'], 'bias': ['b21.fits.gz', 'b22.fits.gz', 'b23.fits.gz'], } all_masters = [ 'MasterArc_A_1_01.fits', 'MasterTiltimg_A_1_01.fits', 'MasterBias_A_1_01.fits', 'MasterTilts_A_1_01.fits', 'MasterEdges_A_1_01.fits.gz', 'MasterFlat_A_1_01.fits', 'MasterWaveCalib_A_1_01.json' ] # Just get a few files for ss, sub_files, masters in zip( range(3), [['arcs', 'flats', 'bias'], ['arcs', 'bias'], ['flats', 'bias']], [ all_masters, [ 'MasterArc_A_1_01.fits', 'MasterTiltimg_A_1_01.fits' ], ['MasterEdges_A_1_01.fits.gz'] ]): # Grab the subset files = [] for sub_file in sub_files: files += all_files[sub_file] # testrawdir = os.path.join(rawdir, 'TEST') if os.path.isdir(testrawdir): shutil.rmtree(testrawdir) os.makedirs(testrawdir) for f in files: shutil.copy(os.path.join(rawdir, f), os.path.join(testrawdir, f)) outdir = os.path.join(os.getenv('PYPEIT_DEV'), 'REDUX_OUT_TEST') # For previously failed tests if os.path.isdir(outdir): shutil.rmtree(outdir) # Run the setup sargs = setup.parser([ '-r', testrawdir, '-s', 'shane_kast_blue', '-c all', '-o', '--output_path', outdir ]) setup.main(sargs) # Change to the configuration directory and set the pypeit file configdir = os.path.join(outdir, 'shane_kast_blue_A') pyp_file = os.path.join(configdir, 'shane_kast_blue_A.pypeit') assert os.path.isfile(pyp_file), 'PypeIt file not written.' # Perform the calib-only reduction pargs = run_pypeit.parser([pyp_file, '-c', '-r', configdir]) run_pypeit.main(pargs) # Test! for master_file in masters: assert os.path.isfile( os.path.join(configdir, 'Masters', master_file)), 'Master File {:s} missing!'.format( master_file) # Clean-up shutil.rmtree(outdir) shutil.rmtree(testrawdir)
def test_run_pypeit(): # Get the directories rawdir = os.path.join(os.environ['PYPEIT_DEV'], 'RAW_DATA', 'shane_kast_blue', '600_4310_d55') assert os.path.isdir(rawdir), 'Incorrect raw directory' # Just get a few files testrawdir = os.path.join(rawdir, 'TEST') if os.path.isdir(testrawdir): shutil.rmtree(testrawdir) os.makedirs(testrawdir) files = [ 'b21.fits.gz', 'b22.fits.gz', 'b23.fits.gz', 'b27.fits.gz', 'b1.fits.gz', 'b11.fits.gz', 'b12.fits.gz', 'b13.fits.gz' ] for f in files: shutil.copy(os.path.join(rawdir, f), os.path.join(testrawdir, f)) outdir = os.path.join(os.getenv('PYPEIT_DEV'), 'REDUX_OUT_TEST') # For previously failed tests if os.path.isdir(outdir): shutil.rmtree(outdir) # Run the setup sargs = setup.parser([ '-r', testrawdir, '-s', 'shane_kast_blue', '-c all', '-o', '--output_path', outdir ]) setup.main(sargs) # Change to the configuration directory and set the pypeit file configdir = os.path.join(outdir, 'shane_kast_blue_A') pyp_file = os.path.join(configdir, 'shane_kast_blue_A.pypeit') assert os.path.isfile(pyp_file), 'PypeIt file not written.' # Try to run with -m and -o pargs = run_pypeit.parser([pyp_file, '-o', '-m', '-r', configdir]) run_pypeit.main(pargs) # #########################################################33 # Test!! # Files exist assert os.path.isfile( os.path.join(configdir, 'Science', 'spec2d_b27-J1217p3905_KASTb_2015May20T045733.560.fits')) # spec1d spec1d_file = os.path.join( configdir, 'Science', 'spec1d_b27-J1217p3905_KASTb_2015May20T045733.560.fits') assert os.path.isfile(spec1d_file) specObjs = specobjs.SpecObjs.from_fitsfile(spec1d_file) # Flexure assert specObjs[0].FLEX_SHIFT != 0., 'Flexure not calculated!' # Helio assert specObjs[0].VEL_CORR != 0., 'Heliocentric not calculated!' # Now re-use those master files pargs = run_pypeit.parser([pyp_file, '-o', '-m', '-r', configdir]) run_pypeit.main(pargs) # Clean-up shutil.rmtree(outdir) shutil.rmtree(testrawdir)