Skip to content

Instantly share code, notes, and snippets.

@bsipocz
Created January 28, 2015 15:54
Show Gist options
  • Save bsipocz/38a4d6bf5041d837a2f8 to your computer and use it in GitHub Desktop.
Save bsipocz/38a4d6bf5041d837a2f8 to your computer and use it in GitHub Desktop.
astropy fails on 32bit
=============================================== test session starts ================================================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
Running tests with Astropy version 1.1.dev11768.
Running tests in astropy /home/bsipocz/devel/astropy/docs.
Platform: Linux-3.2.0-4-686-pae-i686-with-debian-7.8
Executable: /usr/bin/python
Full Python Version:
2.7.3 (default, Mar 14 2014, 11:57:14)
[GCC 4.7.2]
encodings: sys: ascii, locale: ISO-8859-1, filesystem: ISO-8859-1, unicode bits: 20
byteorder: little
float info: dig: 15, mant_dig: 15
Numpy: 1.9.1
Scipy: 0.10.1
Matplotlib: 1.4.2
h5py: not available
collected 8656 items / 2 errors / 7 skipped
astropy/_erfa/tests/test_erfa.py .....
astropy/analytic_functions/tests/test_blackbody.py ....
astropy/config/configuration.py .
astropy/config/tests/test_configs.py ...............
astropy/constants/__init__.py .
astropy/constants/tests/test_constant.py ..............
astropy/constants/tests/test_pickle.py xxxxxxxxx
astropy/convolution/kernels.py ...
astropy/convolution/tests/test_convolve.py ...............................................................................................................
astropy/convolution/tests/test_convolve_fft.py ...................................................................................................................................................................................................................................................................................................................................................
astropy/convolution/tests/test_convolve_kernels.py ..............................................................
astropy/convolution/tests/test_discretize.py ...s...........s...............
astropy/convolution/tests/test_kernel_class.py ............................................................................................................................................................................
astropy/convolution/tests/test_pickle.py .xx.xx.xx
astropy/coordinates/angles.py ..
astropy/coordinates/baseframe.py .
astropy/coordinates/sky_coordinate.py ..
astropy/coordinates/builtin_frames/galactocentric.py .
astropy/coordinates/tests/test_angles.py ............................................................................
astropy/coordinates/tests/test_angular_separation.py ....
astropy/coordinates/tests/test_api_ape5.py ....s
astropy/coordinates/tests/test_arrays.py ..........................
astropy/coordinates/tests/test_distance.py .........
astropy/coordinates/tests/test_earth.py ........................
astropy/coordinates/tests/test_formatting.py ....................
astropy/coordinates/tests/test_frames.py ....................F..
astropy/coordinates/tests/test_funcs.py ..
astropy/coordinates/tests/test_iau_fullstack.py ....................................................
astropy/coordinates/tests/test_matching.py ....F
astropy/coordinates/tests/test_name_resolve.py ssssss
astropy/coordinates/tests/test_pickle.py ....xx.x...xx.x...xx.x.
astropy/coordinates/tests/test_representation.py .............................................................................
astropy/coordinates/tests/test_sky_coord.py .......................................................................................................................................................................................................................................................................................................................................................................................x.......F......
astropy/coordinates/tests/test_transformations.py ......................
astropy/coordinates/tests/accuracy/test_altaz_icrs.py ...x
astropy/coordinates/tests/accuracy/test_fk4_no_e_fk4.py .
astropy/coordinates/tests/accuracy/test_fk4_no_e_fk5.py .
astropy/coordinates/tests/accuracy/test_galactic_fk4.py .
astropy/coordinates/tests/accuracy/test_icrs_fk5.py .
astropy/cosmology/tests/test_cosmology.py ...................................
astropy/cosmology/tests/test_pickle.py ...
astropy/io/ascii/daophot.py .
astropy/io/ascii/ecsv.py ..
astropy/io/ascii/ipac.py .
astropy/io/ascii/tests/test_c_reader.py ...........................x................x.......x.x.............
astropy/io/ascii/tests/test_cds_header_from_readme.py ...
astropy/io/ascii/tests/test_compressed.py .....
astropy/io/ascii/tests/test_connect.py .............ss........
astropy/io/ascii/tests/test_fixedwidth.py ............................................................
astropy/io/ascii/tests/test_html.py s.ssssss.ssss..s
astropy/io/ascii/tests/test_ipac_definitions.py ........................................
astropy/io/ascii/tests/test_read.py ..................................................................................................................................................................................................
astropy/io/ascii/tests/test_types.py ......
astropy/io/ascii/tests/test_write.py ..........................
astropy/io/fits/diff.py .
astropy/io/fits/util.py .
astropy/io/fits/tests/test_checksum.py ....................
astropy/io/fits/tests/test_connect.py .........................
astropy/io/fits/tests/test_core.py .............................................F....F.....
astropy/io/fits/tests/test_diff.py ..................................
astropy/io/fits/tests/test_division.py .....
astropy/io/fits/tests/test_groups.py .......
astropy/io/fits/tests/test_hdulist.py .......................F.................
astropy/io/fits/tests/test_header.py ..............................................................................................................................................
astropy/io/fits/tests/test_image.py ....................................................
astropy/io/fits/tests/test_nonstandard.py F.F
astropy/io/fits/tests/test_structured.py .
astropy/io/fits/tests/test_table.py ...............................................................
astropy/io/fits/tests/test_uint.py ........
astropy/io/fits/tests/test_util.py .
astropy/io/misc/tests/test_hdf5.py sssssssssssssssssssssssssssssssssssssss
astropy/io/misc/tests/test_pickle_helpers.py ....
astropy/io/tests/test_registry.py ............................................................
astropy/io/votable/tests/converter_test.py ............................................
astropy/io/votable/tests/exception_test.py ..
astropy/io/votable/tests/table_test.py ..............
astropy/io/votable/tests/tree_test.py ...
astropy/io/votable/tests/ucd_test.py ..........
astropy/io/votable/tests/util_test.py ......................
astropy/io/votable/tests/vo_test.py ................................................................................................................................................................................................................................................................................................................................
astropy/modeling/_compound_deprecated.py ..
astropy/modeling/core.py ....
astropy/modeling/functional_models.py .
astropy/modeling/mappings.py ..
astropy/modeling/utils.py .
astropy/modeling/tests/test_compound.py ..........................................
astropy/modeling/tests/test_constraints.py .....................
astropy/modeling/tests/test_core.py ........
astropy/modeling/tests/test_fitters.py ...................
astropy/modeling/tests/test_functional_models.py .........
astropy/modeling/tests/test_input.py ......................................................
astropy/modeling/tests/test_mappings.py .....F
astropy/modeling/tests/test_models.py .......................................................ss.s.......................................sssss.s.ss...
astropy/modeling/tests/test_parameters.py .....................................................
astropy/modeling/tests/test_polynomial.py .................
astropy/modeling/tests/test_projections.py ...................
astropy/modeling/tests/test_rotations.py .....
astropy/modeling/tests/test_utils.py ..
astropy/nddata/utils.py ...
astropy/nddata/tests/test_decorators.py ..........
astropy/nddata/tests/test_flag_collection.py ....................
astropy/nddata/tests/test_nddata.py ..................................................................
astropy/nddata/tests/test_nddata_base.py .
astropy/nddata/tests/test_utils.py .........
astropy/stats/funcs.py ....
astropy/stats/sigma_clipping.py .
astropy/stats/tests/test_funcs.py .............
astropy/stats/tests/test_sigma_clipping.py ...
astropy/table/np_utils.py ..
astropy/table/operations.py ..
astropy/table/row.py .
astropy/table/table.py ............
astropy/table/table_helpers.py .
astropy/table/tests/test_column.py ....................................................................................................................................................................
astropy/table/tests/test_groups.py ........................................
astropy/table/tests/test_init_table.py ......................................................................................................................................................................................................................................................................................................
astropy/table/tests/test_item_access.py ........................................................
astropy/table/tests/test_jsviewer.py .
astropy/table/tests/test_masked.py ..................................................................
astropy/table/tests/test_mixin.py ................................................x.
astropy/table/tests/test_np_utils.py .
astropy/table/tests/test_operations.py ..........................................................................
astropy/table/tests/test_pickle.py ............
astropy/table/tests/test_pprint.py ........................................................................................................
astropy/table/tests/test_row.py ....................................................................
astropy/table/tests/test_subclass.py ....
astropy/table/tests/test_table.py ..........................................................................................................................................................................................................................................................................................x..................................................................................................................................................................................................................................................................................................................x........................
astropy/tests/test_logger.py ............................
astropy/tests/tests/test_imports.py ..
astropy/tests/tests/test_open_file_detection.py .
astropy/tests/tests/test_quantity_helpers.py .
astropy/tests/tests/test_run_tests.py ........
astropy/tests/tests/test_skip_remote_data.py s
astropy/tests/tests/test_socketblocker.py ...
astropy/time/core.py ..
astropy/time/tests/test_basic.py ..............................................................................
astropy/time/tests/test_comparisons.py ...
astropy/time/tests/test_delta.py ................................................................................
astropy/time/tests/test_guess.py ....
astropy/time/tests/test_pickle.py .
astropy/time/tests/test_precision.py .......x..
astropy/time/tests/test_quantity_interaction.py ............
astropy/time/tests/test_sidereal.py ...................
astropy/time/tests/test_ut1.py ...s
astropy/units/cds.py .
astropy/units/core.py ....
astropy/units/equivalencies.py ....
astropy/units/imperial.py .
astropy/units/format/console.py .
astropy/units/format/unicode_format.py .
astropy/units/tests/test_equivalencies.py ..................................................
astropy/units/tests/test_format.py ....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
astropy/units/tests/test_physical.py ......................
astropy/units/tests/test_quantity.py ....................................................................
astropy/units/tests/test_quantity_array_methods.py .............................x............x.x.............
astropy/units/tests/test_quantity_decorator.py sssssssssssss...............
astropy/units/tests/test_quantity_non_ufuncs.py xx
astropy/units/tests/test_quantity_ufuncs.py ........................................ss.................................................................................................................
astropy/units/tests/test_units.py ..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
astropy/utils/decorators.py ..
astropy/utils/introspection.py .
astropy/utils/misc.py ..
astropy/utils/timer.py .
astropy/utils/iers/iers.py .
astropy/utils/iers/tests/test_iers.py .s
astropy/utils/tests/test_codegen.py .
astropy/utils/tests/test_collections.py .....
astropy/utils/tests/test_compat.py .
astropy/utils/tests/test_console.py ..................................................
astropy/utils/tests/test_data.py .sssss.........s..s..sssss.........s..s.
astropy/utils/tests/test_decorators.py .......
astropy/utils/tests/test_gzip.py ss
astropy/utils/tests/test_introspection.py ....
astropy/utils/tests/test_metadata.py ...............
astropy/utils/tests/test_misc.py .s...
astropy/utils/tests/test_odict.py sssssssssssssssssssssssssssssssssssssssssss
astropy/utils/tests/test_state.py ..
astropy/utils/tests/test_timer.py .
astropy/utils/tests/test_xml.py ........
astropy/utils/xml/writer.py .
astropy/visualization/scripts/tests/test_fits2bitmap.py ..
astropy/visualization/tests/test_interval.py .................
astropy/visualization/tests/test_norm.py s.....
astropy/visualization/tests/test_stretch.py ...................................................................................................
astropy/visualization/tests/test_ui.py ......
astropy/vo/client/tests/test_conesearch.py ssssssssssssss...x.
astropy/vo/client/tests/test_vos_catalog.py ..............s
astropy/vo/samp/tests/test_client.py ....
astropy/vo/samp/tests/test_errors.py ...
astropy/vo/samp/tests/test_hub.py ..
astropy/vo/samp/tests/test_hub_proxy.py .....
astropy/vo/samp/tests/test_hub_script.py .
astropy/vo/samp/tests/test_standard_profile.py .xx
astropy/vo/samp/tests/test_web_profile.py X.
astropy/vo/validator/tests/test_inpect.py ....
astropy/vo/validator/tests/test_validate.py sss
astropy/wcs/wcs.py F
astropy/wcs/tests/test_pickle.py .F....
astropy/wcs/tests/test_profiling.py ..................................
astropy/wcs/tests/test_utils.py ........................................
astropy/wcs/tests/test_wcs.py ......................................................................................................................................
astropy/wcs/tests/test_wcsprm.py ...........................................................................................x.......
astropy/wcs/tests/extension/test_extension.py .
../../../home/bsipocz/devel/astropy/docs/changelog.rst .
../../../home/bsipocz/devel/astropy/docs/credits.rst .
../../../home/bsipocz/devel/astropy/docs/getting_started.rst .
../../../home/bsipocz/devel/astropy/docs/index.rst .
../../../home/bsipocz/devel/astropy/docs/install.rst .
../../../home/bsipocz/devel/astropy/docs/known_issues.rst .
../../../home/bsipocz/devel/astropy/docs/license.rst .
../../../home/bsipocz/devel/astropy/docs/logging.rst .
../../../home/bsipocz/devel/astropy/docs/overview.rst .
../../../home/bsipocz/devel/astropy/docs/stability.rst .
../../../home/bsipocz/devel/astropy/docs/warnings.rst .
../../../home/bsipocz/devel/astropy/docs/analytic_functions/index.rst .
../../../home/bsipocz/devel/astropy/docs/config/config_0_4_transition.rst .
../../../home/bsipocz/devel/astropy/docs/config/index.rst .
../../../home/bsipocz/devel/astropy/docs/constants/index.rst .
../../../home/bsipocz/devel/astropy/docs/convolution/index.rst .
../../../home/bsipocz/devel/astropy/docs/convolution/kernels.rst .
../../../home/bsipocz/devel/astropy/docs/convolution/using.rst .
../../../home/bsipocz/devel/astropy/docs/coordinates/angles.rst .
../../../home/bsipocz/devel/astropy/docs/coordinates/definitions.rst .
../../../home/bsipocz/devel/astropy/docs/coordinates/formatting.rst .
../../../home/bsipocz/devel/astropy/docs/coordinates/frames.rst .
../../../home/bsipocz/devel/astropy/docs/coordinates/galactocentric.rst .
../../../home/bsipocz/devel/astropy/docs/coordinates/index.rst .
../../../home/bsipocz/devel/astropy/docs/coordinates/matchsep.rst .
../../../home/bsipocz/devel/astropy/docs/coordinates/observing-example.rst .
../../../home/bsipocz/devel/astropy/docs/coordinates/representations.rst .
../../../home/bsipocz/devel/astropy/docs/coordinates/sgr-example.rst .
../../../home/bsipocz/devel/astropy/docs/coordinates/skycoord.rst .
../../../home/bsipocz/devel/astropy/docs/coordinates/transforming.rst .
../../../home/bsipocz/devel/astropy/docs/cosmology/index.rst .
../../../home/bsipocz/devel/astropy/docs/development/affiliated-packages.rst .
../../../home/bsipocz/devel/astropy/docs/development/building.rst .
../../../home/bsipocz/devel/astropy/docs/development/ccython.rst .
../../../home/bsipocz/devel/astropy/docs/development/codeguide.rst .
../../../home/bsipocz/devel/astropy/docs/development/codeguide_emacs.rst .
../../../home/bsipocz/devel/astropy/docs/development/docguide.rst .
../../../home/bsipocz/devel/astropy/docs/development/docrules.rst .
../../../home/bsipocz/devel/astropy/docs/development/releasing.rst .
../../../home/bsipocz/devel/astropy/docs/development/scripts.rst .
../../../home/bsipocz/devel/astropy/docs/development/testguide.rst .
../../../home/bsipocz/devel/astropy/docs/development/vision.rst .
../../../home/bsipocz/devel/astropy/docs/development/workflow/additional_git_topics.rst .
../../../home/bsipocz/devel/astropy/docs/development/workflow/command_history.rst .
../../../home/bsipocz/devel/astropy/docs/development/workflow/development_workflow.rst .
../../../home/bsipocz/devel/astropy/docs/development/workflow/get_devel_version.rst .
../../../home/bsipocz/devel/astropy/docs/development/workflow/git_edit_workflow_examples.rst .
../../../home/bsipocz/devel/astropy/docs/development/workflow/git_install.rst .
../../../home/bsipocz/devel/astropy/docs/development/workflow/git_resources.rst .
../../../home/bsipocz/devel/astropy/docs/development/workflow/maintainer_workflow.rst .
../../../home/bsipocz/devel/astropy/docs/development/workflow/patches.rst .
../../../home/bsipocz/devel/astropy/docs/development/workflow/terminal_cast.rst .
../../../home/bsipocz/devel/astropy/docs/development/workflow/virtual_pythons.rst .
../../../home/bsipocz/devel/astropy/docs/development/workflow/virtualenv_detail.rst .
../../../home/bsipocz/devel/astropy/docs/io/misc.rst .
../../../home/bsipocz/devel/astropy/docs/io/registry.rst .
../../../home/bsipocz/devel/astropy/docs/io/unified.rst .
../../../home/bsipocz/devel/astropy/docs/io/ascii/base_classes.rst .
../../../home/bsipocz/devel/astropy/docs/io/ascii/extension_classes.rst .
../../../home/bsipocz/devel/astropy/docs/io/ascii/fast_ascii_io.rst .
../../../home/bsipocz/devel/astropy/docs/io/ascii/fixed_width_gallery.rst .
../../../home/bsipocz/devel/astropy/docs/io/ascii/index.rst .
../../../home/bsipocz/devel/astropy/docs/io/ascii/read.rst .
../../../home/bsipocz/devel/astropy/docs/io/ascii/write.rst .
../../../home/bsipocz/devel/astropy/docs/io/fits/index.rst .
../../../home/bsipocz/devel/astropy/docs/io/fits/appendix/faq.rst .
../../../home/bsipocz/devel/astropy/docs/io/fits/appendix/header_transition.rst .
../../../home/bsipocz/devel/astropy/docs/io/fits/appendix/history.rst .
../../../home/bsipocz/devel/astropy/docs/io/fits/usage/examples.rst .
../../../home/bsipocz/devel/astropy/docs/io/fits/usage/headers.rst .
../../../home/bsipocz/devel/astropy/docs/io/fits/usage/image.rst .
../../../home/bsipocz/devel/astropy/docs/io/fits/usage/misc.rst .
../../../home/bsipocz/devel/astropy/docs/io/fits/usage/scripts.rst .
../../../home/bsipocz/devel/astropy/docs/io/fits/usage/table.rst .
../../../home/bsipocz/devel/astropy/docs/io/fits/usage/unfamiliar.rst .
../../../home/bsipocz/devel/astropy/docs/io/fits/usage/verification.rst .
../../../home/bsipocz/devel/astropy/docs/io/votable/api_exceptions.rst .
../../../home/bsipocz/devel/astropy/docs/io/votable/index.rst .
../../../home/bsipocz/devel/astropy/docs/modeling/algorithms.rst .
../../../home/bsipocz/devel/astropy/docs/modeling/compound-models.rst .
../../../home/bsipocz/devel/astropy/docs/modeling/fitting.rst .
../../../home/bsipocz/devel/astropy/docs/modeling/index.rst .
../../../home/bsipocz/devel/astropy/docs/modeling/models.rst .
../../../home/bsipocz/devel/astropy/docs/modeling/new.rst .
../../../home/bsipocz/devel/astropy/docs/modeling/parameters.rst .
../../../home/bsipocz/devel/astropy/docs/nddata/decorator.rst .
../../../home/bsipocz/devel/astropy/docs/nddata/index.rst .
../../../home/bsipocz/devel/astropy/docs/nddata/nddata.rst .
../../../home/bsipocz/devel/astropy/docs/nddata/subclassing.rst .
../../../home/bsipocz/devel/astropy/docs/nddata/mixins/index.rst .
../../../home/bsipocz/devel/astropy/docs/nddata/mixins/ndarithmetic.rst .
../../../home/bsipocz/devel/astropy/docs/nddata/mixins/ndio.rst .
../../../home/bsipocz/devel/astropy/docs/nddata/mixins/ndslicing.rst .
../../../home/bsipocz/devel/astropy/docs/stats/index.rst .
../../../home/bsipocz/devel/astropy/docs/table/access_table.rst .
../../../home/bsipocz/devel/astropy/docs/table/construct_table.rst .
../../../home/bsipocz/devel/astropy/docs/table/implementation_change_1.0.rst .
../../../home/bsipocz/devel/astropy/docs/table/implementation_details.rst .
../../../home/bsipocz/devel/astropy/docs/table/index.rst .
../../../home/bsipocz/devel/astropy/docs/table/io.rst .
../../../home/bsipocz/devel/astropy/docs/table/masking.rst .
../../../home/bsipocz/devel/astropy/docs/table/mixin_columns.rst .
../../../home/bsipocz/devel/astropy/docs/table/modify_table.rst .
../../../home/bsipocz/devel/astropy/docs/table/operations.rst .
../../../home/bsipocz/devel/astropy/docs/time/index.rst .
../../../home/bsipocz/devel/astropy/docs/units/combining_and_defining.rst .
../../../home/bsipocz/devel/astropy/docs/units/conversion.rst .
../../../home/bsipocz/devel/astropy/docs/units/decomposing_and_composing.rst .
../../../home/bsipocz/devel/astropy/docs/units/equivalencies.rst .
../../../home/bsipocz/devel/astropy/docs/units/format.rst .
../../../home/bsipocz/devel/astropy/docs/units/index.rst .
../../../home/bsipocz/devel/astropy/docs/units/quantity.rst .
../../../home/bsipocz/devel/astropy/docs/units/standard_units.rst .
../../../home/bsipocz/devel/astropy/docs/utils/index.rst .
../../../home/bsipocz/devel/astropy/docs/utils/numpy.rst .
../../../home/bsipocz/devel/astropy/docs/visualization/index.rst .
../../../home/bsipocz/devel/astropy/docs/visualization/normalization.rst .
../../../home/bsipocz/devel/astropy/docs/vo/index.rst .
../../../home/bsipocz/devel/astropy/docs/vo/conesearch/client.rst .
../../../home/bsipocz/devel/astropy/docs/vo/conesearch/index.rst .
../../../home/bsipocz/devel/astropy/docs/vo/conesearch/validator.rst .
../../../home/bsipocz/devel/astropy/docs/vo/samp/advanced_embed_samp_hub.rst .
../../../home/bsipocz/devel/astropy/docs/vo/samp/example_clients.rst .
../../../home/bsipocz/devel/astropy/docs/vo/samp/example_hub.rst .
../../../home/bsipocz/devel/astropy/docs/vo/samp/example_table_image.rst .
../../../home/bsipocz/devel/astropy/docs/vo/samp/index.rst .
../../../home/bsipocz/devel/astropy/docs/wcs/history.rst .
../../../home/bsipocz/devel/astropy/docs/wcs/index.rst .
../../../home/bsipocz/devel/astropy/docs/wcs/relax.rst .
../../../home/bsipocz/devel/astropy/docs/whatsnew/0.1.rst .
../../../home/bsipocz/devel/astropy/docs/whatsnew/0.2.rst .
../../../home/bsipocz/devel/astropy/docs/whatsnew/0.3.rst .
../../../home/bsipocz/devel/astropy/docs/whatsnew/0.4.rst .
../../../home/bsipocz/devel/astropy/docs/whatsnew/1.0.rst .
../../../home/bsipocz/devel/astropy/docs/whatsnew/index.rst .
====================================================== ERRORS ======================================================
_______________________________ ERROR collecting astropy/io/ascii/tests/test_ecsv.py _______________________________
astropy/io/ascii/tests/test_ecsv.py:42: in <module>
> data = np.arange(3, dtype=dtype)
E TypeError: data type "float128" not understood
_______________________________ ERROR collecting astropy/io/ascii/tests/test_ecsv.py _______________________________
astropy/io/ascii/tests/test_ecsv.py:42: in <module>
> data = np.arange(3, dtype=dtype)
E TypeError: data type "float128" not understood
===================================================== FAILURES =====================================================
_______________________________________________ test_eloc_attributes _______________________________________________
def test_eloc_attributes():
from .. import AltAz, ITRS, GCRS, EarthLocation
el = EarthLocation(lon=12.3*u.deg, lat=45.6*u.deg, height=1*u.km)
it = ITRS(representation.SphericalRepresentation(lon=12.3*u.deg, lat=45.6*u.deg, distance=1*u.km))
gc = GCRS(ra=12.3*u.deg, dec=45.6*u.deg, distance=6375*u.km)
el1 = AltAz(location=el).location
assert isinstance(el1, EarthLocation)
assert el1.latitude == el.latitude
assert el1.longitude == el.longitude
assert el1.height == el.height
el2 = AltAz(location=it).location
assert isinstance(el2, EarthLocation)
assert el2.latitude != it.spherical.lat
> assert el2.longitude != it.spherical.lon
E assert <Longitude [ 12.3] deg> != <Longitude 12.3 deg>
E + where <Longitude [ 12.3] deg> = <EarthLocation [(0.6836029704431764, 0.14904955169200265, 0.7144726796328034)] km>.longitude
E + and <Longitude 12.3 deg> = <SphericalRepresentation lon=12.3 deg, lat=45.6 deg, distance=1.0 km>.lon
E + where <SphericalRepresentation lon=12.3 deg, lat=45.6 deg, distance=1.0 km> = <ITRS Coordinate (obstime=J2000.000): x=0.683602970443 km, y=0.149049551692 km, z=0.714472679633 km>.spherical
astropy/coordinates/tests/test_frames.py:531: AssertionError
________________________________________________ test_search_around ________________________________________________
@pytest.mark.skipif(str('not HAS_SCIPY'))
def test_search_around():
from .. import ICRS
from ..matching import search_around_sky, search_around_3d
coo1 = ICRS([4, 2.1]*u.degree, [0, 0]*u.degree, distance=[1, 5] * u.kpc)
coo2 = ICRS([1, 2, 3, 4]*u.degree, [0, 0, 0, 0]*u.degree, distance=[1, 1, 1, 5] * u.kpc)
> idx1_1deg, idx2_1deg, d2d_1deg, d3d_1deg = search_around_sky(coo1, coo2, 1.01*u.deg)
astropy/coordinates/tests/test_matching.py:126:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
coords1 = <ICRS Coordinate: (ra, dec, distance) in (deg, deg, kpc)
[(4.0, 0.0, 1.0), (2.1, 0.0, 5.0)]>
coords2 = <ICRS Coordinate: (ra, dec, distance) in (deg, deg, kpc)
[(1.0, 0.0, 1.0), (2.0, 0.0, 1.0), (3.0, 0.0, 1.0), (4.0, 0.0, 5.0)]>
seplimit = <Quantity 1.01 deg>, storekdtree = '_kdtree_sky'
def search_around_sky(coords1, coords2, seplimit, storekdtree='_kdtree_sky'):
"""
Searches for pairs of points that have an angular separation at least as
close as a specified angle.
Parameters
----------
coords1 : `~astropy.coordinates.BaseCoordinateFrame` or `~astropy.coordinates.SkyCoord`
The first set of coordinates, which will be searched for matches from
``coords2`` within ``seplimit``.
coords2 : `~astropy.coordinates.BaseCoordinateFrame` or `~astropy.coordinates.SkyCoord`
The second set of coordinates, which will be searched for matches from
``coords1`` within ``seplimit``.
seplimit : `~astropy.units.Quantity` with angle units
The on-sky separation to search within.
storekdtree : bool or str, optional
If a string, will store the KD-Tree used in the search as attributes
with the name ``storekdtree`` in ``coords2``. This speeds up subsequent
calls to this function. If False, the KD-Trees are not saved.
Returns
-------
idx1 : integer array
Indices into ``coords1`` that matches to the corresponding element of
``idx2``. Shape matches ``idx2``.
idx2 : integer array
Indices into ``coords2`` that matches to the corresponding element of
``idx1``. Shape matches ``idx1``.
sep2d : `~astropy.coordinates.Angle`
The on-sky separation between the coordinates. Shape matches ``idx1``
and ``idx2``.
dist3d : `~astropy.units.Quantity`
The 3D distance between the coordinates. Shape matches ``idx1`` and
``idx2``. If either ``coords1`` or ``coords2`` don't have a distance,
this is the 3D distance on the unit sphere, rather than a physical
distance.
Notes
-----
This function requires `SciPy <http://www.scipy.org>`_ to be installed
or it will fail.
In the current implementation, the return values are always sorted in the
same order as the ``coords1`` (so ``idx1`` is in ascending order). This is
considered an implementation detail, though, so it could change in a future
release.
"""
from . import Angle
if not seplimit.isscalar:
raise ValueError('seplimit must be a scalar in search_around_sky')
# we convert coord1 to match coord2's frame. We do it this way
# so that if the conversion does happen, the KD tree of coord2 at least gets
# saved. (by convention, coord2 is the "catalog" if that makes sense)
coords1 = coords1.transform_to(coords2)
#strip out distance info
urepr1 = coords1.data.represent_as(UnitSphericalRepresentation)
ucoords1 = coords1.realize_frame(urepr1)
kdt1 = _get_cartesian_kdtree(ucoords1, storekdtree)
if hasattr(coords2, storekdtree):
#just use the stored KD-Tree
kdt2 = getattr(coords2, storekdtree)
else:
#strip out distance info
urepr2 = coords2.data.represent_as(UnitSphericalRepresentation)
ucoords2 = coords2.realize_frame(urepr2)
kdt2 = _get_cartesian_kdtree(ucoords2, storekdtree)
#save the KD-Tree in coords2, *not* ucoords2
setattr(coords2, storekdtree, kdt2)
# this is the *cartesian* 3D distance that corresponds to the given angle
r = (2 * np.sin(Angle(seplimit) / 2.0)).value
idxs1 = []
idxs2 = []
> for i, matches in enumerate(kdt1.query_ball_tree(kdt2, r)):
for match in matches:
idxs1.append(i)
E AttributeError: 'scipy.spatial.ckdtree.cKDTree' object has no attribute 'query_ball_tree'
astropy/coordinates/matching.py:330: AttributeError
________________________________________________ test_search_around ________________________________________________
@pytest.mark.skipif(str('not HAS_SCIPY'))
def test_search_around():
"""
Test the search_around_* methods
Here we don't actually test the values are right, just that the methods of
SkyCoord work. The accuracy tests are in ``test_matching.py``
"""
from ...utils import NumpyRNGContext
with NumpyRNGContext(987654321):
sc1 = SkyCoord(np.random.rand(20) * 360.*u.degree,
(np.random.rand(20) * 180. - 90.)*u.degree)
sc2 = SkyCoord(np.random.rand(100) * 360. * u.degree,
(np.random.rand(100) * 180. - 90.)*u.degree)
sc1ds = SkyCoord(ra=sc1.ra, dec=sc1.dec, distance=np.random.rand(20)*u.kpc)
sc2ds = SkyCoord(ra=sc2.ra, dec=sc2.dec, distance=np.random.rand(100)*u.kpc)
> idx1_sky, idx2_sky, d2d_sky, d3d_sky = sc1.search_around_sky(sc2, 10*u.deg)
astropy/coordinates/tests/test_sky_coord.py:900:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <SkyCoord (ICRS): (ra, dec) in deg
[(26.275800040259153, -76.7444757037445...2078542803, 28.028547764362997),
(254.21501666703523, 5.911974409973126)]>
searcharoundcoords = <SkyCoord (ICRS): (ra, dec) in deg
[(227.9534475237205, -81.7400657555329)...6713255627, -20.72188123716164),
(141.84561715987917, 49.92058985137862)]>
seplimit = <Quantity 10.0 deg>
def search_around_sky(self, searcharoundcoords, seplimit):
"""
Searches for all coordinates in this object around a supplied set of
points within a given on-sky separation.
Parameters
----------
searcharoundcoords : `~astropy.coordinates.SkyCoord` or `~astropy.coordinates.BaseCoordinateFrame`
The coordinate(s) to search around to try to find matching points in
this `SkyCoord`.
seplimit : `~astropy.units.Quantity` with angle units
The on-sky separation to search within.
Returns
-------
idxsearcharound : integer array
Indices into ``coords1`` that matches to the corresponding element of
``idxself``. Shape matches ``idxself``.
idxself : integer array
Indices into ``coords2`` that matches to the corresponding element of
``idxsearcharound``. Shape matches ``idxsearcharound``.
sep2d : `~astropy.coordinates.Angle`
The on-sky separation between the coordinates. Shape matches
``idxsearcharound`` and ``idxself``.
dist3d : `~astropy.units.Quantity`
The 3D distance between the coordinates. Shape matches
``idxsearcharound`` and ``idxself``.
Notes
-----
This method requires `SciPy <http://www.scipy.org>`_ to be
installed or it will fail.
In the current implementation, the return values are always sorted in
the same order as the ``searcharoundcoords`` (so ``idxsearcharound`` is
in ascending order). This is considered an implementation detail,
though, so it could change in a future release.
See Also
--------
astropy.coordinates.search_around_sky
"""
from .matching import search_around_sky
return search_around_sky(searcharoundcoords, self, seplimit,
> storekdtree='_kdtree_sky')
astropy/coordinates/sky_coordinate.py:798:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
coords1 = <SkyCoord (ICRS): (ra, dec) in deg
[(227.9534475237205, -81.7400657555329)...6713255627, -20.72188123716164),
(141.84561715987917, 49.92058985137862)]>
coords2 = <SkyCoord (ICRS): (ra, dec) in deg
[(26.275800040259153, -76.7444757037445...2078542803, 28.028547764362997),
(254.21501666703523, 5.911974409973126)]>
seplimit = <Quantity 10.0 deg>, storekdtree = '_kdtree_sky'
def search_around_sky(coords1, coords2, seplimit, storekdtree='_kdtree_sky'):
"""
Searches for pairs of points that have an angular separation at least as
close as a specified angle.
Parameters
----------
coords1 : `~astropy.coordinates.BaseCoordinateFrame` or `~astropy.coordinates.SkyCoord`
The first set of coordinates, which will be searched for matches from
``coords2`` within ``seplimit``.
coords2 : `~astropy.coordinates.BaseCoordinateFrame` or `~astropy.coordinates.SkyCoord`
The second set of coordinates, which will be searched for matches from
``coords1`` within ``seplimit``.
seplimit : `~astropy.units.Quantity` with angle units
The on-sky separation to search within.
storekdtree : bool or str, optional
If a string, will store the KD-Tree used in the search as attributes
with the name ``storekdtree`` in ``coords2``. This speeds up subsequent
calls to this function. If False, the KD-Trees are not saved.
Returns
-------
idx1 : integer array
Indices into ``coords1`` that matches to the corresponding element of
``idx2``. Shape matches ``idx2``.
idx2 : integer array
Indices into ``coords2`` that matches to the corresponding element of
``idx1``. Shape matches ``idx1``.
sep2d : `~astropy.coordinates.Angle`
The on-sky separation between the coordinates. Shape matches ``idx1``
and ``idx2``.
dist3d : `~astropy.units.Quantity`
The 3D distance between the coordinates. Shape matches ``idx1`` and
``idx2``. If either ``coords1`` or ``coords2`` don't have a distance,
this is the 3D distance on the unit sphere, rather than a physical
distance.
Notes
-----
This function requires `SciPy <http://www.scipy.org>`_ to be installed
or it will fail.
In the current implementation, the return values are always sorted in the
same order as the ``coords1`` (so ``idx1`` is in ascending order). This is
considered an implementation detail, though, so it could change in a future
release.
"""
from . import Angle
if not seplimit.isscalar:
raise ValueError('seplimit must be a scalar in search_around_sky')
# we convert coord1 to match coord2's frame. We do it this way
# so that if the conversion does happen, the KD tree of coord2 at least gets
# saved. (by convention, coord2 is the "catalog" if that makes sense)
coords1 = coords1.transform_to(coords2)
#strip out distance info
urepr1 = coords1.data.represent_as(UnitSphericalRepresentation)
ucoords1 = coords1.realize_frame(urepr1)
kdt1 = _get_cartesian_kdtree(ucoords1, storekdtree)
if hasattr(coords2, storekdtree):
#just use the stored KD-Tree
kdt2 = getattr(coords2, storekdtree)
else:
#strip out distance info
urepr2 = coords2.data.represent_as(UnitSphericalRepresentation)
ucoords2 = coords2.realize_frame(urepr2)
kdt2 = _get_cartesian_kdtree(ucoords2, storekdtree)
#save the KD-Tree in coords2, *not* ucoords2
setattr(coords2, storekdtree, kdt2)
# this is the *cartesian* 3D distance that corresponds to the given angle
r = (2 * np.sin(Angle(seplimit) / 2.0)).value
idxs1 = []
idxs2 = []
> for i, matches in enumerate(kdt1.query_ball_tree(kdt2, r)):
for match in matches:
idxs1.append(i)
E AttributeError: 'scipy.spatial.ckdtree.cKDTree' object has no attribute 'query_ball_tree'
astropy/coordinates/matching.py:330: AttributeError
_______________________________________ TestFileFunctions.test_write_bytesio _______________________________________
self = <astropy.io.fits.tests.test_core.TestFileFunctions object at 0xe4c768c>
def test_write_bytesio(self):
"""
Regression test for https://github.com/astropy/astropy/issues/2463
Test againt `io.BytesIO`. `io.StringIO` is not supported.
"""
> self._test_write_string_bytes_io(io.BytesIO())
astropy/io/fits/tests/test_core.py:948:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.io.fits.tests.test_core.TestFileFunctions object at 0xe4c768c>
fileobj = <_io.BytesIO object at 0xf224a4c>
def _test_write_string_bytes_io(self, fileobj):
"""
Implemented for both test_write_stringio and test_write_bytesio.
"""
with fits.open(self.data('test0.fits')) as hdul:
> hdul.writeto(fileobj)
astropy/io/fits/tests/test_core.py:973:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = [<astropy.io.fits.hdu.image.PrimaryHDU object at 0xe4c7c0c>, <astropy.io.fits....object at 0xe4b5e8c>, <astropy.io.fits.hdu.image.ImageHDU object at 0xe2d8c2c>]
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xf224a4c>>, output_verify = 'exception'
clobber = False, checksum = False
def writeto(self, fileobj, output_verify='exception', clobber=False,
checksum=False):
"""
Write the `HDUList` to a new file.
Parameters
----------
fileobj : file path, file object or file-like object
File to write to. If a file object, must be opened in a
writeable mode.
output_verify : str
Output verification option. Must be one of ``"fix"``,
``"silentfix"``, ``"ignore"``, ``"warn"``, or
``"exception"``. May also be any combination of ``"fix"`` or
``"silentfix"`` with ``"+ignore"``, ``+warn``, or ``+exception"
(e.g. ``"fix+warn"``). See :ref:`verify` for more info.
clobber : bool
When `True`, overwrite the output file if exists.
checksum : bool
When `True` adds both ``DATASUM`` and ``CHECKSUM`` cards
to the headers of all HDU's written to the file.
"""
if (len(self) == 0):
warnings.warn("There is nothing to write.", AstropyUserWarning)
return
self.verify(option=output_verify)
# make sure the EXTEND keyword is there if there is extension
self.update_extend()
# make note of whether the input file object is already open, in which
# case we should not close it after writing (that should be the job
# of the caller)
closed = isinstance(fileobj, string_types) or fileobj_closed(fileobj)
# writeto is only for writing a new file from scratch, so the most
# sensible mode to require is 'ostream'. This can accept an open
# file object that's open to write only, or in append/update modes
# but only if the file doesn't exist.
fileobj = _File(fileobj, mode='ostream', clobber=clobber)
hdulist = self.fromfile(fileobj)
for hdu in self:
hdu._prewriteto(checksum=checksum)
try:
> hdu._writeto(hdulist.__file)
astropy/io/fits/hdu/hdulist.py:682:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.io.fits.hdu.image.ImageHDU object at 0xe4a7aec>
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xf224a4c>>, inplace = False, copy = False
def _writeto(self, fileobj, inplace=False, copy=False):
# For now fileobj is assumed to be a _File object
if not inplace or self._new:
header_offset, _ = self._writeheader(fileobj)
> data_offset, data_size = self._writedata(fileobj)
astropy/io/fits/hdu/base.py:698:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.io.fits.hdu.image.ImageHDU object at 0xe4a7aec>
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xf224a4c>>
def _writedata(self, fileobj):
# TODO: A lot of the simulateonly stuff should be moved back into the
# _File class--basically it should turn write and flush into a noop
offset = 0
size = 0
if not fileobj.simulateonly:
fileobj.flush()
try:
offset = fileobj.tell()
except IOError:
offset = 0
if self._data_loaded or self._data_needs_rescale:
if self.data is not None:
size += self._writedata_internal(fileobj)
# pad the FITS data block
if size > 0:
padding = _pad_length(size) * self._padding_byte
# TODO: Not that this is ever likely, but if for some odd
# reason _padding_byte is > 0x80 this will fail; but really if
# somebody's custom fits format is doing that, they're doing it
# wrong and should be reprimanded harshly.
fileobj.write(padding.encode('ascii'))
size += len(padding)
else:
# The data has not been modified or does not need need to be
# rescaled, so it can be copied, unmodified, directly from an
# existing file or buffer
> size += self._writedata_direct_copy(fileobj)
astropy/io/fits/hdu/base.py:649:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.io.fits.hdu.image.ImageHDU object at 0xe4a7aec>
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xf224a4c>>
def _writedata_direct_copy(self, fileobj):
"""Copies the data directly from one file/buffer to the new file.
For now this is handled by loading the raw data from the existing data
(including any padding) via a memory map or from an already in-memory
buffer and using Numpy's existing file-writing facilities to write to
the new file.
If this proves too slow a more direct approach may be used.
"""
raw = self._get_raw_data(self._data_size, 'ubyte', self._data_offset)
if raw is not None:
> _array_to_file(raw, fileobj)
astropy/io/fits/hdu/base.py:685:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
arr = array([ 1, 57, 1, ..., 0, 0, 0], dtype=uint8)
outfile = <astropy.io.fits.file._File <_io.BytesIO object at 0xf224a4c>>
def _array_to_file(arr, outfile):
"""
Write a numpy array to a file or a file-like object.
Parameters
----------
arr : `~numpy.ndarray`
The Numpy array to write.
outfile : file-like
A file-like object such as a Python file object, an `io.BytesIO`, or
anything else with a ``write`` method. The file object must support
the buffer interface in its ``write``.
If writing directly to an on-disk file this delegates directly to
`ndarray.tofile`. Otherwise a slower Python implementation is used.
"""
if isfile(outfile):
write = lambda a, f: a.tofile(f)
else:
write = _array_to_file_like
# Implements a workaround for a bug deep in OSX's stdlib file writing
# functions; on 64-bit OSX it is not possible to correctly write a number
# of bytes greater than 2 ** 32 and divisible by 4096 (or possibly 8192--
# whatever the default blocksize for the filesystem is).
# This issue should have a workaround in Numpy too, but hasn't been
# implemented there yet: https://github.com/astropy/astropy/issues/839
#
# Apparently Windows has its own fwrite bug:
# https://github.com/numpy/numpy/issues/2256
if (sys.platform == 'darwin' and arr.nbytes >= _OSX_WRITE_LIMIT + 1 and
arr.nbytes % 4096 == 0):
# chunksize is a count of elements in the array, not bytes
chunksize = _OSX_WRITE_LIMIT // arr.itemsize
elif sys.platform.startswith('win'):
chunksize = _WIN_WRITE_LIMIT // arr.itemsize
else:
# Just pass the whole array to the write routine
> return write(arr, outfile)
astropy/io/fits/util.py:674:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
arr = array([ 1, 57, 1, ..., 0, 0, 0], dtype=uint8)
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xf224a4c>>
def _array_to_file_like(arr, fileobj):
"""
Write a `~numpy.ndarray` to a file-like object (which is not supported by
`numpy.ndarray.tofile`).
"""
if arr.flags.contiguous:
# It suffices to just pass the underlying buffer directly to the
# fileobj's write (assuming it supports the buffer interface, which
# unfortunately there's no simple way to check)
> fileobj.write(arr.data)
astropy/io/fits/util.py:695:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.io.fits.file._File <_io.BytesIO object at 0xf224a4c>>
string = <read-write buffer for 0xe594020, size 5760, offset 0 at 0xe4c8fc0>
def write(self, string):
if hasattr(self.__file, 'write'):
> _write_string(self.__file, string)
astropy/io/fits/file.py:268:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
f = <_io.BytesIO object at 0xf224a4c>, s = <read-write buffer for 0xe594020, size 5760, offset 0 at 0xe4c8fc0>
def _write_string(f, s):
"""
Write a string to a file, encoding to ASCII if the file is open in binary
mode, or decoding if the file is open in text mode.
"""
# Assume if the file object doesn't have a specific mode, that the mode is
# binary
binmode = fileobj_is_binary(f)
if binmode and isinstance(s, text_type):
s = encode_ascii(s)
elif not binmode and not isinstance(f, text_type):
s = decode_ascii(s)
elif isinstance(f, StringIO) and isinstance(s, np.ndarray):
# Workaround for StringIO/ndarray incompatibility
s = s.data
> f.write(s)
E TypeError: 'buffer' does not have the buffer interface
astropy/io/fits/util.py:731: TypeError
____________________________ TestStreamingFunctions.test_streaming_hdu_write_file_like _____________________________
self = <astropy.io.fits.tests.test_core.TestStreamingFunctions object at 0xe681c4c>
def test_streaming_hdu_write_file_like(self):
"""Test streaming an HDU to an open file-like object."""
arr = np.zeros((5, 5), dtype=np.int32)
# The file-like object underlying a StreamingHDU must be in binary mode
sf = io.BytesIO()
shdu = self._make_streaming_hdu(sf)
> shdu.write(arr)
astropy/io/fits/tests/test_core.py:1033:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.io.fits.hdu.streaming.StreamingHDU object at 0xe681cac>
data = array([[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]])
def write(self, data):
"""
Write the given data to the stream.
Parameters
----------
data : ndarray
Data to stream to the file.
Returns
-------
writecomplete : int
Flag that when `True` indicates that all of the required
data has been written to the stream.
Notes
-----
Only the amount of data specified in the header provided to the class
constructor may be written to the stream. If the provided data would
cause the stream to overflow, an `~.exceptions.IOError` exception is
raised and the data is not written. Once sufficient data has been
written to the stream to satisfy the amount specified in the header,
the stream is padded to fill a complete FITS block and no more data
will be accepted. An attempt to write more data after the stream has
been filled will raise an `~.exceptions.IOError` exception. If the
dtype of the input data does not match what is expected by the header,
a `.exceptions.TypeError` exception is raised.
"""
size = self._ffo.tell() - self._data_offset
if self.writecomplete or size + data.nbytes > self._size:
raise IOError('Attempt to write more data to the stream than the '
'header specified.')
if _ImageBaseHDU.NumCode[self._header['BITPIX']] != data.dtype.name:
raise TypeError('Supplied data does not match the type specified '
'in the header.')
if data.dtype.str[0] != '>':
# byteswap little endian arrays before writing
output = data.byteswap()
else:
output = data
> self._ffo.writearray(output)
astropy/io/fits/hdu/streaming.py:184:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.io.fits.file._File <_io.BytesIO object at 0xe1c2b6c>>
array = array([[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]])
def writearray(self, array):
"""
Similar to file.write(), but writes a numpy array instead of a string.
Also like file.write(), a flush() or close() may be needed before
the file on disk reflects the data written.
"""
if hasattr(self.__file, 'write'):
> _array_to_file(array, self.__file)
astropy/io/fits/file.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
arr = array([[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]])
outfile = <_io.BytesIO object at 0xe1c2b6c>
def _array_to_file(arr, outfile):
"""
Write a numpy array to a file or a file-like object.
Parameters
----------
arr : `~numpy.ndarray`
The Numpy array to write.
outfile : file-like
A file-like object such as a Python file object, an `io.BytesIO`, or
anything else with a ``write`` method. The file object must support
the buffer interface in its ``write``.
If writing directly to an on-disk file this delegates directly to
`ndarray.tofile`. Otherwise a slower Python implementation is used.
"""
if isfile(outfile):
write = lambda a, f: a.tofile(f)
else:
write = _array_to_file_like
# Implements a workaround for a bug deep in OSX's stdlib file writing
# functions; on 64-bit OSX it is not possible to correctly write a number
# of bytes greater than 2 ** 32 and divisible by 4096 (or possibly 8192--
# whatever the default blocksize for the filesystem is).
# This issue should have a workaround in Numpy too, but hasn't been
# implemented there yet: https://github.com/astropy/astropy/issues/839
#
# Apparently Windows has its own fwrite bug:
# https://github.com/numpy/numpy/issues/2256
if (sys.platform == 'darwin' and arr.nbytes >= _OSX_WRITE_LIMIT + 1 and
arr.nbytes % 4096 == 0):
# chunksize is a count of elements in the array, not bytes
chunksize = _OSX_WRITE_LIMIT // arr.itemsize
elif sys.platform.startswith('win'):
chunksize = _WIN_WRITE_LIMIT // arr.itemsize
else:
# Just pass the whole array to the write routine
> return write(arr, outfile)
astropy/io/fits/util.py:674:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
arr = array([[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]])
fileobj = <_io.BytesIO object at 0xe1c2b6c>
def _array_to_file_like(arr, fileobj):
"""
Write a `~numpy.ndarray` to a file-like object (which is not supported by
`numpy.ndarray.tofile`).
"""
if arr.flags.contiguous:
# It suffices to just pass the underlying buffer directly to the
# fileobj's write (assuming it supports the buffer interface, which
# unfortunately there's no simple way to check)
> fileobj.write(arr.data)
E TypeError: 'buffer' does not have the buffer interface
astropy/io/fits/util.py:695: TypeError
____________________________________ TestHDUListFunctions.test_update_filelike _____________________________________
self = <astropy.io.fits.tests.test_hdulist.TestHDUListFunctions object at 0xe265dac>
def test_update_filelike(self):
"""Test opening a file-like object in update mode and resizing the
HDU.
"""
sf = io.BytesIO()
arr = np.zeros((100, 100))
hdu = fits.PrimaryHDU(data=arr)
> hdu.writeto(sf)
astropy/io/fits/tests/test_hdulist.py:402:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.io.fits.hdu.image.PrimaryHDU object at 0xe17230c>, name = <_io.BytesIO object at 0xe269aac>
output_verify = 'exception', clobber = False, checksum = False
def writeto(self, name, output_verify='exception', clobber=False,
checksum=False):
"""
Write the HDU to a new file. This is a convenience method to
provide a user easier output interface if only one HDU needs
to be written to a file.
Parameters
----------
name : file path, file object or file-like object
Output FITS file. If the file object is already opened, it must
be opened in a writeable mode.
output_verify : str
Output verification option. Must be one of ``"fix"``,
``"silentfix"``, ``"ignore"``, ``"warn"``, or
``"exception"``. May also be any combination of ``"fix"`` or
``"silentfix"`` with ``"+ignore"``, ``+warn``, or ``+exception"
(e.g. ``"fix+warn"``). See :ref:`verify` for more info.
clobber : bool
Overwrite the output file if exists.
checksum : bool
When `True` adds both ``DATASUM`` and ``CHECKSUM`` cards
to the header of the HDU when written to the file.
"""
from .hdulist import HDUList
hdulist = HDUList([self])
hdulist.writeto(name, output_verify, clobber=clobber,
> checksum=checksum)
astropy/io/fits/hdu/base.py:417:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = [<astropy.io.fits.hdu.image.PrimaryHDU object at 0xe17230c>]
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xe269aac>>, output_verify = 'exception'
clobber = False, checksum = False
def writeto(self, fileobj, output_verify='exception', clobber=False,
checksum=False):
"""
Write the `HDUList` to a new file.
Parameters
----------
fileobj : file path, file object or file-like object
File to write to. If a file object, must be opened in a
writeable mode.
output_verify : str
Output verification option. Must be one of ``"fix"``,
``"silentfix"``, ``"ignore"``, ``"warn"``, or
``"exception"``. May also be any combination of ``"fix"`` or
``"silentfix"`` with ``"+ignore"``, ``+warn``, or ``+exception"
(e.g. ``"fix+warn"``). See :ref:`verify` for more info.
clobber : bool
When `True`, overwrite the output file if exists.
checksum : bool
When `True` adds both ``DATASUM`` and ``CHECKSUM`` cards
to the headers of all HDU's written to the file.
"""
if (len(self) == 0):
warnings.warn("There is nothing to write.", AstropyUserWarning)
return
self.verify(option=output_verify)
# make sure the EXTEND keyword is there if there is extension
self.update_extend()
# make note of whether the input file object is already open, in which
# case we should not close it after writing (that should be the job
# of the caller)
closed = isinstance(fileobj, string_types) or fileobj_closed(fileobj)
# writeto is only for writing a new file from scratch, so the most
# sensible mode to require is 'ostream'. This can accept an open
# file object that's open to write only, or in append/update modes
# but only if the file doesn't exist.
fileobj = _File(fileobj, mode='ostream', clobber=clobber)
hdulist = self.fromfile(fileobj)
for hdu in self:
hdu._prewriteto(checksum=checksum)
try:
> hdu._writeto(hdulist.__file)
astropy/io/fits/hdu/hdulist.py:682:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.io.fits.hdu.image.PrimaryHDU object at 0xe17230c>
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xe269aac>>, inplace = False, copy = False
def _writeto(self, fileobj, inplace=False, copy=False):
# For now fileobj is assumed to be a _File object
if not inplace or self._new:
header_offset, _ = self._writeheader(fileobj)
> data_offset, data_size = self._writedata(fileobj)
astropy/io/fits/hdu/base.py:698:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.io.fits.hdu.image.PrimaryHDU object at 0xe17230c>
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xe269aac>>
def _writedata(self, fileobj):
# TODO: A lot of the simulateonly stuff should be moved back into the
# _File class--basically it should turn write and flush into a noop
offset = 0
size = 0
if not fileobj.simulateonly:
fileobj.flush()
try:
offset = fileobj.tell()
except IOError:
offset = 0
if self._data_loaded or self._data_needs_rescale:
if self.data is not None:
> size += self._writedata_internal(fileobj)
astropy/io/fits/hdu/base.py:635:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.io.fits.hdu.image.PrimaryHDU object at 0xe17230c>
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xe269aac>>
def _writedata_internal(self, fileobj):
size = 0
if self.data is not None:
# Based on the system type, determine the byteorders that
# would need to be swapped to get to big-endian output
if sys.byteorder == 'little':
swap_types = ('<', '=')
else:
swap_types = ('<',)
# deal with unsigned integer 16, 32 and 64 data
if _is_pseudo_unsigned(self.data.dtype):
# Convert the unsigned array to signed
output = np.array(
self.data - _unsigned_zero(self.data.dtype),
dtype='>i%d' % self.data.dtype.itemsize)
should_swap = False
else:
output = self.data
byteorder = output.dtype.str[0]
should_swap = (byteorder in swap_types)
if not fileobj.simulateonly:
if should_swap:
output.byteswap(True)
try:
> fileobj.writearray(output)
astropy/io/fits/hdu/image.py:521:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.io.fits.file._File <_io.BytesIO object at 0xe269aac>>
array = array([[ 0., 0., 0., ..., 0., 0., 0.],
[ 0., 0., 0., ..., 0., ...0., 0., 0., ..., 0., 0., 0.],
[ 0., 0., 0., ..., 0., 0., 0.]])
def writearray(self, array):
"""
Similar to file.write(), but writes a numpy array instead of a string.
Also like file.write(), a flush() or close() may be needed before
the file on disk reflects the data written.
"""
if hasattr(self.__file, 'write'):
> _array_to_file(array, self.__file)
astropy/io/fits/file.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
arr = array([[ 0., 0., 0., ..., 0., 0., 0.],
[ 0., 0., 0., ..., 0., ...0., 0., 0., ..., 0., 0., 0.],
[ 0., 0., 0., ..., 0., 0., 0.]])
outfile = <_io.BytesIO object at 0xe269aac>
def _array_to_file(arr, outfile):
"""
Write a numpy array to a file or a file-like object.
Parameters
----------
arr : `~numpy.ndarray`
The Numpy array to write.
outfile : file-like
A file-like object such as a Python file object, an `io.BytesIO`, or
anything else with a ``write`` method. The file object must support
the buffer interface in its ``write``.
If writing directly to an on-disk file this delegates directly to
`ndarray.tofile`. Otherwise a slower Python implementation is used.
"""
if isfile(outfile):
write = lambda a, f: a.tofile(f)
else:
write = _array_to_file_like
# Implements a workaround for a bug deep in OSX's stdlib file writing
# functions; on 64-bit OSX it is not possible to correctly write a number
# of bytes greater than 2 ** 32 and divisible by 4096 (or possibly 8192--
# whatever the default blocksize for the filesystem is).
# This issue should have a workaround in Numpy too, but hasn't been
# implemented there yet: https://github.com/astropy/astropy/issues/839
#
# Apparently Windows has its own fwrite bug:
# https://github.com/numpy/numpy/issues/2256
if (sys.platform == 'darwin' and arr.nbytes >= _OSX_WRITE_LIMIT + 1 and
arr.nbytes % 4096 == 0):
# chunksize is a count of elements in the array, not bytes
chunksize = _OSX_WRITE_LIMIT // arr.itemsize
elif sys.platform.startswith('win'):
chunksize = _WIN_WRITE_LIMIT // arr.itemsize
else:
# Just pass the whole array to the write routine
> return write(arr, outfile)
astropy/io/fits/util.py:674:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
arr = array([[ 0., 0., 0., ..., 0., 0., 0.],
[ 0., 0., 0., ..., 0., ...0., 0., 0., ..., 0., 0., 0.],
[ 0., 0., 0., ..., 0., 0., 0.]])
fileobj = <_io.BytesIO object at 0xe269aac>
def _array_to_file_like(arr, fileobj):
"""
Write a `~numpy.ndarray` to a file-like object (which is not supported by
`numpy.ndarray.tofile`).
"""
if arr.flags.contiguous:
# It suffices to just pass the underlying buffer directly to the
# fileobj's write (assuming it supports the buffer interface, which
# unfortunately there's no simple way to check)
> fileobj.write(arr.data)
E TypeError: 'buffer' does not have the buffer interface
astropy/io/fits/util.py:695: TypeError
_____________________________________ TestNonstandardHdus.test_create_fitshdu ______________________________________
self = <astropy.io.fits.tests.test_nonstandard.TestNonstandardHdus object at 0xf233e6c>
def test_create_fitshdu(self):
"""
A round trip test of creating a FitsHDU, adding a FITS file to it,
writing the FitsHDU out as part of a new FITS file, and then reading
it and recovering the original FITS file.
"""
> self._test_create_fitshdu(compression=False)
astropy/io/fits/tests/test_nonstandard.py:17:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.io.fits.tests.test_nonstandard.TestNonstandardHdus object at 0xf233e6c>, compression = False
def _test_create_fitshdu(self, compression=False):
hdul_orig = fits.open(self.data('test0.fits'),
do_not_scale_image_data=True)
> fitshdu = fits.FitsHDU.fromhdulist(hdul_orig, compress=compression)
astropy/io/fits/tests/test_nonstandard.py:49:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cls = <class 'astropy.io.fits.hdu.nonstandard.FitsHDU'>
hdulist = [<astropy.io.fits.hdu.image.PrimaryHDU object at 0xf2333cc>, <astropy.io.fits....object at 0xf3a954c>, <astropy.io.fits.hdu.image.ImageHDU object at 0xf24d02c>]
compress = False
@classmethod
def fromhdulist(cls, hdulist, compress=False):
"""
Creates a new FitsHDU from a given HDUList object.
Parameters
----------
hdulist : HDUList
A valid Headerlet object.
compress : bool, optional
Gzip compress the FITS file
"""
fileobj = bs = io.BytesIO()
if compress:
if hasattr(hdulist, '_file'):
name = fileobj_name(hdulist._file)
else:
name = None
fileobj = gzip.GzipFile(name, mode='wb', fileobj=bs)
> hdulist.writeto(fileobj)
astropy/io/fits/hdu/nonstandard.py:79:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = [<astropy.io.fits.hdu.image.PrimaryHDU object at 0xf2333cc>, <astropy.io.fits....object at 0xf3a954c>, <astropy.io.fits.hdu.image.ImageHDU object at 0xf24d02c>]
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xe1fff8c>>, output_verify = 'exception'
clobber = False, checksum = False
def writeto(self, fileobj, output_verify='exception', clobber=False,
checksum=False):
"""
Write the `HDUList` to a new file.
Parameters
----------
fileobj : file path, file object or file-like object
File to write to. If a file object, must be opened in a
writeable mode.
output_verify : str
Output verification option. Must be one of ``"fix"``,
``"silentfix"``, ``"ignore"``, ``"warn"``, or
``"exception"``. May also be any combination of ``"fix"`` or
``"silentfix"`` with ``"+ignore"``, ``+warn``, or ``+exception"
(e.g. ``"fix+warn"``). See :ref:`verify` for more info.
clobber : bool
When `True`, overwrite the output file if exists.
checksum : bool
When `True` adds both ``DATASUM`` and ``CHECKSUM`` cards
to the headers of all HDU's written to the file.
"""
if (len(self) == 0):
warnings.warn("There is nothing to write.", AstropyUserWarning)
return
self.verify(option=output_verify)
# make sure the EXTEND keyword is there if there is extension
self.update_extend()
# make note of whether the input file object is already open, in which
# case we should not close it after writing (that should be the job
# of the caller)
closed = isinstance(fileobj, string_types) or fileobj_closed(fileobj)
# writeto is only for writing a new file from scratch, so the most
# sensible mode to require is 'ostream'. This can accept an open
# file object that's open to write only, or in append/update modes
# but only if the file doesn't exist.
fileobj = _File(fileobj, mode='ostream', clobber=clobber)
hdulist = self.fromfile(fileobj)
for hdu in self:
hdu._prewriteto(checksum=checksum)
try:
> hdu._writeto(hdulist.__file)
astropy/io/fits/hdu/hdulist.py:682:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.io.fits.hdu.image.PrimaryHDU object at 0xf2333cc>
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xe1fff8c>>, inplace = False, copy = False
def _writeto(self, fileobj, inplace=False, copy=False):
# For now fileobj is assumed to be a _File object
if not inplace or self._new:
header_offset, _ = self._writeheader(fileobj)
> data_offset, data_size = self._writedata(fileobj)
astropy/io/fits/hdu/base.py:698:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.io.fits.hdu.image.PrimaryHDU object at 0xf2333cc>
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xe1fff8c>>
def _writedata(self, fileobj):
# TODO: A lot of the simulateonly stuff should be moved back into the
# _File class--basically it should turn write and flush into a noop
offset = 0
size = 0
if not fileobj.simulateonly:
fileobj.flush()
try:
offset = fileobj.tell()
except IOError:
offset = 0
if self._data_loaded or self._data_needs_rescale:
if self.data is not None:
size += self._writedata_internal(fileobj)
# pad the FITS data block
if size > 0:
padding = _pad_length(size) * self._padding_byte
# TODO: Not that this is ever likely, but if for some odd
# reason _padding_byte is > 0x80 this will fail; but really if
# somebody's custom fits format is doing that, they're doing it
# wrong and should be reprimanded harshly.
fileobj.write(padding.encode('ascii'))
size += len(padding)
else:
# The data has not been modified or does not need need to be
# rescaled, so it can be copied, unmodified, directly from an
# existing file or buffer
> size += self._writedata_direct_copy(fileobj)
astropy/io/fits/hdu/base.py:649:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.io.fits.hdu.image.PrimaryHDU object at 0xf2333cc>
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xe1fff8c>>
def _writedata_direct_copy(self, fileobj):
"""Copies the data directly from one file/buffer to the new file.
For now this is handled by loading the raw data from the existing data
(including any padding) via a memory map or from an already in-memory
buffer and using Numpy's existing file-writing facilities to write to
the new file.
If this proves too slow a more direct approach may be used.
"""
raw = self._get_raw_data(self._data_size, 'ubyte', self._data_offset)
if raw is not None:
> _array_to_file(raw, fileobj)
astropy/io/fits/hdu/base.py:685:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
arr = array([], dtype=uint8), outfile = <astropy.io.fits.file._File <_io.BytesIO object at 0xe1fff8c>>
def _array_to_file(arr, outfile):
"""
Write a numpy array to a file or a file-like object.
Parameters
----------
arr : `~numpy.ndarray`
The Numpy array to write.
outfile : file-like
A file-like object such as a Python file object, an `io.BytesIO`, or
anything else with a ``write`` method. The file object must support
the buffer interface in its ``write``.
If writing directly to an on-disk file this delegates directly to
`ndarray.tofile`. Otherwise a slower Python implementation is used.
"""
if isfile(outfile):
write = lambda a, f: a.tofile(f)
else:
write = _array_to_file_like
# Implements a workaround for a bug deep in OSX's stdlib file writing
# functions; on 64-bit OSX it is not possible to correctly write a number
# of bytes greater than 2 ** 32 and divisible by 4096 (or possibly 8192--
# whatever the default blocksize for the filesystem is).
# This issue should have a workaround in Numpy too, but hasn't been
# implemented there yet: https://github.com/astropy/astropy/issues/839
#
# Apparently Windows has its own fwrite bug:
# https://github.com/numpy/numpy/issues/2256
if (sys.platform == 'darwin' and arr.nbytes >= _OSX_WRITE_LIMIT + 1 and
arr.nbytes % 4096 == 0):
# chunksize is a count of elements in the array, not bytes
chunksize = _OSX_WRITE_LIMIT // arr.itemsize
elif sys.platform.startswith('win'):
chunksize = _WIN_WRITE_LIMIT // arr.itemsize
else:
# Just pass the whole array to the write routine
> return write(arr, outfile)
astropy/io/fits/util.py:674:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
arr = array([], dtype=uint8), fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xe1fff8c>>
def _array_to_file_like(arr, fileobj):
"""
Write a `~numpy.ndarray` to a file-like object (which is not supported by
`numpy.ndarray.tofile`).
"""
if arr.flags.contiguous:
# It suffices to just pass the underlying buffer directly to the
# fileobj's write (assuming it supports the buffer interface, which
# unfortunately there's no simple way to check)
> fileobj.write(arr.data)
astropy/io/fits/util.py:695:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.io.fits.file._File <_io.BytesIO object at 0xe1fff8c>>
string = <read-write buffer for 0xe578570, size 0, offset 0 at 0xf5465a0>
def write(self, string):
if hasattr(self.__file, 'write'):
> _write_string(self.__file, string)
astropy/io/fits/file.py:268:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
f = <_io.BytesIO object at 0xe1fff8c>, s = <read-write buffer for 0xe578570, size 0, offset 0 at 0xf5465a0>
def _write_string(f, s):
"""
Write a string to a file, encoding to ASCII if the file is open in binary
mode, or decoding if the file is open in text mode.
"""
# Assume if the file object doesn't have a specific mode, that the mode is
# binary
binmode = fileobj_is_binary(f)
if binmode and isinstance(s, text_type):
s = encode_ascii(s)
elif not binmode and not isinstance(f, text_type):
s = decode_ascii(s)
elif isinstance(f, StringIO) and isinstance(s, np.ndarray):
# Workaround for StringIO/ndarray incompatibility
s = s.data
> f.write(s)
E TypeError: 'buffer' does not have the buffer interface
astropy/io/fits/util.py:731: TypeError
______________________________ TestNonstandardHdus.test_create_fitshdu_from_filename _______________________________
self = <astropy.io.fits.tests.test_nonstandard.TestNonstandardHdus object at 0xe15b18c>
def test_create_fitshdu_from_filename(self):
"""Regression test on `FitsHDU.fromfile`"""
# Build up a simple test FITS file
a = np.arange(100)
phdu = fits.PrimaryHDU(data=a)
phdu.header['TEST1'] = 'A'
phdu.header['TEST2'] = 'B'
imghdu = fits.ImageHDU(data=a + 1)
phdu.header['TEST3'] = 'C'
phdu.header['TEST4'] = 'D'
hdul = fits.HDUList([phdu, imghdu])
hdul.writeto(self.temp('test.fits'))
> fitshdu = fits.FitsHDU.fromfile(self.temp('test.fits'))
astropy/io/fits/tests/test_nonstandard.py:39:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cls = <class 'astropy.io.fits.hdu.nonstandard.FitsHDU'>, filename = '/tmp/fits-test-xyit7B/test.fits'
compress = False
@classmethod
def fromfile(cls, filename, compress=False):
"""
Like `FitsHDU.fromhdulist()`, but creates a FitsHDU from a file on
disk.
Parameters
----------
filename : str
The path to the file to read into a FitsHDU
compress : bool, optional
Gzip compress the FITS file
"""
> return cls.fromhdulist(HDUList.fromfile(filename), compress=compress)
astropy/io/fits/hdu/nonstandard.py:56:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cls = <class 'astropy.io.fits.hdu.nonstandard.FitsHDU'>
hdulist = [<astropy.io.fits.hdu.image.PrimaryHDU object at 0xe15b30c>, <astropy.io.fits.hdu.image.ImageHDU object at 0xe140f6c>]
compress = False
@classmethod
def fromhdulist(cls, hdulist, compress=False):
"""
Creates a new FitsHDU from a given HDUList object.
Parameters
----------
hdulist : HDUList
A valid Headerlet object.
compress : bool, optional
Gzip compress the FITS file
"""
fileobj = bs = io.BytesIO()
if compress:
if hasattr(hdulist, '_file'):
name = fileobj_name(hdulist._file)
else:
name = None
fileobj = gzip.GzipFile(name, mode='wb', fileobj=bs)
> hdulist.writeto(fileobj)
astropy/io/fits/hdu/nonstandard.py:79:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = [<astropy.io.fits.hdu.image.PrimaryHDU object at 0xe15b30c>, <astropy.io.fits.hdu.image.ImageHDU object at 0xe140f6c>]
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xe58c62c>>, output_verify = 'exception'
clobber = False, checksum = False
def writeto(self, fileobj, output_verify='exception', clobber=False,
checksum=False):
"""
Write the `HDUList` to a new file.
Parameters
----------
fileobj : file path, file object or file-like object
File to write to. If a file object, must be opened in a
writeable mode.
output_verify : str
Output verification option. Must be one of ``"fix"``,
``"silentfix"``, ``"ignore"``, ``"warn"``, or
``"exception"``. May also be any combination of ``"fix"`` or
``"silentfix"`` with ``"+ignore"``, ``+warn``, or ``+exception"
(e.g. ``"fix+warn"``). See :ref:`verify` for more info.
clobber : bool
When `True`, overwrite the output file if exists.
checksum : bool
When `True` adds both ``DATASUM`` and ``CHECKSUM`` cards
to the headers of all HDU's written to the file.
"""
if (len(self) == 0):
warnings.warn("There is nothing to write.", AstropyUserWarning)
return
self.verify(option=output_verify)
# make sure the EXTEND keyword is there if there is extension
self.update_extend()
# make note of whether the input file object is already open, in which
# case we should not close it after writing (that should be the job
# of the caller)
closed = isinstance(fileobj, string_types) or fileobj_closed(fileobj)
# writeto is only for writing a new file from scratch, so the most
# sensible mode to require is 'ostream'. This can accept an open
# file object that's open to write only, or in append/update modes
# but only if the file doesn't exist.
fileobj = _File(fileobj, mode='ostream', clobber=clobber)
hdulist = self.fromfile(fileobj)
for hdu in self:
hdu._prewriteto(checksum=checksum)
try:
> hdu._writeto(hdulist.__file)
astropy/io/fits/hdu/hdulist.py:682:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.io.fits.hdu.image.PrimaryHDU object at 0xe15b30c>
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xe58c62c>>, inplace = False, copy = False
def _writeto(self, fileobj, inplace=False, copy=False):
# For now fileobj is assumed to be a _File object
if not inplace or self._new:
header_offset, _ = self._writeheader(fileobj)
> data_offset, data_size = self._writedata(fileobj)
astropy/io/fits/hdu/base.py:698:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.io.fits.hdu.image.PrimaryHDU object at 0xe15b30c>
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xe58c62c>>
def _writedata(self, fileobj):
# TODO: A lot of the simulateonly stuff should be moved back into the
# _File class--basically it should turn write and flush into a noop
offset = 0
size = 0
if not fileobj.simulateonly:
fileobj.flush()
try:
offset = fileobj.tell()
except IOError:
offset = 0
if self._data_loaded or self._data_needs_rescale:
if self.data is not None:
size += self._writedata_internal(fileobj)
# pad the FITS data block
if size > 0:
padding = _pad_length(size) * self._padding_byte
# TODO: Not that this is ever likely, but if for some odd
# reason _padding_byte is > 0x80 this will fail; but really if
# somebody's custom fits format is doing that, they're doing it
# wrong and should be reprimanded harshly.
fileobj.write(padding.encode('ascii'))
size += len(padding)
else:
# The data has not been modified or does not need need to be
# rescaled, so it can be copied, unmodified, directly from an
# existing file or buffer
> size += self._writedata_direct_copy(fileobj)
astropy/io/fits/hdu/base.py:649:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.io.fits.hdu.image.PrimaryHDU object at 0xe15b30c>
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xe58c62c>>
def _writedata_direct_copy(self, fileobj):
"""Copies the data directly from one file/buffer to the new file.
For now this is handled by loading the raw data from the existing data
(including any padding) via a memory map or from an already in-memory
buffer and using Numpy's existing file-writing facilities to write to
the new file.
If this proves too slow a more direct approach may be used.
"""
raw = self._get_raw_data(self._data_size, 'ubyte', self._data_offset)
if raw is not None:
> _array_to_file(raw, fileobj)
astropy/io/fits/hdu/base.py:685:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
arr = array([0, 0, 0, ..., 0, 0, 0], dtype=uint8)
outfile = <astropy.io.fits.file._File <_io.BytesIO object at 0xe58c62c>>
def _array_to_file(arr, outfile):
"""
Write a numpy array to a file or a file-like object.
Parameters
----------
arr : `~numpy.ndarray`
The Numpy array to write.
outfile : file-like
A file-like object such as a Python file object, an `io.BytesIO`, or
anything else with a ``write`` method. The file object must support
the buffer interface in its ``write``.
If writing directly to an on-disk file this delegates directly to
`ndarray.tofile`. Otherwise a slower Python implementation is used.
"""
if isfile(outfile):
write = lambda a, f: a.tofile(f)
else:
write = _array_to_file_like
# Implements a workaround for a bug deep in OSX's stdlib file writing
# functions; on 64-bit OSX it is not possible to correctly write a number
# of bytes greater than 2 ** 32 and divisible by 4096 (or possibly 8192--
# whatever the default blocksize for the filesystem is).
# This issue should have a workaround in Numpy too, but hasn't been
# implemented there yet: https://github.com/astropy/astropy/issues/839
#
# Apparently Windows has its own fwrite bug:
# https://github.com/numpy/numpy/issues/2256
if (sys.platform == 'darwin' and arr.nbytes >= _OSX_WRITE_LIMIT + 1 and
arr.nbytes % 4096 == 0):
# chunksize is a count of elements in the array, not bytes
chunksize = _OSX_WRITE_LIMIT // arr.itemsize
elif sys.platform.startswith('win'):
chunksize = _WIN_WRITE_LIMIT // arr.itemsize
else:
# Just pass the whole array to the write routine
> return write(arr, outfile)
astropy/io/fits/util.py:674:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
arr = array([0, 0, 0, ..., 0, 0, 0], dtype=uint8)
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xe58c62c>>
def _array_to_file_like(arr, fileobj):
"""
Write a `~numpy.ndarray` to a file-like object (which is not supported by
`numpy.ndarray.tofile`).
"""
if arr.flags.contiguous:
# It suffices to just pass the underlying buffer directly to the
# fileobj's write (assuming it supports the buffer interface, which
# unfortunately there's no simple way to check)
> fileobj.write(arr.data)
astropy/io/fits/util.py:695:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.io.fits.file._File <_io.BytesIO object at 0xe58c62c>>
string = <read-write buffer for 0xe578020, size 2880, offset 0 at 0xe140680>
def write(self, string):
if hasattr(self.__file, 'write'):
> _write_string(self.__file, string)
astropy/io/fits/file.py:268:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
f = <_io.BytesIO object at 0xe58c62c>, s = <read-write buffer for 0xe578020, size 2880, offset 0 at 0xe140680>
def _write_string(f, s):
"""
Write a string to a file, encoding to ASCII if the file is open in binary
mode, or decoding if the file is open in text mode.
"""
# Assume if the file object doesn't have a specific mode, that the mode is
# binary
binmode = fileobj_is_binary(f)
if binmode and isinstance(s, text_type):
s = encode_ascii(s)
elif not binmode and not isinstance(f, text_type):
s = decode_ascii(s)
elif isinstance(f, StringIO) and isinstance(s, np.ndarray):
# Workaround for StringIO/ndarray incompatibility
s = s.data
> f.write(s)
E TypeError: 'buffer' does not have the buffer interface
astropy/io/fits/util.py:731: TypeError
__________________________________________________ test_identity ___________________________________________________
def test_identity():
x = np.zeros((2, 3))
y = np.ones((2, 3))
ident1 = Identity(1)
shift = Shift(1)
rotation = Rotation2D(angle=60)
model = ident1 & shift | rotation
assert_allclose(model(1, 2), (-2.098076211353316, 2.3660254037844393))
res_x, res_y = model(x, y)
assert_allclose((res_x, res_y),
(np.array([[-1.73205081, -1.73205081, -1.73205081],
[-1.73205081, -1.73205081, -1.73205081]]),
np.array([[ 1., 1., 1.],
[ 1., 1., 1.]])))
> assert_allclose(model.inverse(res_x, res_y), (x, y))
astropy/modeling/tests/test_mappings.py:64:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
actual = array([[[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
[ 0.0...0000000e+00],
[ 1.00000000e+00, 1.00000000e+00, 1.00000000e+00]]])
desired = array([[[ 0., 0., 0.],
[ 0., 0., 0.]],
[[ 1., 1., 1.],
[ 1., 1., 1.]]])
rtol = 1e-07, atol = 0, err_msg = '', verbose = True
def assert_allclose(actual, desired, rtol=1e-7, atol=0,
err_msg='', verbose=True):
"""
Raises an AssertionError if two objects are not equal up to desired
tolerance.
The test is equivalent to ``allclose(actual, desired, rtol, atol)``.
It compares the difference between `actual` and `desired` to
``atol + rtol * abs(desired)``.
.. versionadded:: 1.5.0
Parameters
----------
actual : array_like
Array obtained.
desired : array_like
Array desired.
rtol : float, optional
Relative tolerance.
atol : float, optional
Absolute tolerance.
err_msg : str, optional
The error message to be printed in case of failure.
verbose : bool, optional
If True, the conflicting values are appended to the error message.
Raises
------
AssertionError
If actual and desired are not equal up to specified precision.
See Also
--------
assert_array_almost_equal_nulp, assert_array_max_ulp
Examples
--------
>>> x = [1e-5, 1e-3, 1e-1]
>>> y = np.arccos(np.cos(x))
>>> assert_allclose(x, y, rtol=1e-5, atol=0)
"""
import numpy as np
def compare(x, y):
return np.allclose(x, y, rtol=rtol, atol=atol)
actual, desired = np.asanyarray(actual), np.asanyarray(desired)
header = 'Not equal to tolerance rtol=%g, atol=%g' % (rtol, atol)
assert_array_compare(compare, actual, desired, err_msg=str(err_msg),
> verbose=verbose, header=header)
/home/bsipocz/.local/lib/python2.7/site-packages/numpy/testing/utils.py:1297:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
comparison = <function compare at 0xe175aac>
x = array([[[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
[ 0.0...0000000e+00],
[ 1.00000000e+00, 1.00000000e+00, 1.00000000e+00]]])
y = array([[[ 0., 0., 0.],
[ 0., 0., 0.]],
[[ 1., 1., 1.],
[ 1., 1., 1.]]])
err_msg = '', verbose = True, header = 'Not equal to tolerance rtol=1e-07, atol=0', precision = 6
def assert_array_compare(comparison, x, y, err_msg='', verbose=True,
header='', precision=6):
from numpy.core import array, isnan, isinf, any, all, inf
x = array(x, copy=False, subok=True)
y = array(y, copy=False, subok=True)
def isnumber(x):
return x.dtype.char in '?bhilqpBHILQPefdgFDG'
def chk_same_position(x_id, y_id, hasval='nan'):
"""Handling nan/inf: check that x and y have the nan/inf at the same
locations."""
try:
assert_array_equal(x_id, y_id)
except AssertionError:
msg = build_err_msg([x, y],
err_msg + '\nx and y %s location mismatch:' \
% (hasval), verbose=verbose, header=header,
names=('x', 'y'), precision=precision)
raise AssertionError(msg)
try:
cond = (x.shape==() or y.shape==()) or x.shape == y.shape
if not cond:
msg = build_err_msg([x, y],
err_msg
+ '\n(shapes %s, %s mismatch)' % (x.shape,
y.shape),
verbose=verbose, header=header,
names=('x', 'y'), precision=precision)
if not cond :
raise AssertionError(msg)
if isnumber(x) and isnumber(y):
x_isnan, y_isnan = isnan(x), isnan(y)
x_isinf, y_isinf = isinf(x), isinf(y)
# Validate that the special values are in the same place
if any(x_isnan) or any(y_isnan):
chk_same_position(x_isnan, y_isnan, hasval='nan')
if any(x_isinf) or any(y_isinf):
# Check +inf and -inf separately, since they are different
chk_same_position(x == +inf, y == +inf, hasval='+inf')
chk_same_position(x == -inf, y == -inf, hasval='-inf')
# Combine all the special values
x_id, y_id = x_isnan, y_isnan
x_id |= x_isinf
y_id |= y_isinf
# Only do the comparison if actual values are left
if all(x_id):
return
if any(x_id):
val = comparison(x[~x_id], y[~y_id])
else:
val = comparison(x, y)
else:
val = comparison(x, y)
if isinstance(val, bool):
cond = val
reduced = [0]
else:
reduced = val.ravel()
cond = reduced.all()
reduced = reduced.tolist()
if not cond:
match = 100-100.0*reduced.count(1)/len(reduced)
msg = build_err_msg([x, y],
err_msg
+ '\n(mismatch %s%%)' % (match,),
verbose=verbose, header=header,
names=('x', 'y'), precision=precision)
if not cond :
> raise AssertionError(msg)
E AssertionError:
E Not equal to tolerance rtol=1e-07, atol=0
E
E (mismatch 100.0%)
E x: array([[[ 0.000000e+00, 0.000000e+00, 0.000000e+00],
E [ 0.000000e+00, 0.000000e+00, -2.976135e-17]],
E ...
E y: array([[[ 0., 0., 0.],
E [ 0., 0., 0.]],
E ...
/home/bsipocz/.local/lib/python2.7/site-packages/numpy/testing/utils.py:665: AssertionError
___________________________________ [doctest] astropy.wcs.wcs.WCS.all_world2pix ____________________________________
1944 ...
1945 NoConvergence: 'WCS.all_world2pix' failed to converge to the
1946 requested accuracy. After 3 iterations, the solution is
1947 diverging at least for one input point.
1948
1949 >>> # Now try to use some diverging data:
1950 >>> divradec = w.all_pix2world([[1.0, 1.0],
1951 ... [10000.0, 50000.0],
1952 ... [3.0, 1.0]], 1)
1953 >>> print(divradec)
Expected:
[ 0.99999996 0.99999997 0.99999997]
Got:
[ 0.99999997 0.99999997 0.99999997]
astropy/wcs/wcs.py:1953: DocTestFailure
____________________________________________________ test_dist _____________________________________________________
def test_dist():
with get_pkg_data_fileobj(
os.path.join("data", "dist.fits"), encoding='binary') as test_file:
hdulist = fits.open(test_file)
wcs1 = wcs.WCS(hdulist[0].header, hdulist)
assert wcs1.det2im2 is not None
> s = cPickle.dumps(wcs1)
astropy/wcs/tests/test_pickle.py:29:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.wcs.wcs.WCS object at 0x11142f7c>
def __reduce__(self):
"""
Support pickling of WCS objects. This is done by serializing
to an in-memory FITS file and dumping that as a string.
"""
hdulist = self.to_fits(relax=True)
buffer = io.BytesIO()
> hdulist.writeto(buffer)
astropy/wcs/wcs.py:2579:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = [<astropy.io.fits.hdu.image.PrimaryHDU object at 0x10aef5ec>, <astropy.io.fits.hdu.image.ImageHDU object at 0x10aef3cc>]
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0x112470ec>>, output_verify = 'exception'
clobber = False, checksum = False
def writeto(self, fileobj, output_verify='exception', clobber=False,
checksum=False):
"""
Write the `HDUList` to a new file.
Parameters
----------
fileobj : file path, file object or file-like object
File to write to. If a file object, must be opened in a
writeable mode.
output_verify : str
Output verification option. Must be one of ``"fix"``,
``"silentfix"``, ``"ignore"``, ``"warn"``, or
``"exception"``. May also be any combination of ``"fix"`` or
``"silentfix"`` with ``"+ignore"``, ``+warn``, or ``+exception"
(e.g. ``"fix+warn"``). See :ref:`verify` for more info.
clobber : bool
When `True`, overwrite the output file if exists.
checksum : bool
When `True` adds both ``DATASUM`` and ``CHECKSUM`` cards
to the headers of all HDU's written to the file.
"""
if (len(self) == 0):
warnings.warn("There is nothing to write.", AstropyUserWarning)
return
self.verify(option=output_verify)
# make sure the EXTEND keyword is there if there is extension
self.update_extend()
# make note of whether the input file object is already open, in which
# case we should not close it after writing (that should be the job
# of the caller)
closed = isinstance(fileobj, string_types) or fileobj_closed(fileobj)
# writeto is only for writing a new file from scratch, so the most
# sensible mode to require is 'ostream'. This can accept an open
# file object that's open to write only, or in append/update modes
# but only if the file doesn't exist.
fileobj = _File(fileobj, mode='ostream', clobber=clobber)
hdulist = self.fromfile(fileobj)
for hdu in self:
hdu._prewriteto(checksum=checksum)
try:
> hdu._writeto(hdulist.__file)
astropy/io/fits/hdu/hdulist.py:682:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.io.fits.hdu.image.ImageHDU object at 0x10aef3cc>
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0x112470ec>>, inplace = False, copy = False
def _writeto(self, fileobj, inplace=False, copy=False):
# For now fileobj is assumed to be a _File object
if not inplace or self._new:
header_offset, _ = self._writeheader(fileobj)
> data_offset, data_size = self._writedata(fileobj)
astropy/io/fits/hdu/base.py:698:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.io.fits.hdu.image.ImageHDU object at 0x10aef3cc>
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0x112470ec>>
def _writedata(self, fileobj):
# TODO: A lot of the simulateonly stuff should be moved back into the
# _File class--basically it should turn write and flush into a noop
offset = 0
size = 0
if not fileobj.simulateonly:
fileobj.flush()
try:
offset = fileobj.tell()
except IOError:
offset = 0
if self._data_loaded or self._data_needs_rescale:
if self.data is not None:
> size += self._writedata_internal(fileobj)
astropy/io/fits/hdu/base.py:635:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.io.fits.hdu.image.ImageHDU object at 0x10aef3cc>
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0x112470ec>>
def _writedata_internal(self, fileobj):
size = 0
if self.data is not None:
# Based on the system type, determine the byteorders that
# would need to be swapped to get to big-endian output
if sys.byteorder == 'little':
swap_types = ('<', '=')
else:
swap_types = ('<',)
# deal with unsigned integer 16, 32 and 64 data
if _is_pseudo_unsigned(self.data.dtype):
# Convert the unsigned array to signed
output = np.array(
self.data - _unsigned_zero(self.data.dtype),
dtype='>i%d' % self.data.dtype.itemsize)
should_swap = False
else:
output = self.data
byteorder = output.dtype.str[0]
should_swap = (byteorder in swap_types)
if not fileobj.simulateonly:
if should_swap:
output.byteswap(True)
try:
> fileobj.writearray(output)
astropy/io/fits/hdu/image.py:521:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.io.fits.file._File <_io.BytesIO object at 0x112470ec>>
array = array([[ -1.27305422e-04, -2.63464113e-04, -5.10875077e-04, ...,
2.40933063e-04, 1.06801039e-04, -3.66208042e-08]], dtype=float32)
def writearray(self, array):
"""
Similar to file.write(), but writes a numpy array instead of a string.
Also like file.write(), a flush() or close() may be needed before
the file on disk reflects the data written.
"""
if hasattr(self.__file, 'write'):
> _array_to_file(array, self.__file)
astropy/io/fits/file.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
arr = array([[ -1.27305422e-04, -2.63464113e-04, -5.10875077e-04, ...,
2.40933063e-04, 1.06801039e-04, -3.66208042e-08]], dtype=float32)
outfile = <_io.BytesIO object at 0x112470ec>
def _array_to_file(arr, outfile):
"""
Write a numpy array to a file or a file-like object.
Parameters
----------
arr : `~numpy.ndarray`
The Numpy array to write.
outfile : file-like
A file-like object such as a Python file object, an `io.BytesIO`, or
anything else with a ``write`` method. The file object must support
the buffer interface in its ``write``.
If writing directly to an on-disk file this delegates directly to
`ndarray.tofile`. Otherwise a slower Python implementation is used.
"""
if isfile(outfile):
write = lambda a, f: a.tofile(f)
else:
write = _array_to_file_like
# Implements a workaround for a bug deep in OSX's stdlib file writing
# functions; on 64-bit OSX it is not possible to correctly write a number
# of bytes greater than 2 ** 32 and divisible by 4096 (or possibly 8192--
# whatever the default blocksize for the filesystem is).
# This issue should have a workaround in Numpy too, but hasn't been
# implemented there yet: https://github.com/astropy/astropy/issues/839
#
# Apparently Windows has its own fwrite bug:
# https://github.com/numpy/numpy/issues/2256
if (sys.platform == 'darwin' and arr.nbytes >= _OSX_WRITE_LIMIT + 1 and
arr.nbytes % 4096 == 0):
# chunksize is a count of elements in the array, not bytes
chunksize = _OSX_WRITE_LIMIT // arr.itemsize
elif sys.platform.startswith('win'):
chunksize = _WIN_WRITE_LIMIT // arr.itemsize
else:
# Just pass the whole array to the write routine
> return write(arr, outfile)
astropy/io/fits/util.py:674:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
arr = array([[ -1.27305422e-04, -2.63464113e-04, -5.10875077e-04, ...,
2.40933063e-04, 1.06801039e-04, -3.66208042e-08]], dtype=float32)
fileobj = <_io.BytesIO object at 0x112470ec>
def _array_to_file_like(arr, fileobj):
"""
Write a `~numpy.ndarray` to a file-like object (which is not supported by
`numpy.ndarray.tofile`).
"""
if arr.flags.contiguous:
# It suffices to just pass the underlying buffer directly to the
# fileobj's write (assuming it supports the buffer interface, which
# unfortunately there's no simple way to check)
> fileobj.write(arr.data)
E TypeError: 'buffer' does not have the buffer interface
astropy/io/fits/util.py:695: TypeError
============== 11 failed, 8431 passed, 177 skipped, 43 xfailed, 1 xpassed, 2 error in 1692.95 seconds ==============
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment