Here is sample code demonstrating the problem I'm having with
pyhd5/numpy/matplotlib

import h5py
import numpy
import re

import sys
import os
import gtk
import pdb
import gc

from matplotlib.figure import Figure
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as
FigureCanvas




def doplot(widget,box1):
    id=h5py.h5f.open("MLS-Aura_L1BRADD_v02-23-c01_2009d001.h5")
    data_id = h5py.h5d.open(id,"R1A:118.B22D:PT.S0.DACS-4")
    dataspaceID = h5py.h5d.DatasetID.get_space(data_id)
    noDims = h5py.h5s.SpaceID.get_simple_extent_ndims(dataspaceID)
    dims  = h5py.h5s.SpaceID.get_simple_extent_dims(dataspaceID)
    start=tuple([0]*noDims)
    h5py.h5s.SpaceID.select_hyperslab(dataspaceID,start,dims,None,None,
                                    h5py.h5s.SELECT_SET)
    memory_space_id = h5py.h5s.create_simple(dims)
    data=numpy.memmap('tmpdat',dtype=numpy.float64,mode='w+',shape=dims)
    h5py.h5d.DatasetID.read(data_id,memory_space_id,dataspaceID,data)
    del data
    data=numpy.memmap('tmpdat',dtype=numpy.float64,mode='r',shape=dims)

    fig = Figure(figsize=(5,5), dpi=100)
    ax = fig.add_subplot(111)
    plot_data=data[0,0:,0]
    mif=numpy.arange(plot_data.shape[0])
    #if the next line is commented out, all is good
    ax.plot(plot_data,mif)
    canvas = FigureCanvas(fig)
    box1.pack_start(canvas, True, True, 0)
    canvas.show()
    id.close()
    del data
    del fig
    del ax
    del plot_data
    del canvas
    gc.collect()
    #the following line fails
    os.remove('tmpdat')

def delete_event(widget, event, data=None):
    return False

window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.connect("destroy", lambda x: gtk.main_quit())
box1 = gtk.HBox(False, 0)
window.add(box1)


button = gtk.Button("Hello World")
box1.pack_start(button, True, True, 0)
#window.add(box1)
button.show()
button.connect("clicked", doplot, box1)
box1.show()
window.set_default_size(500,400)

window.show()
gtk.main()
------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing. 
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to