Converting float64 to float32 rounds off data in hdu object
See original GitHub issueHi, Why do we round off the data to integers before changing the data type in this line? https://github.com/astropy/astropy/blob/5f88a0ede0d03cf6329d9d5e0971d540275a8b55/astropy/io/fits/hdu/image.py#L549
To save hardisk space, I wanted to convert my float64 fits images to float32.
I used the hdulist[0].scale('float32')
method to do that.
However, instead of changing float64 to float32, it rounded off to nearest integer.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Pandas float64 to float 32 ,then the data changes
Pandas defaults to displaying floating points with a precision of 6, and trailing 0s are dropped in the default output. float64 can accurately ......
Read more >Unified File Read/Write Interface — Astropy v5.2
For writing and reading tables to ASCII in a way that fully reproduces the table data, types, and metadata (i.e., the table will...
Read more >astropy.io.fits History
This FITS_rec object can then be used as the data argument in the constructors ... uint32, or uint64) instead of into the normal...
Read more >Projection — spectral-cube v0.6.1.dev244+g13f4ea9
Python buffer object pointing to the start of the array's data. ... means only safe casts or casts within a kind, like float64...
Read more >a commented Python script - GREAT
Actually, there is one more data type, called ``object``: this makes it ... this is easily fixed by converting them to normal float...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
From what I understand the
.scale
method should only be used to scale to (unsigned) int. (From the FITS standard, “Use of the BSCALE and BZERO keywords is not recommended” for floats).For a float64->float32 conversion, converting the data directly with
.astype
is the good way.@pllim , Yes. That is what I did now as a workaround. used the
.data.astype()
, and it worked as expected.