F I T S_Tutorial 1

Open a FITS file and retrieve the first plane of the image array as a TImage object

Author: Claudi Martinez
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Friday, September 25, 2020 at 07:37 AM.

Here we open a fits file that contains only the primary hdu, consisting on an image. The object you will see is a snapshot of the NGC7662 nebula, which was taken by the author on November 2009 in Barcelona.

In [ ]:
TString dir = gROOT->GetTutorialDir();

Open primary hdu from file

In [ ]:
TFITSHDU hdu(dir + "/fitsio/sample1.fits");

Dump the hdus within the fits file and also their metadata printf("Press ENTER to see summary of all data stored in the file:"); getchar();

In [ ]:
hdu.Print("F+");

Here we get the exposure time.

In [ ]:
printf("Exposure time = %s\n", hdu.GetKeywordValue("EXPTIME").Data());

Read the primary array as a matrix, selecting only layer 0. This function may be useful to do image processing, e.g. custom filtering

In [ ]:
std::unique_ptr<TMatrixD> mat(hdu.ReadAsMatrix(0));
mat->Print();

Read the primary array as an image, selecting only layer 0.

In [ ]:
TImage * im = (TImage *)hdu.ReadAsImage(0);

Read the primary array as a histogram. depending on array dimensions, the returned histogram will be 1D, 2D or 3D.

In [ ]:
TH1 * hist = (TH1 *)hdu.ReadAsHistogram();

auto c = new TCanvas("c1", "FITS tutorial #1", 1400, 800);
c->Divide(2, 1);
c->cd(1);
im->Draw();
c->cd(2);
hist->Draw("COL");

Draw all canvases

In [ ]:
gROOT->GetListOfCanvases()->Draw()