<jupyter_start><jupyter_text>DEMO Notebook Using imexam inside a Jupyter notebook with DS9 as your viewerDS9 can be used as a viewer for the imexam package. While the DS9 viewer is active you have access to all the DS9 menu options as well, and imexam will attempt to keep track of changes you make through either the command line or the DS9 menus.This and other demo notebooks can be found on the SpaceTelescope github site: https://github.com/spacetelescope/imexam/Communication with the DS9 display window is done through the XPA. More information on the XPA access points which are available can be found here: http://ds9.si.edu/doc/ref/xpa.html  Ok, now on to the good stuff!In this example I have my local environment using the qt5agg backend, with the environment variable QT_API='pyqt'<jupyter_code>import imexam<jupyter_output><empty_output><jupyter_text>Starts up a DS9 window with no options<jupyter_code>a=imexam.connect() # allow time for the window to start before you proceed to the next cell<jupyter_output><empty_output><jupyter_text>Allow DS9 to start and accept the network connections before executing the following cell<jupyter_code>a.load_fits('iacs01t4q_flt.fits') #display fits image in ds9
a.scale()
a.grab()  # if you are running on OSX, then this function shouldn't be available<jupyter_output><empty_output><jupyter_text>In order to interact directly with the DS9 window, we have to start up a loop which looks for mouse and keyboard press events. In order to get out of this loop, press the "q" key<jupyter_code>a.imexam()
# all of the plots are customizable; the parameters are stored in regular dictionaries
a.eimexam()
#maybe we want to change the colormap on the DS9 display? You can see the available maps:
a.cmap()
a.cmap(color='heat')
#You can customize the plotting parameters (or any function in the imexam loop)
a.set_plot_pars('e','title','This is my favorite galaxy')
a.set_plot_pars('e','ncontours',4)
a.set_plot_pars('e','cmap','YlOrRd') #see http://matplotlib.org/users/colormaps.html

#lets see how the plot changed
a.imexam()
a.unlearn() #you can always go back to the default plot settings<jupyter_output><empty_output><jupyter_text>If you want to pull the data array from the display and do some other calculations with it, you can ask for it:<jupyter_code>data=a.get_data()
data
#you can also get the header, which will be returned as a string
header=a.get_header()
print(header)<jupyter_output><empty_output><jupyter_text>Quick photometry can be pulled with the "a" key and uses the photutils package to do the work. More information on photutils can be found at http://photutils.readthedocs.org/en/latest/You can also look at the example notebook with DS9 photometry which uses photutils<jupyter_code>#any numpy array can be displayed in the viewer
import numpy as np
data=np.random.rand(100) * np.ones((100,100))
a.view(data)
a.zoomtofit()
#or you can use astropy nddata arrays (which really are numpy arrays with meta data)
from astropy.nddata import NDData
array = np.random.random((12, 12, 12))  # a random 3-dimensional array
ndd = NDData(array)
a.view(ndd.data[3])
a.zoom()
a.close() #close the ds9 window<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07800751879699248, 'fraction_numerical': 0.011278195488721804, 'mean_word_length': 5.597107438016529, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '440134', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1018, 'n_tokens_neox': 981, 'n_words': 412, 'path': 'example_notebooks/imexam_ds9_example.ipynb', 'repo_name': 'patkel/imexam', 'size': '3192'}