Example 1

Basic Usage

First you need to import the package

import imexam

Start up a DS9 window (by default), a new DS9 window will be opened

a=imexam.connect()

If you already have a window running, you can ask for a list of windows

imexam.list_active_ds9()
DS9 ds9 gs 82a7e75f:57222 sosey

You can attach to a current DS9 window be specifying its unique name

a=imexam.connect('ds9')

If you haven’t given your windows unique names, then you must use the ip:port address

a=imexam.connect('82a7e75f:57222')

Load a fits image into the window

a.load_fits('test.fits')

Scale to default using zscale

a.scale()

Change to heat map colorscheme

a.cmap(color='heat')

Make some marks on the image and save the regions

a.save_regions('test.reg')

Delete all the regions you made, then load from file

a.load_regions('test.reg')

Plot stuff at cursor location, in a while loop. Type a key when the mouse is over your desired location and continue plotting with the available options

a.imexam()

 'a': 'aperture sum, with radius region_size, optional sky subtraction',
 'j': '1D  line fit ',
 'k': '1D  column fit ',
 'm': 'median square region stats, in region_size square',
 'n': 'move to the next frame',
 'p': 'move to the previous frame',
 'x': 'return x,y coords of pixel',
 'y': 'return x,y coords of pixel',
 'l': 'return line plot',
 'c': 'return column plot',
 'r': 'return curve of growth plot',
 'h': 'return a histogram in the region around the cursor'
 'e': 'return a contour plot in a region around the cursor'
 's': 'save current figure to plotname'
 'b': 'return the gauss fit center of the object'
 'w': 'display a surface plot around the cursor location'

Quit out and delete windows and references

a.close()

Example 2

Aperture Photometry

  • Perform manual aperture photometry on supplied image
  • Make curve of growth plot
  • Save the profile data and plot to files.

Method 1

Assuming we’ve already connected to the DS9 window where the data is displayed with the object called “ds9”;

  • This method first uses the “a” key to check out the aperture photometry with the default settings
  • Display a profile plot around the start we choose
  • Fine tune default curve of growth plot according to the object we’d like to examine
  • Make a new profile plot, print the plotted points to the screen, and save a copy of the plotting window for reference

Here a picture of the area I’m looking at in my ds9 window ( created with ds9.snapsave(filename=’photometry_subsection.jpg’) )

subsection of image being examined
ds9.imexam() #start an imexam session

Press 'q' to quit

Available options: * are NOT fully implemented

a       aperture sum, with radius region_size
b       return the gauss fit center of the object
c       return column plot
e       return a contour plot in a region around the cursor
h       return a histogram in the region around the cursor
j       1D [gaussian|moffat] line fit
k       1D [gaussian|moffat] column fit
l       return line plot
m       square region stats, in [region_size],defayult is median
r       return curve of growth plot *
s       save current figure to disk as [plot_name]
w       display a surface plot around the cursor location
x       return x,y coords of pixel
y       return x,y coords of pixel


xc=813.109250   yc=706.437612
x           y       radius      flux           mag(zpt=25.00)  sky           fwhm
813.11  706.44  5           1299406.51     9.72            11429.80      4.83


ds9.aimexam() # print out the parameters for aperture photometry, returns a dictionary which you can save and edit


{'function': ['aperphot'],
 'center': [True, 'Center the object location using a 2d gaussian fit'],
 'subsky': [True, 'Subtract a sky background?'],
 'width': [5, 'Width of sky annulus in pixels'],
 'radius': [5, 'Radius of aperture for star flux'],
 'skyrad': [15, 'Distance to start sky annulus is pixels'],
 'zmag': [25.0, 'zeropoint for the magnitude calculation']}


ds.imexam() #lets look at a curve of growth for the star in question

xc=813.109250   yc=706.687612 <--printed because centering is turned on
radii:[1 2 3 4 5 6 7 8]
flux:[131647.90413345056, 498482.2347664542, 914397.81480508228, 1132799.3621327095, 1329352.9123961448, 1519686.5943709521, 1608342.6952771661, 1677361.8581732502]
curve of growth plot with defaults
It looks like we should extend the radius out for the photometry to enclose the turn-off, and extend the sky annulus along with that.
Let's alter the defaults for the aperture photometry, get some new values and then make a nicer curve of growth.


ds9.exam.aperphot_pars["radius"][0]=10
ds9.exam.aperphot_pars["skyrad"][0]=20 #it looks like there are some nearby spoilers
ds9.exam.aperphot_pars["width"][0]=10  #maybe we should just give the sky some more space (haha)

We'll update the curve of growth plot to match those:

ds9.exam.curve_of_growth_pars

{'function': ['curve_of_growth_plot'],
'center': [True, 'Solve for center using 2d Gaussian? [bool]'],
'pointmode': [True, 'plot points instead of lines? [bool]'],
'title': ['Curve of Growth', 'Title of the plot'],
'buffer': [25.0, 'Background inner radius in pixels,from center of star'],
'background': [True, 'Fit and subtract background? [bool]'],
'magzero': [25.0, 'magnitude zero point'],
'rplot': [8.0, 'Plotting radius in pixels'],
'logy': [False, 'log scale y-axis?'],
'width': [5.0, 'Background annulus width in pixels'],
'xlabel': ['radius', 'The string for the xaxis label'],
'logx': [False, 'log scale x-axis?'],
'minflux': [0.0, 'only measure flux above this value'],
'ylabel': ['Flux', 'The string for the yaxis label'],
'marker': ['o', 'The marker character to use, matplotlib style'],
'getdata': [True, 'return the plotted data values']}


ds9.exam.curve_of_growth_pars["buffer"][0]=20
ds9.exam.curve_of_growth_pars["rplot"][0]=15 #we'll go a little farther than the aperture photometry
ds9.exam.curve_of_growth_pars["width"][0]=10
ds9.exam.curve_of_growth_pars["title"][0]="My favorite star at 813,706"

xc=813.109250   yc=706.437612
radii:[ 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15]
flux:[131842.06947972983, 499258.8961515713, 916145.30292159575, 1135906.0076731779, 1334207.0460531267, 1526676.5468370058, 1617856.7972448503, 1689788.4403351238, 1767218.0485707363, 1823198.9507934339, 1859976.8895604345, 1898754.5043149013, 1936825.2692955555, 1970456.6085569942, 2025720.3180976035]

Below are the final curve of growth plot as well as the the gaussian fit to the columns of the same star:

radial profile plot with alterations gaussian fit column profile of star

Method 2

Assuming we’ve already connected to the DS9 window where the data is displayed with the object called “ds9”;

  • First we turn on logging so that everything gets saved to a file
  • We then use the “a” key to check out the aperture photometry with the default settings, and then with our our own settings
  • We can then use the log file, to create a plot

Here a picture of the area I’m looking at in my DS9 window ( created with ds9.snapsave(filename=’photometry_subsection.jpg’) )

subsection of image being examined
ds9.setlog(filename="aperture_phot.log")
ds9.unlearn() #reset all the parameters to their default values for good measure
ds9.imexam()

Press the "a" key around the star:

xc=813.109250   yc=706.437612
x       y       radius  flux    mag(zpt=25.00)  sky     fwhm
813.11  706.44  5       1299406.51      9.72    11429.80        4.83

Press the "r" key to look at the curve of growth:

xc=813.109250   yc=706.437612
radii:[1 2 3 4 5 6 7 8]
flux:[131647.90413345056, 498482.2347664542, 914397.81480508228, 1132799.3621327095, 1329352.9123961448, 1519686.5943709521, 1608342.6952771661, 1677361.8581732502]


Lets get some more aperture photometry at larger radii by resetting some of the "a" key values and saving the results to the log

    {'center': [True, 'Center the object location using a 2d gaussian fit'],
    'function': ['aperphot'],
    'radius': [5, 'Radius of aperture for star flux'],
    'skyrad': [15, 'Distance to start sky annulus is pixels'],
    'subsky': [True, 'Subtract a sky background?'],
    'width': [5, 'Width of sky annulus in pixels'],
    'zmag': [25.0, 'zeropoint for the magnitude calculation']}

ds9.exam.aperphot_pars["radius"][0]=9

ds9.imexam() #use the "a" key

ds9.exam.aperphot_pars["radius"][0]=10

ds9.imexam() #use the "a" key

ds9.exam.aperphot_pars["radius"][0]=11

ds9.imexam() #use the "a" key

This is what aperture_phot.log contains:

gauss_center
xc=813.234250   yc=706.562612

aper_phot
x       y       radius  flux    mag(zpt=25.00)  sky     fwhm

aper_phot
813.23  706.56  5       1302108.24      9.71    11414.03        4.83

gauss_center
xc=813.234250   yc=706.562612

gauss_center
xc=813.234262   yc=706.062641

aper_phot
x       y       radius  flux    mag(zpt=25.00)  sky     fwhm

aper_phot
813.23  706.06  9       1614448.12      9.48    11470.77        4.83

gauss_center
xc=812.734152   yc=706.562401

aper_phot
x       y       radius  flux    mag(zpt=25.00)  sky     fwhm

aper_phot
812.73  706.56  10      1704647.07      9.42    11415.03        4.84

gauss_center
xc=812.984250   yc=706.062612

aper_phot
x       y       radius  flux    mag(zpt=25.00)  sky     fwhm

aper_phot
812.98  706.06  11      1642049.31      9.46    11471.58        4.83

You can parse the log, or copy the data and use as you like to make interesting plots. Once a plot is displayed on your screen from imexam, you can also grab it’s information through matplotlib and edit it before saving.

Example 3

Advanced Usage - Interact with Daophot and astropy

While the original intent for the imexam module was to replicate the realtime interaction of the old IRAF imexamine interface with data, there are other posibilities for data analysis which this module can support. One such example, performing more advanced interaction which can be scripted, is outlined below.

If you have a list of source identifications, perhaps prepared by SExtractor, DAOFind, Starfind or a similar program, you can use imexam to display the science image and overlay apertures for all their locations. From there you can do some visual examination and cleaning up of the list with a combination of region manipulation and useful imexam methods.

Here’s our example image to work with, which is a subsection of a larger image:

subsection of image being examined

I’ll use the IRAF DAOFind to find objects in my field:

from pyraf import iraf
from iraf import noao,digiphot,daophot
from astropy.io import fits

image='iabf01bzq_flt.fits'

fits.info('iabf01bzq_flt.fits')

    Filename: iabf01bzq_flt.fits
    No.    Name         Type      Cards   Dimensions   Format
    0    PRIMARY     PrimaryHDU     210   ()           int16
    1    SCI         ImageHDU        81   (1014, 1014)   float32
    2    ERR         ImageHDU        43   (1014, 1014)   float32
    3    DQ          ImageHDU        35   (1014, 1014)   int16
    4    SAMP        ImageHDU        30   ()           int16
    5    TIME        ImageHDU        30   ()           float32



#set up some finding parameters, you can make this more explicit
iraf.daophot.findpars.threshold=3.0 #3sigma detections only
iraf.daophot.findpars.nsigma=1.5 #width of convolution kernal in sigma
iraf.daophot.findpars.ratio=1.0 #ratio of gaussian axes
iraf.daophot.findpars.theta=0.
iraf.daophot.findpars.sharplo=0.2 #lower bound on feature
iraf.daophot.findpars.sharphi=1.0 #upper bound on feature
iraf.daophot.findpars.roundlo=-1.0 #lower bound on roundness
iraf.daophot.findpars.roundhi=1.0 #upper bound on roundness
iraf.daophot.findpars.mkdetections="no"

    In [84]: iraf.lpar(iraf.daophot.datapars)
           (scale = 1.0)            Image scale in units per pixel
         (fwhmpsf = 2.5)            FWHM of the PSF in scale units
        (emission = yes)            Features are positive?
           (sigma = 1.0)            Standard deviation of background in counts
         (datamin = 0.0)            Minimum good data value
         (datamax = INDEF)          Maximum good data value
           (noise = "poisson")      Noise model
         (ccdread = "")             CCD readout noise image header keyword
            (gain = "ccdgain")      CCD gain image header keyword
       (readnoise = 2.0)            CCD readout noise in electrons
           (epadu = 1.0)            Gain in electrons per count
        (exposure = "exptime")      Exposure time image header keyword
         (airmass = "")             Airmass image header keyword
          (filter = "")             Filter image header keyword
         (obstime = "")             Time of observation image header keyword
           (itime = 1.0)            Exposure time
        (xairmass = INDEF)          Airmass
         (ifilter = "INDEF")        Filter
           (otime = "INDEF")        Time of observation
            (mode = "ql")

iraf.daophot.datapars.datamin=0.
iraf.daophot.datapars.gain="ccdgain"
iraf.daophot.datapars.exposure="exptime"
iraf.daophot.datapars.sigma=105.



#assume the science extension and find some stars
sci="[SCI,1]"
output_locations='iabf01bzq_stars.dat'
iraf.daofind(image=image+sci,output=output_locations,interactive="no",verify="no",verbose="no")

#This is just the top of the file that daofind produced:

    In [24]: more iabf01bzq_stars.dat
    #K IRAF       = NOAO/IRAFV2.16          version    %-23s
    #K USER       = sosey                   name       %-23s
    #K HOST       = intimachay.stsci.edu    computer   %-23s
    #K DATE       = 2014-03-28              yyyy-mm-dd %-23s
    #K TIME       = 15:34:56                hh:mm:ss   %-23s
    #K PACKAGE    = apphot                  name       %-23s
    #K TASK       = daofind                 name       %-23s
    #
    #K SCALE      = 1.                      units      %-23.7g
    #K FWHMPSF    = 2.5                     scaleunit  %-23.7g
    #K EMISSION   = yes                     switch     %-23b
    #K DATAMIN    = 0.                      counts     %-23.7g
    #K DATAMAX    = INDEF                   counts     %-23.7g
    #K EXPOSURE   = exptime                 keyword    %-23s
    #K AIRMASS    = ""                      keyword    %-23s
    #K FILTER     = ""                      keyword    %-23s
    #K OBSTIME    = ""                      keyword    %-23s
    #
    #K NOISE      = poisson                 model      %-23s
    #K SIGMA      = 105.                    counts     %-23.7g
    #K GAIN       = ccdgain                 keyword    %-23s
    #K EPADU      = 2.5                     e-/adu     %-23.7g
    #K CCDREAD    = ""                      keyword    %-23s
    #K READNOISE  = 0.                      e-         %-23.7g
    #
    #K IMAGE      = iabf01bzq_flt.fits[SCI, imagename  %-23s
    #K FWHMPSF    = 2.5                     scaleunit  %-23.7g
    #K THRESHOLD  = 3.                      sigma      %-23.7g
    #K NSIGMA     = 2.                      sigma      %-23.7g
    #K RATIO      = 1.                      number     %-23.7g
    #K THETA      = 0.                      degrees    %-23.7g
    #
    #K SHARPLO    = 0.2                     number     %-23.7g
    #K SHARPHI    = 1.                      number     %-23.7g
    #K ROUNDLO    = -1.                     number     %-23.7g
    #K ROUNDHI    = 1.                      number     %-23.7g
    #
    #N XCENTER   YCENTER   MAG      SHARPNESS   SROUND      GROUND      ID         \
    #U pixels    pixels    #        #           #           #           #          \
    #F %-13.3f   %-10.3f   %-9.3f   %-12.3f     %-12.3f     %-12.3f     %-6d       \
    #
       194.694   2.357     -3.335   0.919       0.141       -0.004      1
       232.659   2.889     -1.208   0.768       0.572       -0.289      2
       237.782   2.925     -1.182   0.669       0.789       -0.971      3
       265.715   2.797     -1.395   0.976       -0.450      -0.669      4
       419.792   2.902     -3.045   0.925       -0.990      0.213       5
       424.566   3.081     -1.202   0.923       0.513       -0.555      6
       534.758   2.856     -1.341   0.659       -0.676      -0.302      7
       580.964   2.485     -1.326   0.821       -0.489      -0.752      8
       587.521   3.568     -1.282   0.911       -0.537      -0.119      9
       725.016   3.999     -1.103   0.714       -0.653      -0.490      10
       736.495   2.808     -1.345   0.710       -0.996      -0.730      11
       746.529   3.200     -0.868   0.303       -0.376      -0.682      12
       757.672   3.172     -1.527   0.420       0.271       0.211       13
       768.768   2.830     -1.321   0.741       -0.842      -0.252      14
       799.199   2.696     -2.096   0.926       0.476       -0.511      15
       807.575   2.445     -4.136   0.745       0.171       -0.131      16
       836.661   2.790     -1.482   0.709       0.205       0.636       17
       879.390   3.069     -1.018   0.549       -0.479      -0.495      18
       912.820   2.806     -1.414   0.576       0.504       0.109       19
       938.794   3.448     -1.731   0.997       -0.239      0.100       20
       17.713    2.731     -1.896   0.286       -0.947      -0.359      21
       48.757    2.755     -1.172   0.586       0.646       -0.543      22
       105.894   3.030     -1.700   0.321       -0.233      -0.006      23

Now we want to read in the file that Daofind produced and save the x,y and ID information. I’m going to read the results using astropy.io.ascii

reader=ascii.Daophot()
photfile=reader.read(output_locations)

#some quick information on what we have now
photfile.colnames

    ['XCENTER', 'YCENTER', 'MAG', 'SHARPNESS', 'SROUND', 'GROUND', 'ID']

photfile.print()

    In [103]: photfile.pprint()
       XCENTER     YCENTER      MAG     SHARPNESS      SROUND       GROUND      ID
    ------------- ---------- --------- ------------ ------------ ------------ ------
    194.694       2.357      -3.335    0.919        0.141        -0.004       1
    232.659       2.889      -1.208    0.768        0.572        -0.289       2
    237.782       2.925      -1.182    0.669        0.789        -0.971       3
    265.715       2.797      -1.395    0.976        -0.450       -0.669       4
    419.792       2.902      -3.045    0.925        -0.990       0.213        5
    424.566       3.081      -1.202    0.923        0.513        -0.555       6
    534.758       2.856      -1.341    0.659        -0.676       -0.302       7
    580.964       2.485      -1.326    0.821        -0.489       -0.752       8
    587.521       3.568      -1.282    0.911        -0.537       -0.119       9
    725.016       3.999      -1.103    0.714        -0.653       -0.490       10
    736.495       2.808      -1.345    0.710        -0.996       -0.730       11
    746.529       3.200      -0.868    0.303        -0.376       -0.682       12
    757.672       3.172      -1.527    0.420        0.271        0.211        13
    768.768       2.830      -1.321    0.741        -0.842       -0.252       14
    799.199       2.696      -2.096    0.926        0.476        -0.511       15
    807.575       2.445      -4.136    0.745        0.171        -0.131       16

You can even pop this up in your web browser if that’s a good format for you: photfile.show_in_browser(). imexam has several functions to help display regions on the DS9 window. Since we have this data loaded into memory, the one we will use here is mark_region_from_array(). Let’s make an array that the method will accept, namely a list of tuples which contain the (x,y,comment) that we want marked to the display. It will also accept a single tuple, or a string containing “x,y,comment”.

#lets make a list of our locations as a tuple of x,y,comment
#we'll cut the list to a smaller area and only include those points whose mag is < -4.
locations=list()
for point in range(0,len(photfile['XCENTER']),1):
    if photfile['MAG'][point] < -4:
        locations.append((photfile['XCENTER'][point],photfile['YCENTER'][point],photfile['ID'][point]))

#so the first item looks like:
In [91]: locations[0]
Out[91]: (807.57500000000005, 2.4449999999999998, 16)

Let’s open up a DS9 window (if you haven’t already) and display your image. This will let us display our source locations and play with them

ds9=imexam.connect()
ds9.load_fits('iabf01bzq_flt.fits')
ds9.scale() #scale to DS9 zscale by default
ds9.mark_region_from_array(locations)
subsection of image being examined

Now we can get rid of some of the stars by hand and save a new file of locations we like. I did this arbitrarily because I decided I didn’t like stars in this part of space. Click on the regions you don’t want and delete them from the screen. You can even add more regions of your own choosing.

subsection of image being examined

Now you can save these new regions to a DS9 style region file, either through DS9 or imexam

ds9.save_regions('badstars.reg')

Here is what the saved region file looks like, you can choose to import this file into any future DS9 display of the same image using the ds9.load_regions() method. You might also want to parse the file to save just the location and comment information in a separate text file.

In [7]: !head badstars.reg
# Region file format: DS9 version 4.1
# Filename: /Users/sosey/ssb/sosey/testme/iabf01bzq_flt.fits[SCI]
global color=green dashlist=8 3 width=1 font="helvetica 10 normal roman" select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1
fk5
circle(0:22:38.709,-72:02:50.58,0.677464")
# text(0:22:39.097,-72:02:50.86) font="time 12 bold" text={ 16 }
circle(0:22:36.340,-72:02:58.27,0.677464")
# text(0:22:36.729,-72:02:58.55) font="time 12 bold" text={ 140 }
circle(0:22:29.068,-72:03:20.78,0.677464")
# text(0:22:29.457,-72:03:21.06) font="time 12 bold" text={ 225 }

            . . .

# text(0:22:56.855,-72:04:23.16) font="time 12 bold" text={ 21985 }
circle(0:22:42.791,-72:05:04.04,0.677464")
# text(0:22:43.180,-72:05:04.32) font="time 12 bold" text={ 22002 }
box(0:22:45.694,-72:04:19.19,14.593",13.1774",149.933) # color=red font="helvetica 16 normal roman" text={I DONT LIKE THE STARS HERE}

Advanced Usage II - Cycle through objects from a list

This example will step through a list of object locations and center that object in the DS9 window with a narrow zoom so that you can examine it further (think about PSF profile creation options here..)

If you haven’t already, start DS9 and load your image into the viewer. I’ll assume that you started DS9 outside of imexam and will need to connect to the window first.

import imexam
imexam.list_active_ds9()

    DS9 1396283378.28 gs 82a7e75f:53892 sosey

ds9=imexam.connect('82a7e75f:53892')

#A little unsure this is the corrent window? Let's check by asking what image is loaded. The image I'm working with is iabf01bzq_flt.fits

ds9.get_data_filename()

    '/Users/sosey/ssb/sosey/testme/iabf01bzq_flt.fits'  <-- notice it returned the full pathname to the file

ds9.zoomtofit()  <-- let's zoom out  to see the whole image, incase just a small section was loaded

Read in your list of object locations, I’ll use the same DAOphot targets from the previous example

from astropy.io import ascii
reader=ascii.Daophot()
output_locations='iabf01bzq_stars.dat'
photfile=reader.read(output_locations)

#make some cuts on the list

locations=list()
for point in range(0,len(photfile['XCENTER']),1):
    if photfile['MAG'][point] < -4:
        locations.append((photfile['XCENTER'][point],photfile['YCENTER'][point],photfile['ID'][point])) <-- appending tuple to the list

Take your list of locations and cycle through each one, displaying a zoomed in section on the DS9 window and starting imexam for each coordinate. I’m just going to go through 10 or so random stars. You can set this up however you like, including using a keystroke as your stopping condition in conjuection with the ds9.readcursor()

I’ll also mark the object we’re interested in on the display for reference

ds9.zoom(8)
for object in locations[100:110]:
    ds9.panto_image(object[0],object[1])
    ds9.mark_region_from_array(object)
    ds9.imexam()

Example 4

Load and examine an image CUBE

Image cubes can be multi-extension fits files which have multidimensional (> 2) images in any of their extensions. When they are loaded into DS9, a cube dialog frame is opened along with a box which allows the user to control which slices are displayed. Here’s what the structure of such a file might look like:

astropy.io.fits.info('test_cube.fits')

Filename: test_cube.fits
No.    Name         Type      Cards   Dimensions   Format
0    PRIMARY     PrimaryHDU     215   ()
1    SCI         ImageHDU        13   (1032, 1024, 35, 5)   int16
2    REFOUT      ImageHDU        13   (258, 1024, 35, 5)   int16

Here’s an image of what this looks like displayed in DS9:

image capture of cube image displayed in DS9

You can use all the regular imexam methods with this image, including imexam() and the current slice which you have selected will be used for analysis. You can also ask imexam which slice is display, or the full image information of what is in the current frame for your own use (ds9 is just the name I chose, you can call the control object connected to your display window anything)

ds9=imexam.connect()
ds9.load_fits('test_cube.fits')
ds9.window.get_filename()

Out[24]: '/Users/sosey/ssb/imexam/test_cube.fits'

ds9.window.get_frame_info()
Out[25]: '/Users/sosey/ssb/imexam/test_cube.fits[SCI,1](0, 0)'

Now I’m going to use the Cube dialog to change the slice I’m looking at to (4,14) -> as displayed in the dialog. DS9 displayed 1-indexed numbers, and the fits utitlity behind imexam uses 0-indexed numbers, so expect the return to be off by a value of 1.

image capture of cube image displayed in DS9

Let’s ask for the information again:

In [26]: ds9.window.get_filename()
Out[26]: '/Users/sosey/ssb/imexam/test_cube.fits'

In [27]: ds9.window.get_frame_info()
Out[27]: '/Users/sosey/ssb/imexam/test_cube.fits[SCI,1](3, 13)'

You can ask for just the information about which slice is displayed and it will return the tuple(extension n, ...., extension n-1). The extensions are ordered in row-major form in astropy.io.fits:

In [28]: a.window.get_slice_info()
Out[28]: (3, 13)

The returned tuple contains just which 2d slice is displayed. In our cube image, which is 4D (1032, 1024, 35, 5) == (NAXIS1, NAXIS2, NAXIS3, NAXIS4) in DS9, however in astropy.io.fits this is (5,35,1024,1032) == (NAXIS4, NAXIS3, NAXIS2, NAXIS1)

By default, the first extension will be loaded from the cube fits file if none is specified. If you would rather see another extension, you can load it the same as with simpler fits files:

ds9.load_fits('test_cube.fits',extname='REFOUT')