Created
April 28, 2014 14:48
-
-
Save cdeil/11374384 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python3.2 setup.py test | |
/Users/deil/Library/Python/3.2/lib/python/site-packages/astropy-0.4.dev8186-py3.2-macosx-10.9-x86_64.egg/astropy/setup_helpers.py:1023: AstropyDeprecationWarning: astropy.setup_helpers.update_package_files is deprecated. Update your setup.py to use astropy.setup_helpers.get_package_info instead. | |
AstropyDeprecationWarning) | |
running test | |
running build | |
running build_py | |
regenerating default gammapy.cfg file | |
copying gammapy/gammapy.cfg -> build/lib.macosx-10.9-x86_64-3.2/gammapy | |
running build_scripts | |
==================================================================== test session starts ==================================================================== | |
platform darwin -- Python 3.2.5 -- pytest-2.5.1 | |
Running tests with Astropy version 0.4.dev8186. | |
Running tests in gammapy /Users/deil/code/gammapy/docs. | |
Platform: Darwin-13.1.0-x86_64-i386-64bit | |
Executable: /opt/local/Library/Frameworks/Python.framework/Versions/3.2/Resources/Python.app/Contents/MacOS/Python | |
Full Python Version: | |
3.2.5 (default, Nov 26 2013, 10:28:25) | |
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] | |
encodings: sys: utf-8, locale: UTF-8, filesystem: utf-8, unicode bits: 15 | |
byteorder: little | |
float info: dig: 15, mant_dig: 15 | |
Numpy: 1.8.1 | |
Scipy: 0.13.3 | |
Matplotlib: not available | |
h5py: 2.2.1 | |
Running doctests in .rst files is not supported on Python 3.x | |
collected 126 items | |
gammapy/astro/population/tests/test_spatial.py . | |
gammapy/astro/population/tests/test_velocity.py . | |
gammapy/astro/source/tests/test_pulsar.py .. | |
gammapy/astro/source/tests/test_pwn.py . | |
gammapy/astro/source/tests/test_snr.py .. | |
gammapy/background/tests/test_maps.py x | |
gammapy/background/tests/test_reflected.py x | |
gammapy/background/tests/test_ring.py .... | |
gammapy/catalog/tests/test_analysis.py . | |
gammapy/catalog/tests/test_utils.py ... | |
gammapy/datasets/tests/test_all.py ....s | |
gammapy/detect/tests/test_blob.py . | |
gammapy/detect/tests/test_cwt.py . | |
gammapy/detect/tests/test_iterfind.py . | |
gammapy/detect/tests/test_matched_filter.py .x | |
gammapy/detect/tests/test_sex.py . | |
gammapy/detect/tests/test_test_statistic.py xxx | |
gammapy/detect/tests/test_utils.py . | |
gammapy/image/tests/test_healpix.py s | |
gammapy/image/tests/test_measure.py . | |
gammapy/image/tests/test_plotting.py ss | |
gammapy/image/tests/test_profile.py . | |
gammapy/image/tests/test_utils.py ....x.xFFFF.F | |
gammapy/irf/tests/test_effective_area.py . | |
gammapy/irf/tests/test_energy_dispersion.py x | |
gammapy/morphology/tests/test_fermi_psf.py . | |
gammapy/morphology/tests/test_gauss.py ............ | |
gammapy/morphology/tests/test_model.py . | |
gammapy/morphology/tests/test_psf.py ... | |
gammapy/morphology/tests/test_theta.py .... | |
gammapy/obs/tests/test_run.py .. | |
gammapy/shower/tests/test_hillas.py . | |
gammapy/shower/tests/test_image.py .. | |
gammapy/spectrum/tests/test_cosmic_ray.py ... | |
gammapy/spectrum/tests/test_crab.py . | |
gammapy/spectrum/tests/test_diffuse.py x | |
gammapy/spectrum/tests/test_flux_point.py xx | |
gammapy/spectrum/tests/test_inverse_compton.py . | |
gammapy/spectrum/tests/test_isrf.py xx. | |
gammapy/spectrum/tests/test_pion.py x | |
gammapy/spectrum/tests/test_powerlaw.py x..... | |
gammapy/spectrum/tests/test_sed.py xxxx | |
gammapy/spectrum/tests/test_utils.py . | |
gammapy/stats/tests/test_data.py ... | |
gammapy/stats/tests/test_fit_statistics.py ... | |
gammapy/stats/tests/test_fitting.py . | |
gammapy/stats/tests/test_poisson.py .x | |
gammapy/stats/tests/test_utils.py . | |
gammapy/utils/coordinates/tests/test_celestial.py ...... | |
gammapy/utils/coordinates/tests/test_other.py . | |
gammapy/utils/distributions/tests/test_general_random.py x | |
gammapy/utils/root/tests/test_convert.py sss | |
gammapy/utils/tests/test_const.py . | |
gammapy/utils/tests/test_random.py .. | |
gammapy/utils/tests/test_region.py . | |
========================================================================= FAILURES ========================================================================== | |
_________________________________________________________ TestBlockReduceHDU.test_image[operation0] _________________________________________________________ | |
self = <gammapy.image.tests.test_utils.TestBlockReduceHDU object at 0x108335f90>, operation = <function sum at 0x103b64b78> | |
@pytest.mark.parametrize(('operation'), list([np.sum, np.mean])) | |
def test_image(self, operation): | |
> image_1 = utils.block_reduce_hdu(self.image, (2, 4), func=operation) | |
gammapy/image/tests/test_utils.py:130: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
input_hdu = <astropy.io.fits.hdu.image.ImageHDU object at 0x108335250>, block_size = (4, 2), func = <function sum at 0x103b64b78>, cval = 0 | |
def block_reduce_hdu(input_hdu, block_size, func, cval=0): | |
"""Provides block reduce functionality for image HDUs. | |
See http://scikit-image.org/docs/dev/api/skimage.measure.html#skimage.measure.block_reduce | |
Parameters | |
---------- | |
image_hdu : `astropy.io.fits.ImageHDU` | |
Original image HDU, unscaled | |
block_size : array_like | |
Array containing down-sampling integer factor along each axis. | |
func : callable | |
Function object which is used to calculate the return value for each local block. | |
This function must implement an axis parameter such as `numpy.sum` or `numpy.mean`. | |
cval : float (optional) | |
Constant padding value if image is not perfectly divisible by the block size. Default 0. | |
Returns | |
------- | |
image_hdu : `astropy.io.fits.ImageHDU` | |
Rebinned Image HDU | |
""" | |
from skimage.measure import block_reduce | |
header = input_hdu.header.copy() | |
data = input_hdu.data | |
# Define new header values for new resolution | |
header['CDELT1'] = header['CDELT1'] * block_size[0] | |
header['CDELT2'] = header['CDELT2'] * block_size[1] | |
header['CRPIX1'] = ((header['CRPIX1'] - 0.5) / block_size[0]) + 0.5 | |
header['CRPIX2'] = ((header['CRPIX2'] - 0.5) / block_size[1]) + 0.5 | |
if len(input_hdu.data.shape) == 3: | |
block_size = (1, block_size[1], block_size[0]) | |
elif len(input_hdu.data.shape) == 2: | |
block_size = (block_size[1], block_size[0]) | |
> data_reduced = block_reduce(data, block_size, func, cval) | |
gammapy/image/utils.py:871: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
image = array([[ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.], | |
[ 1., 1., 1., 1., 1., 1., 1., 1., ...1., 1., 1., 1., 1., 1., 1., 1., 1., 1.], | |
[ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]]) | |
block_size = (4, 2), func = <function sum at 0x103b64b78>, cval = 0 | |
def block_reduce(image, block_size, func=np.sum, cval=0): | |
"""Down-sample image by applying function to local blocks. | |
Parameters | |
---------- | |
image : ndarray | |
N-dimensional input image. | |
block_size : array_like | |
Array containing down-sampling integer factor along each axis. | |
func : callable | |
Function object which is used to calculate the return value for each | |
local block. This function must implement an ``axis`` parameter such as | |
``numpy.sum`` or ``numpy.min``. | |
cval : float | |
Constant padding value if image is not perfectly divisible by the | |
block size. | |
Returns | |
------- | |
image : ndarray | |
Down-sampled image with same number of dimensions as input image. | |
Examples | |
-------- | |
>>> from skimage.measure import block_reduce | |
>>> image = np.arange(3*3*4).reshape(3, 3, 4) | |
>>> image # doctest: +NORMALIZE_WHITESPACE | |
array([[[ 0, 1, 2, 3], | |
[ 4, 5, 6, 7], | |
[ 8, 9, 10, 11]], | |
[[12, 13, 14, 15], | |
[16, 17, 18, 19], | |
[20, 21, 22, 23]], | |
[[24, 25, 26, 27], | |
[28, 29, 30, 31], | |
[32, 33, 34, 35]]]) | |
>>> block_reduce(image, block_size=(3, 3, 1), func=np.mean) | |
array([[[ 16., 17., 18., 19.]]]) | |
>>> image_max1 = block_reduce(image, block_size=(1, 3, 4), func=np.max) | |
>>> image_max1 # doctest: +NORMALIZE_WHITESPACE | |
array([[[11]], | |
[[23]], | |
[[35]]]) | |
>>> image_max2 = block_reduce(image, block_size=(3, 1, 4), func=np.max) | |
>>> image_max2 # doctest: +NORMALIZE_WHITESPACE | |
array([[[27], | |
[31], | |
[35]]]) | |
""" | |
if len(block_size) != image.ndim: | |
raise ValueError("`block_size` must have the same length " | |
"as `image.shape`.") | |
pad_width = [] | |
for i in range(len(block_size)): | |
if image.shape[i] % block_size[i] != 0: | |
after_width = block_size[i] - (image.shape[i] % block_size[i]) | |
else: | |
after_width = 0 | |
pad_width.append((0, after_width)) | |
image = pad(image, pad_width=pad_width, mode='constant', | |
constant_values=cval) | |
> out = view_as_blocks(image, block_size) | |
/Users/deil/Library/Python/3.2/lib/python/site-packages/scikit_image-0.10dev-py3.2-macosx-10.9-x86_64.egg/skimage/measure/block.py:70: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
arr_in = array([[ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.], | |
[ 1., 1., 1., 1., 1., 1., 1., 1., ...1., 1., 1., 1., 1., 1., 1., 1., 1., 1.], | |
[ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]]) | |
block_shape = array([4, 2]) | |
def view_as_blocks(arr_in, block_shape): | |
"""Block view of the input n-dimensional array (using re-striding). | |
Blocks are non-overlapping views of the input array. | |
Parameters | |
---------- | |
arr_in : ndarray | |
N-d input array. | |
block_shape : tuple | |
The shape of the block. Each dimension must divide evenly into the | |
corresponding dimensions of `arr_in`. | |
Returns | |
------- | |
arr_out : ndarray | |
Block view of the input array. If `arr_in` is non-contiguous, a copy | |
is made. | |
Examples | |
-------- | |
>>> import numpy as np | |
>>> from skimage.util.shape import view_as_blocks | |
>>> A = np.arange(4*4).reshape(4,4) | |
>>> A | |
array([[ 0, 1, 2, 3], | |
[ 4, 5, 6, 7], | |
[ 8, 9, 10, 11], | |
[12, 13, 14, 15]]) | |
>>> B = view_as_blocks(A, block_shape=(2, 2)) | |
>>> B[0, 0] | |
array([[0, 1], | |
[4, 5]]) | |
>>> B[0, 1] | |
array([[2, 3], | |
[6, 7]]) | |
>>> B[1, 0, 1, 1] | |
13 | |
>>> A = np.arange(4*4*6).reshape(4,4,6) | |
>>> A # doctest: +NORMALIZE_WHITESPACE | |
array([[[ 0, 1, 2, 3, 4, 5], | |
[ 6, 7, 8, 9, 10, 11], | |
[12, 13, 14, 15, 16, 17], | |
[18, 19, 20, 21, 22, 23]], | |
[[24, 25, 26, 27, 28, 29], | |
[30, 31, 32, 33, 34, 35], | |
[36, 37, 38, 39, 40, 41], | |
[42, 43, 44, 45, 46, 47]], | |
[[48, 49, 50, 51, 52, 53], | |
[54, 55, 56, 57, 58, 59], | |
[60, 61, 62, 63, 64, 65], | |
[66, 67, 68, 69, 70, 71]], | |
[[72, 73, 74, 75, 76, 77], | |
[78, 79, 80, 81, 82, 83], | |
[84, 85, 86, 87, 88, 89], | |
[90, 91, 92, 93, 94, 95]]]) | |
>>> B = view_as_blocks(A, block_shape=(1, 2, 2)) | |
>>> B.shape | |
(4, 2, 3, 1, 2, 2) | |
>>> B[2:, 0, 2] # doctest: +NORMALIZE_WHITESPACE | |
array([[[[52, 53], | |
[58, 59]]], | |
[[[76, 77], | |
[82, 83]]]]) | |
""" | |
if not isinstance(block_shape, tuple): | |
raise TypeError('block needs to be a tuple') | |
block_shape = np.array(block_shape) | |
if (block_shape <= 0).any(): | |
raise ValueError("'block_shape' elements must be strictly positive") | |
if block_shape.size != arr_in.ndim: | |
raise ValueError("'block_shape' must have the same length " | |
"as 'arr_in.shape'") | |
arr_shape = np.array(arr_in.shape) | |
if (arr_shape % block_shape).sum() != 0: | |
raise ValueError("'block_shape' is not compatible with 'arr_in'") | |
# -- restride the array to build the block view | |
if not arr_in.flags.contiguous: | |
warn(RuntimeWarning("Cannot provide views on a non-contiguous input " | |
"array without copying.")) | |
arr_in = np.ascontiguousarray(arr_in) | |
new_shape = tuple(arr_shape / block_shape) + tuple(block_shape) | |
new_strides = tuple(arr_in.strides * block_shape) + arr_in.strides | |
> arr_out = as_strided(arr_in, shape=new_shape, strides=new_strides) | |
/Users/deil/Library/Python/3.2/lib/python/site-packages/scikit_image-0.10dev-py3.2-macosx-10.9-x86_64.egg/skimage/util/shape.py:100: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
x = array([[ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.], | |
[ 1., 1., 1., 1., 1., 1., 1., 1., ...1., 1., 1., 1., 1., 1., 1., 1., 1., 1.], | |
[ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]]) | |
shape = (2.0, 6.0, 4, 2), strides = (384, 16, 96, 8) | |
def as_strided(x, shape=None, strides=None): | |
""" Make an ndarray from the given array with the given shape and strides. | |
""" | |
interface = dict(x.__array_interface__) | |
if shape is not None: | |
interface['shape'] = tuple(shape) | |
if strides is not None: | |
interface['strides'] = tuple(strides) | |
> array = np.asarray(DummyArray(interface, base=x)) | |
/opt/local/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/lib/stride_tricks.py:30: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
a = <numpy.lib.stride_tricks.DummyArray object at 0x10840bbd0>, dtype = None, order = None | |
def asarray(a, dtype=None, order=None): | |
""" | |
Convert the input to an array. | |
Parameters | |
---------- | |
a : array_like | |
Input data, in any form that can be converted to an array. This | |
includes lists, lists of tuples, tuples, tuples of tuples, tuples | |
of lists and ndarrays. | |
dtype : data-type, optional | |
By default, the data-type is inferred from the input data. | |
order : {'C', 'F'}, optional | |
Whether to use row-major ('C') or column-major ('F' for FORTRAN) | |
memory representation. Defaults to 'C'. | |
Returns | |
------- | |
out : ndarray | |
Array interpretation of `a`. No copy is performed if the input | |
is already an ndarray. If `a` is a subclass of ndarray, a base | |
class ndarray is returned. | |
See Also | |
-------- | |
asanyarray : Similar function which passes through subclasses. | |
ascontiguousarray : Convert input to a contiguous array. | |
asfarray : Convert input to a floating point ndarray. | |
asfortranarray : Convert input to an ndarray with column-major | |
memory order. | |
asarray_chkfinite : Similar function which checks input for NaNs and Infs. | |
fromiter : Create an array from an iterator. | |
fromfunction : Construct an array by executing a function on grid | |
positions. | |
Examples | |
-------- | |
Convert a list into an array: | |
>>> a = [1, 2] | |
>>> np.asarray(a) | |
array([1, 2]) | |
Existing arrays are not copied: | |
>>> a = np.array([1, 2]) | |
>>> np.asarray(a) is a | |
True | |
If `dtype` is set, array is copied only if dtype does not match: | |
>>> a = np.array([1, 2], dtype=np.float32) | |
>>> np.asarray(a, dtype=np.float32) is a | |
True | |
>>> np.asarray(a, dtype=np.float64) is a | |
False | |
Contrary to `asanyarray`, ndarray subclasses are not passed through: | |
>>> issubclass(np.matrix, np.ndarray) | |
True | |
>>> a = np.matrix([[1, 2]]) | |
>>> np.asarray(a) is a | |
False | |
>>> np.asanyarray(a) is a | |
True | |
""" | |
> return array(a, dtype, copy=False, order=order) | |
E DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future | |
/opt/local/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/core/numeric.py:460: DeprecationWarning |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment