Problems using rootpy over ssh

Hi everyone,
I am having some trouble using rootpy over SSH. It only happens intermittently so I am having real trouble working out what the problem is. My function starts off with:

def PtDifferential(InputCentral, InputHalf, InputDouble):

import ROOT
import numpy as np
import sys
import rootpy
from   rootpy.plotting import Hist, HistStack, Legend, Canvas
from   rootpy.plotting.style import get_style, set_style
from   rootpy.interactive import wait
from   rootpy import asrootpy
import rootpy.plotting.root2matplotlib as rplt
    ....

and then goes on to manipulate some histograms eventually saving them to *.pdf files. But sometimes I get the following error:

DISPLAY not set, setting it to t050.ph.ed.ac.uk:0.0
WARNING:rootpy.interactive.rootwait] unable to access ROOT’s GUI thread either because PyROOT’s finalSetup() was called while in batch mode or because PyROOT is using the new PyOS_InputHook based mechanism that is not yet supported in rootpy (PyConfig.StartGuiThread == ‘inputhook’ or gSystem.InheritsFrom(‘TMacOSXSystem’)). wait() etc. will instead call raw_input() and wait for [Enter]
Traceback (most recent call last):
File “Analysis.py”, line 1217, in
PtDifferential(“LatestShowered”, “ShowwerHalf3”, “ShowwerDouble3”)
File “Analysis.py”, line 840, in PtDifferential
fig = plt.figure(figsize = (7, 5), dpi = 100, facecolor = ‘white’)
File “/Home/s1231192/.local/lib/python2.6/site-packages/matplotlib-1.3.0-py2.6-linux-x86_64.egg/matplotlib/pyplot.py”, line 423, in figure
**kwargs)
File “/Home/s1231192/.local/lib/python2.6/site-packages/matplotlib-1.3.0-py2.6-linux-x86_64.egg/matplotlib/backends/backend_qt4agg.py”, line 31, in new_figure_manager
return new_figure_manager_given_figure(num, thisFig)
File “/Home/s1231192/.local/lib/python2.6/site-packages/matplotlib-1.3.0-py2.6-linux-x86_64.egg/matplotlib/backends/backend_qt4agg.py”, line 38, in new_figure_manager_given_figure
canvas = FigureCanvasQTAgg(figure)
File “/Home/s1231192/.local/lib/python2.6/site-packages/matplotlib-1.3.0-py2.6-linux-x86_64.egg/matplotlib/backends/backend_qt4agg.py”, line 70, in init
FigureCanvasQT.init( self, figure )
File “/Home/s1231192/.local/lib/python2.6/site-packages/matplotlib-1.3.0-py2.6-linux-x86_64.egg/matplotlib/backends/backend_qt4.py”, line 207, in init
_create_qApp()
File “/Home/s1231192/.local/lib/python2.6/site-packages/matplotlib-1.3.0-py2.6-linux-x86_64.egg/matplotlib/backends/backend_qt4.py”, line 62, in _create_qApp
raise RuntimeError(‘Invalid DISPLAY variable’)
RuntimeError: Invalid DISPLAY variable

Any help would be greatly appreciated. Thanks
Jack

It sounds like the ssh connection wasn’t set up to allow graphics. Did you do ssh -X or ssh -Y, or just plain ssh?

The easiest way to test if your ssh connection can forward graphics is by trying to run the program “xclock” which all unixes/linuxes should have. If you get the same error as using rootpy, then the error isn’t with rootpy, but with the connection.

There may be additional settings needed to allow graphics connections:
http://www.craigryder.com/linux-ubuntudebetc/x11-forwarding-and-ssh-for-remote-linux-ubuntu-desktop/

Jean-François

If you just want to save image files and don’t want matplotlib to attempt to create a graphical window you can do this:

import matplotlib matplotlib.use('Agg') # do this before importing pyplot from matplotlib import pyplot pyplot.ioff()

This puts matplotlib into a batch state similar to ROOT’s ROOT.gROOT.SetBatch(True).

By the way, a better place to ask questions regarding rootpy, although this one is more of a matplotlib question, is on the rootpy-users mailing list:

rootpy-users@googlegroups.com (https://groups.google.com/forum/#!forum/rootpy-users)

or on stackoverflow while tagging your question as rootpy (and matplotlib in this case):

http://stackoverflow.com/questions/tagged/rootpy

If you find a rootpy bug, you can report it on rootpy’s issue tracker:

https://github.com/rootpy/rootpy/issues

This way we get an email automatically with your question and you should get a quicker response.