hipspy / hips

Python library to handle HiPS
https://hips.readthedocs.io
13 stars 16 forks source link

Add tests for HiPS tile <-> Numpy conversions #140

Closed cdeil closed 5 years ago

cdeil commented 5 years ago

Today I wanted to make the healpix_to_hips work for RGB JPEG and RGBA PNG data. I'll make a pull request for that shortly.

However, I noticed that there seems to be a bug in our HipsTile.from_numpy or HipsTile.to_numpy for the RGB JPEG case. This PR shows the issue via a regression test. It works for FITS and also for RGBA PNG as expected.

Looking for old issues I saw #112, possibly this is the same issue. I did try adding .copy calls before and after the flipud calls in from_numpy, no change, so transposed Numpy arrays don't seem to be the issue.

@tboch and maybe if you have time @adl1995 or @adonath - If you have time, could you please have a look at this and comment if you have any idea?

This is blocking the work on HEALPix -> HiPS and the v0.3 release, so we should try to figure this out ASAP.

cdeil commented 5 years ago

Actually it looks like the issue is just "JPEG encoding noise", if I change the example to larger integer numbers in the unit8 range (e.g. 0, 100, 200 instead of 0, 1, 2) they approximately round-trip.

https://nbviewer.jupyter.org/gist/cdeil/c5401336d7d5eb477263fb8b7b358de1

adl1995 commented 5 years ago

@cdeil - Thanks for looking into this.

Could this possibly have something to do with JPEG being a lossy format? We currently save the image using the Image.save function from Pillow, without providing any extra parameters for controlling the image quality.

This documentation for JPEG file format lists other keyword parameters that can be used e.g. dpi and quality (which is a number from 0 to 100, default is set to 75).

Maybe you could try setting this to 100 and see if it affects the output?

cdeil commented 5 years ago

This is not changing any behaviour. It's just adding tests that prove that tile Numpy array conversions are working OK and doing some (accidentally applied) code formatting.

coveralls commented 5 years ago

Coverage Status

Coverage increased (+0.006%) to 95.675% when pulling 83d317444218ffbadf9c6b403b4a27d5f8a0723c on cdeil:tile-numpy into a9660bdc4083ff648d56a74e437c308d5a9881a4 on hipspy:master.