def test_run_pypeit(): # Just get a few files testrawdir = data_path('') outdir = data_path('REDUX_OUT_TEST') # For previously failed tests if os.path.isdir(outdir): shutil.rmtree(outdir) # Run the setup sargs = Setup.parse_args([ '-r', testrawdir + 'b', '-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 = RunPypeIt.parse_args([pyp_file, '-o', '-m', '-r', configdir]) RunPypeIt.main(pargs) # TODO: Add some code that will try to open the QA HTML and check that it # has the correct PNGs in it. # ######################################################### # Test!! # Files exist spec1d_file = os.path.join( configdir, 'Science', 'spec1d_b27-J1217p3905_KASTb_20150520T045733.560.fits') assert os.path.isfile(spec1d_file), 'spec1d file missing' # spec1d specObjs = specobjs.SpecObjs.from_fitsfile(spec1d_file) # Check RMS assert specObjs[ 0].WAVE_RMS < 0.02 # difference must be less than 0.02 pixels # Flexure assert abs(-0.03 - specObjs[0].FLEX_SHIFT_TOTAL ) < 0.1 # difference must be less than 0.1 pixels # Helio assert abs(specObjs[0].VEL_CORR - 0.9999261685542624) < 1.0E-10 # Now re-use those master files pargs = RunPypeIt.parse_args([pyp_file, '-o', '-r', configdir]) RunPypeIt.main(pargs) # Clean-up shutil.rmtree(outdir)
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'][np.where(~indx) [0]][0] == -1, 'Incorrect combination group ID' shutil.rmtree(config_dir)
def test_setup_keck_lris_red_mark4(): droot = os.path.join(os.environ['PYPEIT_DEV'], 'RAW_DATA/keck_lris_red_mark4/long_400_8500_d560') droot += '/' pargs = Setup.parse_args(['-r', droot, '-s', 'keck_lris_red_mark4']) 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_mark4*')) 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_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_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 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.parse_args(['-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.parse_args(['-r', droot, '-s', 'shane_kast_blu', '-c=all', '--extension=fits.gz', '--output_path={:s}'.format(data_path(''))]) with pytest.raises(ValueError): Setup.main(pargs2) # Cleanup shutil.rmtree(data_path('setup_files'))
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 = ChkForCalibs.parse_args([droot, '-s', 'vlt_fors2']) answers, ps = ChkForCalibs.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' master_key = 'A_1_DET01' # 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 = [ f'MasterArc_{master_key}.fits', f'MasterTiltimg_{master_key}.fits', f'MasterBias_{master_key}.fits', f'MasterTilts_{master_key}.fits', f'MasterEdges_{master_key}.fits.gz', f'MasterFlat_{master_key}.fits', f'MasterWaveCalib_{master_key}.fits' ] # Just get a few files for ss, sub_files, masters in zip(range(3), [[ 'arcs', 'flats', 'bias' ], ['arcs', 'bias'], ['flats', 'bias']], [ all_masters, [f'MasterArc_{master_key}.fits', f'MasterTiltimg_{master_key}.fits'], [f'MasterEdges_{master_key}.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.parse_args([ '-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 = RunPypeIt.parse_args([pyp_file, '-c', '-r', configdir]) RunPypeIt.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) # Now test parse_calib_id if ss == 0: pargs2 = ParseCalibID.parse_args([pyp_file]) calib_dict = ParseCalibID.main(pargs2) assert isinstance(calib_dict, dict) assert len(calib_dict) > 0 assert calib_dict['1'][master_key]['arc']['raw_files'][ 0] == 'b1.fits.gz' # Clean-up shutil.rmtree(outdir) shutil.rmtree(testrawdir)