Commit 38f3d16e authored by Jérémy Baudry's avatar Jérémy Baudry

first commit

parents
#!/usr/bin/python
from gi.repository import Gtk
from netCDF4 import Dataset
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo as FigureCanvas
from matplotlib.backends.backend_gtk3 import NavigationToolbar2GTK3 as NavigationToolbar
class Handler:
def __init__(self):
self.gladefile = "/home/jeremy/Bureau/GUI/wim.glade"
self.builder = Gtk.Builder()
self.builder.add_from_file(self.gladefile)
self.builder.connect_signals(self)
self.window = self.builder.get_object("window1")
self.window.show()
self.hscale1 = self.builder.get_object("hscale1")
self.hscale2 = self.builder.get_object("hscale2")
self.thick = self.builder.get_object("checkbutton1")
self.conc = self.builder.get_object("checkbutton2")
self.meanfloe = self.builder.get_object("checkbutton3")
self.FSTD = self.builder.get_object("checkbutton5")
def disable(self,widget,event):
return True
def on_destroy(self,closewindow):
closewindow.hide()
def on_window1_destroy(self,window):
Gtk.main_quit()
#===================choose_file_button===================================
def on_filechooserbutton1_file_set(self,choosefile):
global data
data = choosefile.get_filename()
self.readnc(data)
ad1 = Gtk.Adjustment(25,0,99,1,1, 0)
self.hscale1.set_adjustment(adjustment=ad1)
ad2 = Gtk.Adjustment(25,0,99,1,1, 0)
self.hscale2.set_adjustment(adjustment=ad2)
global xvalue
xvalue=x_axis[0]
global timevalue
timevalue=time[0]
self.windowthick = Gtk.Window()
self.windowthick.set_default_size(400,400)
self.windowthick.connect("delete-event",self.disable)
self.fig1=plt.figure(1)
canvas1 = FigureCanvas(self.fig1)
canvas1.set_size_request(100,100)
self.axthick = self.fig1.add_subplot(111)
self.axthick.plot(x_axis,thickness)
self.vline1=self.axthick.axvline(x_axis[xvalue],color='k',ls='dashed')
self.hline1=self.axthick.axhline(thickness[xvalue],color='k',ls='dashed')
self.pointer=self.axthick.plot(x_axis[xvalue],thickness[xvalue],'ro',markersize=10.0)[0]
self.axthick.set_ylabel('Mean ice thickness')
self.windowthick.set_title('Mean ice thickness')
self.vbox = Gtk.VBox()
self.windowthick.add(self.vbox)
self.vbox.pack_start(canvas1,True,True, 0)
toolbar = NavigationToolbar(canvas1,self.windowthick)
self.vbox.pack_start(toolbar, False, False,0)
self.windowconc = Gtk.Window()
self.windowconc.set_default_size(400,400)
self.windowconc.set_title('Ice concentration')
self.windowconc.connect("delete-event",self.disable)
self.fig3=plt.figure(3)
canvas3 = FigureCanvas(self.fig3)
canvas3.set_size_request(100,100)
self.axconc = self.fig3.add_subplot(111)
self.axconc.plot(x_axis,ice_concentration)
self.vline2=self.axconc.axvline(x_axis[xvalue],color='k',ls='dashed')
self.hline2=self.axconc.axhline(ice_concentration[xvalue],color='k',ls='dashed')
self.pointer2=self.axconc.plot(x_axis[xvalue],ice_concentration[xvalue],'ro',markersize=10.0)[0]
self.axconc.set_ylabel('Ice concentration')
self.vboxconc = Gtk.VBox()
self.windowconc.add(self.vboxconc)
self.vboxconc.pack_start(canvas3,True,True, 0)
toolbar3 = NavigationToolbar(canvas3,self.windowconc)
self.vboxconc.pack_start(toolbar3, False, False,0)
self.windowmeanfloe = Gtk.Window()
self.windowmeanfloe.set_default_size(400,400)
self.windowmeanfloe.set_title('Mean Floe size')
self.windowmeanfloe.connect("delete-event",self.disable)
self.fig4=plt.figure(4)
canvas4 = FigureCanvas(self.fig4)
canvas4.set_size_request(100,100)
self.axmeanfloe = self.fig4.add_subplot(111)
self.axmeanfloe.plot(x_axis,D_ave)
self.vline3=self.axmeanfloe.axvline(x_axis[xvalue],color='k',ls='dashed')
self.hline3=self.axmeanfloe.axhline(D_ave[xvalue],color='k',ls='dashed')
self.pointer3=self.axmeanfloe.plot(x_axis[xvalue],D_ave[xvalue],'ro',markersize=10.0)[0]
self.axconc.set_ylabel('Mean floe size')
self.vboxmeanfloe = Gtk.VBox()
self.windowmeanfloe.add(self.vboxmeanfloe)
self.vboxmeanfloe.pack_start(canvas4,True,True, 0)
toolbar4 = NavigationToolbar(canvas4,self.windowmeanfloe)
self.vboxmeanfloe.pack_start(toolbar4, False, False,0)
self.windowfstd = Gtk.Window()
self.windowfstd.set_default_size(400,400)
self.windowfstd.set_title('FSTD')
self.windowfstd.connect("delete-event",self.disable)
self.fig2=plt.figure(2)
canvas2 = FigureCanvas(self.fig2)
canvas2.set_size_request(100,100)
self.axfstd= self.fig2.add_subplot(111)
FSD2=FSD[:,:,xvalue,timevalue]
ITD2=ITD[:,xvalue]
global FSTD
FSTD=np.zeros((50,60))
for i in xrange(0,49):
FSTD[i,:]=FSD2[i,:]*ITD2[i]
self.fstdplot=self.axfstd.imshow(FSTD, interpolation='nearest', cmap=cm.coolwarm)
self.cbar = self.fig2.colorbar(self.fstdplot)
self.cbar.set_clim(0,0.1)
self.vboxfstd = Gtk.VBox()
self.windowfstd.add(self.vboxfstd)
self.vboxfstd.pack_start(canvas2,True,True, 0)
toolbar2 = NavigationToolbar(canvas2,self.windowfstd)
self.vboxfstd.pack_start(toolbar2, False, False,0)
if self.thick.get_active():
self.plot_thick(x_axis,thickness,xvalue)
if self.conc.get_active():
self.plot_conc(x_axis,ice_concentration,xvalue)
if self.meanfloe.get_active():
self.plot_meanfloe(x_axis,D_ave,xvalue)
if self.FSTD.get_active():
self.plot_FSTD(xvalue,timevalue,Fsize,hcat,FSD,ITD)
#======================scale_buttons======================================
def on_hscale1_value_changed(self,timescale):
timevalue=timescale.get_value()
if self.FSTD.get_active():
self.plot_FSTD(xvalue,timevalue,Fsize,hcat,FSD,ITD)
def on_hscale2_value_changed(self,xscale):
xvalue=xscale.get_value()
if self.thick.get_active():
self.plot_thick(x_axis,thickness,xvalue)
if self.FSTD.get_active():
self.plot_FSTD(xvalue,timevalue,Fsize,hcat,FSD,ITD)
if self.conc.get_active():
self.plot_conc(x_axis,ice_concentration,xvalue)
if self.meanfloe.get_active():
self.plot_meanfloe(x_axis,D_ave,xvalue)
#====================toggle_button=========================================
def on_checkbutton1_toggled(self,but1):
if but1.get_active():
self.plot_thick(x_axis,thickness,xvalue)
else:
self.on_destroy(self.windowthick)
def on_checkbutton2_toggled(self,butconc):
if butconc.get_active():
self.plot_conc(x_axis,ice_concentration,xvalue)
else:
self.on_destroy(self.windowconc)
def on_checkbutton3_toggled(self,butmeanfloe):
if butmeanfloe.get_active():
self.plot_meanfloe(x_axis,D_ave,xvalue)
else:
self.on_destroy(self.windowmeanfloe)
def on_checkbutton5_toggled(self,butFSTD):
if butFSTD.get_active():
self.plot_FSTD(xvalue,timevalue,Fsize,hcat,FSD,ITD)
else:
self.on_destroy(self.windowfstd)
#==========================================================================
def plot_thick(self,x_axis,thickness,xvalue):
self.pointer.set_ydata(thickness[xvalue])
self.vline1.set_xdata(x_axis[xvalue])
self.hline1.set_ydata(thickness[xvalue])
self.pointer.set_xdata(x_axis[xvalue])
self.windowthick.show_all()
self.windowthick.present()
self.window.present()
#==========================================================================
def plot_conc(self,x_axis,ice_concentration,xvalue):
self.pointer2.set_ydata(ice_concentration[xvalue])
self.vline2.set_xdata(x_axis[xvalue])
self.hline2.set_ydata(ice_concentration[xvalue])
self.pointer2.set_xdata(x_axis[xvalue])
self.windowconc.show_all()
self.windowconc.present()
self.window.present()
#==========================================================================
def plot_meanfloe(self,x_axis,D_ave,xvalue):
self.pointer3.set_ydata(D_ave[xvalue])
self.vline3.set_xdata(x_axis[xvalue])
self.hline3.set_ydata(D_ave[xvalue])
self.pointer3.set_xdata(x_axis[xvalue])
self.windowmeanfloe.show_all()
self.windowmeanfloe.present()
self.window.present()
#=========================================================================
def plot_FSTD(self,xvalue,timevalue,Fsize,hcat,FSD,ITD):
FSD2=FSD[:,:,xvalue,timevalue]
ITD2=ITD[:,xvalue]
global FSTD
FSTD=np.zeros((50,60))
for i in xrange(0,49):
FSTD[i,:]=FSD2[i,:]*ITD2[i]
self.fstdplot.set_data(FSTD)
plt.draw()
self.windowfstd.show_all()
self.windowfstd.present()
self.window.present()
#==========================================================================
def readnc(self,data):
global omega
global x_axis
global time
global hcat
global Fsize
global spectrum
global D_ave
global ice_concentration
global FSD
global Hs
global ITD
global thickness
fh = Dataset(data)
omega = fh.variables['omega'][:]
x_axis = fh.variables['x_axis'][:]
time = fh.variables['time'][:]
hcat= fh.variables['thickness categories'][:]
Fsize= fh.variables['floe size'][:]
spectrum = fh.variables['Spectrum'][:,:,:]
D_ave = fh.variables['Dave'][:]
ice_concentration = fh.variables['Ice concentration'][:]
thickness = fh.variables['Ice thickness'][:]
FSD = fh.variables['Floe size distribution'][:,:,:,:]
Hs = fh.variables['significant height'][:,:]
ITD = fh.variables['Ice Thickness Distribution'][:,:]
fh.close()
if __name__ == "__main__":
main = Handler()
Gtk.main()
#!/usr/bin/python
from gi.repository import Gtk
from netCDF4 import Dataset
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo as FigureCanvas
from matplotlib.backends.backend_gtk3 import NavigationToolbar2GTK3 as NavigationToolbar
class Handler:
def __init__(self):
self.gladefile = "/home/jeremy/Bureau/GUI/wim.glade"
self.builder = Gtk.Builder()
self.builder.add_from_file(self.gladefile)
self.builder.connect_signals(self)
self.window = self.builder.get_object("window1")
self.window.show()
self.hscale1 = self.builder.get_object("hscale1")
self.hscale2 = self.builder.get_object("hscale2")
self.thick = self.builder.get_object("checkbutton1")
self.conc = self.builder.get_object("checkbutton2")
self.meanfloe = self.builder.get_object("checkbutton3")
self.FSTD = self.builder.get_object("checkbutton5")
def disable(self,widget,event):
return True
def on_destroy(self,closewindow):
closewindow.hide()
def on_window1_destroy(self,window):
Gtk.main_quit()
#===================choose_file_button===================================
def on_filechooserbutton1_file_set(self,choosefile):
global data
data = choosefile.get_filename()
self.readnc(data)
ad1 = Gtk.Adjustment(25,0,99,1,1, 0)
self.hscale1.set_adjustment(adjustment=ad1)
ad2 = Gtk.Adjustment(25,0,99,1,1, 0)
self.hscale2.set_adjustment(adjustment=ad2)
global xvalue
xvalue=x_axis[0]
global timevalue
timevalue=time[0]
self.windowthick = Gtk.Window()
self.windowthick.set_default_size(400,400)
self.windowthick.connect("delete-event",self.disable)
self.fig1=plt.figure(1)
canvas1 = FigureCanvas(self.fig1)
canvas1.set_size_request(100,100)
self.axthick = self.fig1.add_subplot(111)
self.axthick.plot(x_axis,thickness)
self.vline1=self.axthick.axvline(x_axis[xvalue],color='k',ls='dashed')
self.hline1=self.axthick.axhline(thickness[xvalue],color='k',ls='dashed')
self.pointer=self.axthick.plot(x_axis[xvalue],thickness[xvalue],'ro',markersize=10.0)[0]
self.axthick.set_ylabel('Mean ice thickness')
self.windowthick.set_title('Mean ice thickness')
self.vbox = Gtk.VBox()
self.windowthick.add(self.vbox)
self.vbox.pack_start(canvas1,True,True, 0)
toolbar = NavigationToolbar(canvas1,self.windowthick)
self.vbox.pack_start(toolbar, False, False,0)
self.windowconc = Gtk.Window()
self.windowconc.set_default_size(400,400)
self.windowconc.set_title('Ice concentration')
self.windowconc.connect("delete-event",self.disable)
self.fig3=plt.figure(3)
canvas3 = FigureCanvas(self.fig3)
canvas3.set_size_request(100,100)
self.axconc = self.fig3.add_subplot(111)
self.axconc.plot(x_axis,ice_concentration)
self.vline2=self.axconc.axvline(x_axis[xvalue],color='k',ls='dashed')
self.hline2=self.axconc.axhline(ice_concentration[xvalue],color='k',ls='dashed')
self.pointer2=self.axconc.plot(x_axis[xvalue],ice_concentration[xvalue],'ro',markersize=10.0)[0]
self.axconc.set_ylabel('Ice concentration')
self.vboxconc = Gtk.VBox()
self.windowconc.add(self.vboxconc)
self.vboxconc.pack_start(canvas3,True,True, 0)
toolbar3 = NavigationToolbar(canvas3,self.windowconc)
self.vboxconc.pack_start(toolbar3, False, False,0)
self.windowmeanfloe = Gtk.Window()
self.windowmeanfloe.set_default_size(400,400)
self.windowmeanfloe.set_title('Mean Floe size')
self.windowmeanfloe.connect("delete-event",self.disable)
self.fig4=plt.figure(4)
canvas4 = FigureCanvas(self.fig4)
canvas4.set_size_request(100,100)
self.axmeanfloe = self.fig4.add_subplot(111)
self.axmeanfloe.plot(x_axis,D_ave)
self.vline3=self.axmeanfloe.axvline(x_axis[xvalue],color='k',ls='dashed')
self.hline3=self.axmeanfloe.axhline(D_ave[xvalue],color='k',ls='dashed')
self.pointer3=self.axmeanfloe.plot(x_axis[xvalue],D_ave[xvalue],'ro',markersize=10.0)[0]
self.axconc.set_ylabel('Mean floe size')
self.vboxmeanfloe = Gtk.VBox()
self.windowmeanfloe.add(self.vboxmeanfloe)
self.vboxmeanfloe.pack_start(canvas4,True,True, 0)
toolbar4 = NavigationToolbar(canvas4,self.windowmeanfloe)
self.vboxmeanfloe.pack_start(toolbar4, False, False,0)
self.windowfstd = Gtk.Window()
self.windowfstd.set_default_size(400,400)
self.windowfstd.set_title('FSTD')
self.windowfstd.connect("delete-event",self.disable)
self.fig2=plt.figure(2)
canvas2 = FigureCanvas(self.fig2)
canvas2.set_size_request(100,100)
self.axfstd= self.fig2.add_subplot(111)
FSD2=FSD[:,:,xvalue,timevalue]
ITD2=ITD[:,xvalue]
global FSTD
FSTD=np.zeros((50,60))
for i in xrange(0,49):
FSTD[i,:]=FSD2[i,:]*ITD2[i]
self.fstdplot=self.axfstd.imshow(FSTD, interpolation='nearest', cmap=cm.coolwarm)
self.cbar = self.fig2.colorbar(self.fstdplot)
self.cbar.set_clim(0,0.1)
self.vboxfstd = Gtk.VBox()
self.windowfstd.add(self.vboxfstd)
self.vboxfstd.pack_start(canvas2,True,True, 0)
toolbar2 = NavigationToolbar(canvas2,self.windowfstd)
self.vboxfstd.pack_start(toolbar2, False, False,0)
if self.thick.get_active():
self.plot_thick(x_axis,thickness,xvalue)
if self.conc.get_active():
self.plot_conc(x_axis,ice_concentration,xvalue)
if self.meanfloe.get_active():
self.plot_meanfloe(x_axis,D_ave,xvalue)
if self.FSTD.get_active():
self.plot_FSTD(xvalue,timevalue,Fsize,hcat,FSD,ITD)
#======================scale_buttons======================================
def on_hscale1_value_changed(self,timescale):
timevalue=timescale.get_value()
if self.FSTD.get_active():
self.plot_FSTD(xvalue,timevalue,Fsize,hcat,FSD,ITD)
def on_hscale2_value_changed(self,xscale):
xvalue=xscale.get_value()
if self.thick.get_active():
self.plot_thick(x_axis,thickness,xvalue)
if self.FSTD.get_active():
self.plot_FSTD(xvalue,timevalue,Fsize,hcat,FSD,ITD)
if self.conc.get_active():
self.plot_conc(x_axis,ice_concentration,xvalue)
if self.meanfloe.get_active():
self.plot_meanfloe(x_axis,D_ave,xvalue)
#====================toggle_button=========================================
def on_checkbutton1_toggled(self,but1):
if but1.get_active():
self.plot_thick(x_axis,thickness,xvalue)
else:
self.on_destroy(self.windowthick)
def on_checkbutton2_toggled(self,butconc):
if butconc.get_active():
self.plot_conc(x_axis,ice_concentration,xvalue)
else:
self.on_destroy(self.windowconc)
def on_checkbutton3_toggled(self,butmeanfloe):
if butmeanfloe.get_active():
self.plot_meanfloe(x_axis,D_ave,xvalue)
else:
self.on_destroy(self.windowmeanfloe)
def on_checkbutton5_toggled(self,butFSTD):
if butFSTD.get_active():
self.plot_FSTD(xvalue,timevalue,Fsize,hcat,FSD,ITD)
else:
self.on_destroy(self.windowfstd)
#==========================================================================
def plot_thick(self,x_axis,thickness,xvalue):
self.pointer.set_ydata(thickness[xvalue])
self.vline1.set_xdata(x_axis[xvalue])
self.hline1.set_ydata(thickness[xvalue])
self.pointer.set_xdata(x_axis[xvalue])
self.windowthick.show_all()
self.windowthick.present()
self.window.present()
#==========================================================================
def plot_conc(self,x_axis,ice_concentration,xvalue):
self.pointer2.set_ydata(ice_concentration[xvalue])
self.vline2.set_xdata(x_axis[xvalue])
self.hline2.set_ydata(ice_concentration[xvalue])
self.pointer2.set_xdata(x_axis[xvalue])
self.windowconc.show_all()
self.windowconc.present()
self.window.present()
#==========================================================================
def plot_meanfloe(self,x_axis,D_ave,xvalue):
self.pointer3.set_ydata(D_ave[xvalue])
self.vline3.set_xdata(x_axis[xvalue])
self.hline3.set_ydata(D_ave[xvalue])
self.pointer3.set_xdata(x_axis[xvalue])
self.windowmeanfloe.show_all()
self.windowmeanfloe.present()
self.window.present()
#=========================================================================
def plot_FSTD(self,xvalue,timevalue,Fsize,hcat,FSD,ITD):
FSD2=FSD[:,:,xvalue,timevalue]
ITD2=ITD[:,xvalue]
global FSTD
FSTD=np.zeros((50,60))
for i in xrange(0,49):
FSTD[i,:]=FSD2[i,:]*ITD2[i]
self.fstdplot.set_data(FSTD)
plt.draw()
self.windowfstd.show_all()
self.windowfstd.present()
self.window.present()
#==========================================================================
def readnc(self,data):
global omega
global x_axis
global time
global hcat
global Fsize
global spectrum
global D_ave
global ice_concentration
global FSD
global Hs
global ITD
global thickness
fh = Dataset(data)
omega = fh.variables['omega'][:]
x_axis = fh.variables['x_axis'][:]
time = fh.variables['time'][:]
hcat= fh.variables['thickness categories'][:]
Fsize= fh.variables['floe size'][:]
spectrum = fh.variables['Spectrum'][:,:,:]
D_ave = fh.variables['Dave'][:]
ice_concentration = fh.variables['Ice concentration'][:]
thickness = fh.variables['Ice thickness'][:]
FSD = fh.variables['Floe size distribution'][:,:,:,:]
Hs = fh.variables['significant height'][:,:]
ITD = fh.variables['Ice Thickness Distribution'][:,:]
fh.close()
if __name__ == "__main__":
main = Handler()
Gtk.main()
sea-ice.jpg

27.6 KB

#!/usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
plt.ion()
img = np.random.rand(40,40)
fig=plt.figure(1)
image = plt.imshow(img,interpolation='nearest',animated=True,label="blah")
for k in range(1,10000):
img = np.random.rand(40,40)
image.set_data(img)
plt.draw()
#!/usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
plt.ion()
img = np.random.rand(40,40)
fig=plt.figure(1)
image = plt.imshow(img,interpolation='nearest',animated=True,label="blah")
for k in range(1,10000):
img = np.random.rand(40,40)
image.set_data(img)
plt.draw()
File added
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment