Plotting an Image

Besides the DataStruct that we have just encountered, all ATK data structures support plotting functionality. A good first example would be to recreate the image seen in tutorial one. To fetch the data we need, a similar query can be performed to the one we used in the previous tutorial:

from AstroToolkit.Tools import query

image_data = query(
    kind="image",
    source=2552928187080872832,
    survey="panstarrs",
    overlays=["gaia", "galex"],
    size=120,
)

where we have used some additional parameters that are specific to image queries: overlays tells the tool which surveys to fetch overlay data for, and size gives the required size of the image in arcseconds. To see the resulting data structure, we can once again make use of the showdata method:

image_data.showdata()
.kind:       image
.survey:     panstarrs
.source:     2552928187080872832
.pos:        [12.291243181037652, 5.388609421763333]
.identifier: J004909.90+052318.99
.figure:     None
.dataname:   J004909.90+052318.99_2552928187080872832_panstarrs_ATKimage.fits
.plotname:   J004909.90+052318.99_2552928187080872832_panstarrs_ATKimage.html
.trace:      start -> extracted pos from source query, assumed [2016, 0] -> initial query performed -> panstarrs (image_time): [2012, 1] -> final query performed -> [2000,0] -> end

.data:
    image_data:   <Image Data>
    image_header: <Image Header>
    size:         120
    image_time:   [2012    1]
    wcs:          <WCS Object>
    image_focus:  [12.29539461  5.37950704]
    overlay:      <Overlay Data>

Available Methods: .exportplot(), .plot(), .savedata(), .saveplot(), .showdata(), .showplot()

Most of the above should be familiar from the previous tutorial, but there are now some additional attributes and methods to have a look at.

  • The first additional attribute is figure, which stores any plot which is derived from the data structure’s data. Since we haven’t made one yet, this is currently empty.

  • The only other new attribute is plotname, which stores the default file name to which this figure will be saved locally using the showplot(), saveplot() and exportplot() methods.


We can now use one of the new methods to plot our data! The plot() method plots the data structure’s data and assigns the resulting Bokeh figure to the figure attribute:

image_data.plot()

Using showdata() again reveals that the figure attribute of our data structure has now been filled:

Plotting image data...

.kind:       image
.survey:     panstarrs
.source:     2552928187080872832
.pos:        [12.291243181037652, 5.388609421763333]
.identifier: J004909.90+052318.99
.figure:     figure(id='p1001', ...)
.dataname:   J004909.90+052318.99_2552928187080872832_panstarrs_ATKimage.fits
.plotname:   J004909.90+052318.99_2552928187080872832_panstarrs_ATKimage.html
.trace:      start -> extracted pos from source query, assumed [2016, 0] -> initial query performed -> panstarrs (image_time): [2012, 1] -> final query performed -> [2000,0] -> end

.data:
    image_data:   <Image Data>
    image_header: <Image Header>
    size:         120
    image_time:   [2012    1]
    wcs:          <WCS Object>
    image_focus:  [12.29539461  5.37950704]
    overlay:      <Overlay Data>

Available Methods: .exportplot(), .plot(), .savedata(), .saveplot(), .showdata(), .showplot()

We can open the resulting figure in the web browser using another of the new methods: showplot().

image_data.showplot()

And with that, we have recreated the image from the first tutorial! Here, we first generated the plot using plot() and then opened it with showplot(), but we since we did not customise the plot in any way we also could have just used showplot() and one would have automatically been generated. The use case for plot() will be shown in the next section.


Note: The code used in this tutorial can be executed using:

from AstroToolkit.Examples import image_plotting