Exemplo n.º 1
0
def test_catalogs_query_region(patch_post):
    result = mast.Catalogs.query_region(regionCoords, radius=0.002 * u.deg)
    assert isinstance(result, Table)

    result = mast.Catalogs.query_region(regionCoords, radius=0.002 * u.deg, catalog="hsc", version=2)
    assert isinstance(result, Table)

    with pytest.warns(InputWarning) as i_w:
        mast.Catalogs.query_region(regionCoords, radius=0.002 * u.deg, catalog="hsc", version=5)
    assert "Invalid HSC version number" in str(i_w[0].message)

    result = mast.Catalogs.query_region(regionCoords, radius=0.002 * u.deg, catalog="galex")
    assert isinstance(result, Table)

    result = mast.Catalogs.query_region(regionCoords, radius=0.002 * u.deg, catalog="gaia", version=2)
    assert isinstance(result, Table)

    result = mast.Catalogs.query_region(regionCoords, radius=0.002 * u.deg, catalog="gaia", version=1)
    assert isinstance(result, Table)

    with pytest.warns(InputWarning) as i_w:
        mast.Catalogs.query_region(regionCoords, radius=0.002 * u.deg, catalog="gaia", version=5)
    assert "Invalid Gaia version number" in str(i_w[0].message)

    result = mast.Catalogs.query_region(regionCoords, radius=0.002 * u.deg, catalog="Sample")
    assert isinstance(result, Table)
Exemplo n.º 2
0
def test_colorbar_location():
    f = FITSFigure(ARRAY)
    f.show_grayscale()
    f.add_colorbar()
    f.colorbar.set_location('top')
    with pytest.warns(UserWarning, match='Bottom colorbar not fully implemented'):
        f.colorbar.set_location('bottom')
    with pytest.warns(UserWarning, match='Left colorbar not fully implemented'):
        f.colorbar.set_location('left')
    f.colorbar.set_location('right')
    f.close()
Exemplo n.º 3
0
def test_colorbar_location():
    f = FITSFigure(ARRAY)
    f.show_grayscale()
    f.add_colorbar()
    f.colorbar.set_location('top')
    with pytest.warns(UserWarning,
                      match='Bottom colorbar not fully implemented'):
        f.colorbar.set_location('bottom')
    with pytest.warns(UserWarning,
                      match='Left colorbar not fully implemented'):
        f.colorbar.set_location('left')
    f.colorbar.set_location('right')
    f.close()
Exemplo n.º 4
0
 def test_lc_keyword_deprecation(self):
     cs1 = AveragedPowerspectrum(self.lc, segment_size=self.lc.tseg)
     with pytest.warns(DeprecationWarning) as record:
         cs2 = AveragedPowerspectrum(lc=self.lc, segment_size=self.lc.tseg)
     assert np.any(['lc keyword' in r.message.args[0] for r in record])
     assert np.allclose(cs1.power, cs2.power)
     assert np.allclose(cs1.freq, cs2.freq)
Exemplo n.º 5
0
def test_observations_query_criteria(patch_post):
    # without position
    result = mast.Observations.query_criteria(dataproduct_type=["image"],
                                              proposal_pi="Ost*",
                                              s_dec=[43.5, 45.5])
    assert isinstance(result, Table)

    # with position
    result = mast.Observations.query_criteria(filters=["NUV", "FUV"],
                                              objectname="M101")
    assert isinstance(result, Table)

    # TEMPORARY test the obstype deprecation
    with catch_warnings(AstropyDeprecationWarning) as warning_lines:
        result = mast.Observations.query_criteria(objectname="M101",
                                                  dataproduct_type="IMAGE",
                                                  obstype="science")
        assert isinstance(result, Table)

    with pytest.warns(InputWarning) as i_w:
        mast.Observations.query_criteria(obstype="science",
                                         intentType="science")
    assert "obstype and intentType" in str(i_w[0].message)

    with pytest.raises(InvalidQueryError) as invalid_query:
        mast.Observations.query_criteria(objectname="M101")
    assert "least one non-positional criterion" in str(invalid_query.value)

    with pytest.raises(InvalidQueryError) as invalid_query:
        mast.Observations.query_criteria(objectname="M101",
                                         coordinates=regionCoords,
                                         intentType="science")
    assert "one of objectname and coordinates" in str(invalid_query.value)
Exemplo n.º 6
0
 def test_event_file_read_xmm(self):
     """Test event file reading."""
     fname = os.path.join(datadir, 'xmm_test.fits')
     with pytest.warns(UserWarning) as record:
         load_events_and_gtis(fname, additional_columns=['PRIOR'])
     assert np.any(["Trying first extension"
             in r.message.args[0] for r in record])
Exemplo n.º 7
0
 def test_event_file_read_additional_warns(self):
     """Test event file reading."""
     fname = os.path.join(datadir, 'monol_testA.evt')
     with pytest.warns(UserWarning) as record:
         load_events_and_gtis(fname, additional_columns=["energy"])
     assert np.any(
         ["Column energy not found" in r.message.args[0] for r in record])
Exemplo n.º 8
0
 def test_lc_keyword_deprecation(self):
     cs1 = Powerspectrum(self.lc, norm="Leahy")
     with pytest.warns(DeprecationWarning) as record:
         cs2 = Powerspectrum(lc=self.lc, norm="Leahy")
     assert np.any(['lc keyword' in r.message.args[0] for r in record])
     assert np.allclose(cs1.power, cs2.power)
     assert np.allclose(cs1.freq, cs2.freq)
 def test_cov_invalid_evlist_warns(self):
     ev = EventList(time=[], energy=[], gti=self.test_ev1.gti)
     with pytest.warns(UserWarning) as record:
         rms = CovarianceSpectrum(ev, [0.0, 100], (0.3, 12, 5, "lin"),
                                  bin_time=0.01,
                                  segment_size=100)
     assert np.all(np.isnan(rms.spectrum))
     assert np.all(np.isnan(rms.spectrum_error))
Exemplo n.º 10
0
 def test_lc_keyword_deprecation(self):
     mtp1 = Multitaper(self.lc)
     with pytest.warns(DeprecationWarning) as record:
         mtp2 = Multitaper(lc=self.lc)
     assert np.any(['lc keyword' in r.message.args[0]
                    for r in record])
     assert np.allclose(mtp1.power, mtp2.power)
     assert np.allclose(mtp1.freq, mtp2.freq)
Exemplo n.º 11
0
 def test_read_from_lcurve_1(self):
     fname = 'lcurveA.fits'
     with pytest.warns(UserWarning):
         lc = Lightcurve.read(os.path.join(datadir, fname),
                              format_='hea',
                              skip_checks=True)
     ctrate = 1
     assert np.isclose(lc.countrate[0], ctrate)
Exemplo n.º 12
0
    def test_no_counts_warns(self):
        newlc = copy.deepcopy(self.lc)
        newlc.counts[:newlc.counts.size // 2] = \
            0 * newlc.counts[:newlc.counts.size // 2]

        with pytest.warns(UserWarning) as record:
            ps = AveragedPowerspectrum(newlc, 0.2)

        assert np.any(["No counts in " in r.message.args[0] for r in record])
Exemplo n.º 13
0
    def test_read_from_lcurve_2(self):
        fname = 'lcurve_new.fits'
        with pytest.warns(UserWarning):
            lc = Lightcurve.read(os.path.join(datadir, fname),
                                 format_='hea',
                                 skip_checks=True)
        ctrate = 0.91

        assert np.isclose(lc.countrate[0], ctrate)
        assert np.isclose(lc.mjdref, 55197.00076601852)
Exemplo n.º 14
0
    def test_lag_invalid_evlist_warns(self):
        ev = EventList(time=[], energy=[], gti=self.lag.events1.gti)
        with pytest.warns(UserWarning) as record:
            lag = LagEnergySpectrum(ev, [0., 0.5], (0.3, 9, 4, "lin"), [9, 12],
                                    bin_time=0.1,
                                    segment_size=30,
                                    events2=self.lag.events2)

        assert np.allclose(lag.spectrum, 0)
        assert np.allclose(lag.spectrum_error, 0)
Exemplo n.º 15
0
 def test_event_file_read_additional_warns_uncal(self):
     """Test event file reading."""
     fname = os.path.join(datadir, 'monol_testA.evt')
     with pytest.warns(UserWarning) as record:
         vals = load_events_and_gtis(fname, additional_columns=["energy"])
     assert np.any(["Column energy not found"
                    in r.message.args[0] for r in record])
     # This is the default calibration for nustar data, as returned
     # from rough_calibration
     assert np.allclose(vals.energy_list, vals.pi_list * 0.04 + 1.6)
Exemplo n.º 16
0
def test_catalogs_query_hsc_matchid_async(patch_post):
    responses = mast.Catalogs.query_hsc_matchid_async(82371983)
    assert isinstance(responses, list)

    responses = mast.Catalogs.query_hsc_matchid_async(82371983, version=2)
    assert isinstance(responses, list)

    with pytest.warns(InputWarning) as i_w:
        mast.Catalogs.query_hsc_matchid_async(82371983, version=5)
    assert "Invalid HSC version number" in str(i_w[0].message)
Exemplo n.º 17
0
    def test_rms_invalid_evlist_warns(self):
        ev = EventList(time=[], energy=[], gti=self.rms.events1.gti)
        with pytest.warns(UserWarning) as record:
            rms = RmsEnergySpectrum(ev, [0., 100], (0.3, 12, 5, "lin"),
                                    bin_time=0.01,
                                    segment_size=100,
                                    events2=self.rms.events2)

        assert np.allclose(rms.spectrum, 0)
        assert np.allclose(rms.spectrum_error, 0)
Exemplo n.º 18
0
    def test_lag_invalid_evlist_warns(self):
        ev = EventList(time=[], energy=[], gti=self.lag.events1.gti)
        with pytest.warns(UserWarning) as record:
            lag = LagEnergySpectrum(ev, [0., 0.5],
                                    (0.3, 9, 4, "lin"), [9, 12],
                                    bin_time=0.1,
                                    segment_size=30,
                                    events2=self.lag.events2)

        assert np.allclose(lag.spectrum, 0)
        assert np.allclose(lag.spectrum_error, 0)
Exemplo n.º 19
0
    def test_rms_invalid_evlist_warns(self):
        ev = EventList(time=[], energy=[], gti=self.rms.events1.gti)
        with pytest.warns(UserWarning) as record:
            rms = RmsEnergySpectrum(ev, [0., 100],
                                    (0.3, 12, 5, "lin"),
                                    bin_time=0.01,
                                    segment_size=100,
                                    events2=self.rms.events2)

        assert np.allclose(rms.spectrum, 0)
        assert np.allclose(rms.spectrum_error, 0)
Exemplo n.º 20
0
    def test_lc_baseline_offset_fewbins(self):
        times = np.arange(0, 4, 1)
        input_stdev = 0.1
        counts = np.random.normal(100, input_stdev, len(times)) + \
            0.001 * times
        gti = [[-0.005, 4.005]]
        lc = Lightcurve(times, counts, gti=gti)
        with pytest.warns(UserWarning) as record:
            lc.baseline(10000, 0.01, offset_correction=True)

        assert np.any(["Too few bins to perform baseline offset correction"
                       in r.message.args[0] for r in record])
Exemplo n.º 21
0
    def test_subtract_with_different_mjdref(self):
        shift = 86400.  # day
        lc1 = Lightcurve(self.times + shift,
                         self.counts,
                         gti=self.gti + shift,
                         mjdref=57000)
        lc2 = Lightcurve(self.times, self.counts, gti=self.gti, mjdref=57001)
        with pytest.warns(UserWarning) as record:
            newlc = lc1 - lc2
        assert np.any(["MJDref" in r.message.args[0] for r in record])

        assert np.allclose(newlc.counts, 0)
Exemplo n.º 22
0
    def test_lc_baseline_offset_fewbins(self):
        times = np.arange(0, 4, 1)
        input_stdev = 0.1
        counts = np.random.normal(100, input_stdev, len(times)) + \
            0.001 * times
        gti = [[-0.005, 4.005]]
        lc = Lightcurve(times, counts, gti=gti)
        with pytest.warns(UserWarning) as record:
            lc.baseline(10000, 0.01, offset_correction=True)

        assert np.any(["Too few bins to perform baseline offset correction"
                       in r.message.args[0] for r in record])
Exemplo n.º 23
0
def test_psf_photometry_uncertainties_warning_check():
    psf = IntegratedGaussianPRF(sigma=GAUSSIAN_WIDTH)
    with pytest.warns(AstropyUserWarning):
        f = psf_photometry(image, INTAB, psf, fitter=SLSQPLSQFitter(),
                           param_uncert=True)
        assert_equal('flux_fit_uncertainty' in f.colnames or
                     'y_0_fit_uncertainty' in f.colnames or
                     'x_0_fit_uncertainty' in f.colnames, False)
        # test that AstropyUserWarning is raised
        warnings.warn('uncertainties on fitted parameters cannot be '
                      'computed because fitter does not contain '
                      '`param_cov` key in its `fit_info` dictionary.',
                      AstropyUserWarning)
Exemplo n.º 24
0
    def test_make_multitaper_var(self, lightcurve):

        if getattr(self, lightcurve).err_dist == "poisson":
            mtp = Multitaper(getattr(self, lightcurve))
            assert mtp.err_dist == "poisson"
            assert mtp.var == getattr(self, lightcurve).meancounts
        else:
            with pytest.warns(UserWarning) as record:
                mtp = Multitaper(getattr(self, lightcurve))
            assert mtp.err_dist == "gauss"
            assert mtp.var == \
                np.mean(getattr(self, lightcurve).counts_err) ** 2
            assert np.any(["not poisson" in r.message.args[0]
                           for r in record])
Exemplo n.º 25
0
    def test_lagspectrum_invalid_warns(self):
        ev = EventList(time=[], energy=[], gti=self.lag.events1.gti)
        with pytest.warns(UserWarning) as record:
            lag = LagSpectrum(
                ev,
                [0.0, 0.5],
                (0.3, 9, 4, "lin"),
                [9, 12],
                bin_time=0.1,
                segment_size=30,
                events2=self.lag.events2,
            )

        assert np.all(np.isnan(lag.spectrum))
        assert np.all(np.isnan(lag.spectrum_error))
Exemplo n.º 26
0
def test_psf_photometry_uncertainties_warning_check():
    psf = IntegratedGaussianPRF(sigma=GAUSSIAN_WIDTH)
    with pytest.warns(AstropyUserWarning):
        f = psf_photometry(image,
                           INTAB,
                           psf,
                           fitter=SLSQPLSQFitter(),
                           param_uncert=True)
        assert_equal(
            'flux_fit_uncertainty' in f.colnames
            or 'y_0_fit_uncertainty' in f.colnames
            or 'x_0_fit_uncertainty' in f.colnames, False)
        # test that AstropyUserWarning is raised
        warnings.warn(
            'uncertainties on fitted parameters cannot be '
            'computed because fitter does not contain '
            '`param_cov` key in its `fit_info` dictionary.',
            AstropyUserWarning)
Exemplo n.º 27
0
def test_serialize_fits_masked(tmpdir):
    tm = Time([1, 2, 3], format='cxcsec')
    tm[1] = np.ma.masked

    fn = str(tmpdir.join('tempfile.fits'))
    t = Table([tm])
    t.write(fn)

    # Warning is a bug; https://github.com/astropy/astropy/issues/8773
    with pytest.warns(VerifyWarning):
        t2 = Table.read(fn, astropy_native=True)

    # Time FITS handling does not current round-trip format in FITS
    t2['col0'].format = tm.format

    assert t2['col0'].masked
    assert np.all(t2['col0'].mask == [False, True, False])
    assert np.all(t2['col0'].value == t['col0'].value)
Exemplo n.º 28
0
    def test_with_iterable_of_lightcurves(self, legacy):
        def iter_lc(lc, n):
            "Generator of n parts of lc."
            t0 = int(len(lc) / n)
            t = t0
            i = 0
            while (True):
                lc_seg = lc[i:t]
                yield lc_seg
                if t + t0 > len(lc):
                    break
                else:
                    i, t = t, t + t0
        with pytest.warns(UserWarning) as record:
            cs = AveragedPowerspectrum(
                iter_lc(self.lc, 1),
                segment_size=1, legacy=legacy,
                gti=self.lc.gti)
        message = "The averaged Power spectrum from a generator "

        assert np.any([message in r.message.args[0]
                    for r in record])
Exemplo n.º 29
0
    def test_multitaper_lombscargle(self):
        rng = np.random.default_rng()
        N = 1000

        white_noise_irregular = rng.normal(loc=0.0, scale=7, size=N)
        start = 0.0
        end = 9.0

        # Generating uneven sampling times by adding white noise. Do tell a better way
        time_irregular = np.linspace(start, end, N) + rng.normal(loc=0.0,
                                                                 scale=(end-start)/(3*N), size=N)
        time_irregular = np.sort(time_irregular)

        with pytest.warns(UserWarning) as record:
            lc_nonuni = Lightcurve(time=time_irregular,
                                   counts=white_noise_irregular, err_dist="gauss",
                                   err=np.ones_like(time_irregular) + np.sqrt(0.))  # Zero mean
        assert np.any(["aren't equal" in r.message.args[0]
                       for r in record])

        mtls_white = Multitaper(lc_nonuni, lombscargle=True, low_bias=True, NW=4)
        assert mtls_white.norm == "frac"
        assert mtls_white.fullspec is False
        assert mtls_white.meancounts == lc_nonuni.meancounts
        assert mtls_white.nphots == np.float64(np.sum(lc_nonuni.counts))
        assert mtls_white.err_dist == lc_nonuni.err_dist
        assert mtls_white.dt == lc_nonuni.dt
        assert mtls_white.n == lc_nonuni.time.shape[0]
        assert mtls_white.df == 1.0 / lc_nonuni.tseg
        assert mtls_white.m == 1
        assert mtls_white.freq is not None
        assert mtls_white.multitaper_norm_power is not None
        assert mtls_white.power is not None
        assert mtls_white.power_err is not None
        assert mtls_white.jk_var_deg_freedom is None  # Not supported yet
        assert len(mtls_white.eigvals) > 0
Exemplo n.º 30
0
 def test_warn_wrong_keywords(self):
     lc = copy.deepcopy(self.lc)
     with pytest.warns(UserWarning) as record:
         _ = Lightcurve(lc.time, lc.counts, gti=lc.gti, bubu='settete')
     assert np.any(
         ["Unrecognized keywords:" in r.message.args[0] for r in record])
Exemplo n.º 31
0
 def test_max_eigval_less_than_threshold(self, lombscargle):
     with pytest.warns(UserWarning) as record:
         mtp = Multitaper(lc=self.lc, NW=0.5, low_bias=True, lombscargle=lombscargle)
     assert np.any(['not properly use low_bias' in r.message.args[0]
                    for r in record])
     assert len(mtp.eigvals) > 0
Exemplo n.º 32
0
 def test_get_adaptive_psd_with_less_tapers(self):
     with pytest.warns(UserWarning) as record:
         mtp = Multitaper(lc=self.lc, NW=1.5, adaptive=True)
     assert np.any(['Not adaptively' in r.message.args[0]
                    for r in record])
     assert mtp.multitaper_norm_power is not None