Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError from flipup call in Tile.to_numpy #112

Open
cdeil opened this issue Oct 16, 2017 · 1 comment
Open

ValueError from flipup call in Tile.to_numpy #112

cdeil opened this issue Oct 16, 2017 · 1 comment
Assignees
Labels
Milestone

Comments

@cdeil
Copy link
Contributor

cdeil commented Oct 16, 2017

Sometimes an error occurs in the np.flipup call here when converting JPEG to numpy array:

data = np.flipud(data)

    with Image.open(bio) as image:
                data = np.array(image)
                # Flip tile to be consistent with FITS orientation
                data = np.flipud(data)

ValueError: Input must be >= 1-d.

I saw this here: https://travis-ci.org/hipspy/hips/jobs/288318105#L1611
and also locally (from a different test) here: https://gist.github.com/cdeil/ad3dd0dc6a6c1fe8d58ec22ecdad03d0

It doesn't seem to be deterministic, I re-ran the same test and the fail doesn't show up.

I'm not sure what causes it, it looks like Pillow doesn't read the file properly, but only sometimes!???
For now, I'll just keep this issue open as a reminder, and try one thing: move the np.flipup call out of the with block, to make sure that the file was closed and Pillow was done for sure:

            with Image.open(bio) as image:
                data = np.array(image)
                # Flip tile to be consistent with FITS orientation
            data = np.flipud(data)
@cdeil cdeil added the bug label Oct 16, 2017
@cdeil cdeil added this to the wishlist milestone Oct 16, 2017
@cdeil cdeil modified the milestones: wishlist, 0.3 Jun 28, 2018
@cdeil
Copy link
Contributor Author

cdeil commented Jul 19, 2018

I don't have time to look into this issue now, but wanted to leave a note:

When @adonath and @tboch implemented the HiPS gen, they noticed an issue that FITS I/O doesn't work properly for a Numpy array that's transposed, as the result of calling np.rot90 is:
https://github.com/hipspy/hips/pull/123/files#diff-4de2f89531f836afdfd881e73aea8632R43
Probably here where we call np.flipup also a transposed Numpy array is created and from the comments above it seems that also Pillow I/O sometimes doesn't work properly with that.

There is astropy/astropy#2150 describing the issue for Gzipped FITS, but I'm not aware of an open issue in the Astropy tracker without Gzip compression, which I think is what we're using for HiPS.

So basically this issue needs someone to look in detail at how FITS / PNG / JPEG I/O react to passing in transposed Numpy arrays (add test cases for that), and where necessary add a np.copy or np.ascontiguousarray call to make sure a "normal" Numpy array is used in those places.
That should be done in the I/O code, not in random code places like here:
https://github.com/hipspy/hips/pull/123/files#diff-4de2f89531f836afdfd881e73aea8632R43

@adl1995 or @adonath - If you don't have time for this, I could give it a try in the coming weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant