FITS_tutorial1.C

Go to the documentation of this file.
00001 // Open a FITS file and retrieve the first plane of the image array 
00002 // as a TASImage object
00003 void FITS_tutorial1()
00004 {
00005    printf("\n\n--------------------------------\n");
00006    printf("WELCOME TO FITS tutorial #1 !!!!\n");
00007    printf("--------------------------------\n");
00008    printf("We're gonna open a FITS file that contains only the\n");
00009    printf("primary HDU, consisting on an image.\n");
00010    printf("The object you will see is a snapshot of the NGC7662 nebula,\n");
00011    printf("which was taken by the author on November 2009 in Barcelona (CATALONIA).\n\n");
00012       
00013    if (!gROOT->IsBatch()) {
00014       //printf("Press ENTER to start..."); getchar();
00015    }
00016    
00017    // Open primary HDU from file
00018    TFITSHDU *hdu = new TFITSHDU("sample1.fits");
00019    if (hdu == 0) {
00020       printf("ERROR: could not access the HDU\n"); return;
00021    }
00022    printf("File successfully open!\n");
00023    
00024    // Dump the HDUs within the FITS file
00025    // and also their metadata
00026    //printf("Press ENTER to see summary of all data stored in the file:"); getchar();
00027    
00028    hdu->Print("F+");
00029    
00030    printf("....................................\n");
00031    // Here we get the exposure time.
00032    //printf("Press ENTER to retrieve the exposure time from the HDU metadata..."); getchar();
00033    printf("Exposure time = %s\n", hdu->GetKeywordValue("EXPTIME").Data());
00034 
00035    
00036    // Read the primary array as a matrix,
00037    // selecting only layer 0.
00038    // This function may be useful to
00039    // do image processing.
00040    printf("....................................\n");
00041    printf("We can read the image as a matrix of values.\n");
00042    printf("This feature is useful to do image processing, e.g:\n");
00043    printf("histogram equalization, custom filtering, ...\n");
00044    //printf("Press ENTER to continue..."); getchar();
00045    
00046    TMatrixD *mat = hdu->ReadAsMatrix(0);
00047    mat->Print();
00048    delete mat;
00049    
00050    // Read the primary array as an image,
00051    // selecting only layer 0.
00052    printf("....................................\n");
00053    printf("Now the primary array will be read both as an image and as a histogram,\n");
00054    printf("and they will be shown in a canvas.\n");
00055    //printf("Press ENTER to continue..."); getchar();
00056    
00057    TASImage *im = hdu->ReadAsImage(0);
00058    
00059    // Read the primary array as a histogram.
00060    // Depending on array dimensions, returned
00061    // histogram will be 1D, 2D or 3D
00062    TH1 *hist = hdu->ReadAsHistogram();
00063    
00064    
00065    TCanvas *c = new TCanvas("c1", "FITS tutorial #1", 800, 300);
00066    c->Divide(2,1);
00067    c->cd(1);
00068    im->Draw();
00069    c->cd(2);
00070    hist->Draw("COL");
00071 
00072    // Clean up
00073    delete hdu;
00074 }
00075 
00076  

Generated on Tue Jul 5 15:44:09 2011 for ROOT_528-00b_version by  doxygen 1.5.1