コード例 #1
0
ファイル: FITS_tutorial3.C プロジェクト: My-Source/root
// Open a FITS file and retrieve the first plane of the image array 
// as a TASImage object
void FITS_tutorial3()
{
   printf("\n\n--------------------------------\n");
   printf("WELCOME TO FITS tutorial #3 !!!!\n");
   printf("--------------------------------\n");
   printf("We're gonna open a FITS file that contains several image\n");
   printf("extensions. The primary HDU contains no data.\n");
   printf("Data copyright: NASA\n\n");
   
   if (!gROOT->IsBatch()) {
      //printf("Press ENTER to start..."); getchar();
   }
   
   // Open extensions 1 to 5 from file
   //printf("Press ENTER to see a canvas with all images within the file:"); getchar();
   
   TCanvas *c = new TCanvas("c1", "FITS tutorial #1", 800, 700);
   c->Divide(2,3);
   for (int i=1; i <= 5; i++) {
      TFITSHDU *hdu = new TFITSHDU("sample3.fits", i);
      if (hdu == 0) {
         printf("ERROR: could not access the HDU\n"); return;
      }
      
      TASImage *im = hdu->ReadAsImage(0);
      c->cd(i);
      im->Draw();
      delete hdu;
   }
}
コード例 #2
0
ファイル: FITS_tutorial6.C プロジェクト: MycrofD/root
void FITS_tutorial6()
{
   TVectorD *v;

   printf("\n\n--------------------------------\n");
   printf("WELCOME TO FITS tutorial #6 !!!!\n");
   printf("--------------------------------\n");
   printf("We are going to open a table from a FITS file\n");
   printf("and dump its columns.\n\n");

   TString dir = gSystem->DirName(__FILE__);

   //Open the table
   TFITSHDU *hdu = new TFITSHDU(dir+"/sample4.fits[1]");
   if (hdu == 0) {
      printf("ERROR: could not access the HDU\n"); return;
   }

   //Show columns
   Int_t nColumns = hdu->GetTabNColumns();
   printf("The table has %d columns:\n", nColumns);
   for (Int_t i = 0; i < nColumns; i++) {
      printf("...Column %d: %s\n", i, hdu->GetColumnName(i).Data());
   }
   puts("");

   delete hdu;
}
コード例 #3
0
ファイル: FITS_tutorial2.C プロジェクト: digideskio/root
// Open a FITS file whose primary array represents
// a spectrum (flux vs wavelength)
void FITS_tutorial2()
{
   printf("\n\n--------------------------------\n");
   printf("WELCOME TO FITS tutorial #2 !!!!\n");
   printf("--------------------------------\n");
   printf("We're gonna open a FITS file that contains the\n");
   printf("primary HDU and a little data table.\n");
   printf("The primary HDU is an array of 2 rows by 2040 columns, and\n");
   printf("they represent a radiation spectrum. The first row contains\n");
   printf("the flux data, whereas the second row the wavelengths.\n");
   printf("Data copyright: NASA\n\n");

   if (!gROOT->IsBatch()) {
      //printf("Press ENTER to start..."); getchar();
   }
   TString dir = gSystem->DirName(__FILE__);

   // Open primary HDU from file
   TFITSHDU *hdu = new TFITSHDU(dir+"/sample2.fits");
   if (hdu == 0) {
      printf("ERROR: could not access the HDU\n"); return;
   }
   printf("File successfully open!\n");


   // 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();
   hdu->Print("F+");

   printf("....................................\n");
   printf("We are going to generate a TGraph from vectors\n");
   //printf("within the primary array. Press ENTER to continue.."); getchar();

   TVectorD *Y = hdu->GetArrayRow(0);
   TVectorD *X = hdu->GetArrayRow(1);
   TGraph *gr = new TGraph(*X,*Y);

   // Show the graphic
   TCanvas *c = new TCanvas("c1", "FITS tutorial #2", 800, 800);
   gr->Draw("BA");


   // Clean up
   delete X;
   delete Y;
   delete hdu;
}
コード例 #4
0
// Open a FITS file whose primary array represents
// a spectrum (flux vs wavelength)
void FITS_tutorial4()
{
   printf("\n\n--------------------------------\n");
   printf("WELCOME TO FITS tutorial #4 !!!!\n");
   printf("--------------------------------\n");
   printf("We're gonna open a FITS file that contains the\n");
   printf("primary HDU and a little data table.\n");
   printf("The data table is extension #1 and it has 2 rows.\n");
   printf("We want to read only the rows that have the column\n");
   printf("named DATAMAX greater than 2e-15 (there's only 1\n");
   printf("matching row)\n");
   printf("Data copyright: NASA\n\n");
   
   if (!gROOT->IsBatch()) {
      //printf("Press ENTER to start..."); getchar();
   }
   TString dir = gSystem->DirName(gInterpreter->GetCurrentMacroName());

   //Open the table extension number 1)
   TFITSHDU *hdu = new TFITSHDU(dir+"/sample2.fits[1][DATAMAX > 2e-15]");
   if (hdu == 0) {
      printf("ERROR: could not access the HDU\n"); return;
   }
   //printf("Press ENTER to see information about the table's columns..."); getchar();
   hdu->Print("T");
   
   printf("\n\n........................................\n");
   printf("Press ENTER to see full table contents (maybe you should resize\n");
   //printf("this window as large as possible before)..."); getchar();   
   hdu->Print("T+");
   
   printf("\n\n........................................\n");
   //printf("Press ENTER to get only the DATAMAX value of the matched row..."); getchar();
   TVectorD *v = hdu->GetTabRealVectorColumn("DATAMAX");
   printf("%lg\n", (*v)[0]);
   
   
   printf("Does the matched row have DATAMAX > 2e-15? :-)\n");
   
   //Clean up 
   delete v;  
   delete hdu;
}
コード例 #5
0
ファイル: FITS_tutorial1.C プロジェクト: My-Source/root
// Open a FITS file and retrieve the first plane of the image array 
// as a TASImage object
void FITS_tutorial1()
{
   printf("\n\n--------------------------------\n");
   printf("WELCOME TO FITS tutorial #1 !!!!\n");
   printf("--------------------------------\n");
   printf("We're gonna open a FITS file that contains only the\n");
   printf("primary HDU, consisting on an image.\n");
   printf("The object you will see is a snapshot of the NGC7662 nebula,\n");
   printf("which was taken by the author on November 2009 in Barcelona (CATALONIA).\n\n");
      
   if (!gROOT->IsBatch()) {
      //printf("Press ENTER to start..."); getchar();
   }
   
   // Open primary HDU from file
   TFITSHDU *hdu = new TFITSHDU("sample1.fits");
   if (hdu == 0) {
      printf("ERROR: could not access the HDU\n"); return;
   }
   printf("File successfully open!\n");
   
   // 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();
   
   hdu->Print("F+");
   
   printf("....................................\n");
   // Here we get the exposure time.
   //printf("Press ENTER to retrieve the exposure time from the HDU metadata..."); getchar();
   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.
   printf("....................................\n");
   printf("We can read the image as a matrix of values.\n");
   printf("This feature is useful to do image processing, e.g:\n");
   printf("histogram equalization, custom filtering, ...\n");
   //printf("Press ENTER to continue..."); getchar();
   
   TMatrixD *mat = hdu->ReadAsMatrix(0);
   mat->Print();
   delete mat;
   
   // Read the primary array as an image,
   // selecting only layer 0.
   printf("....................................\n");
   printf("Now the primary array will be read both as an image and as a histogram,\n");
   printf("and they will be shown in a canvas.\n");
   //printf("Press ENTER to continue..."); getchar();
   
   TASImage *im = hdu->ReadAsImage(0);
   
   // Read the primary array as a histogram.
   // Depending on array dimensions, returned
   // histogram will be 1D, 2D or 3D
   TH1 *hist = hdu->ReadAsHistogram();
   
   
   TCanvas *c = new TCanvas("c1", "FITS tutorial #1", 800, 300);
   c->Divide(2,1);
   c->cd(1);
   im->Draw();
   c->cd(2);
   hist->Draw("COL");

   // Clean up
   delete hdu;
}