diff --git a/dzetsaka.py b/dzetsaka.py index 868a381..a21fb7e 100644 --- a/dzetsaka.py +++ b/dzetsaka.py @@ -432,6 +432,13 @@ def loadMenu(self): self.menu.filterMedian = QAction(QIcon(":/plugins/dzetsaka/img/filter.png"), "Median", self.iface.mainWindow()) QObject.connect(self.menu.filterMedian, SIGNAL("triggered()"), self.loadFilters) filterMenu.addAction(self.menu.filterMedian) + + ## Separator + filterMenu.addSeparator() + + self.menu.filterClass = QAction(QIcon(":/plugins/dzetsaka/img/historicalmap.png"), "Classification to Vector (single class)", self.iface.mainWindow()) + QObject.connect(self.menu.filterClass, SIGNAL("triggered()"), self.loadHistoricalMap) + filterMenu.addAction(self.menu.filterClass) ## Separator filterMenu.addSeparator() @@ -774,9 +781,10 @@ def loadHistoricalMap(self): """!@brief Load and init historical map dock""" self.historicalmap = historical_dock() - self.historicalmap.show() - + if self.sender()==self.menu.filterClass: + self.historicalmap.tabWidget.setCurrentIndex(1) + self.historicalmap.show() # save raster self.historicalmap.outRasterButton.clicked.connect(self.select_output_file) diff --git a/metadata.txt b/metadata.txt index cbfdcee..cc2e584 100644 --- a/metadata.txt +++ b/metadata.txt @@ -1,4 +1,4 @@ -# This file contains metadata for your plugin. Since +# This file contains metadata for your plugin. Since # version 2.0 of QGIS this is the proper way to supply # information about a plugin. The old method of # embedding metadata in __init__.py will @@ -8,7 +8,7 @@ [general] name=dzetsaka : Classification tool -qgisMinimumVersion=2.0 +qgisMinimumVersion=2.0.1 description=Fast and Easy Classification plugin for Qgis version=2.0 author=Nicolaï Van Lennepkade @@ -23,7 +23,7 @@ repository=http://www.github.com/lennepkade/dzetsaka # Recommended items: # Uncomment the following line and add your changelog: -changelog= Now support Random Forest, SVM and KNN classifiers. Correct some bugs and add settings management. +changelog= Now support Random Forest, SVM and KNN classifiers (v2.0). Correct some bugs (split classification) and add classification to vector in filters menu. # Tags are comma separated with spaces allowed tags=classification,semi-automatic,gaussian,mixture,model,random forest,svm,knn,forest diff --git a/scripts/mainfunction.py b/scripts/mainfunction.py index 5dd2ed0..8776869 100644 --- a/scripts/mainfunction.py +++ b/scripts/mainfunction.py @@ -103,7 +103,7 @@ def __init__(self,inRaster,inVector,inField='Class',outModel=None,inSplit=1,inSe learningProgress.addStep() # Add Step to ProgressBar # Learning process take split of groundthruth pixels for training and the remaining for testing - """ + try: if SPLIT < 1: @@ -128,7 +128,7 @@ def __init__(self,inRaster,inVector,inField='Class',outModel=None,inSplit=1,inSe #Add Pb except: QgsMessageLog.logMessage("Problem while learning if SPLIT <1") - """ + x,y=X,Y @@ -150,12 +150,20 @@ def __init__(self,inRaster,inVector,inField='Class',outModel=None,inSplit=1,inSe from sklearn.ensemble import RandomForestClassifier from sklearn.cross_validation import StratifiedKFold from sklearn.grid_search import GridSearchCV - try: + try: + + # AS Qgis in Windows doensn't manage multiprocessing, force to use 1 thread for not linux system + if os.name == 'posix': + n_jobs=-1 + else: + n_jobs=1 + + # if inClassifier == 'RF': param_grid_rf = dict(n_estimators=3**sp.arange(1,5),max_features=sp.arange(1,4)) y.shape=(y.size,) cv = StratifiedKFold(y, n_folds=3) - grid = GridSearchCV(RandomForestClassifier(), param_grid=param_grid_rf, cv=cv,n_jobs=1) + grid = GridSearchCV(RandomForestClassifier(), param_grid=param_grid_rf, cv=cv,n_jobs=n_jobs) grid.fit(x, y) model = grid.best_estimator_ model.fit(x,y) @@ -163,7 +171,7 @@ def __init__(self,inRaster,inVector,inField='Class',outModel=None,inSplit=1,inSe param_grid_svm = dict(gamma=2.0**sp.arange(-4,4), C=10.0**sp.arange(-2,5)) y.shape=(y.size,) cv = StratifiedKFold(y, n_folds=5) - grid = GridSearchCV(SVC(), param_grid=param_grid_svm, cv=cv,n_jobs=1) + grid = GridSearchCV(SVC(), param_grid=param_grid_svm, cv=cv,n_jobs=n_jobs) grid.fit(x, y) model = grid.best_estimator_ model.fit(x,y) @@ -171,7 +179,7 @@ def __init__(self,inRaster,inVector,inField='Class',outModel=None,inSplit=1,inSe param_grid_knn = dict(n_neighbors = sp.arange(1,20,4)) y.shape=(y.size,) cv = StratifiedKFold(y, n_folds=3) - grid = GridSearchCV(neighbors.KNeighborsClassifier(), param_grid=param_grid_knn, cv=cv,n_jobs=1) + grid = GridSearchCV(neighbors.KNeighborsClassifier(), param_grid=param_grid_knn, cv=cv,n_jobs=n_jobs) grid.fit(x, y) model = grid.best_estimator_ model.fit(x,y)