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

Delete scaling keywords from header when unsigned int data converted to another type #5053

Merged
merged 3 commits into from Jun 10, 2016

Conversation

mwcraig
Copy link
Member

@mwcraig mwcraig commented Jun 9, 2016

Ideally this would get into 1.2 (not necessary into the RC, but before the final release). It addresses #4974 but involved a fair bit of monkeying around with the internals of scaling.

@embray, if you could take a look that would be great.

Changelog as soon as I find out which section to put the entry in....

@mwcraig mwcraig mentioned this pull request Jun 9, 2016
14 tasks
@pllim pllim added this to the v1.2.0 milestone Jun 10, 2016
@embray
Copy link
Member

embray commented Jun 10, 2016

The bscale/bzero handling has always been a mess. I've attempted a couple times to clean it up, and it always just ends up a mess again. I think some deeper refactoring is needed (stuff I had planned to but never had the time).

(What I'm saying is, I'm sorry you had to deal with it!)

@@ -135,9 +147,31 @@ def __init__(self, data=None, header=None, do_not_scale_image_data=False,
self._data_needs_rescale = True
return
else:
# Setting data will set set _bitpix, _bzero, and _bscale to the
# appropriate BITPIX for the data, and always sets _bzero=0 and
# _bscale=1.
self.data = data
self.update_header()
Copy link
Member

Choose a reason for hiding this comment

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

It looks to me like update_header() already gets called when setting self.data. See https://github.com/mwcraig/astropy/blob/0627686c4c422c7f183e552d70d320a0f1540a5f/astropy/io/fits/hdu/image.py#L288

So this can probably be removed (if somehow things break unless it's called twice then that would be something to look into as well).

Basically most of this business of setting self._bitpix shouldn't be happening here in __init__ at all, and should just happen when setting self.data =... (since that can happen outside of __init__ as well).

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, passes locally, will fix in separate PR addressing the remaining comments too.

@embray
Copy link
Member

embray commented Jun 10, 2016

I think if this fixes the immediate bug and passes all the tests then I think it should be merged (and backported as relevant). But I have a lot of comments above, as you can see, which I think should be addressed. If not by this PR then an issue should be opened for the followup work.

@astrofrog
Copy link
Member

@mwcraig - let me know how you want to proceed. If you would prefer to address the issues now, we could just put this in 1.2.1 instead?

@mwcraig
Copy link
Member Author

mwcraig commented Jun 10, 2016

@astrofrog -- let's merge as is. I've got a couple questions about @embray's (very helpful) comments and will start a follow-up PR today for 1.2.1.

The underlying bug is fairly serious, though, and should be addressed asap: Reading unsigned data, performing floating point operations on it, then writing it out will result in corrupt data values.

@mwcraig
Copy link
Member Author

mwcraig commented Jun 10, 2016

(What I'm saying is, I'm sorry you had to deal with it!)

Not a problem; it sounds like we can work out some kind of sensible internal behavior which I can then implement!

@astrofrog
Copy link
Member

@mwcraig - ok, in that case, can you add a changelog entry, with [ci skip]?

@mwcraig
Copy link
Member Author

mwcraig commented Jun 10, 2016

@astrofrog -- done.

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.

None yet

4 participants