Commit 37a3ba0d authored by Ole Streicher's avatar Ole Streicher

New Beta version 1.1~b1

parent 91538aaf
This diff is collapsed.
Metadata-Version: 1.1
Name: astropy
Version: 1.0.5
Version: 1.1b1
Summary: Community-developed python astronomy tools
Home-page: http://astropy.org
Author: The Astropy Developers
Author-email: astropy.team@gmail.com
License: BSD
Download-URL: http://pypi.python.org/packages/source/a/astropy/astropy-1.0.5.tar.gz
Download-URL: http://pypi.python.org/packages/source/a/astropy/astropy-1.1b1.tar.gz
Description:
Astropy is a package intended to contain core functionality and some
common tools needed for performing astronomy and astrophysics research with
......
......@@ -2,10 +2,10 @@
Astropy
=======
.. image:: https://pypip.in/v/astropy/badge.png
.. image:: https://img.shields.io/pypi/v/astropy.svg
:target: https://pypi.python.org/pypi/astropy
.. image:: https://pypip.in/d/astropy/badge.png
.. image:: https://img.shields.io/pypi/dm/astropy.svg
:target: https://pypi.python.org/pypi/astropy
Astropy (http://astropy.org/) is a package intended to contain much of
......@@ -29,10 +29,10 @@ reach out to PyPI.
Project Status
--------------
.. image:: https://travis-ci.org/astropy/astropy.png
.. image:: https://travis-ci.org/astropy/astropy.svg
:target: https://travis-ci.org/astropy/astropy
.. image:: https://coveralls.io/repos/astropy/astropy/badge.png
.. image:: https://coveralls.io/repos/astropy/astropy/badge.svg
:target: https://coveralls.io/r/astropy/astropy
.. image:: https://ci.appveyor.com/api/projects/status/ym7lxajcs5qwm31e/branch/master?svg=true
......
......@@ -18,8 +18,7 @@ except NameError:
else:
import __builtin__ as builtins
builtins._ASTROPY_SETUP_ = False
del version_info
del builtins
try:
from .version import version as __version__
......@@ -113,96 +112,9 @@ UNICODE_OUTPUT = _config.ConfigAlias(
'0.4', 'UNICODE_OUTPUT', 'unicode_output')
del sys
# set up the test command
def _get_test_runner():
from .tests.helper import TestRunner
return TestRunner(__path__[0])
def test(package=None, test_path=None, args=None, plugins=None,
verbose=False, pastebin=None, remote_data=False, pep8=False,
pdb=False, open_files=False, parallel=0, docs_path=None,
skip_docs=False, repeat=None):
"""
Run Astropy tests using py.test. A proper set of arguments is
constructed and passed to `pytest.main`.
Parameters
----------
package : str, optional
The name of a specific package to test, e.g. 'io.fits' or 'utils'.
If nothing is specified all default Astropy tests are run.
test_path : str, optional
Specify location to test by path. May be a single file or
directory. Must be specified absolutely or relative to the
calling directory.
args : str, optional
Additional arguments to be passed to `pytest.main` in the `args`
keyword argument.
plugins : list, optional
Plugins to be passed to `pytest.main` in the `plugins` keyword
argument.
verbose : bool, optional
Convenience option to turn on verbose output from py.test. Passing
True is the same as specifying `-v` in `args`.
pastebin : {'failed','all',None}, optional
Convenience option for turning on py.test pastebin output. Set to
'failed' to upload info for failed tests, or 'all' to upload info
for all tests.
remote_data : bool, optional
Controls whether to run tests marked with @remote_data. These
tests use online data and are not run by default. Set to True to
run these tests.
pep8 : bool, optional
Turn on PEP8 checking via the pytest-pep8 plugin and disable normal
tests. Same as specifying `--pep8 -k pep8` in `args`.
pdb : bool, optional
Turn on PDB post-mortem analysis for failing tests. Same as
specifying `--pdb` in `args`.
open_files : bool, optional
Fail when any tests leave files open. Off by default, because
this adds extra run time to the test suite. Requires the
``psutil`` package.
parallel : int, optional
When provided, run the tests in parallel on the specified
number of CPUs. If parallel is negative, it will use the all
the cores on the machine. Requires the `pytest-xdist` plugin.
docs_path : str, optional
The path to the documentation .rst files.
skip_docs : bool, optional
When `True`, skips running the doctests in the .rst files.
repeat : int, optional
If set, specifies how many times each test should be run. This is
useful for diagnosing sporadic failures.
See Also
--------
pytest.main : py.test function wrapped by `run_tests`.
"""
test_runner = _get_test_runner()
return test_runner.run_tests(
package=package, test_path=test_path, args=args,
plugins=plugins, verbose=verbose, pastebin=pastebin,
remote_data=remote_data, pep8=pep8, pdb=pdb,
open_files=open_files, parallel=parallel, docs_path=docs_path,
skip_docs=skip_docs, repeat=repeat)
# Create the test() function
from .tests.runner import TestRunner
test = TestRunner.make_test_runner_in(__path__[0])
# if we are *not* in setup mode, import the logger and possibly populate the
......@@ -213,12 +125,17 @@ def _initialize_astropy():
import os
import sys
from warnings import warn
from .utils.exceptions import AstropyDeprecationWarning
# If this __init__.py file is in ./astropy/ then import is within a source dir
source_dir = os.path.abspath(os.path.dirname(__file__))
is_astropy_source_dir = os.path.exists(os.path.join(source_dir, os.pardir,
'.astropy-root'))
if sys.version_info[:2] < (2, 7):
warn("Python 2.6 will no longer be supported from Astropy v1.2.0 and "
"above", AstropyDeprecationWarning)
def _rollback_import(message):
log.error(message)
# Now disable exception logging to avoid an annoying error in the
......@@ -341,3 +258,54 @@ if not _ASTROPY_SETUP_:
_initialize_astropy()
from .utils.misc import find_api_page
def online_help(query):
"""
Search the online Astropy documentation for the given query.
Opens the results in the default web browser. Requires an active
Internet connection.
Parameters
----------
query : str
The search query.
"""
from .extern.six.moves.urllib.parse import urlencode
import webbrowser
version = __version__
if 'dev' in version:
version = 'latest'
else:
version = 'v' + version
url = 'http://docs.astropy.org/en/{0}/search.html?{1}'.format(
version, urlencode({'q': query}))
webbrowser.open(url)
__dir__ = ['__version__', '__githash__', '__minimum_numpy_version__',
'__bibtex__', 'test', 'log', 'find_api_page', 'online_help',
'online_docs_root', 'conf', 'UNICODE_OUTPUT']
from types import ModuleType as __module_type__
# Clean up top-level namespace--delete everything that isn't in __dir__
# or is a magic attribute, and that isn't a submodule of this package
for varname in dir():
if not ((varname.startswith('__') and varname.endswith('__')) or
varname in __dir__ or
(varname[0] != '_' and
isinstance(locals()[varname], __module_type__) and
locals()[varname].__name__.startswith(__name__ + '.'))):
# The last clause in the the above disjunction deserves explanation:
# When using relative imports like ``from .. import config``, the
# ``config`` variable is automatically created in the namespace of
# whatever module ``..`` resolves to (in this case astropy). This
# happens a few times just in the module setup above. This allows
# the cleanup to keep any public submodules of the astropy package
del locals()[varname]
del varname, __module_type__
......@@ -8,8 +8,9 @@
update it. */
#include "Python.h"
#include "numpy/arrayobject.h"
#include <Python.h>
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#include <numpy/arrayobject.h>
#include "erfa.h"
......
......@@ -8,8 +8,9 @@
update it. */
#include "Python.h"
#include "numpy/arrayobject.h"
#include <Python.h>
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#include <numpy/arrayobject.h>
#include "erfa.h"
......
......@@ -6880,7 +6880,7 @@ def pmsafe(ra1, dec1, pmr1, pmd1, px1, rv1, ep1a, ep1b, ep2a, ep2b):
rv2_out = rv2_out.reshape(rv2_out.shape[1:])
return ra2_out, dec2_out, pmr2_out, pmd2_out, px2_out, rv2_out
STATUS_CODES['pmsafe'] = {0: 'no warnings or errors', 1: 'distance overridden (Note 6)', 2: 'excessive velocity (Note 7)', 4: "solution didn't converge (Note 8)", 'else': 'binary logical OR of the above warnings', -1: 'system error (should not occur)'}
STATUS_CODES['pmsafe'] = {0: 'no warnings or errors', 1: 'distance overridden (Note 6)', 2: 'excessive velocity (Note 7)', 4: "solution didn't converge (Note 8)", -1: 'system error (should not occur)', 'else': 'binary logical OR of the above warnings'}
......@@ -19802,7 +19802,7 @@ def starpm(ra1, dec1, pmr1, pmd1, px1, rv1, ep1a, ep1b, ep2a, ep2b):
rv2_out = rv2_out.reshape(rv2_out.shape[1:])
return ra2_out, dec2_out, pmr2_out, pmd2_out, px2_out, rv2_out
STATUS_CODES['starpm'] = {0: 'no warnings or errors', 1: 'distance overridden (Note 6)', 2: 'excessive velocity (Note 7)', 4: "solution didn't converge (Note 8)", 'else': 'binary logical OR of the above warnings', -1: 'system error (should not occur)'}
STATUS_CODES['starpm'] = {0: 'no warnings or errors', 1: 'distance overridden (Note 6)', 2: 'excessive velocity (Note 7)', 4: "solution didn't converge (Note 8)", -1: 'system error (should not occur)', 'else': 'binary logical OR of the above warnings'}
......@@ -21189,7 +21189,7 @@ def dtf2d(scale, iy, im, id, ihr, imn, sec):
d2_out = d2_out.reshape(d2_out.shape[1:])
return d1_out, d2_out
STATUS_CODES['dtf2d'] = {0: 'OK', 1: 'dubious year (Note 6)', 2: 'time is after end of day (Note 5)', 3: 'both of next two', -1: 'bad year', -6: 'bad second (<0)', -5: 'bad minute', -4: 'bad hour', -3: 'bad day', -2: 'bad month'}
STATUS_CODES['dtf2d'] = {0: 'OK', 1: 'dubious year (Note 6)', 2: 'time is after end of day (Note 5)', 3: 'both of next two', -2: 'bad month', -6: 'bad second (<0)', -5: 'bad minute', -4: 'bad hour', -3: 'bad day', -1: 'bad year'}
......
......@@ -66,7 +66,7 @@ def blackbody_nu(in_x, temperature):
# Check if input values are physically possible
if temp < 0:
raise ValueError('Invalid temperature {0}'.format(temp))
if np.any(freq <= 0): # pragma: no cover
if not np.all(np.isfinite(freq)) or np.any(freq <= 0):
warnings.warn('Input contains invalid wavelength/frequency value(s)',
AstropyUserWarning)
......
......@@ -4,6 +4,7 @@ from __future__ import (absolute_import, division, print_function,
unicode_literals)
import os
import warnings
# THIRD-PARTY
import numpy as np
......@@ -11,7 +12,8 @@ import numpy as np
from ..blackbody import blackbody_nu, blackbody_lambda, FNU
from ... import units as u
from ... import constants as const
from ...tests.helper import pytest
from ...tests.helper import pytest, catch_warnings
from ...utils.exceptions import AstropyUserWarning
try:
from scipy import integrate # pylint: disable=W0611
......@@ -85,13 +87,21 @@ def test_blackbody_synphot():
rtol=0.01) # 1% accuracy
def test_blackbody_exceptions():
def test_blackbody_exceptions_and_warnings():
"""Test exceptions."""
# Negative temperature
with pytest.raises(ValueError):
flux = blackbody_nu(1000 * u.AA, -100)
blackbody_nu(1000 * u.AA, -100)
# Zero wavelength given for conversion to Hz
with pytest.raises(ZeroDivisionError):
flux = blackbody_nu(0 * u.AA, 5000)
with catch_warnings(AstropyUserWarning) as w:
blackbody_nu(0 * u.AA, 5000)
assert len(w) == 1
assert 'invalid' in w[0].message.args[0]
# Negative wavelength given for conversion to Hz
with catch_warnings(AstropyUserWarning) as w:
blackbody_nu(-1. * u.AA, 5000)
assert len(w) == 1
assert 'invalid' in w[0].message.args[0]
......@@ -26,6 +26,7 @@ from warnings import warn
from ..extern.configobj import configobj, validate
from ..utils.exceptions import AstropyWarning, AstropyDeprecationWarning
from ..utils import find_current_module
from ..utils.introspection import resolve_name
from ..utils.misc import InheritDocstrings
from .paths import get_config_dir
......@@ -219,6 +220,11 @@ class ConfigItem(object):
# this is used to make validation faster so a Validator object doesn't
# have to be created every time
_validator = validate.Validator()
cfgtype = None
"""
A type specifier like those used as the *values* of a particular key in a
``configspec`` file of ``configobj``.
"""
def __init__(self, defaultvalue='', description=None, cfgtype=None,
module=None, aliases=None):
......@@ -308,10 +314,12 @@ class ConfigItem(object):
Sets this item to a specified value only inside a with block.
Use as::
ITEM = ConfigItem('ITEM', 'default', 'description')
with ITEM.set_temp('newval'):
... do something that wants ITEM's value to be 'newval' ...
#... do something that wants ITEM's value to be 'newval' ...
print(ITEM)
# ITEM is now 'default' after the with block
......@@ -565,11 +573,7 @@ class ConfigAlias(ConfigItem):
AstropyDeprecationWarning)
def _get_target(self):
if self._new_module not in sys.modules:
__import__(self._new_module)
mod = sys.modules[self._new_module]
cfg = getattr(mod, 'conf')
return cfg
return resolve_name(self._new_module, 'conf')
def set(self, value):
self._deprecation_warning()
......@@ -841,8 +845,7 @@ def update_default_config(pkg, default_cfg_dir_or_fn, version=None):
identical = False
if version is None:
mod = __import__(pkg)
version = mod.__version__
version = resolve_name(pkg, '__version__')
# Don't install template files for dev versions, or we'll end up
# spamming `~/.astropy/config`.
......
......@@ -6,12 +6,15 @@ from __future__ import (absolute_import, division, print_function,
unicode_literals)
from ..extern import six
from ..utils.decorators import wraps
import os
import shutil
import sys
__all__ = ['get_config_dir', 'get_cache_dir']
__all__ = ['get_config_dir', 'get_cache_dir', 'set_temp_config',
'set_temp_cache']
def _find_home():
......@@ -105,6 +108,15 @@ def get_config_dir(create=True):
# symlink will be set to this if the directory is created
linkto = None
# If using set_temp_config, that overrides all
if set_temp_config._temp_path is not None:
xch = set_temp_config._temp_path
config_path = os.path.join(xch, 'astropy')
if not os.path.exists(config_path):
os.mkdir(config_path)
return os.path.abspath(config_path)
# first look for XDG_CONFIG_HOME
xch = os.environ.get('XDG_CONFIG_HOME')
......@@ -137,6 +149,15 @@ def get_cache_dir():
# symlink will be set to this if the directory is created
linkto = None
# If using set_temp_cache, that overrides all
if set_temp_cache._temp_path is not None:
xch = set_temp_cache._temp_path
cache_path = os.path.join(xch, 'astropy')
if not os.path.exists(cache_path):
os.mkdir(cache_path)
return os.path.abspath(cache_path)
# first look for XDG_CACHE_HOME
xch = os.environ.get('XDG_CACHE_HOME')
......@@ -151,6 +172,116 @@ def get_cache_dir():
return os.path.abspath(_find_or_create_astropy_dir('cache', linkto))
class _SetTempPath(object):
_temp_path = None
_default_path_getter = None
def __init__(self, path=None, delete=False):
if path is not None:
path = os.path.abspath(path)
self._path = path
self._delete = delete
self._prev_path = self.__class__._temp_path
def __enter__(self):
self.__class__._temp_path = self._path
return self._default_path_getter()
def __exit__(self, *args):
self.__class__._temp_path = self._prev_path
if self._delete and self._path is not None:
shutil.rmtree(self._path)
def __call__(self, func):
"""Implements use as a decorator."""
@wraps(func)
def wrapper(*args, **kwargs):
with self:
func(*args, **kwargs)
return wrapper
class set_temp_config(_SetTempPath):
"""
Context manager to set a temporary path for the Astropy config, primarily
for use with testing.
If the path set by this context manager does not already exist it will be
created, if possible.
This may also be used as a decorator on a function to set the config path
just within that function.
Parameters
----------
path : str, optional
The directory (which must exist) in which to find the Astropy config
files, or create them if they do not already exist. If None, this
restores the config path to the user's default config path as returned
by `get_config_dir` as though this context manager were not in effect
(this is useful for testing). In this case the ``delete`` argument is
always ignored.
delete : bool, optional
If True, cleans up the temporary directory after exiting the temp
context (default: False).
"""
_default_path_getter = staticmethod(get_config_dir)
def __enter__(self):
# Special case for the config case, where we need to reset all the
# cached config objects
from .configuration import _cfgobjs
path = super(set_temp_config, self).__enter__()
_cfgobjs.clear()
return path
def __exit__(self, *args):
from .configuration import _cfgobjs
super(set_temp_config, self).__exit__(*args)
_cfgobjs.clear()
class set_temp_cache(_SetTempPath):
"""
Context manager to set a temporary path for the Astropy download cache,
primarily for use with testing (though there may be other applications
for setting a different cache directory, for example to switch to a cache
dedicated to large files).
If the path set by this context manager does not already exist it will be
created, if possible.
This may also be used as a decorator on a function to set the cache path
just within that function.
Parameters
----------
path : str
The directory (which must exist) in which to find the Astropy cache
files, or create them if they do not already exist. If None, this
restores the cache path to the user's default cache path as returned