From 20cffd6797a25aa2fbea52d1c2be3da1a228466a Mon Sep 17 00:00:00 2001 From: Emmanuel Heriberto Oceguera Conchas <e.oceguera@gmx.de> Date: Tue, 11 Oct 2022 11:31:12 +0200 Subject: [PATCH] modul netCDF4 does not work --- netCDFVisualizer.ui | 4 ++-- netCDF_visualizer.py | 20 +++++++++++--------- netCDF_visualizer_funtionality.py | 21 +++++++++++++++++++-- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/netCDFVisualizer.ui b/netCDFVisualizer.ui index 7d046f3..d0b36e5 100644 --- a/netCDFVisualizer.ui +++ b/netCDFVisualizer.ui @@ -6,8 +6,8 @@ <rect> <x>0</x> <y>0</y> - <width>771</width> - <height>835</height> + <width>389</width> + <height>518</height> </rect> </property> <property name="windowTitle"> diff --git a/netCDF_visualizer.py b/netCDF_visualizer.py index 4faa3dd..573f060 100644 --- a/netCDF_visualizer.py +++ b/netCDF_visualizer.py @@ -50,7 +50,7 @@ class netCDFVisualizer: #decalre instance attributes self.actions = [] self.menu = self.tr(u'&netCDFVisualizer') - + def tr(self, message): """Get the translation for a string using Qt translation API. @@ -135,22 +135,24 @@ class netCDFVisualizer: #when we click the plugin in QGIS the plugin will be loaded def initGui(self): """Create the menu entries and toolbar icons inside the QGIS GUI.""" - icon_path = ':/plugins/netCDFVisualizer/icon.png' + icon_path = ':/plugins/netCDFVisualizer/adventure.png' self.add_action( icon_path, text=self.tr(u'netCDFVisualizer'), callback=self.callMask, parent=self.iface.mainWindow()) - - - #when we close the plugin in QGIS the plugin will be unloaded def unload(self): - #we remove the menu item - self.iface.removePluginMenu('netCDFVisualizer', self.pluginButton) - #we remove the menu item - self.iface.removeToolBarIcon(self.pluginButton) + """Removes the plugin menu item and icon from QGIS GUI.""" + for action in self.actions: + self.iface.removePluginMenu( + self.tr(u'&netCDFVisualizer'), + action) + self.iface.removeToolBarIcon(action) + else : + self.toolbar.removeAction(action) + #we create a function to call the mask def callMask(self): diff --git a/netCDF_visualizer_funtionality.py b/netCDF_visualizer_funtionality.py index 6bc87dc..f55b69b 100644 --- a/netCDF_visualizer_funtionality.py +++ b/netCDF_visualizer_funtionality.py @@ -34,7 +34,8 @@ import os #to import general tools from QGIS we need the qgis.core module from qgis.core import * #for loading the netCDF files we need the netCDF4 module - +import netCDF4 as nc +from netCDF4 import Dataset #we create the path to the ui file #Path to the Ordner where the ui file is ncvPath = os.path.dirname(__file__) #the comand dirname gives the path to the directory where the file is @@ -58,6 +59,8 @@ class maskAndFuntionality (BASE, WIDGET): """ Here is the place for the Clicked Signal""" self.btn_closePlugin.clicked.connect(self.closePlugin) self.btn_inputFile.clicked.connect(self.importData) + self.btn_remove.clicked.connect(self.removePath) + self.btn_load.clicked.connect(self.loadNetCDF) def closePlugin(self): @@ -76,7 +79,21 @@ class maskAndFuntionality (BASE, WIDGET): """This function removes the path from the text space""" #we remove the path from the text space self.text_set.clear() - + + def loadNetCDF(self): + """This function loads the netCDF file""" + #we get the path from the text space + path = self.text_set.text() + #we load the netCDF file + self.nc = Dataset(path, 'r', format='NETCDF4') + #we get the name of the variables + self.variables = self.nc.variables.keys() + #we set the name of the variables in the combo box + self.txt_tab_dataSet.addItems(self.variables) + #we get the name of the dimensions + self.dimensions = self.nc.dimensions.keys() + #we set the name of the dimensions in the combo box + self.txt_tab_dataSet.addItems(self.dimensions) -- GitLab