Created
February 12, 2015 22:16
-
-
Save bsipocz/38fed6fe8f20e5f19c07 to your computer and use it in GitHub Desktop.
rc2 on debian 7.8 i686
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> import astropy | |
astropy.__version__ | |
WARNING: ConfigurationChangedWarning: The configuration options in astropy 1.0rc2 may have changed, your configuration file was not updated in order to preserve local changes. A new configuration template has been saved to '/home/bsipocz/.astropy/config/astropy.1.0rc2.cfg'. [astropy.config.configuration] | |
>>> astropy.__version__ | |
u'1.0rc2' | |
>>> astropy.test() | |
============================= test session starts ============================== | |
platform linux2 -- Python 2.7.3 -- pytest-2.5.1 | |
Running tests with Astropy version 1.0rc2. | |
Running tests in /home/bsipocz/.local/lib/python2.7/site-packages/astropy. | |
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.12.1 | |
Matplotlib: 1.4.2 | |
h5py: not available | |
collected 8466 items / 7 skipped | |
.local/lib/python2.7/site-packages/astropy/_erfa/tests/test_erfa.py ..... | |
.local/lib/python2.7/site-packages/astropy/analytic_functions/tests/test_blackbody.py .... | |
.local/lib/python2.7/site-packages/astropy/config/tests/test_configs.py ............... | |
.local/lib/python2.7/site-packages/astropy/constants/tests/test_constant.py .............. | |
.local/lib/python2.7/site-packages/astropy/constants/tests/test_pickle.py xxxxxxxxx | |
.local/lib/python2.7/site-packages/astropy/convolution/tests/test_convolve.py ............................................................................................................... | |
.local/lib/python2.7/site-packages/astropy/convolution/tests/test_convolve_fft.py ................................................................................................................................................................................................................................................................................................................................................... | |
.local/lib/python2.7/site-packages/astropy/convolution/tests/test_convolve_kernels.py .............................................................. | |
.local/lib/python2.7/site-packages/astropy/convolution/tests/test_discretize.py ...s...........s............... | |
.local/lib/python2.7/site-packages/astropy/convolution/tests/test_kernel_class.py ............................................................................................................................................................................ | |
.local/lib/python2.7/site-packages/astropy/convolution/tests/test_pickle.py .xx.xx.xx | |
.local/lib/python2.7/site-packages/astropy/coordinates/tests/test_angles.py ............................................................................ | |
.local/lib/python2.7/site-packages/astropy/coordinates/tests/test_angular_separation.py .... | |
.local/lib/python2.7/site-packages/astropy/coordinates/tests/test_api_ape5.py ....s | |
.local/lib/python2.7/site-packages/astropy/coordinates/tests/test_arrays.py .......................... | |
.local/lib/python2.7/site-packages/astropy/coordinates/tests/test_distance.py ......... | |
.local/lib/python2.7/site-packages/astropy/coordinates/tests/test_earth.py ........................ | |
.local/lib/python2.7/site-packages/astropy/coordinates/tests/test_formatting.py .................... | |
.local/lib/python2.7/site-packages/astropy/coordinates/tests/test_frames.py ....................F.. | |
.local/lib/python2.7/site-packages/astropy/coordinates/tests/test_funcs.py .. | |
.local/lib/python2.7/site-packages/astropy/coordinates/tests/test_iau_fullstack.py .................................................... | |
.local/lib/python2.7/site-packages/astropy/coordinates/tests/test_matching.py ...... | |
.local/lib/python2.7/site-packages/astropy/coordinates/tests/test_name_resolve.py ssssss | |
.local/lib/python2.7/site-packages/astropy/coordinates/tests/test_pickle.py ....xx.x...xx.x...xx.x. | |
.local/lib/python2.7/site-packages/astropy/coordinates/tests/test_representation.py ............................................................................. | |
.local/lib/python2.7/site-packages/astropy/coordinates/tests/test_sky_coord.py .......................................................................................................................................................................................................................................................................................................................................................................................x.............. | |
.local/lib/python2.7/site-packages/astropy/coordinates/tests/test_transformations.py ...................... | |
.local/lib/python2.7/site-packages/astropy/coordinates/tests/accuracy/test_altaz_icrs.py ...x | |
.local/lib/python2.7/site-packages/astropy/coordinates/tests/accuracy/test_fk4_no_e_fk4.py . | |
.local/lib/python2.7/site-packages/astropy/coordinates/tests/accuracy/test_fk4_no_e_fk5.py . | |
.local/lib/python2.7/site-packages/astropy/coordinates/tests/accuracy/test_galactic_fk4.py . | |
.local/lib/python2.7/site-packages/astropy/coordinates/tests/accuracy/test_icrs_fk5.py . | |
.local/lib/python2.7/site-packages/astropy/cosmology/tests/test_cosmology.py ................................... | |
.local/lib/python2.7/site-packages/astropy/cosmology/tests/test_pickle.py ... | |
.local/lib/python2.7/site-packages/astropy/io/ascii/tests/test_c_reader.py ...........................x................x.......x.x............... | |
.local/lib/python2.7/site-packages/astropy/io/ascii/tests/test_cds_header_from_readme.py ... | |
.local/lib/python2.7/site-packages/astropy/io/ascii/tests/test_compressed.py ..... | |
.local/lib/python2.7/site-packages/astropy/io/ascii/tests/test_connect.py .............ss........ | |
.local/lib/python2.7/site-packages/astropy/io/ascii/tests/test_ecsv.py sssssss | |
.local/lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.py ............................................................ | |
.local/lib/python2.7/site-packages/astropy/io/ascii/tests/test_html.py s.ssssss.ssss..s | |
.local/lib/python2.7/site-packages/astropy/io/ascii/tests/test_ipac_definitions.py ........................................ | |
.local/lib/python2.7/site-packages/astropy/io/ascii/tests/test_read.py .................................................................................................................................................................................................. | |
.local/lib/python2.7/site-packages/astropy/io/ascii/tests/test_types.py ...... | |
.local/lib/python2.7/site-packages/astropy/io/ascii/tests/test_write.py .......................... | |
.local/lib/python2.7/site-packages/astropy/io/fits/tests/test_checksum.py .................... | |
.local/lib/python2.7/site-packages/astropy/io/fits/tests/test_connect.py ......................... | |
.local/lib/python2.7/site-packages/astropy/io/fits/tests/test_core.py .............................................F....F..... | |
.local/lib/python2.7/site-packages/astropy/io/fits/tests/test_diff.py .................................. | |
.local/lib/python2.7/site-packages/astropy/io/fits/tests/test_division.py ..... | |
.local/lib/python2.7/site-packages/astropy/io/fits/tests/test_groups.py ....... | |
.local/lib/python2.7/site-packages/astropy/io/fits/tests/test_hdulist.py .......................F................. | |
.local/lib/python2.7/site-packages/astropy/io/fits/tests/test_header.py .............................................................................................................................................. | |
.local/lib/python2.7/site-packages/astropy/io/fits/tests/test_image.py .................................................... | |
.local/lib/python2.7/site-packages/astropy/io/fits/tests/test_nonstandard.py F.F | |
.local/lib/python2.7/site-packages/astropy/io/fits/tests/test_structured.py . | |
.local/lib/python2.7/site-packages/astropy/io/fits/tests/test_table.py ................................................................ | |
.local/lib/python2.7/site-packages/astropy/io/fits/tests/test_uint.py ........ | |
.local/lib/python2.7/site-packages/astropy/io/fits/tests/test_util.py . | |
.local/lib/python2.7/site-packages/astropy/io/misc/tests/test_hdf5.py sssssssssssssssssssssssssssssssssssssss | |
.local/lib/python2.7/site-packages/astropy/io/misc/tests/test_pickle_helpers.py .... | |
.local/lib/python2.7/site-packages/astropy/io/tests/test_registry.py ............................................................ | |
.local/lib/python2.7/site-packages/astropy/io/votable/tests/converter_test.py ............................................ | |
.local/lib/python2.7/site-packages/astropy/io/votable/tests/exception_test.py .. | |
.local/lib/python2.7/site-packages/astropy/io/votable/tests/table_test.py .............. | |
.local/lib/python2.7/site-packages/astropy/io/votable/tests/tree_test.py ... | |
.local/lib/python2.7/site-packages/astropy/io/votable/tests/ucd_test.py .......... | |
.local/lib/python2.7/site-packages/astropy/io/votable/tests/util_test.py ...................... | |
.local/lib/python2.7/site-packages/astropy/io/votable/tests/vo_test.py ................................................................................................................................................................................................................................................................................................................................ | |
.local/lib/python2.7/site-packages/astropy/modeling/tests/test_compound.py .......................................... | |
.local/lib/python2.7/site-packages/astropy/modeling/tests/test_constraints.py ..................... | |
.local/lib/python2.7/site-packages/astropy/modeling/tests/test_core.py ........ | |
.local/lib/python2.7/site-packages/astropy/modeling/tests/test_fitters.py ................... | |
.local/lib/python2.7/site-packages/astropy/modeling/tests/test_functional_models.py ......... | |
.local/lib/python2.7/site-packages/astropy/modeling/tests/test_input.py ...................................................... | |
.local/lib/python2.7/site-packages/astropy/modeling/tests/test_mappings.py .....F | |
.local/lib/python2.7/site-packages/astropy/modeling/tests/test_models.py .......................................................s....s.....s...............................ssss..ssss... | |
.local/lib/python2.7/site-packages/astropy/modeling/tests/test_parameters.py ..................................................... | |
.local/lib/python2.7/site-packages/astropy/modeling/tests/test_polynomial.py ................. | |
.local/lib/python2.7/site-packages/astropy/modeling/tests/test_projections.py ................... | |
.local/lib/python2.7/site-packages/astropy/modeling/tests/test_rotations.py ..... | |
.local/lib/python2.7/site-packages/astropy/modeling/tests/test_utils.py .. | |
.local/lib/python2.7/site-packages/astropy/nddata/tests/test_decorators.py .......... | |
.local/lib/python2.7/site-packages/astropy/nddata/tests/test_flag_collection.py .................... | |
.local/lib/python2.7/site-packages/astropy/nddata/tests/test_nddata.py .................................................................... | |
.local/lib/python2.7/site-packages/astropy/nddata/tests/test_nddata_base.py . | |
.local/lib/python2.7/site-packages/astropy/nddata/tests/test_utils.py ......... | |
.local/lib/python2.7/site-packages/astropy/stats/tests/test_funcs.py ............. | |
.local/lib/python2.7/site-packages/astropy/stats/tests/test_sigma_clipping.py ... | |
.local/lib/python2.7/site-packages/astropy/table/tests/test_column.py .................................................................................................................................................................... | |
.local/lib/python2.7/site-packages/astropy/table/tests/test_groups.py ........................................ | |
.local/lib/python2.7/site-packages/astropy/table/tests/test_init_table.py ...................................................................................................................................................................................................................................................................................................... | |
.local/lib/python2.7/site-packages/astropy/table/tests/test_item_access.py ............................................................ | |
.local/lib/python2.7/site-packages/astropy/table/tests/test_jsviewer.py . | |
.local/lib/python2.7/site-packages/astropy/table/tests/test_masked.py .................................................................. | |
.local/lib/python2.7/site-packages/astropy/table/tests/test_mixin.py ................................................x. | |
.local/lib/python2.7/site-packages/astropy/table/tests/test_np_utils.py . | |
.local/lib/python2.7/site-packages/astropy/table/tests/test_operations.py .......................................................................... | |
.local/lib/python2.7/site-packages/astropy/table/tests/test_pickle.py ............ | |
.local/lib/python2.7/site-packages/astropy/table/tests/test_pprint.py ........................................................................................................ | |
.local/lib/python2.7/site-packages/astropy/table/tests/test_row.py .................................................................... | |
.local/lib/python2.7/site-packages/astropy/table/tests/test_subclass.py .... | |
.local/lib/python2.7/site-packages/astropy/table/tests/test_table.py ..........................................................................................................................................................................................................................................................................................x..................................................................................................................................................................................................................................................................................................................x........................ | |
.local/lib/python2.7/site-packages/astropy/tests/test_logger.py ............................ | |
.local/lib/python2.7/site-packages/astropy/tests/tests/test_imports.py .. | |
.local/lib/python2.7/site-packages/astropy/tests/tests/test_open_file_detection.py . | |
.local/lib/python2.7/site-packages/astropy/tests/tests/test_quantity_helpers.py . | |
.local/lib/python2.7/site-packages/astropy/tests/tests/test_run_tests.py ........ | |
.local/lib/python2.7/site-packages/astropy/tests/tests/test_skip_remote_data.py s | |
.local/lib/python2.7/site-packages/astropy/tests/tests/test_socketblocker.py ... | |
.local/lib/python2.7/site-packages/astropy/time/tests/test_basic.py .............................................................................. | |
.local/lib/python2.7/site-packages/astropy/time/tests/test_comparisons.py ... | |
.local/lib/python2.7/site-packages/astropy/time/tests/test_delta.py ................................................................................ | |
.local/lib/python2.7/site-packages/astropy/time/tests/test_guess.py .... | |
.local/lib/python2.7/site-packages/astropy/time/tests/test_pickle.py . | |
.local/lib/python2.7/site-packages/astropy/time/tests/test_precision.py .......x.. | |
.local/lib/python2.7/site-packages/astropy/time/tests/test_quantity_interaction.py ............ | |
.local/lib/python2.7/site-packages/astropy/time/tests/test_sidereal.py ................... | |
.local/lib/python2.7/site-packages/astropy/time/tests/test_ut1.py ...s | |
.local/lib/python2.7/site-packages/astropy/units/tests/test_equivalencies.py .................................................. | |
.local/lib/python2.7/site-packages/astropy/units/tests/test_format.py .................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................... | |
.local/lib/python2.7/site-packages/astropy/units/tests/test_physical.py ...................... | |
.local/lib/python2.7/site-packages/astropy/units/tests/test_quantity.py .................................................................... | |
.local/lib/python2.7/site-packages/astropy/units/tests/test_quantity_array_methods.py .............................x............x.x............. | |
.local/lib/python2.7/site-packages/astropy/units/tests/test_quantity_decorator.py sssssssssssss............... | |
.local/lib/python2.7/site-packages/astropy/units/tests/test_quantity_non_ufuncs.py xx | |
.local/lib/python2.7/site-packages/astropy/units/tests/test_quantity_ufuncs.py ........................................ss................................................................................................................. | |
.local/lib/python2.7/site-packages/astropy/units/tests/test_units.py .............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................. | |
.local/lib/python2.7/site-packages/astropy/utils/compat/numpy/tests/test_broadcast_arrays.py ... | |
.local/lib/python2.7/site-packages/astropy/utils/iers/tests/test_iers.py .s | |
.local/lib/python2.7/site-packages/astropy/utils/tests/test_codegen.py . | |
.local/lib/python2.7/site-packages/astropy/utils/tests/test_collections.py ..... | |
.local/lib/python2.7/site-packages/astropy/utils/tests/test_compat.py . | |
.local/lib/python2.7/site-packages/astropy/utils/tests/test_console.py .................................................. | |
.local/lib/python2.7/site-packages/astropy/utils/tests/test_data.py .sssss.........s..s..sssss.........s..s. | |
.local/lib/python2.7/site-packages/astropy/utils/tests/test_decorators.py ....... | |
.local/lib/python2.7/site-packages/astropy/utils/tests/test_gzip.py ss | |
.local/lib/python2.7/site-packages/astropy/utils/tests/test_introspection.py .... | |
.local/lib/python2.7/site-packages/astropy/utils/tests/test_metadata.py ............... | |
.local/lib/python2.7/site-packages/astropy/utils/tests/test_misc.py .s... | |
.local/lib/python2.7/site-packages/astropy/utils/tests/test_odict.py sssssssssssssssssssssssssssssssssssssssssss | |
.local/lib/python2.7/site-packages/astropy/utils/tests/test_state.py .. | |
.local/lib/python2.7/site-packages/astropy/utils/tests/test_timer.py . | |
.local/lib/python2.7/site-packages/astropy/utils/tests/test_xml.py ........ | |
.local/lib/python2.7/site-packages/astropy/visualization/scripts/tests/test_fits2bitmap.py .. | |
.local/lib/python2.7/site-packages/astropy/visualization/tests/test_interval.py ................. | |
.local/lib/python2.7/site-packages/astropy/visualization/tests/test_norm.py s..... | |
.local/lib/python2.7/site-packages/astropy/visualization/tests/test_stretch.py ................................................................................................... | |
.local/lib/python2.7/site-packages/astropy/visualization/tests/test_ui.py ...... | |
.local/lib/python2.7/site-packages/astropy/vo/client/tests/test_conesearch.py ssssssssssssss...x. | |
.local/lib/python2.7/site-packages/astropy/vo/client/tests/test_vos_catalog.py ..............s | |
.local/lib/python2.7/site-packages/astropy/vo/samp/tests/test_client.py .... | |
.local/lib/python2.7/site-packages/astropy/vo/samp/tests/test_errors.py ... | |
.local/lib/python2.7/site-packages/astropy/vo/samp/tests/test_hub.py .. | |
.local/lib/python2.7/site-packages/astropy/vo/samp/tests/test_hub_proxy.py ..... | |
.local/lib/python2.7/site-packages/astropy/vo/samp/tests/test_hub_script.py . | |
.local/lib/python2.7/site-packages/astropy/vo/samp/tests/test_standard_profile.py .xx | |
.local/lib/python2.7/site-packages/astropy/vo/samp/tests/test_web_profile.py X. | |
.local/lib/python2.7/site-packages/astropy/vo/validator/tests/test_inpect.py .... | |
.local/lib/python2.7/site-packages/astropy/vo/validator/tests/test_validate.py sss | |
.local/lib/python2.7/site-packages/astropy/wcs/tests/test_pickle.py .F.... | |
.local/lib/python2.7/site-packages/astropy/wcs/tests/test_profiling.py .................................. | |
.local/lib/python2.7/site-packages/astropy/wcs/tests/test_utils.py ......................................... | |
.local/lib/python2.7/site-packages/astropy/wcs/tests/test_wcs.py ...................................................................................................................................... | |
.local/lib/python2.7/site-packages/astropy/wcs/tests/test_wcsprm.py ...........................................................................................x.....XX | |
.local/lib/python2.7/site-packages/astropy/wcs/tests/extension/test_extension.py . | |
=================================== 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, lat, distance) in (deg, deg, km)\n (12.3, 45.6, 1.0)>.lon | |
E + where <SphericalRepresentation (lon, lat, distance) in (deg, deg, km)\n (12.3, 45.6, 1.0)> = <ITRS Coordinate (obstime=J2000.000): (x, y, z) in km\n (0.68360297, 0.14904955, 0.71447268)>.spherical | |
.local/lib/python2.7/site-packages/astropy/coordinates/tests/test_frames.py:562: AssertionError | |
_____________________ TestFileFunctions.test_write_bytesio _____________________ | |
self = <astropy.io.fits.tests.test_core.TestFileFunctions object at 0xb3f3012c> | |
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()) | |
.local/lib/python2.7/site-packages/astropy/io/fits/tests/test_core.py:948: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <astropy.io.fits.tests.test_core.TestFileFunctions object at 0xb3f3012c> | |
fileobj = <_io.BytesIO object at 0xff42c8c> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/tests/test_core.py:973: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = [<astropy.io.fits.hdu.image.PrimaryHDU object at 0xb3f30ecc>, <astropy.io.fits...ject at 0xb3f53c6c>, <astropy.io.fits.hdu.image.ImageHDU object at 0x10735c2c>] | |
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xff42c8c>> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/hdu/hdulist.py:682: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <astropy.io.fits.hdu.image.ImageHDU object at 0xf6894ec> | |
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xff42c8c>> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/hdu/base.py:698: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <astropy.io.fits.hdu.image.ImageHDU object at 0xf6894ec> | |
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xff42c8c>> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/hdu/base.py:649: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <astropy.io.fits.hdu.image.ImageHDU object at 0xf6894ec> | |
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xff42c8c>> | |
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) | |
.local/lib/python2.7/site-packages/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 0xff42c8c>> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/util.py:675: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
arr = array([ 1, 57, 1, ..., 0, 0, 0], dtype=uint8) | |
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xff42c8c>> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/util.py:696: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <astropy.io.fits.file._File <_io.BytesIO object at 0xff42c8c>> | |
string = <read-write buffer for 0xff70638, size 5760, offset 0 at 0xfff54c0> | |
def write(self, string): | |
if hasattr(self.__file, 'write'): | |
> _write_string(self.__file, string) | |
.local/lib/python2.7/site-packages/astropy/io/fits/file.py:268: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
f = <_io.BytesIO object at 0xff42c8c> | |
s = <read-write buffer for 0xff70638, size 5760, offset 0 at 0xfff54c0> | |
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 | |
.local/lib/python2.7/site-packages/astropy/io/fits/util.py:732: TypeError | |
__________ TestStreamingFunctions.test_streaming_hdu_write_file_like ___________ | |
self = <astropy.io.fits.tests.test_core.TestStreamingFunctions object at 0xb3f4eeec> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/tests/test_core.py:1033: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <astropy.io.fits.hdu.streaming.StreamingHDU object at 0xb3f4ec4c> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/hdu/streaming.py:184: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <astropy.io.fits.file._File <_io.BytesIO object at 0xb3dc7ecc>> | |
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) | |
.local/lib/python2.7/site-packages/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 0xb3dc7ecc> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/util.py:675: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
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 0xb3dc7ecc> | |
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 | |
.local/lib/python2.7/site-packages/astropy/io/fits/util.py:696: TypeError | |
__________________ TestHDUListFunctions.test_update_filelike ___________________ | |
self = <astropy.io.fits.tests.test_hdulist.TestHDUListFunctions object at 0xcca6dac> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/tests/test_hdulist.py:402: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <astropy.io.fits.hdu.image.PrimaryHDU object at 0xb3fc8e6c> | |
name = <_io.BytesIO object at 0xff767dc>, 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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/hdu/base.py:417: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = [<astropy.io.fits.hdu.image.PrimaryHDU object at 0xb3fc8e6c>] | |
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xff767dc>> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/hdu/hdulist.py:682: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <astropy.io.fits.hdu.image.PrimaryHDU object at 0xb3fc8e6c> | |
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xff767dc>> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/hdu/base.py:698: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <astropy.io.fits.hdu.image.PrimaryHDU object at 0xb3fc8e6c> | |
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xff767dc>> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/hdu/base.py:635: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <astropy.io.fits.hdu.image.PrimaryHDU object at 0xb3fc8e6c> | |
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xff767dc>> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/hdu/image.py:521: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <astropy.io.fits.file._File <_io.BytesIO object at 0xff767dc>> | |
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) | |
.local/lib/python2.7/site-packages/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 0xff767dc> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/util.py:675: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
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 0xff767dc> | |
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 | |
.local/lib/python2.7/site-packages/astropy/io/fits/util.py:696: TypeError | |
___________________ TestNonstandardHdus.test_create_fitshdu ____________________ | |
self = <astropy.io.fits.tests.test_nonstandard.TestNonstandardHdus object at 0xb3f43c4c> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/tests/test_nonstandard.py:17: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <astropy.io.fits.tests.test_nonstandard.TestNonstandardHdus object at 0xb3f43c4c> | |
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) | |
.local/lib/python2.7/site-packages/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 0xff679ac>, <astropy.io.fits....object at 0xff5acec>, <astropy.io.fits.hdu.image.ImageHDU object at 0xff5830c>] | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/hdu/nonstandard.py:79: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = [<astropy.io.fits.hdu.image.PrimaryHDU object at 0xff679ac>, <astropy.io.fits....object at 0xff5acec>, <astropy.io.fits.hdu.image.ImageHDU object at 0xff5830c>] | |
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xb3f2abcc>> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/hdu/hdulist.py:682: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <astropy.io.fits.hdu.image.PrimaryHDU object at 0xff679ac> | |
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xb3f2abcc>> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/hdu/base.py:698: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <astropy.io.fits.hdu.image.PrimaryHDU object at 0xff679ac> | |
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xb3f2abcc>> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/hdu/base.py:649: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <astropy.io.fits.hdu.image.PrimaryHDU object at 0xff679ac> | |
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xb3f2abcc>> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/hdu/base.py:685: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
arr = array([], dtype=uint8) | |
outfile = <astropy.io.fits.file._File <_io.BytesIO object at 0xb3f2abcc>> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/util.py:675: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
arr = array([], dtype=uint8) | |
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xb3f2abcc>> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/util.py:696: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <astropy.io.fits.file._File <_io.BytesIO object at 0xb3f2abcc>> | |
string = <read-write buffer for 0xb3d3f110, size 0, offset 0 at 0x101da560> | |
def write(self, string): | |
if hasattr(self.__file, 'write'): | |
> _write_string(self.__file, string) | |
.local/lib/python2.7/site-packages/astropy/io/fits/file.py:268: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
f = <_io.BytesIO object at 0xb3f2abcc> | |
s = <read-write buffer for 0xb3d3f110, size 0, offset 0 at 0x101da560> | |
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 | |
.local/lib/python2.7/site-packages/astropy/io/fits/util.py:732: TypeError | |
____________ TestNonstandardHdus.test_create_fitshdu_from_filename _____________ | |
self = <astropy.io.fits.tests.test_nonstandard.TestNonstandardHdus object at 0xb3fc354c> | |
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')) | |
.local/lib/python2.7/site-packages/astropy/io/fits/tests/test_nonstandard.py:39: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
cls = <class 'astropy.io.fits.hdu.nonstandard.FitsHDU'> | |
filename = '/tmp/fits-test-iYT8tl/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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/hdu/nonstandard.py:56: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
cls = <class 'astropy.io.fits.hdu.nonstandard.FitsHDU'> | |
hdulist = [<astropy.io.fits.hdu.image.PrimaryHDU object at 0xb3fc156c>, <astropy.io.fits.hdu.image.ImageHDU object at 0xff5d96c>] | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/hdu/nonstandard.py:79: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = [<astropy.io.fits.hdu.image.PrimaryHDU object at 0xb3fc156c>, <astropy.io.fits.hdu.image.ImageHDU object at 0xff5d96c>] | |
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xb3d3e5cc>> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/hdu/hdulist.py:682: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <astropy.io.fits.hdu.image.PrimaryHDU object at 0xb3fc156c> | |
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xb3d3e5cc>> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/hdu/base.py:698: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <astropy.io.fits.hdu.image.PrimaryHDU object at 0xb3fc156c> | |
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xb3d3e5cc>> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/hdu/base.py:649: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <astropy.io.fits.hdu.image.PrimaryHDU object at 0xb3fc156c> | |
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xb3d3e5cc>> | |
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) | |
.local/lib/python2.7/site-packages/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 0xb3d3e5cc>> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/util.py:675: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
arr = array([0, 0, 0, ..., 0, 0, 0], dtype=uint8) | |
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0xb3d3e5cc>> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/util.py:696: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <astropy.io.fits.file._File <_io.BytesIO object at 0xb3d3e5cc>> | |
string = <read-write buffer for 0xb3d1f2a0, size 2880, offset 0 at 0xff5d020> | |
def write(self, string): | |
if hasattr(self.__file, 'write'): | |
> _write_string(self.__file, string) | |
.local/lib/python2.7/site-packages/astropy/io/fits/file.py:268: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
f = <_io.BytesIO object at 0xb3d3e5cc> | |
s = <read-write buffer for 0xb3d1f2a0, size 2880, offset 0 at 0xff5d020> | |
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 | |
.local/lib/python2.7/site-packages/astropy/io/fits/util.py:732: 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)) | |
.local/lib/python2.7/site-packages/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) | |
.local/lib/python2.7/site-packages/numpy/testing/utils.py:1297: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
comparison = <function compare at 0xfb025dc> | |
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 ... | |
.local/lib/python2.7/site-packages/numpy/testing/utils.py:665: AssertionError | |
__________________________________ 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) | |
.local/lib/python2.7/site-packages/astropy/wcs/tests/test_pickle.py:29: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <astropy.wcs.wcs.WCS object at 0x11d1a2fc> | |
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) | |
.local/lib/python2.7/site-packages/astropy/wcs/wcs.py:2579: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = [<astropy.io.fits.hdu.image.PrimaryHDU object at 0x1220958c>, <astropy.io.fits.hdu.image.ImageHDU object at 0x12209d4c>] | |
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0x11830ddc>> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/hdu/hdulist.py:682: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <astropy.io.fits.hdu.image.ImageHDU object at 0x12209d4c> | |
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0x11830ddc>> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/hdu/base.py:698: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <astropy.io.fits.hdu.image.ImageHDU object at 0x12209d4c> | |
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0x11830ddc>> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/hdu/base.py:635: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <astropy.io.fits.hdu.image.ImageHDU object at 0x12209d4c> | |
fileobj = <astropy.io.fits.file._File <_io.BytesIO object at 0x11830ddc>> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/hdu/image.py:521: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <astropy.io.fits.file._File <_io.BytesIO object at 0x11830ddc>> | |
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) | |
.local/lib/python2.7/site-packages/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 0x11830ddc> | |
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) | |
.local/lib/python2.7/site-packages/astropy/io/fits/util.py:675: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
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 0x11830ddc> | |
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 | |
.local/lib/python2.7/site-packages/astropy/io/fits/util.py:696: TypeError | |
= 8 failed, 8235 passed, 184 skipped, 43 xfailed, 3 xpassed in 1268.05 seconds = | |
1 | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment