Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Data conversion of FITS images in PDL

by Xilman (Hermit)
on Aug 23, 2020 at 19:26 UTC ( [id://11121012] : perlquestion . print w/replies, xml ) Need Help??

Xilman has asked for the wisdom of the Perl Monks concerning the following question:

I am being stupid. Either that, or less likely, the documentation in PDL::IO::FITS is wrong.

I have a FITS image in which each pixel is a 32-bit float. That is, BITPIX == -32. I wish to convert it to 32-bit fixed-point format, where BITPIX == 16.

This is my script.

#! /usr/bin/perl

use strict;
use warnings;
use PDL;
use PDL::IO::FITS;
 
my $x = rfits('foo.fits');
$x->wfits('bar.fits', 16);

And here is what happens:

pcl@nut:~/Astro/Code$ imhead foo.fits | grep BITPIX
BITPIX  =                  -32 /
pcl@nut:~/Astro/Code$ perl to_int.pl
pcl@nut:~/Astro/Code$ imhead bar.fits | grep BITPIX
BITPIX  =                  -32

The output file is not converted to 16-bit unsigned format, despite what the documentation appears to say.

What am I not understanding and how do I get data conversion?

Replies are listed 'Best First'.
Re: Data conversion of FITS images in PDL
by swl (Parson) on Aug 23, 2020 at 22:24 UTC

      Many thanks. Your suggestion works a treat.

      I will submit a bug report.

        Thanks for this report! The bug was fixed by Derek Lamb, and released as PDL 2.022 in Sep 2020.