Contents

◼
  • Download a FITS table file from a URL
  • ◼
  • Open a FITS table file and view table contents
  • ◼
  • Make 1D and 2D histograms with the data
  • Summary

    FITS files are used in astronomy to store large amounts of multi-dimensional data and tables. The FITS file we use here comes from an online tutorial and contains observations from the NASA Chandra observatory. It contains, among other things, a list of events with x and y coordinates:
    In[]:=
    url="http://data.astropy.org/tutorials/FITS-tables/chandra_events.fits";
    Download the data. If you already downloaded the file you can skip this step and just evaluate the next input cell to set your local file location:
    In[]:=
    file=URLDownload[url,"~/chandra_events.fits"];
    In[]:=
    file="~/chandra_events.fits";
    In[]:=
    FileSize[file]
    Out[]=
    31.0781
    MB
    You can use Import on the file with the “Elements” argument to see the various data elements you can import:
    In[]:=
    Import[file,"Elements"]
    Out[]=
    {Airmass,Author,BitDepth,Channels,ColorSpace,Comments,Data,DataType,Declination,Device,Dimensions,Equinox,ExposureTime,Extension,Graphics,HDUCount,History,HourAngle,Image,ImageSize,MetaInformation,Object,ObservationDate,Observer,Organization,Plaintext,Range,RawData,RawMetaInformation,Reference,RightAscension,SiderealTime,Summary,SummarySlideView,TableData,TableHeaders,TableUnits,Telescope}
    For example “Summary” gets a top-level summary of the data:
    In[]:=
    summary=Import[file,"Summary"]
    Out[]=
    Format
    FITS
    ExtensionsCount
    7
    Extensions
    1Image,2BinaryTable,3BinaryTable,4BinaryTable,5BinaryTable,6BinaryTable,7BinaryTable
    FileName
    chandra_events.fits
    FileSize
    31.0781MB
    We need a little bit more details so we use “MetaInformation” to get a complete picture:
    In[]:=
    information=Dataset[Import[file,"MetaInformation"]]

    Processing and Displaying

    We are specifically interested in reading the “EVENTS” data which is in the second record:
    In[]:=
    information[All,"GENERAL INFORMATION","EXTNAME"]
    Out[]=
    1
    —
    2
    {EVENTS,name of this binary table extension}
    3
    {GTI,name of this binary table extension}
    4
    {GTI,name of this binary table extension}
    5
    {GTI,name of this binary table extension}
    6
    {GTI,name of this binary table extension}
    7
    {GTI,name of this binary table extension}
    This gets the raw events data from the second record:
    In[]:=
    rawdata=Import[file,{"FITS","Data",2}];
    There are 483,964 rows and 19 columns
    In[]:=
    Dimensions[rawdata]
    Out[]=
    {483964,19}
    The column types can be obtained from the meta-information:
    In[]:=
    types=information[2,1,KeySelect[StringStartsQ[#,"TTYPE"]&]]
    Out[]=
    TTYPE1
    {time,S/C TT corresponding to mid-exposure}
    TTYPE2
    {ccd_id,CCD reporting event}
    TTYPE3
    {node_id,CCD serial readout amplifier node}
    TTYPE4
    {expno,Exposure number of CCD frame containing event}
    TTYPE5
    {chipx,Chip coords}
    TTYPE6
    {chipy,Chip coords}
    TTYPE7
    {tdetx,ACIS tiled detector coordinates}
    TTYPE8
    {tdety,ACIS tiled detector coordinates}
    TTYPE9
    {detx,ACIS detector coordinates}
    TTYPE10
    {dety,ACIS detector coordinates}
    TTYPE11
    {x,sky coordinates}
    TTYPE12
    {y,sky coordinates}
    TTYPE13
    {pha,total pulse height of event}
    TTYPE14
    {pha_ro,total read-out pulse height of event}
    TTYPE15
    {energy,nominal energy of event (eV)}
    TTYPE16
    {pi,pulse invariant energy of event}
    TTYPE17
    {fltgrade,event grade, flight system}
    TTYPE18
    {grade,binned event grade}
    TTYPE19
    {status,event status bits}
    This extracts the column names by themselves:
    In[]:=
    columns=Normal[Values[types[All,First]]]
    Out[]=
    {time,ccd_id,node_id,expno,chipx,chipy,tdetx,tdety,detx,dety,x,y,pha,pha_ro,energy,pi,fltgrade,grade,status}
    This creates a dataset from the column names and the raw data:
    Here are the first ten rows:
    We can easily make a histogram for the “energy” column:
    The following gets the x-y values for the events. We need to select the main ACIS-I chips, which are the CCDs with ids 0, 1, 2, and 3:
    Make a basic density histogram for the x-y data. Note that due to scaling issues there is not a lot of useful visible detail in this histogram:
    We can improve this by using a logarithmic scaling function:

    CITE THIS NOTEBOOK

    Getting a Glimpse of the Galactic Center using NASA Chandra FITS data​
    by Arnoud Buzing​
    Wolfram Community, STAFF PICKS, January 19, 2024
    ​https://community.wolfram.com/groups/-/m/t/3106056