def test_solve_field_unsolved(unsolved_fits_file):
    with pytest.raises(KeyError):
        fits_utils.getval(unsolved_fits_file, 'WCSAXES')

    assert 'crpix0' not in fits_utils.get_wcsinfo(unsolved_fits_file)

    proc = fits_utils.solve_field(unsolved_fits_file)
    assert isinstance(proc, subprocess.Popen)
    proc.wait()
    try:
        outs, errs = proc.communicate(timeout=15)
    except subprocess.TimeoutExpired:
        proc.kill()
        outs, errs = proc.communicate()

    assert proc.returncode == 0, f'{outs}\n{errs}'

    wcs_info = fits_utils.get_wcsinfo(
        unsolved_fits_file.replace('.fits', '.new'))
    assert 'crpix0' in wcs_info
    assert wcs_info['crpix0'] == 350.5 * u.pixel

    for ext in ['.wcs', '.new']:
        with suppress(FileNotFoundError):
            os.remove(unsolved_fits_file.replace('.fits', ext))
Beispiel #2
0
def test_save_rgb_bg_fits(solved_fits_file, tmpdir):
    d0, h0 = fits_utils.getdata(solved_fits_file, header=True)

    temp_fn = tmpdir / 'temp.fits'

    h0['test'] = True

    rgb_data = bayer.get_rgb_background(d0, return_separate=True)
    bayer.save_rgb_bg_fits(rgb_data,
                           output_filename=str(temp_fn),
                           header=h0,
                           fpack=False)
    assert fits_utils.getval(str(temp_fn), 'test') is True

    with pytest.raises(OSError):
        bayer.save_rgb_bg_fits(rgb_data,
                               output_filename=str(temp_fn),
                               header=h0,
                               fpack=False,
                               overwrite=False)

    temp_fn = bayer.save_rgb_bg_fits(rgb_data,
                                     output_filename=str(temp_fn),
                                     fpack=True,
                                     overwrite=True)

    # Didn't use our header.
    with pytest.raises(KeyError):
        fits_utils.getval(str(temp_fn), 'test')
def test_getval(solved_fits_file):
    img_id = fits_utils.getval(solved_fits_file, 'IMAGEID')
    assert img_id == 'PAN001_XXXXXX_20160909T081152'