Skip to content

Fits merge - #495

Merged
embray merged 12 commits into
astropy:masterfrom
embray:fits-merge
Dec 5, 2012
Merged

embray merged 12 commits into
astropy:masterfrom
embray:fits-merge

Conversation

@embray

@embray embray commented Nov 20, 2012

Copy link
Copy Markdown
Member

This merges up through r1927 from pyfits' SVN repository. It's probably more than any one person can trawl through but I'd appreciate any comments nonetheless. It might be easier to go back to the pyfits repo itself and look through the individual commits.

Before merging this I do need to update the changelog with a list of all the issues closed. This is already added to the documentation in the "PyFITS History" page but the relevant fixes should also be copied over to the actual Astropy changelog.

This also adds support for using --use-system-cfitsio to build the compression module with an already installed copy of CFITSIO rather than the one I'm including in Astropy. This will close #318.

This merges up through r1927 from pyfits' trunk in SVN.  Closes the following
issues in Astropy:

Closes astropy#339 astropy.io.fits.Header totextfile and Header.__init__ disagree on 'endcard' convention
Closes astropy#318 Move io.fits external C dependencies into cextern

Conflicts:
	README.txt
	astropy/io/fits/src/compress.c
	astropy/io/fits/src/crc32.h
	astropy/io/fits/src/deflate.h
	astropy/io/fits/src/fits_hcompress.c
	astropy/io/fits/src/fits_hdecompress.c
	astropy/io/fits/src/fitsio.c
	astropy/io/fits/src/fitsio.h
	astropy/io/fits/src/inffast.c
	astropy/io/fits/src/inffast.h
	astropy/io/fits/src/inffixed.h
	astropy/io/fits/src/inflate.h
	astropy/io/fits/src/inftrees.c
	astropy/io/fits/src/inftrees.h
	astropy/io/fits/src/pliocomp.c
	astropy/io/fits/src/quantize.c
	astropy/io/fits/src/ricecomp.c
	astropy/io/fits/src/ricecomp.h
	astropy/io/fits/src/trees.c
	astropy/io/fits/src/trees.h
	astropy/io/fits/src/zlib.c
	astropy/io/fits/src/zlib.h
	astropy/io/fits/src/zutil.h
	cextern/cfitsio/crc32.h
	cextern/cfitsio/deflate.h
	cextern/cfitsio/fits_hcompress.c
	cextern/cfitsio/fits_hdecompress.c
	cextern/cfitsio/inffast.c
	cextern/cfitsio/inffixed.h
	cextern/cfitsio/inftrees.c
	cextern/cfitsio/pliocomp.c
	cextern/cfitsio/quantize.c
	cextern/cfitsio/ricecomp.c
	cextern/cfitsio/trees.c
	cextern/cfitsio/trees.h
	cextern/cfitsio/zutil.h
	setup.cfg
	src/crc32.h
	src/deflate.h
	src/fits_hcompress.c
	src/fits_hdecompress.c
	src/inffast.c
	src/inffixed.h
	src/inftrees.c
	src/pliocomp.c
	src/quantize.c
	src/ricecomp.c
	src/trees.c
	src/trees.h
	src/zutil.h
	tox.ini

Conflicts:

	astropy/io/fits/diff.py
	astropy/io/fits/hdu/base.py
	astropy/io/fits/hdu/compressed.py
	astropy/io/fits/hdu/image.py
	astropy/io/fits/src/compressionmodule.c
	astropy/io/fits/tests/cfitsio_verify.c
	astropy/io/fits/tests/test_core.py
	astropy/io/fits/tests/test_header.py
	astropy/io/fits/tests/test_image.py
	astropy/io/fits/tests/test_uint.py
…pression module with a system version of CFITSIO.
@ghost ghost assigned embray Nov 20, 2012
@astrofrog

Copy link
Copy Markdown
Member

138k additions? seriously? ;-)

This will make the linux package managers happy! I will try and review this broadly, and wil test out the --use-system-cfitsio option.

@embray

embray commented Nov 20, 2012

Copy link
Copy Markdown
Member Author

@astrofrog Most of that is just CFITSIO and its cross product of source modules for getting/putting each data type supported by FITS. I tried to hack it down to a bare minimum required for the pyfits compression module, but that turned out to be too unmanageable from a maintenance perspective.

…ngelog. At this point the pyfits changes kind of dominate the changelog. I hope that's okay but if not we could think of a way of collapsing it (though I'd rather not; the 'What's New' page in the docs will provide a broader overview, I think.
@embray

embray commented Nov 20, 2012

Copy link
Copy Markdown
Member Author

Looks like there are some test failures related to the new compression module not building/working properly in Python 3. I'll look into this.

@astrofrog

Copy link
Copy Markdown
Member

.I got the following error when trying to compile with --use-system-cfitsio:

/usr/bin/gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -pipe -O2 -fwrapv -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/include -I/opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c astropy/io/fits/src/compressionmodule.c -o build/temp.macosx-10.6-x86_64-2.7/astropy/io/fits/src/compressionmodule.o
astropy/io/fits/src/compressionmodule.c: In function ‘configure_compression’:
astropy/io/fits/src/compressionmodule.c:513: error: ‘FITSfile’ has no member named ‘cn_gzip_data’
astropy/io/fits/src/compressionmodule.c:523: error: ‘FITSfile’ has no member named ‘cn_gzip_data’
error: command '/usr/bin/gcc-4.2' failed with exit status 1

I presume this is an issue to do with the CFITSIO version? This makes me think, should we check the versions of system libraries and raise a proper error if they are too old? (the same point applies to expat and wcslib). Or is it basically up to the user to make sure the versions work out? I guess we should explicitly list the required versions in the documentation.

@embray

embray commented Nov 20, 2012

Copy link
Copy Markdown
Member Author

There are some version checks, but it looks like I missed that. I can certainly fix it.
Specifically, support for the GZIP_COMPRESSED_DATA column was added in CFITSIO 3.28. On the PyFITS end I already check for that version before doing anything with the GZIP_COMPRESSED_DATA column. But in the C source it doesn't do the same check before trying to assign to that struct member.

@embray

embray commented Nov 20, 2012

Copy link
Copy Markdown
Member Author

Got it building in Python 3, but now I'm getting a segfault. The segfault itself doesn't occur in my compression code, but rather from Numpy. That doesn't necessarily mean there's not a bug in my code somewhere. It's just hard to see it as of yet.

@embray

embray commented Nov 20, 2012

Copy link
Copy Markdown
Member Author

No, I think it is Numpy. I'm using Numpy 1.5.1 on my Python 3.2 installation, apparently. And this is a bug I've seen before where Numpy assumes that an array descriptor's shape will always be a tuple, and is inconsistent about making sure to convert scalar values (such as an int) to a tuple when constructing arrays and such. Should be easy enough to fix.

This *should* fix all the issues that were causing the build to fail in

Conflicts:

	astropy/io/fits/util.py
@embray

embray commented Nov 21, 2012

Copy link
Copy Markdown
Member Author

Oh, I still need to fix @astrofrog's issue with compiling with a <3.28 version of cfitsio.

@embray

embray commented Nov 23, 2012

Copy link
Copy Markdown
Member Author

@astrofrog With the last set of commits I should have improved support for older versions of CFITSIO. Specifically, 3.09 and up should all work. YMMV with earlier versions. Could you give the --use-system-cfitsio build another go? And if it still doesn't work you'll have to find out for me what version of cfitsio you're using.

@embray

embray commented Nov 23, 2012

Copy link
Copy Markdown
Member Author

Also, where do you think would be the best place to document CFITSIO version support?

@astrofrog

Copy link
Copy Markdown
Member

@astrofrog

Copy link
Copy Markdown
Member

Works for me! This looks good to go once you've added a note in the docs about the version number.

@embray

embray commented Nov 23, 2012

Copy link
Copy Markdown
Member Author

Any idea what these Travis failures are all about? It says it can't run setup.py egg_info?

@astrofrog

Copy link
Copy Markdown
Member

I don't understand, it's been doing that with some other PRs too. I will look into it.

@embray

embray commented Nov 23, 2012

Copy link
Copy Markdown
Member Author

Well, when I run the tests locally with Python 3.2 all the fits tests pass, but I get several errors in the logging tests due to, for some reason, 'asctime' being missing from LogRecords.

@astrofrog

Copy link
Copy Markdown
Member

Here's how to reproduce the error - it's actually to do with numpy, not astropy:

$ pip-3.2 install --upgrade "numpy<=999.99" --use-mirrors
[snip]
Running from numpy source directory.Traceback (most recent call last):

  File "<string>", line 14, in <module>

  File "/Users/tom/tmp/build/numpy/setup.py", line 214, in <module>

    setup_package()

  File "/Users/tom/tmp/build/numpy/setup.py", line 207, in setup_package

    configuration=configuration )

  File "/Users/tom/tmp/build/numpy/build/py3k/numpy/distutils/core.py", line 186, in setup

    return old_setup(**new_attr)

  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/distutils/core.py", line 148, in setup

    dist.run_commands()

  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/distutils/dist.py", line 929, in run_commands

    self.run_command(cmd)

  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/distutils/dist.py", line 948, in run_command

    cmd_obj.run()

  File "/Users/tom/tmp/build/numpy/build/py3k/numpy/distutils/command/egg_info.py", line 8, in run

    self.run_command("build_src")

  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/distutils/cmd.py", line 313, in run_command

    self.distribution.run_command(command)

  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/distutils/dist.py", line 948, in run_command

    cmd_obj.run()

  File "/Users/tom/tmp/build/numpy/build/py3k/numpy/distutils/command/build_src.py", line 152, in run

    self.build_sources()

  File "/Users/tom/tmp/build/numpy/build/py3k/numpy/distutils/command/build_src.py", line 163, in build_sources

    self.build_library_sources(*libname_info)

  File "/Users/tom/tmp/build/numpy/build/py3k/numpy/distutils/command/build_src.py", line 298, in build_library_sources

    sources = self.generate_sources(sources, (lib_name, build_info))

  File "/Users/tom/tmp/build/numpy/build/py3k/numpy/distutils/command/build_src.py", line 385, in generate_sources

    source = func(extension, build_dir)

  File "numpy/core/setup.py", line 694, in get_mathlib_info

    st = config_cmd.try_link('int main(void) { return 0;}')

  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/distutils/command/config.py", line 243, in try_link

    self._check_compiler()

  File "/Users/tom/tmp/build/numpy/build/py3k/numpy/distutils/command/config.py", line 75, in _check_compiler

    c_compiler=self.compiler)

  File "/Users/tom/tmp/build/numpy/build/py3k/numpy/distutils/fcompiler/__init__.py", line 832, in new_fcompiler

    c_compiler=c_compiler)

  File "/Users/tom/tmp/build/numpy/build/py3k/numpy/distutils/fcompiler/__init__.py", line 814, in get_default_fcompiler

    c_compiler=c_compiler)

  File "/Users/tom/tmp/build/numpy/build/py3k/numpy/distutils/fcompiler/__init__.py", line 763, in _find_existing_fcompiler

    c.customize(dist)

  File "/Users/tom/tmp/build/numpy/build/py3k/numpy/distutils/fcompiler/__init__.py", line 502, in customize

    get_flags('arch', aflags)

  File "/Users/tom/tmp/build/numpy/build/py3k/numpy/distutils/fcompiler/__init__.py", line 491, in get_flags

    flags.extend(getattr(self.flag_vars, tag))

  File "/Users/tom/tmp/build/numpy/build/py3k/numpy/distutils/environment.py", line 37, in __getattr__

    return self._get_var(name, conf_desc)

  File "/Users/tom/tmp/build/numpy/build/py3k/numpy/distutils/environment.py", line 51, in _get_var

    var = self._hook_handler(name, hook)

  File "/Users/tom/tmp/build/numpy/build/py3k/numpy/distutils/fcompiler/__init__.py", line 698, in _environment_hook

    return hook()

  File "/Users/tom/tmp/build/numpy/build/py3k/numpy/distutils/fcompiler/intel.py", line 63, in get_flags_arch

    v = self.get_version()

  File "/Users/tom/tmp/build/numpy/build/py3k/numpy/distutils/fcompiler/__init__.py", line 430, in get_version

    version = CCompiler.get_version(self, force=force, ok_status=ok_status)

  File "/Users/tom/tmp/build/numpy/build/py3k/numpy/distutils/ccompiler.py", line 26, in <lambda>

    m = lambda self, *args, **kw: func(self, *args, **kw)

  File "/Users/tom/tmp/build/numpy/build/py3k/numpy/distutils/ccompiler.py", line 458, in CCompiler_get_version

    status, output = exec_command(version_cmd,use_tee=0)

  File "/Users/tom/tmp/build/numpy/build/py3k/numpy/distutils/exec_command.py", line 197, in exec_command

    if _with_python and (0 or sys.__stdout__.fileno()==-1):

ValueError: underlying buffer has been detached

I wonder what changed suddenly. Either numpy 1.6.2 was only recently added to pip, or maybe they did a hot swap? In any case, this is not something I think we can do anything about, so I would trust the staging branch in Jenkins over Travis.

@embray

embray commented Nov 23, 2012

Copy link
Copy Markdown
Member Author

Yup, I'm baffled by that. I'll go ahead and try my staging branch.

@astrofrog

Copy link
Copy Markdown
Member

@iguananaut - did you try and start the MacOS X staging build from the jenkins interface? (https://jenkins.shiningpanda.com/astropy/job/astropy-staging-iguananaut-osx-10.7-multiconfig/NV=1.5.1,PV=3.1/12/console - it says 'started by user iguananaut').

@embray

embray commented Nov 26, 2012

Copy link
Copy Markdown
Member Author

Yeah, I did. Did I screw it up? Sorry if so.

Edit: I went ahead and deleted the project. I didn't realize the OSX builds weren't hosted by Shining Panda--I'm now guilty of my own pet peeve with Jenkins--sorry about that.

@astrofrog

Copy link
Copy Markdown
Member

@astrofrog

Copy link
Copy Markdown
Member

I tried upgrading to this branch, and I am no longer able to read some files I have that are in Rice compressed format, for example http://www.mpia.de/~robitaille/astropy/w20050513_01570_sf_st.fit

In [1]: from astropy.io import fits

In [2]: hdulist = fits.open('w20050513_01570_sf_st.fit')

In [5]: hdulist[1].data
ERROR: RuntimeError: Error reading elements 1 thru 3727 from column 1 (ffgclb). [astropy.io.fits.hdu.compressed]
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/Volumes/Scratch/UKIDSS/frames/stack/<ipython-input-5-507714abff29> in <module>()
----> 1 hdulist[1].data

/Volumes/Raptor/Library/Python/2.7/lib/python/site-packages/astropy/utils/misc.pyc in __get__(self, obj, owner)
    256         key = self._fget.func_name
    257         if key not in obj.__dict__:
--> 258             val = self._fget(obj)
    259             obj.__dict__[key] = val
    260             return val

/Volumes/Raptor/Library/Python/2.7/lib/python/site-packages/astropy/io/fits/hdu/compressed.pyc in data(self)
    901     def data(self):
    902         # The data attribute is the image data (not the table data).

--> 903         data = compression.decompress_hdu(self)
    904 
    905         # Scale the data if necessary


RuntimeError: Error reading elements 1 thru 3727 from column 1 (ffgclb).

What has changed that is causing this to fail?

@embray

embray commented Dec 3, 2012

Copy link
Copy Markdown
Member Author

What has changed that is causing this to fail?

Well the almost complete rewrite of the compression module would be a start :)

What version of CFITSIO did you build/link with? You can double check this with
>>> fits.compression.CFITSIO_VERSION

For what it's worth the data in that file is loading for me using the built-in cfitsio and looks fine (assuming that it's supposed to have those dots in the middle of each star--I obviously have no idea what that's supposed to mean).

@astrofrog

Copy link
Copy Markdown
Member

The holes in the stars are normal (just saturation). I did a clean install and it still doesn't work here. I get:

In [6]: fits.compression.CFITSIO_VERSION
Out[6]: 3.3

This is on MacOS 10.7. This is strange...

@embray

embray commented Dec 4, 2012

Copy link
Copy Markdown
Member Author

Strange indeed--I realized that when I tested this yesterday I was testing with pyfits, not astropy. But even with this PR on astropy it's working for me. d3fc78c fixed a bug that looked just like that, but you should have that in your copy by now.

@embray

embray commented Dec 4, 2012

Copy link
Copy Markdown
Member Author

I guess there's nothing to do but start knocking out other possibilities. OSX is a start--I'll try testing on there. Also, what Numpy version are you using? I have:

Astropy version 0.2.dev2294
with Numpy version 1.6.1
Decompressed with CFITSIO version 3.30

@astrofrog

Copy link
Copy Markdown
Member

Here's mine:

In [4]: astropy.__version__
Out[4]: '0.2.dev2294'

In [6]: np.__version__
Out[6]: '1.8.0.dev-a289be8'

In [7]: fits.compression.CFITSIO_VERSION
Out[7]: 3.3

I can try and downgrade numpy

@astrofrog

Copy link
Copy Markdown
Member

Ah, it works with Numpy 1.6.1 and 1.6.2, but not the latest developer version. Does this help identify the issue?

@astrofrog

Copy link
Copy Markdown
Member

I'm going to try and git bisect to find out when the breakage occurred

@embray

embray commented Dec 4, 2012

Copy link
Copy Markdown
Member Author

Okay, I got the same error using the latest dev Numpy. So that at least partially explains that. I should try to fix it though.

@embray

embray commented Dec 4, 2012

Copy link
Copy Markdown
Member Author

Don't bother with the bisect--I'm pretty sure it has to do with this: numpy/numpy#438
I knew this change was being made, but now it's more annoying than I realized. I think this is going to cause some problems in pyfits' implementation where Numpy 1.8 is concerned. Specifically, it's dropping any references to the raw_data base array that holds the entire table data including the heap which is kind of bizarre.

@astrofrog

Copy link
Copy Markdown
Member

I did bisect anyway for fun (never had a chance before), and this is what I get:

e411631e136bcdf53ef421102d8cb989beaacf08 is the first bad commit
commit e411631e136bcdf53ef421102d8cb989beaacf08
Author: 87 <[email protected]>
Date:   Tue Aug 30 21:44:54 2011 +0200

    BUG: PyArray_SetBaseObject didn't set proper base when collapsing views

:040000 040000 5edbf90d3f1b4b54215490cc823b7381f3782af5 69023dcfcc56be0a84454205e3c8b93336ae1ad1 M  numpy

@astrofrog

Copy link
Copy Markdown
Member

Interestingly, the commit I found was much earlier than the issue you pointed to.

@astrofrog

Copy link
Copy Markdown
Member

I guess it will also cause issues with Numpy 1.7.0 once it's out?

@astrofrog

Copy link
Copy Markdown
Member

Just confirming that I get the error with Numpy 1.7.0b2.

@embray

embray commented Dec 4, 2012

Copy link
Copy Markdown
Member Author

numpy/numpy#2746 fixes the issue. So for now I'll assume it will get pulled.

@astrofrog

Copy link
Copy Markdown
Member

Awesome, thanks for following this up!

@njsmith

njsmith commented Dec 5, 2012

Copy link
Copy Markdown

I think this is going to cause some problems in pyfits' implementation where Numpy 1.8 is concerned. Specifically, it's dropping any references to the raw_data base array that holds the entire table data including the heap which is kind of bizarre.

^ Can you guys elaborate on this? I'm glad if this has been fixed for 1.7/current master, but the .base handling code may change again in the future and this statement is very worrisome. Even with the original pre-fixup code that was originally in 1.7, it shouldn't have been losing references to arrays that are actually holding data...

@astrofrog

Copy link
Copy Markdown
Member

@iguananaut - just to confirm, updating to the latest numpy dev version now makes this PR work properly.

…m that it *does* pass when the test suite is run outside of Jenkins, even on the configurations where it was failing.
@embray

embray commented Dec 5, 2012

Copy link
Copy Markdown
Member Author

@njsmith Thanks for checking in on this. Let me try to clarify. FITS tables have a strange structure for supporting variable length fields by which it includes a "heap" section to the data after the data itself. Variable length columns then contain just offsets into the heap portion, for the value of that column for each row. So basically the data consists of a table, followed by some additional arbitrary-length data.

What I'm doing, in order to keep all the data together, is to create a byte array of all the data, then taking a slice of that for the portion that contains the actual table and viewing it as a recarray with the appropriate columns. The details of retrieving the variable length data from the heap are handled elsewhere.

The problem here is that I have some C code that, when passed one of these recarrays, needed to be able to traverse the bases to find the original byte array containing both the table and heap data. It was references to this array that were being lost.

To complicate matters, that data is normally mmap'd. What was not lost was the reference to the original mmap.mmap object that was used as the original array's buffer. But the C code was expecting to find an ndarray of the appropriate size in the bases, and doesn't know what to do when it instead encounters an mmap object.

@embray

embray commented Dec 5, 2012

Copy link
Copy Markdown
Member Author

Going ahead and merging this. Travis is happy with it now, as is my Windows staging branch and the OSX staging branch. Linux should be fine.

embray added a commit that referenced this pull request Dec 5, 2012
@embray
embray merged commit 6f4fad3 into astropy:master Dec 5, 2012
keflavich pushed a commit to keflavich/astropy that referenced this pull request Oct 9, 2013
jeffjennings pushed a commit to jeffjennings/astropy that referenced this pull request Jul 2, 2025
…mission#161) (astropy#495)

Adding ZodiPy to Affiliated packages (in future "legacy" list)

Co-authored-by: Derek Homeier <[email protected]>
jeffjennings pushed a commit to jeffjennings/astropy that referenced this pull request Jul 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move io.fits external C dependencies into cextern

3 participants