📜 ⬆️ ⬇️

FITS (Flexible Image Transport System) format in Octave

Continuing my acquaintance with Octave, I decided to try performing elementary operations with FITS files. As it turned out, in the "default" Octave there are no means for working with FITS. But google helped me. So, Google brought me to the Octave page on sourceforge. I downloaded the FITS package I needed, unpacked it and tried to compile it. But it was not there! When you run ./configure, nothing happened. Looking into the src directory, I didn't see anything interesting, just an elementary Makefile. The content of it prompted me to install the Octave package compiler - mkoctfile. In Mandriva it is in the octave-devel package. Having installed the required package, I ran make and got three files:
  read_fits_image.oct save_fits_image.oct save_fits_image_multi_ext.oct 
Where to put them, I had no idea, but
  locate \ .oct 
brought me to the directory
  /usr/lib/octave/3.4.2/oct/i586-mandriva-linux-gnu/ 
where (on behalf of the root, of course) the files were copied. Having started Octave, I first checked whether these commands work. Work. To read the file filename.fits in the var variable you need to do:
var = read_fits_image("filename.fits"); 
The main thing is not to forget the semicolon at the end of the command, in order not to get streams of numbers! I remembered the semicolon when I forgot to put it. I was pleasantly surprised that, unlike the matlab, flooding the user with an endless stream of data, Octave splits the output by pages (to all appearances, less is used to display on the screen). To read the file header, let's execute:
 [var, head] = read_fits_image("filename.fits"); 
The whos command shows that head is a string array with a length of 80 characters (recall the FITS format restrictions), into which the entire file header is simply rewritten line by line without splitting into name / value / comment (that is, if you plan to work with Octave in , I’ll have to do all this myself, or I can add the necessary functions to the FITS package, there is a good tool for this). I tried to display the file on the screen using imshow. Oh no! I saw ... absolutely nothing. But imagesc showed me a picture and even changed the color map for colormap commands. If you want to display a picture on a logarithmic scale:
 imagesc(log(var)); 
The display will be more pleasant. Remembering my fitsview , I regretted that using gnuplot as an “scribe” is very irritating: you have to wait for quite a while for Octave to transfer the necessary data to the screen, and then to display it on the screen. and finally, a simple little program for adding files in a directory that looks like object_XXXX.fit (where XXXX is a number), starting with the first number and ending with the last number:
 function ret = sum_fits(first, last) ret = [1 2 3]; frst = 1; i = 0; for num = [ first : last ] i++; name = sprintf("object_%04d.fit", num); %    II = read_fits_image(name); %   med = median(median(II)); %      printf("%d:\tread file %s, median = %d\n", i, name, med); fflush(1); %    ! II -= med; %  "" (bias'  ) if(frst == 1) %  frst = 0; ret = II; else ret += II; end end end 
And an example for images obtained to determine the coordinates of the center of rotation of the field:
 II = sum_fits(1,147); a = II; a(find(a < 1)) = 1; imagesc(log(a)) 
We get this picture:
Yes, I almost forgot: Octave also has matlab-like interfaces, for example, QtOctave: In general, the interface design is quite decent, however, it is very annoying that the command line is rendered separately and you need to click on it to start writing something. So, Octave's CLI is much better and more convenient.

')

Source: https://habr.com/ru/post/132784/


All Articles