Esempio n. 1
0
def test_iers_download_error_handling(tmpdir):
    # Make sure we don't have IERS-A data available anywhere
    with set_temp_cache(tmpdir):
        iers.IERS_A.close()
        iers.IERS_Auto.close()
        iers.IERS.close()
        now = Time.now()

        # bad site name
        with iers.conf.set_temp('iers_auto_url', 'FAIL FAIL'):
            # site that exists but doesn't have IERS data
            with iers.conf.set_temp('iers_auto_url_mirror',
                                    'https://google.com'):
                with pytest.warns(iers.IERSWarning) as record:
                    with iers.conf.set_temp('iers_degraded_accuracy',
                                            'ignore'):
                        (now + 100 * u.day).ut1

                assert len(record) == 3
                assert str(record[0].message).startswith(
                    'failed to download FAIL FAIL: Malformed URL')
                assert str(record[1].message).startswith(
                    'malformed IERS table from https://google.com')
                assert str(record[2].message).startswith(
                    'unable to download valid IERS file, using local IERS-B')
Esempio n. 2
0
def test_apVisit_loader(tmpdir):
    apvisit_url = ("https://data.sdss.org/sas/dr16/apogee/spectro/redux/r12/"
                   "visit/apo25m/N7789/5094/55874/"
                   "apVisit-r12-5094-55874-123.fits")
    with set_temp_cache(path=str(tmpdir)):
        filename = download_file(apvisit_url, cache=True)
        spectrum = apVisit_loader(filename)  # noqa
Esempio n. 3
0
def download_dbase(ascii_dbase_root, version=None, ask_before=True):
    """
    Download the database if it does not exist locally.
    """
    # VERSION file as a proxy for whether whole dbase exists
    # TODO: version checking, download newest version if installed version is out of date
    if os.path.isfile(os.path.join(ascii_dbase_root, 'VERSION')):
        return None
    if version is None:
        dbase_url = CHIANTI_URL.format(version=LATEST_VERSION)
    else:
        dbase_url = CHIANTI_URL.format(version=version)
    if ask_before:
        question = f"No CHIANTI database found at {ascii_dbase_root}. Download it from {dbase_url}?"
        answer = query_yes_no(question, default='no')
        if not answer:
            return None

    # Download and extract
    tar_tmp_dir = os.path.join(FIASCO_HOME, 'tmp')
    if not os.path.exists(tar_tmp_dir):
        os.makedirs(tar_tmp_dir)
    with set_temp_cache(path=tar_tmp_dir, delete=True):
        tmp_tar = download_file(dbase_url, cache=True, show_progress=True)
        with tarfile.open(tmp_tar) as tar:
            tar.extractall(path=ascii_dbase_root)
Esempio n. 4
0
def download_dbase(ascii_dbase_url, ascii_dbase_root):
    """
    Download the CHIANTI database in ASCII format
    """
    tar_tmp_dir = os.path.join(FIASCO_HOME, 'tmp')
    if not os.path.exists(tar_tmp_dir):
        os.makedirs(tar_tmp_dir)
    with set_temp_cache(path=tar_tmp_dir, delete=True):
        tmp_tar = download_file(ascii_dbase_url,
                                cache=True,
                                show_progress=True)
        with tarfile.open(tmp_tar) as tar:
            tar.extractall(path=ascii_dbase_root)
Esempio n. 5
0
def test_iers_out_of_range_handling(tmpdir):
    # Make sure we don't have IERS-A data available anywhere
    with set_temp_cache(tmpdir):
        iers.IERS_A.close()
        iers.IERS_Auto.close()
        iers.IERS.close()
        now = Time.now()
        with iers.conf.set_temp('auto_download', False):
            # Should be fine with built-in IERS_B
            (now - 300 * u.day).ut1

            # Default is to raise an error
            match = r'\(some\) times are outside of range covered by IERS table'
            with pytest.raises(iers.IERSRangeError, match=match):
                (now + 100 * u.day).ut1

            with iers.conf.set_temp('iers_degraded_accuracy', 'warn'):
                with pytest.warns(iers.IERSDegradedAccuracyWarning,
                                  match=match):
                    (now + 100 * u.day).ut1

            with iers.conf.set_temp('iers_degraded_accuracy', 'ignore'):
                (now + 100 * u.day).ut1
Esempio n. 6
0
def test_aspcapStar_loader(tmpdir):
    aspcap_url = ("https://data.sdss.org/sas/dr16/apogee/spectro/aspcap/r12/"
                  "l33/apo25m/N7789/aspcapStar-r12-2M00005414+5522241.fits")
    with set_temp_cache(path=str(tmpdir)):
        filename = download_file(aspcap_url, cache=True)
        spectrum = aspcapStar_loader(filename)  # noqa