-
Notifications
You must be signed in to change notification settings - Fork 15
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
FitsHdu::read_key
returns different values for f32
and i32
types
#167
Comments
You're absolutely right - confirmed with this #include <assert.h>
#include <fitsio.h>
int main() {
fitsfile *fptr = NULL;
int status = 0;
const char *filename =
"../examples/M_27_Light_30_secs_2022-06-29T00-53-28_024.fits";
if (fits_open_file(&fptr, filename, READONLY, &status)) {
fprintf(stderr, "error opening file\n");
fits_report_error(stderr, status);
return status;
}
float floatval = 0;
if (fits_read_key(fptr, TFLOAT, "GAIN", &floatval, NULL, &status)) {
fprintf(stderr, "reading float key\n");
fits_report_error(stderr, status);
return status;
}
int intval = 0;
if (fits_read_key(fptr, TINT, "GAIN", &intval, NULL, &status)) {
fprintf(stderr, "reading int key\n");
fits_report_error(stderr, status);
return status;
}
printf("Got float value %f, int value %d\n", floatval, intval);
if (fits_close_file(fptr, &status)) {
fprintf(stderr, "error closing file\n");
fits_report_error(stderr, status);
return status;
}
assert(status == 0);
return 0;
} Thanks for raising, I'll take a look 👍 |
It looks like it's only reading i32 values from the header that is broken. Looking through the docs, I see the name of the I think instead the better option is to remove the ability to read I'm interested to gauge whether this is sensible or not. While I'm at it I might remove the ability to read
Image or table data I can imagine caring deeply about the bit-size of the result since I may be reading thousands of pixels and so decreasing the number of bytes by two is preferable. For header cards however, it's unlikely they will be read in in such large quantities to justify using a smaller bit-size. |
Yep, this is a pain. As I discovered a few years ago now, Should we change things in |
Hm... May be better to use |
What is you result? Mine is Ok
|
Yeah I get the same. When I use To @cjordan's point - both I had toyed with the idea of understanding what the type of the header was and returning something type-aware, e.g. an enum enum HeaderValue {
Int(i64),
Float(f64),
String(String),
Bool(bool),
} then the user gets the type of the key, however they have to match each time which also may be a pain. @cjordan your function is conceptually similar - the user has to determine the type of the header value, but using I think the best bet is to remove the |
Annoyingly I can't mark the |
It's Ok for me. I will simply rewrite little part of my code. |
@mindriot101 I appreciate the concern! There might be some things that break, but as long as semver is honoured, I'm happy for the changes to proceed. I don't think I ever read |
@cjordan what are you weary about with cfitsio's reading of f42s? I might just fix i32 reading, since it may be more convenient for the user if they do 32-bit arithmetic on the value to not cast it. This will leave i32 and f32 reading available It might be good to perform a read that knows the type so the user gets the type back, I'll do some research |
@mindriot101 I'm probably overthinking it, but due to these surprises when reading fits keys, I've kept a (un)healthy amount of scepticism when reading in floats. In my work, we care a lot about precision, so if there's a chance that reading a f64 and demoting it is somehow better than reading an f32 directly, I'll probably do that. Fortunately in most cases f32 values are reserved for the bulk of our data, not metadata where I'd be reading fits keys. |
Looks like I removed the |
...erm i misread the output of the github cli - ignore me 🤦 |
hdu.read_key::<f32>(fptr, "GAIN")
returnsSome(200.0)
hdu.read_key::<i32>(fptr, "GAIN")
returnsSome(1)
FITS file is here: https://drive.google.com/file/d/1CalgywTpuKKXDqO8rwc31APoVSxv_c-R/view?usp=sharing
The text was updated successfully, but these errors were encountered: