question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Converting float64 to float32 rounds off data in hdu object

See original GitHub issue

Hi, 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:open
  • Created 6 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
saimncommented, Nov 14, 2017

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.

1reaction
indiajoecommented, Nov 13, 2017

@pllim , Yes. That is what I did now as a workaround. used the .data.astype(), and it worked as expected.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found