コード例 #1
0
    def __init__(self, filename):
        # super(Nc, self).__init__(filename, mode, clobber, diskless, persist, keepweakref, format)
        dataset = Dataset(filename)
        if dataset == None:
            print("Set Dataset Error")
            return
        self.dataset = dataset

        # 基础信息
        self.file_path = filename
        self.file_name = gp.get_filename(self.file_path)
        self.file_format = self.dataset.disk_format

        self.variables = self.dataset.variables
        self.dimensions = self.dataset.dimensions
        self.dim_variable, self.var_variable = self.__get_dim_var_variables()
        self.variables_data_orderDict = self.__get_variables_data()
コード例 #2
0
    def __init__(self, filename):
        #super(HDF, self).__init__(filename)

        dataset = Dataset(filename)
        if dataset == None:
            print("Set Dataset Error")
            return
        self.dataset = dataset

        # 基础信息
        self.file_path = filename
        self.file_name = gp.get_filename(self.file_path)
        self.file_format = self.dataset.disk_format

        self.groups = self.dataset.groups

        self.contains_group = False if len(self.groups) == 0 else True

        self.variables = self.__get_variables()
        self.dimensions = self.__get_dimensions()
        self.dim_variable, self.var_variable = self.__get_dim_var_variables()
コード例 #3
0
    def Init(self):
        print("")
        if not isinstance(self.action, ActionQ) or not isinstance(self.mainWindow,QMainWindow):
            return None

        self.error = "menu.openfilecmd,we have a error : "
        files = self.OpenFile()  # 打开文件

        algorithmList={}

        # 执行解码算法
        for file in files:
            algorithmObject = PyMeteoObject()
            algorithmObject.file=file
            algorithmObject.fileName=gp.get_filename(file)
            algorithmObject.meteoDataInfo=AlgorithmFactory.create_algorithm(file)
            if algorithmObject.meteoDataInfo==None:
                QMessageBox.warning(self.mainWindow,"错误","Unknown file format: %s"%(algorithmObject.fileName))
                continue
            else:
                algorithmList.setdefault(algorithmObject.fileName,algorithmObject)

        self.treeWidget.SetTreeWidgetItem(algorithmList)
コード例 #4
0
    def SetTreeWidgetItem(self, files):

        self.files = files

        for file in self.files:
            algorithmObject = PyMeteoObject()
            algorithmObject.file = file
            algorithmObject.fileName = gp.get_filename(file)
            algorithmObject.meteoDataInfo, modelDataType = self.AlgorithmFactory.create_algorithm(
                file)

            #modelDataType = jt.judge_model_data_type(file)

            if modelDataType == ModelDataType.NETCDF:
                grpvar = DisposeNetCDF(file)
                self.grpvar = grpvar
                self.grpinfo = grpvar.getgrpAndVariableInfo()
                textContext = algorithmObject.meteoDataInfo.print_property_info(
                )
                self.tabWidget.tab1UI(textContext)
                self.fdict[str(file)] = [self.grpinfo, textContext]
                root = QTreeWidgetItem(self)
                self.rootlist.append(root)
                root.setText(0, algorithmObject.fileName)
                #root.setText(1, algorithmObject.fileName)
                root.setText(1, 'Local File')
                root.setText(2, file)
                root.setText(3, 'NETCDF')
                # brush_red = QBrush(Qt.red)
                root.setBackground(0, QBrush(QColor(237, 243, 254)))
                # brush_blue = QBrush(Qt.blue)
                root.setBackground(1, QBrush(QColor(237, 243, 254)))
                root.setBackground(2, QBrush(QColor(237, 243, 254)))
                tmp = list(self.grpinfo.values())[0]
                if isinstance(tmp, nct.Variable):
                    for k, v in self.grpinfo.items():
                        child1 = QTreeWidgetItem()
                        child1.setText(0, k)
                        #child1.setText(1, k)
                        child1.setText(1,
                                       'Geo2D' if len(v.shape) > 1 else '1D')
                        child1.setText(2, file)
                        child1.setText(3, 'NETCDF Child')
                        root.addChild(child1)

                elif isinstance(tmp, dict):
                    for k, v in self.grpinfo.items():
                        child1 = QTreeWidgetItem()
                        child1.setText(0, k)
                        #child1.setText(1, k)
                        child1.setText(1, '    ***  ')
                        child1.setText(2, file)
                        child1.setText(3, 'NETCDF Group')
                        root.addChild(child1)
                        for val in v:
                            child3 = QTreeWidgetItem(child1)
                            child3.setText(0, val)
                            #child3.setText(1, val)
                            child3.setText(
                                1, 'Geo2D' if len(v[val].shape) > 1 else '1D')
                            child3.setText(2, file)
                            child3.setText(3, 'NETCDF Chlid')

            elif modelDataType == ModelDataType.HDF:
                grpvar = DisposeNetCDF(file)
                self.grpvar = grpvar
                self.grpinfo = grpvar.getgrpAndVariableInfo()
                textContext = algorithmObject.meteoDataInfo.print_property_info(
                )
                self.tabWidget.tab1UI(textContext)
                self.fdict[str(file)] = [self.grpinfo, textContext]
                root = QTreeWidgetItem(self)
                self.rootlist.append(root)
                root.setText(0, algorithmObject.fileName)
                #root.setText(1, algorithmObject.fileName)
                root.setText(1, 'Local File')
                root.setText(2, file)
                root.setText(3, 'HDF')
                # brush_red = QBrush(Qt.red)
                root.setBackground(0, QBrush(QColor(237, 243, 254)))
                # brush_blue = QBrush(Qt.blue)
                root.setBackground(1, QBrush(QColor(237, 243, 254)))
                root.setBackground(2, QBrush(QColor(237, 243, 254)))
                tmp = list(self.grpinfo.values())[0]
                if isinstance(tmp, nct.Variable):
                    for k, v in self.grpinfo.items():
                        child1 = QTreeWidgetItem()
                        child1.setText(0, k)
                        #child1.setText(1, k)
                        child1.setText(1,
                                       'Geo2D' if len(v.shape) > 1 else '1D')
                        child1.setText(2, file)
                        child1.setText(3, 'HDF Chlid')
                        root.addChild(child1)

                elif isinstance(tmp, dict):
                    for k, v in self.grpinfo.items():
                        child1 = QTreeWidgetItem()
                        child1.setText(0, k)
                        #child1.setText(1, k)
                        child1.setText(1, '    ***  ')
                        child1.setText(2, file)
                        child1.setText(3, 'HDF Group')
                        root.addChild(child1)
                        for val in v:
                            child3 = QTreeWidgetItem(child1)
                            child3.setText(0, val)
                            #child3.setText(1, val)
                            child3.setText(
                                1, 'Geo2D' if len(v[val].shape) > 1 else '1D')
                            child3.setText(2, file)
                            child3.setText(3, 'HDF Chlid')

            elif modelDataType == ModelDataType.MICAPS4:
                self.headcontext = algorithmObject.meteoDataInfo.print_property_info(
                )
                self.tabWidget.tab1UI(self.headcontext)
                root = QTreeWidgetItem(self)
                self.rootlist.append(root)
                root.setText(0, algorithmObject.fileName)
                #root.setText(1, algorithmObject.fileName)
                root.setText(1, 'Local File')
                root.setText(2, file)
                root.setText(3, 'Micaps4')
                m4 = DisposeM4file(file).disposeM4()
                self.fdict[str(file)] = [m4, self.headcontext]
                # brush_red = QBrush(Qt.red)
                root.setBackground(0, QBrush(QColor(237, 243, 254)))
                # brush_blue = QBrush(Qt.blue)
                root.setBackground(1, QBrush(QColor(237, 243, 254)))
                root.setBackground(2, QBrush(QColor(237, 243, 254)))
                self.tabWidget.tab3UI(m4, model='MICAPS4')

            elif modelDataType == ModelDataType.GRIB:
                grib_property = algorithmObject.meteoDataInfo.print_property_info(
                )
                self.tabWidget.tab1UI(grib_property)
                self.headcontext = grib_property
                #self.fdict[str(file)] = [self.grpinfo, self.headcontext]
                root = QTreeWidgetItem(self)
                self.rootlist.append(root)
                root.setText(0, algorithmObject.fileName)
                # root.setText(1, algorithmObject.fileName)
                root.setText(1, 'Local File')
                root.setText(2, file)
                root.setText(3, 'GRIB')  #MessageID

        self.expandAll()  # 全部展开节点