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

Introduce class HipsDrawResult in simple.py #91

Merged
merged 3 commits into from
Jul 26, 2017

Conversation

adl1995
Copy link
Member

@adl1995 adl1995 commented Jul 25, 2017

As outlined in issue #80, I have added a class HipsDrawResult. This still needs more work, currently it only stores image and geometry.

@cdeil cdeil self-assigned this Jul 25, 2017
@cdeil cdeil added this to the 0.1 milestone Jul 25, 2017
@cdeil
Copy link
Contributor

cdeil commented Jul 25, 2017

This looks good to me. I think you can just continue with this PR for ~ a day, adding more features.

I would suggest adding a __str__ method so that print(result) will print out infos about the result.
I've added __repr__ to a few other other classes that do something similar, e.g. HipsTileMeta.
Here for the sky image, things that would be good to know are the width and height and number of channels, the dtype of the data, and some info about the WCS geometry.

Another thing I would suggest is to add a write_image method, so that users can do:

result.write_image('image.fits')

and then change the high-level docs example at https://hips.readthedocs.io/en/latest/getting_started.html to call that write_image convenience method instead of the three lines we currently have:

from astropy.io import fits
hdu = fits.PrimaryHDU(data=data, header=geometry.fits_header)
hdu.writeto('my_image.fits')

@adl1995
Copy link
Member Author

adl1995 commented Jul 25, 2017

@cdeil I just made these updates. Please review.

@adl1995 adl1995 force-pushed the HipsDrawResult branch 2 times, most recently from 55aa6e0 to f4401da Compare July 25, 2017 14:37
Copy link
Contributor

@cdeil cdeil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks mostly good. I left some inline comments.

@adl1995 - Do you want to leave it at that or continue in this PR for a bit?

One thing that I think would be nice would be if there were a result.plot method that would plot the sky image, using wcsaxes and showing the HEALPix grid, i.e. something that will with one line let people see the result and get some info about the tiles that were drawn.

I guess it would mean that you have to store extra info on the result object about the tiles. You could either do that, or for now just attach the painter to result, as a simple way for now to expose all intermediate data to "power users" like us, even though they used the high-level interface to run the example.

assert_allclose(np.sum(result.image), pars['data_sum'])
assert_allclose(result.image[200, 994], pars['data_1'])
assert_allclose(result.image[200, 995], pars['data_2'])
result.write_image('test.' + pars['file_format'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When writing files from tests, you should always do it using tmpdir.
Examples: https://github.com/hipspy/hips/search?utf8=%E2%9C%93&q=tmpdir&type=

'This class object contains two attributes: image and geometry'
)

def __repr__(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow the common pattern of mentioning the class name in the repr, like in this example:

def __repr__(self):


def __str__(self):
return (
'This class object contains two attributes: image and geometry'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't useful. The idea of having a separate __str__ is that you give more information.
In this case, it could be something like this:

def __str__(self):
    ss = 'HiPS draw result:\n'
    ss += 'Sky image: .... infos about sky image pixel data (shape, dtype) ...\n'
    ss += f'WCS geometry: {self.geometry}\n'
    .... later add more info about number of tiles used and fetched, time to exectute, memory used
   ... i.e. print out a nice report
    return ss

from astropy.io import fits
hdu = fits.PrimaryHDU(data=data, header=geometry.fits_header)
hdu.writeto('my_image.fits')
result.write_image('my_image.fits')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This info in the high-level section is now a little short, you should give some more infos what people can do with the result, namely that they can get at the pixel data as a numpy array, the WCS for the image and print out info about the result.

@adl1995
Copy link
Member Author

adl1995 commented Jul 26, 2017

@cdeil I just pushed my latest code. Now there is a method in HipsDrawResult named plot which plots the all-sky image with HEALPix grid. I also made some changes to the high-level docs and added the __str__ method in WCSGeometry.

@cdeil cdeil merged commit 1a2c763 into hipspy:master Jul 26, 2017
@cdeil
Copy link
Contributor

cdeil commented Jul 26, 2017

Thanks! (I'll do some small follow-up edits in master later today.)

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.03%) to 97.292% when pulling 821f335 on adl1995:HipsDrawResult into a357718 on hipspy:master.

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

Successfully merging this pull request may close these issues.

3 participants