ROOT
master
Reference Guide
FITS_tutorial1.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_FITS
3
/// \notebook -draw
4
/// Open a FITS file and retrieve the first plane of the image array
5
/// as a TImage object
6
///
7
/// \macro_image
8
/// \macro_code
9
/// \macro_output
10
///
11
/// \author Claudi Martinez
12
13
void
FITS_tutorial1()
14
{
15
// Here we open a FITS file that contains only the primary HDU, consisting on an image.
16
// The object you will see is a snapshot of the NGC7662 nebula,
17
// which was taken by the author on November 2009 in Barcelona.
18
19
TString
dir =
gROOT
->GetTutorialDir();
20
21
// Open primary HDU from file
22
TFITSHDU
hdu(dir +
"/fitsio/sample1.fits"
);
23
24
// Dump the HDUs within the FITS file
25
// and also their metadata
26
// printf("Press ENTER to see summary of all data stored in the file:"); getchar();
27
28
hdu.Print(
"F+"
);
29
30
// Here we get the exposure time.
31
printf(
"Exposure time = %s\n"
, hdu.GetKeywordValue(
"EXPTIME"
).Data());
32
33
// Read the primary array as a matrix, selecting only layer 0.
34
// This function may be useful to do image processing, e.g. custom filtering
35
36
std::unique_ptr<TMatrixD> mat(hdu.ReadAsMatrix(0));
37
mat->Print();
38
39
// Read the primary array as an image, selecting only layer 0.
40
TImage
* im = (
TImage
*)hdu.ReadAsImage(0);
41
42
// Read the primary array as a histogram. Depending on array dimensions, the returned
43
// histogram will be 1D, 2D or 3D.
44
TH1
* hist = (
TH1
*)hdu.ReadAsHistogram();
45
46
auto
c
=
new
TCanvas
(
"c1"
,
"FITS tutorial #1"
, 1400, 800);
47
c
->Divide(2, 1);
48
c
->cd(1);
49
im->
Draw
();
50
c
->cd(2);
51
hist->
Draw
(
"COL"
);
52
}
c
#define c(i)
Definition:
RSha256.hxx:101
TImage
An abstract interface to image processing library.
Definition:
TImage.h:29
TString
Basic string class.
Definition:
TString.h:136
TObject::Draw
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition:
TObject.cxx:197
TCanvas
The Canvas class.
Definition:
TCanvas.h:23
TFITSHDU
FITS file interface class.
Definition:
TFITS.h:35
TH1
TH1 is the base class of all histogramm classes in ROOT.
Definition:
TH1.h:58
gROOT
#define gROOT
Definition:
TROOT.h:406
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition:
TH1.cxx:3069
tutorials
fitsio
FITS_tutorial1.C
ROOT master - Reference Guide Generated on Sat Jan 16 2021 12:34:09 (GVA Time) using Doxygen 1.9.0