plotting in ipython notebook

Asked by Yaakoub El Khamra

Greetings
I am trying to find a convenient way to plot in ipython notebooks. The plot to png file and imshow said file comes to mind. Problem is when I try to do that I get the following:
*** Warning: Environment variable DOLFIN_NOPLOT set: Plotting disabled.

even when I know that the env variable was never set. Setting to '1' or '0' with
os.environ['DOLFIN_NOPLOT']
makes no difference.

I am using the latest from bzr (bzr branch lp:dolfin ) so I am hoping this includes the dolfin-plot patches.

Thank you very much in advance.

Regards
Yaakoub

PS I am considering starting a ParaViewWeb server to do the viz but thought I would give dumping to images a shot first.

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Yaakoub El Khamra
Solved:
Last query:
Last reply:

This question was reopened

Revision history for this message
Joachim Haga (jobh) said :
#1

I think the error message may be misleading in this case - the no_plot case
is activated also if DISPLAY is unset (on X11).

On 14 January 2013 23:01, Yaakoub El Khamra <
<email address hidden>> wrote:

> New question #219188 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/219188
>
>
>
> Greetings
> I am trying to find a convenient way to plot in ipython notebooks. The
> plot to png file and imshow said file comes to mind. Problem is when I try
> to do that I get the following:
> *** Warning: Environment variable DOLFIN_NOPLOT set: Plotting disabled.
>
> even when I know that the env variable was never set. Setting to '1' or
> '0' with
> os.environ['DOLFIN_NOPLOT']
> makes no difference.
>
> I am using the latest from bzr (bzr branch lp:dolfin ) so I am hoping this
> includes the dolfin-plot patches.
>
> Thank you very much in advance.
>
> Regards
> Yaakoub
>
> PS I am considering starting a ParaViewWeb server to do the viz but
> thought I would give dumping to images a shot first.
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>

Revision history for this message
Yaakoub El Khamra (yelkhamra) said :
#2

Yes, I get the following output actually:

--------------------------------------------------------------------------
*** Warning: DISPLAY not set, disabling plotting
*** Warning: Environment variable DOLFIN_NOPLOT set: Plotting disabled.

setting DISPLAY in os.environ still produces no png file.

Revision history for this message
Yaakoub El Khamra (yelkhamra) said :
#3

On the other side, if I try to this in python I get the following:
>>> from dolfin import *
>>> mesh = UnitSquareMesh(16, 16, "crossed")
>>> plot_of_mesh=plot(mesh)
>>> plot_of_mesh.write_png("/home/yye00/Dropbox/Code/IPython/Notebooks/mesh_plot")
Saving plot to file: /home/yye00/Dropbox/Code/IPython/Notebooks/mesh_plot.png
ERROR: In /builddir/build/BUILD/VTK/IO/vtkPNGWriter.cxx, line 233
vtkPNGWriter (0x3245bd0): Unable to open file /home/yye00/Dropbox/Code/IPython/Notebooks/mesh_plot.png

ERROR: In /builddir/build/BUILD/VTK/IO/vtkImageWriter.cxx, line 492
vtkPNGWriter (0x3245bd0): Ran out of disk space; deleting file(s) already written

I have 449 GB of free space.

Revision history for this message
Joachim Haga (jobh) said :
#4

Looks like another misleading error message (from VTK this time, not
Dolfin). Check write permissions? (This is based on
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=499580)

On 14 January 2013 23:20, Yaakoub El Khamra <
<email address hidden>> wrote:

> Question #219188 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/219188
>
> Yaakoub El Khamra posted a new comment:
>
> On the other side, if I try to this in python I get the following:
> >>> from dolfin import *
> >>> mesh = UnitSquareMesh(16, 16, "crossed")
> >>> plot_of_mesh=plot(mesh)
> >>>
> plot_of_mesh.write_png("/home/yye00/Dropbox/Code/IPython/Notebooks/mesh_plot")
> Saving plot to file:
> /home/yye00/Dropbox/Code/IPython/Notebooks/mesh_plot.png
> ERROR: In /builddir/build/BUILD/VTK/IO/vtkPNGWriter.cxx, line 233
> vtkPNGWriter (0x3245bd0): Unable to open file
> /home/yye00/Dropbox/Code/IPython/Notebooks/mesh_plot.png
>
> ERROR: In /builddir/build/BUILD/VTK/IO/vtkImageWriter.cxx, line 492
> vtkPNGWriter (0x3245bd0): Ran out of disk space; deleting file(s) already
> written
>
>
> I have 449 GB of free space.
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>

Revision history for this message
Yaakoub El Khamra (yelkhamra) said :
#5

Correct you are sir. It was a iPython not IPython for the local one. However the ipython notebook issue persists. Am I supposed to unset DISPLAY and set DOLFIN_NOPLOT to 1 to prevent interactive plotting and be able to get the png file?

Regards
Yaakoub

Revision history for this message
Yaakoub El Khamra (yelkhamra) said :
#6

(sorry, accidentally resolved the problem)

Revision history for this message
Joachim Haga (jobh) said :
#7

I'm afraid that saving to png still requires a window. This is a vtk
limitation, and hence not likely to change soon.
Den 14. jan. 2013 23:45 skrev "Yaakoub El Khamra" <
<email address hidden>> følgende:

> Question #219188 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/219188
>
> Status: Answered => Solved
>
> Yaakoub El Khamra confirmed that the question is solved:
> Correct you are sir. It was a iPython not IPython for the local one.
> However the ipython notebook issue persists. Am I supposed to unset
> DISPLAY and set DOLFIN_NOPLOT to 1 to prevent interactive plotting and
> be able to get the png file?
>
> Regards
> Yaakoub
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>

Revision history for this message
Johan Hake (johan-hake) said :
#8

An other option is to store the file in XDFM or PDV format. Copy the
files to a work station and open it in ParaView. ParaView gives you much
larger flexibility than the builtin VTKPlotter in DOLFIN.

Johan

On 01/15/2013 08:15 AM, Joachim Haga wrote:
> Question #219188 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/219188
>
> Status: Open => Answered
>
> Joachim Haga proposed the following answer:
> I'm afraid that saving to png still requires a window. This is a vtk
> limitation, and hence not likely to change soon.
> Den 14. jan. 2013 23:45 skrev "Yaakoub El Khamra" <
> <email address hidden>> følgende:
>
>> Question #219188 on DOLFIN changed:
>> https://answers.launchpad.net/dolfin/+question/219188
>>
>> Status: Answered => Solved
>>
>> Yaakoub El Khamra confirmed that the question is solved:
>> Correct you are sir. It was a iPython not IPython for the local one.
>> However the ipython notebook issue persists. Am I supposed to unset
>> DISPLAY and set DOLFIN_NOPLOT to 1 to prevent interactive plotting and
>> be able to get the png file?
>>
>> Regards
>> Yaakoub
>>
>> --
>> You received this question notification because you are a member of
>> DOLFIN Team, which is an answer contact for DOLFIN.
>>
>

Revision history for this message
Yaakoub El Khamra (yelkhamra) said :
#9

Thank you. I am struggling with ParaViewWeb but will see it through somehow. Thanks again.

Revision history for this message
Yaakoub El Khamra (yelkhamra) said :
#10

A note for posterity:
there is a very nasty solution. Compile VTK with OSMesa, disable all dri and gle/s/w and use that for dolfin. This will allow you to plot to a file without a graphics card and without an active X connection. You can also do the ParaViewWeb thing:
http://www.paraview.org/Wiki/ParaViewWeb

the setup for ParaViewWeb is tricky and you end up with visualization software that runs on the CPU (you will have to use OSMesa and no dri or gl extensions for this one too). The results are less than impressive and there is significant lag in rendering. An alternative, but not a good one.

Revision history for this message
Yaakoub El Khamra (yelkhamra) said :
#11

I think I found the best solution thus far is to compile with osmesa, disable dri and gl/e/s/w but use paraview python instead of setting up paraviewweb. The following script is the one I used to generate a movie that I embed in ipython. You need ffmpeg to do this. Also run this script with pvpython or make sure you put all the paraview python modules in PYTHONPATH

# -*- coding: utf-8 -*-
"""
@author: yye00
"""
# this is an example script of how to do things for one file.
# you will want to change this to suit your needs.

from paraview.simple import *

reader = PVDReader(FileName="results/Sw.pvd")
Show(reader)
Render()

pdi = reader.PointData
ai = pdi[0]
my_range = ai.GetRange(0)

dp = GetDisplayProperties(reader)
dp.Representation = 'Surface With Edges'
dp.LookupTable = MakeBlueToRedLT(my_range[0], my_range[1])
dp.ColorAttributeType = 'POINT_DATA'
dp.ColorArrayName = 'u'

bar = CreateScalarBar(LookupTable=dp.LookupTable, Title="Normalized Saturation")
GetRenderView().Representations.append(bar)

Show()
Render()

# Animate over all time steps. Note that we are not passing the optional
# 3rd argument here. If you pass a filename as the 3rd argument,
# AnimateReader will create a movie.
#AnimateReader(reader)
# Save the animation to an avi file
# The following "might" fail unless you compiled paraview with ffmpeg support
# AnimateReader(reader, filename="saturation.avi")
# alternatively output a whole lot of png files:
AnimateReader(reader, filename="results/saturation.png")

# optional: if we have png's let's do the decent thing
# and mencode them
# Now that we have the png's we call mencode
import subprocess

ffmpeg_output = subprocess.check_call(["/usr/bin/ffmpeg -f image2 -i results/saturation.%04d.png results/saturation.m4v"], shell=True, executable='/bin/bash')