Exemplo n.º 1
0
def test_pix_to_shapely(region):
    try:
        from shapely.geometry.base import BaseGeometry
        shape = region.to_shapely()
        assert isinstance(shape, BaseGeometry)
    except NotImplementedError:
        pytest.xfail()
Exemplo n.º 2
0
def test_pix_to_mask(region, mode):
    try:
        mask = region.to_mask(mode=mode)
        assert isinstance(mask, np.ndarray)
        assert mask.ndim == 2
    except NotImplementedError:
        pytest.xfail()
Exemplo n.º 3
0
    def test_searches(self):
        tab_2 = conesearch.conesearch(SCS_CENTER,
                                      SCS_RADIUS,
                                      catalog_db=self.url,
                                      pedantic=self.pedantic,
                                      verbose=self.verbose)

        tab_3 = conesearch.conesearch(SCS_CENTER,
                                      SCS_RADIUS,
                                      catalog_db=[self.catname, self.url],
                                      pedantic=self.pedantic,
                                      verbose=self.verbose)

        tab_4 = conesearch.conesearch(
            SCS_CENTER,
            SCS_RADIUS,
            catalog_db=vos_catalog.get_remote_catalog_db(
                conf.conesearch_dbname),
            pedantic=self.pedantic,
            verbose=self.verbose)

        assert tab_2.url == tab_3.url
        np.testing.assert_array_equal(tab_2.array, tab_3.array)

        # If this fails, it is because of dict hashing, no big deal.
        if tab_2.url == tab_4.url:
            np.testing.assert_array_equal(tab_2.array, tab_4.array)
        else:
            pytest.xfail('conesearch_simple.json used a different URL')
Exemplo n.º 4
0
    def test_obs_flux(self, fluxtype, thresh=0.01):
        """Test flux for observation in PHOTLAM."""
        wave = self.obsref.wave
        flux = self.obs(wave).value

        # Native
        if fluxtype == 'zero':
            self._compare_zero(flux, self.obsref.flux, thresh=thresh)
        else:  # nonzero
            self._compare_nonzero(flux, self.obsref.flux, thresh=thresh)

        if not self._has_obswave:  # Do not compare binned flux
            return

        # Binned (cannot be resampled)
        binflux = self.obs.binflux.value
        if fluxtype == 'zero':
            self._compare_zero(binflux, self.obsref.binflux, thresh=thresh)
        else:  # nonzero
            try:
                self._compare_nonzero(binflux,
                                      self.obsref.binflux,
                                      thresh=thresh)
            except AssertionError as e:
                if 'unit(' in self.spectrum:
                    pytest.xfail('Flat does not use default waveset anymore:\n'
                                 '{0}'.format(str(e)))
                else:
                    raise
Exemplo n.º 5
0
def test_pix_to_shapely(region):
    try:
        from shapely.geometry.base import BaseGeometry
        shape = region.to_shapely()
        assert isinstance(shape, BaseGeometry)
    except NotImplementedError:
        pytest.xfail()
Exemplo n.º 6
0
def test_pix_to_mask(region, mode):
    try:
        mask = region.to_mask(mode=mode)
        assert isinstance(mask, np.ndarray)
        assert mask.ndim == 2
    except NotImplementedError:
        pytest.xfail()
Exemplo n.º 7
0
 def _compare_zero(self, new, old, thresh=0.01):
     """Special handling for comparison when one of the results
     is zero. This is because ``rtol`` will not work."""
     i = ((new == 0) | (old == 0)) & (new != old)
     try:
         self._assert_allclose(new[i], old[i], rtol=thresh)
     except AssertionError as e:
         pytest.xfail(str(e))  # TODO: Will revisit later
Exemplo n.º 8
0
def compare_xid_data(xid, data):
    if six.PY3:
        pytest.xfail('xid/data comparison fails in PY3 because the instrument '
                     'column is bytes in xid and str in data')
    else:
        for col in xid.colnames:
            if xid[col].dtype.type is np.string_:
                assert xid[col] == data[col]
            else:
                assert_allclose(xid[col], data[col])
Exemplo n.º 9
0
def compare_xid_data(xid, data):
    if six.PY3:
        pytest.xfail('xid/data comparison fails in PY3 because the instrument '
                     'column is bytes in xid and str in data')
    else:
        for col in xid.colnames:
            if xid[col].dtype.type is np.string_:
                assert xid[col] == data[col]
            else:
                assert_allclose(xid[col], data[col])
Exemplo n.º 10
0
    def test_extrap_mjd(self, interpval, ans):
        """Test extrapolation without using default column."""
        try:
            sp = spectrum.interpolate_spectral_element(self.fname_cos,
                                                       interpval)
        except RuntimeError:
            if _IS_PY32:
                pytest.xfail('python3.2 urllib bug')
            else:
                raise

        w = sp.waveset[400:3000:500]
        np.testing.assert_allclose(sp(w).value, ans, rtol=1e-5)
Exemplo n.º 11
0
    def test_uresp(self, obsmode, ans):
        """Unit response for different detector settings."""
        try:
            obs = spectrum.band(obsmode, graphtable=GT_FILE, comptable=CP_FILE)
        except RuntimeError:
            if _IS_PY32:
                pytest.xfail('python3.2 urllib bug')
            else:
                raise

        np.testing.assert_allclose(obs.unit_response(obs.area).value,
                                   ans,
                                   rtol=1e-4)
Exemplo n.º 12
0
    def test_spec_wave(self, thresh=0.01):
        """Test source spectrum waveset."""
        wave = self._get_new_wave(self.sp)

        # TODO: Failure due to different wavesets for blackbody; Ignore?
        try:
            self._assert_allclose(wave, self.spref.wave, rtol=thresh)
        except (AssertionError, ValueError) as e:
            self._has_obswave = False  # Skip obs waveset tests
            if 'bb(' in self.spectrum:
                pytest.xfail('Blackbody waveset implementations are different')
            elif 'unit(' in self.spectrum:
                pytest.xfail('Flat does not use default waveset anymore')
            else:
                raise
Exemplo n.º 13
0
def test_write_eps(tmpdir, format):
    filename = os.path.join(str(tmpdir), 'test_output.eps')
    data = np.zeros((16, 16))
    f = FITSFigure(data)
    f.show_grayscale()
    try:
        f.save(filename, format=format)
    except TypeError:
        pytest.xfail()
    finally:
        f.close()
    if format is None:
        assert is_format(filename, 'eps')
    else:
        assert is_format(filename, format)
Exemplo n.º 14
0
    def conesearch_compare(self, xmlfile, msg):
        """
        Bypassing Cone Search query and just imitating the reply,
        then check if appropriate error message is caught.
        """
        # conesearch_error4.xml is a wont-fix for now
        if xmlfile == 'conesearch_error4.xml':
            pytest.xfail('Currently not supported, '
                         'see astropy.io.votable.exceptions.W22')

        url = get_pkg_data_filename(os.path.join(self.datadir, xmlfile))
        try:
            vos_catalog._vo_service_request(url, self.pedantic, {})
        except VOSError as e:
            assert msg in str(e)
Exemplo n.º 15
0
    def test_async(self):
        async_search = conesearch.AsyncConeSearch(SCS_CENTER,
                                                  SCS_RADIUS,
                                                  pedantic=self.pedantic)

        # Wait a little for the instance to set up properly
        time.sleep(1)

        tab = async_search.get(timeout=data.conf.remote_timeout)

        try:
            assert async_search.done()
        except AssertionError as exc:
            pytest.xfail(str(exc))
        else:
            assert tab.array.size > 0
Exemplo n.º 16
0
    def test_to_yt(self, tmpdir, grid_type):

        from yt.mods import ProjectionPlot

        g = self.grid[grid_type]
        g['density'] = []
        g['density'].append(self.density[grid_type])
        pf = g.to_yt()

        # TEMP: xfail due to bug in yt
        # https://bitbucket.org/yt_analysis/yt/pull-requests/2362/fix-type-issue-in-octree-construction/diff
        if grid_type == 'oct':
            pytest.xfail()

        p = ProjectionPlot(pf, 'x', ["density"], center='c', origin='native')
        p.save(tmpdir.join('test.png').strpath)
Exemplo n.º 17
0
def test_write_stringio(tmpdir, format):
    s = StringIO()
    data = np.zeros((16, 16))
    f = FITSFigure(data)
    f.show_grayscale()
    try:
        f.save(s, format=format)
    except TypeError:
        pytest.xfail()
    finally:
        f.close()
    s.seek(0)
    if format is None:
        assert is_format(s, 'png')
    else:
        assert is_format(s, format)
Exemplo n.º 18
0
def test_write_stringio(tmpdir, format):
    s = StringIO()
    data = np.zeros((16, 16))
    f = FITSFigure(data)
    f.show_grayscale()
    try:
        f.save(s, format=format)
    except TypeError:
        pytest.xfail()
    finally:
        f.close()
    s.seek(0)
    if format is None:
        assert is_format(s, 'png')
    else:
        assert is_format(s, format)
Exemplo n.º 19
0
def test_arithmetic_ops(op2):
    if not MIN_VERSIONS['NUMPY_1_10'] and isinstance(op2, np.ma.MaskedArray):
        pytest.xfail("masked arrays didn't respect numpy priority yet...")

    ndd = create_ndd()
    compare_ndd_identical(ndd.add(op2),      ndd + op2)
    compare_ndd_identical(ndd.subtract(op2), ndd - op2)
    compare_ndd_identical(ndd.multiply(op2), ndd * op2)
    compare_ndd_identical(ndd.divide(op2),   ndd / op2)
    compare_ndd_identical(ndd.power(op2),    ndd ** op2)

    # and reverse
    compare_ndd_identical(ndd.add(op2, ndd),      op2 + ndd)
    compare_ndd_identical(ndd.subtract(op2, ndd), op2 - ndd)
    compare_ndd_identical(ndd.multiply(op2, ndd), op2 * ndd)
    compare_ndd_identical(ndd.divide(op2, ndd),   op2 / ndd)
    compare_ndd_identical(ndd.power(op2, ndd),    op2 ** ndd)
Exemplo n.º 20
0
    def test_async_all(self):
        async_search_all = conesearch.AsyncSearchAll(SCS_CENTER,
                                                     SCS_RADIUS,
                                                     pedantic=self.pedantic)

        # Wait a little for the instance to set up properly
        time.sleep(1)

        all_results = async_search_all.get(timeout=data.conf.remote_timeout *
                                           3)

        try:
            assert async_search_all.done()
        except AssertionError as exc:
            pytest.xfail(str(exc))
        else:
            for tab in all_results.values():
                assert tab.array.size > 0
Exemplo n.º 21
0
def test_gtanalysis_sed(create_diffuse_dir, create_draco_analysis):
    gta = create_draco_analysis
    gta.load_roi('fit1')
    np.random.seed(1)
    gta.simulate_roi()

    params = gta.roi['draco'].params

    prefactor = 3E-12
    index = 1.9
    scale = params['Scale']['value']
    emin = gta.energies[:-1]
    emax = gta.energies[1:]

    flux_true = spectrum.PowerLaw.eval_flux(emin, emax, [prefactor, -index],
                                            scale)

    gta.simulate_source({
        'SpatialModel': 'PointSource',
        'Index': index,
        'Scale': scale,
        'Prefactor': prefactor
    })

    gta.free_source('draco')
    gta.fit()

    o = gta.sed('draco', make_plots=True)

    flux_resid = (flux_true - o['flux']) / o['flux_err']
    assert_allclose(flux_resid, 0, atol=3.0)

    params = gta.roi['draco'].params
    index_resid = (-params['Index']['value'] - index) / \
        params['Index']['error']
    assert_allclose(index_resid, 0, atol=3.0)

    prefactor_resid = (params['Prefactor']['value'] -
                       prefactor) / params['Prefactor']['error']
    try:
        assert_allclose(prefactor_resid, 0, atol=3.0)
        gta.simulate_roi(restore=True)
    except AssertionError:
        pytest.xfail("Known issue with fit stability in macos")
Exemplo n.º 22
0
    def test_therm_spec(self, fluxtype, thresh=0.01):
        """Test bandpass thermal spectrum."""
        thspref = self.bpref.obsmode.ThermalSpectrum()
        thsp = self.bp.obsmode.thermal_spectrum()

        # Make sure comparing same units
        thspref.convert(thsp._internal_wave_unit.name)
        thspref.convert(thsp._internal_flux_unit.name)

        # waveset not expected to be same here, so just compare flux
        flux = thsp(thspref.wave).value
        if fluxtype == 'zero':
            self._compare_zero(flux, thspref.flux, thresh=thresh)
        else:  # nonzero
            # TODO: Is the refactored version really better?
            try:
                self._compare_nonzero(flux, thspref.flux, thresh=thresh)
            except AssertionError:
                pytest.xfail('New thermal spectrum samples better')
Exemplo n.º 23
0
    def test_reference_file(filename):
        basename = os.path.basename(filename)

        known_fail = False
        if sys.version_info[:2] == (2, 6):
            known_fail = (basename in ('complex.asdf', 'unicode_spp.asdf'))
        elif sys.version_info[:2] == (2, 7):
            known_fail = (basename in ('complex.asdf'))

        try:
            with open(filename) as asdf:
                asdf.resolve_and_inline()

                with open(filename[:-4] + "yaml") as ref:
                        assert_tree_match(asdf.tree, ref.tree, 'assert_allclose')
        except:
            if known_fail:
                pytest.xfail()
            else:
                raise
Exemplo n.º 24
0
    def test_reference_file(filename):
        basename = os.path.basename(filename)

        known_fail = False
        if sys.version_info[:2] == (2, 6):
            known_fail = (basename in ('complex.asdf', 'unicode_spp.asdf'))
        elif sys.version_info[:2] == (2, 7):
            known_fail = (basename in ('complex.asdf'))

        try:
            with open(filename) as asdf:
                asdf.resolve_and_inline()

                with open(filename[:-4] + "yaml") as ref:
                    assert_tree_match(asdf.tree, ref.tree, 'assert_allclose')
        except:
            if known_fail:
                pytest.xfail()
            else:
                raise
Exemplo n.º 25
0
    def test_interp_mjd(self):
        """Test whether the algorithm gets the correct throughput table
        when input value does not correspond to a column and interpolation
        is required.

        """
        try:
            sp = spectrum.interpolate_spectral_element(self.fname_stis, 51000)
        except RuntimeError:
            if _IS_PY32:
                pytest.xfail('python3.2 urllib bug')
            else:
                raise

        np.testing.assert_array_equal(sp.waveset[::25].value, self.wave_stis)
        np.testing.assert_allclose(
            sp(sp.waveset[:10]).value, [
                0, 0.97830353, 0.97830353, 0.97830353, 0.97722476, 0.98524689,
                0.98975077, 0.99019109, 0.98536552, 0.97710241
            ])
        assert sp(sp.waveset[0]) == sp(sp.waveset[-1])
Exemplo n.º 26
0
def test_write_stringio(tmpdir, format):
    s = StringIO()
    data = np.zeros((16, 16))
    f = FITSFigure(data)
    f.show_grayscale()
    try:
        f.save(s, format=format)
    except TypeError:
        pytest.xfail()
    finally:
        f.close()
    try:
        s.seek(0)
    except ValueError:
        if format == 'svg' and sys.version_info[:2] >= (3, 3):
            pytest.xfail()
        else:
            raise
    if format is None:
        assert is_format(s, 'png')
    else:
        assert is_format(s, format)
Exemplo n.º 27
0
    def test_obs_wave(self, thresh=0.01):
        """Test observation waveset."""
        if not self._has_obswave:  # Nothing to test
            return

        # Native
        wave = self.obs.waveset.value

        # TODO: Failure due to different wavesets for blackbody; Ignore?
        try:
            self._assert_allclose(wave, self.obsref.wave, rtol=thresh)
        except (AssertionError, ValueError) as e:
            if 'bb(' in self.spectrum:
                pytest.xfail('Blackbody waveset implementations are different')
            elif 'unit(' in self.spectrum:
                self._has_obswave = False  # Skip binned flux test
                pytest.xfail('Flat does not use default waveset anymore')
            else:
                raise

        # Binned
        binset = self.obs.binset.value
        self._assert_allclose(binset, self.obsref.binwave, rtol=thresh)
Exemplo n.º 28
0
def test_arithmetic_ops_optional_kwargs(op2):
    if not MIN_VERSIONS['NUMPY_1_10'] and isinstance(op2, np.ma.MaskedArray):
        pytest.xfail("masked arrays didn't respect numpy priority yet...")

    ndd = create_ndd()

    # Let us test the context manager ... to change the defaults.
    with ContextArithmeticDefaults() as d:
        d['handle_mask'] = None
        d['propagate_uncertainties'] = None

        opkwargs = {'handle_mask': None, 'propagate_uncertainties': None}
        compare_ndd_identical(ndd.add(op2, **opkwargs),      ndd + op2)
        compare_ndd_identical(ndd.subtract(op2, **opkwargs), ndd - op2)
        compare_ndd_identical(ndd.multiply(op2, **opkwargs), ndd * op2)
        compare_ndd_identical(ndd.divide(op2, **opkwargs),   ndd / op2)
        compare_ndd_identical(ndd.power(op2, **opkwargs),    ndd ** op2)

        # and reverse
        compare_ndd_identical(ndd.add(op2, ndd, **opkwargs),      op2 + ndd)
        compare_ndd_identical(ndd.subtract(op2, ndd, **opkwargs), op2 - ndd)
        compare_ndd_identical(ndd.multiply(op2, ndd, **opkwargs), op2 * ndd)
        compare_ndd_identical(ndd.divide(op2, ndd, **opkwargs),   op2 / ndd)
        compare_ndd_identical(ndd.power(op2, ndd, **opkwargs),    op2 ** ndd)
Exemplo n.º 29
0
def test_castro_test_spectra_yaml(yamlfile):
    # There is a bug in numpy that won't let it read back the yaml file we are using for
    # this test in python 3.
    # Catch this for now
    try:
        c = castro.CastroData.create_from_yamlfile(yamlfile)
    except Exception:
        pytest.xfail("Known issue with numpy/pyyaml")

    test_dict = c.test_spectra()

    assert_allclose(test_dict['PowerLaw']['TS'][0], 0.0, atol=0.01)
    assert_allclose(test_dict['LogParabola']['TS'][0], 0.01304611, atol=0.01)
    assert_allclose(test_dict['PLExpCutoff']['TS'][0], 0.33051415, atol=0.01)

    assert_allclose(test_dict['PowerLaw']['Result'],
                    np.array([0.0, -3.44375000e+00]),
                    atol=0.01)
    assert_allclose(test_dict['LogParabola']['Result'],
                    np.array([0.0, -2.70092870e+00, 1.73633042e-03]),
                    atol=0.01)
    assert_allclose(test_dict['PLExpCutoff']['Result'],
                    np.array([0.0, -1.00927917e+00, 7.18812858e+02]),
                    atol=0.01)
Exemplo n.º 30
0
def test_pix_area(region):
    try:
        area = region.area
        assert not isinstance(area, u.Quantity)
    except NotImplementedError:
        pytest.xfail()
Exemplo n.º 31
0
def test_pix_to_sky(region, mode):
    try:
        sky_region = region.to_sky(COMMON_WCS, mode=mode)
        assert isinstance(sky_region, SkyRegion)
    except NotImplementedError:
        pytest.xfail()
Exemplo n.º 32
0
def test_sky_to_pix(region, mode):
    try:
        pix_region = region.to_pixel(mode=mode, wcs=COMMON_WCS)
        assert isinstance(pix_region, PixelRegion)
    except NotImplementedError:
        pytest.xfail()
Exemplo n.º 33
0
def _compare_xid_data(xid ,data):
    if six.PY3:
        pytest.xfail('xid/data comparison fails in PY3 because the instrument column is bytes in xid and str in data')
    else:
        return all(xid == data)
Exemplo n.º 34
0
def test_pix_to_sky(region, mode):
    try:
        sky_region = region.to_sky(COMMON_WCS, mode=mode)
        assert isinstance(sky_region, SkyRegion)
    except NotImplementedError:
        pytest.xfail()
Exemplo n.º 35
0
def test_pix_area(region):
    try:
        area = region.area
        assert not isinstance(area, u.Quantity)
    except NotImplementedError:
        pytest.xfail()
Exemplo n.º 36
0
def test_pix_in(region):
    try:
        PixCoord(1, 1) in region
    except NotImplementedError:
        pytest.xfail()
Exemplo n.º 37
0
def test_sky_to_pix(region, mode):
    try:
        pix_region = region.to_pixel(mode=mode, wcs=COMMON_WCS)
        assert isinstance(pix_region, PixelRegion)
    except NotImplementedError:
        pytest.xfail()
Exemplo n.º 38
0
def test_sky_in(region):
    try:
        ICRS(1 * u.deg, 1 * u.deg) in region
    except NotImplementedError:
        pytest.xfail()
Exemplo n.º 39
0
def test_pix_in(region):
    try:
        PixCoord(1, 1) in region
    except NotImplementedError:
        pytest.xfail()
Exemplo n.º 40
0
def _url_tester(dr):
    if dr < 11:
        pytest.xfail('DR<12 not yet supported')
        assert sdss.core.SDSS._last_url == 'http://skyserver.sdss.org/dr' + str(dr) + '/en/tools/search/sql.asp'
    if dr == 12:
        assert sdss.core.SDSS._last_url == 'http://skyserver.sdss.org/dr12/en/tools/search/x_sql.aspx'
Exemplo n.º 41
0
 def test_isfile(self):
     if self.vegafile.startswith('ftp'):
         # This is the case on Travis CI
         pytest.xfail('Cannot test this over FTP')
     else:
         assert os.path.isfile(self.vegafile)
Exemplo n.º 42
0
def test_pix_to_mask(region, mode):
    try:
        mask = region.to_mask(mode=mode)
        assert isinstance(mask, Mask)
    except NotImplementedError:
        pytest.xfail()
Exemplo n.º 43
0
def test_pix_area(region):
    try:
        area = region.area
        assert not isinstance(area, u.Quantity)
    except AttributeError:
        pytest.xfail()
Exemplo n.º 44
0
def test_sky_in(region):
    try:
        ICRS(1 * u.deg, 1 * u.deg) in region
    except NotImplementedError:
        pytest.xfail()