Search code examples
python-3.xwxpython

ERROR WHEN SHOWING VALUE OF VARIABLES FROM 2 PANELS


i have 2 panels when i extract values of variables

what i need to do is to show all value from 3 panels in the same panel ..

the panel is for showing all information about files in the 3 panels

i try to add in this panels of value of variables from 3 panels to showing in this panel but i get error like :

Traceback (most recent call last):
  File "C:\Users\majdoulina\Anaconda3\lib\site-packages\matplotlib\cbook\__init__.py", line 215, in process
    func(*args, **kwargs)
  File "D:\DATA\app6.py", line 450, in on_press
    self.GrandParent.right.bottom.bottom.top.Update(x1,y1,list_var3,lon,lat)
TypeError: Update() missing 1 required positional argument: 'list_var4'

what i need to do is to show value of variable from 3 panels in this panel this is part of code wher i have error :

 class MiddlePanelTop(wx.Panel):
        def __init__(self, parent):
            super().__init__(parent, name="MiddleTop", style = wx.SUNKEN_BORDER,size = (500,200))
            self.SetBackgroundColour('black')

        def Update(self,zoom_axes):
            #Load axis values of the selected rectangle
            #zoom_axes=parent.zoom_axes

            #duplicate the plot from the main panel
            self.figure = Figure(figsize =(5,4))
            self.canvas = FigureCanvas(self, -1, self.figure)
            self.axes = self.figure.add_subplot(111)
            self.figure.subplots_adjust(left=0.009,right=0.99,bottom=0.09,top=0.99)

            #Apply axis of drawn rectangle to the plot
            self.axes.axis(zoom_axes)

            path=file_names
            nc = netCDF4.Dataset(file_names)
            fic1='D:/DATA/latlon_+000.0_globe.nc'
            fic2='D:/DATA/landsea_+000.0.h5'
            hdf=h5py.File(fic2,'r')
            landsea=hdf['dataset'][:]

            var = nc.variables.keys()

            list_var3 = [nc.variables['VIS006'],nc.variables['VIS008'],nc.variables['IR_120'],nc.variables['IR_108'],nc.variables['IR_087'],
                        nc.variables['IR_134'],nc.variables['IR_039'],nc.variables['WV_073'],nc.variables['WV_062'],nc.variables['IR_097']]
            print("update2")
            data_list = ['VIS006','VIS008','IR_120','IR_108','IR_087','IR_134','IR_039','WV_073','WV_062','IR_097']

            list_var3 = [nc.variables[f] for f in data_list]
            nc1 = netCDF4.Dataset(fic1,'r')
            lons = nc1.variables['lon'][:]
            lats = nc1.variables['lat'][:]
            self.lons = lons[:]
            self.lats = lats[:]

            print("Option chosen update")
            global index
            print("index=",index)
            self.list_var3 = list_var3[index][:]
            self.axes.imshow(self.list_var3,cmap=plt.cm.gist_yarg)
            self.clevs=np.arange(0,3,1)
            self.axes.contour(landsea,self.clevs,extend="max",colors='y')
            self.axes.get_xaxis().set_visible(False)
            self.axes.get_yaxis().set_visible(False)

            self.canvas.mpl_connect('button_press_event', self.on_press)
            global x1,y1 
            self.rect = patches.Rectangle((x1, y1), 40, 40,edgecolor='g', alpha=1, fill=None, label='Label')
            self.axes.add_patch(self.rect)

            self.figure.add_axes(self.axes)

            'self.figure.show()'
            self.axes.plot()
            #add_artist(t)


        def on_press(self, click):
            global x1, y1
            x1, y1 = click.xdata, click.ydata
            list_var3 = self.list_var3[int(y1),int(x1)]
            lon = self.lons[int(y1),int(x1)]
            lat = self.lats[int(y1),int(x1)]
            self.GrandParent.right.bottom.bottom.top.Update(x1,y1,list_var3,lon,lat)
            zx1 = x1 - 20
            zy1 = y1 - 20
            zx2 = x1 + 20
            zy2 = y1 + 20
            self.rect.set_x(x1 - 20) #Move the rectangle and centre it on the X click point
            self.rect.set_y(y1 - 20) #Move the rectangle and centre it on the Y click point
            x1=x1-20
            y1=y1-20

            self.axes.plot()
            self.canvas.draw()
            self.zoom_axes=[zx1,zx2,zy1,zy2]
            global zoom
            global zoom2
            zoom2=self.zoom_axes
            self.GrandParent.right.bottom.top.left.Update(self.zoom_axes)
            'self.GrandParent.middle.top.Update(zoom)'
            self.GrandParent.middle.bottom.Update(zoom)
            self.GrandParent.right.top.Update(zoom)

            self.GrandParent.right.bottom.top.right.Update(self.zoom_axes)
            self.GrandParent.right.bottom.top.left.Update(self.zoom_axes)
            self.GrandParent.right.bottom.top.middle.Update(self.zoom_axes)


   class MiddlePanelBottom(wx.Panel):
    def __init__(self, parent):
        super().__init__(parent, name="MiddleBottom", style = wx.SUNKEN_BORDER,size = (300,200))
        self.SetBackgroundColour('black')

    def Update(self,zoom_axes):
        #Load axis values of the selected rectangle
        #zoom_axes=parent.zoom_axes

        #duplicate the plot from the main panel
        self.figure = Figure(figsize =(5,4))
        self.canvas = FigureCanvas(self, -1, self.figure)
        self.axes = self.figure.add_subplot(111)
        self.figure.subplots_adjust(left=0.009,right=0.99,bottom=0.1,top=0.98)

        #Apply axis of drawn rectangle to the plot
        self.axes.axis(zoom_axes)

        path=file_names
        nc = netCDF4.Dataset(file_names)
        fic1='D:/DATA/latlon_+000.0_globe.nc'

        var = nc.variables.keys()

        list_var4 = [nc.variables['VIS006'],nc.variables['VIS008'],nc.variables['IR_120'],nc.variables['IR_108'],nc.variables['IR_087'],
                    nc.variables['IR_134'],nc.variables['IR_039'],nc.variables['WV_073'],nc.variables['WV_062'],nc.variables['IR_097']]
        print("update3")
        data_list = ['VIS006','VIS008','IR_120','IR_108','IR_087','IR_134','IR_039','WV_073','WV_062','IR_097']

        list_var4 = [nc.variables[f] for f in data_list][:]
        nc1 = netCDF4.Dataset(fic1,'r')
        lons = nc1.variables['lon'][:]
        lats = nc1.variables['lat'][:]
        self.lons = lons[:]
        self.lats = lats[:]
        print("Option chosen update")
        global index
        print("index=",index)
        self.list_var4 = list_var4[index][:]
        self.axes.imshow(self.list_var4,origin ='lower')

        self.axes.get_xaxis().set_visible(False)
        self.axes.get_yaxis().set_visible(False)
        self.canvas.mpl_connect('button_press_event', self.on_press)
        global x1,y1 
        self.rect = patches.Rectangle((x1, y1), 40, 40,edgecolor='g', alpha=1, fill=None, label='Label')
        self.axes.add_patch(self.rect)

        self.axes.plot()

    def on_press(self, click):
        global x1, y1
        x1, y1 = click.xdata, click.ydata
        list_var4 = self.list_var4[int(y1),int(x1)]
        lon = self.lons[int(y1),int(x1)]
        lat = self.lats[int(y1),int(x1)]

        self.GrandParent.right.bottom.bottom.top.Update(list_var4)

        zx1 = x1 - 20
        zy1 = y1 - 20
        zx2 = x1 + 20
        zy2 = y1 + 20
        self.rect.set_x(x1 - 20 ) #Move the rectangle and centre it on the X click point
        self.rect.set_y(y1 - 20 ) #Move the rectangle and centre it on the Y click point
        x1=x1-20
        y1=y1-20

        self.axes.plot()
        self.canvas.draw()
        self.zoom_axes=[zx1,zx2,zy1,zy2]
        global zoom
        global zoom2
        zoom=self.zoom_axes
        self.GrandParent.right.bottom.top.left.Update(self.zoom_axes)
        self.GrandParent.middle.top.Update(zoom)
        'self.GrandParent.middle.bottom.Update(zoom)'
        self.GrandParent.right.top.Update(zoom)

        self.GrandParent.right.bottom.top.right.Update(self.zoom_axes)
        self.GrandParent.right.bottom.top.left.Update(self.zoom_axes)
        self.GrandParent.right.bottom.top.middle.Update(self.zoom_axes)


    class RightPanelBottomBottomTop(wx.Panel):
        def __init__(self,parent):
            super().__init__(parent,style = wx.SUNKEN_BORDER)
            self.text_ctrl = wx.TextCtrl(self, -1, "", style=wx.TE_MULTILINE|wx.BORDER_SUNKEN|wx.TE_READONLY|wx.TE_RICH2, size=(700,30))
            self.text_ctrl.SetBackgroundColour('cyan')

            sizer = wx.BoxSizer(wx.VERTICAL)

            sizer.Add(self.text_ctrl,0)
            self.SetSizer(sizer)

        def Update(self,x1,y1,list_var3,lon,lat,list_var4):
            update_str =  "X :"+str(int(x1)) + "   " +"Y :"+str(int(y1)) + "   "+ "var3 :"+str(int(list_var3))+"  "+"Lon : "+str(int(lon))+"  "+"Lat :"+str(int(lat))+ "var4 :"+str(int(list_var4))
            self.text_ctrl.SetValue(update_str)

panel where i showing information is : class RightPanelBottomBottomTop

thank you


Solution

  • I find solution myself but i still have some problem with value i visualize like

    i can show name for variables from 2 panel just the first and x y lat lon and name of variable for other panels but still can't show value from var2 and var3 just for var1 !