add history
change table layer
This commit is contained in:
		
							parent
							
								
									cb9a09f23d
								
							
						
					
					
						commit
						53bd8c22e9
					
				
							
								
								
									
										5
									
								
								plugins/ai_method/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								plugins/ai_method/__init__.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,5 @@
 | 
			
		||||
from misc.utils import Register
 | 
			
		||||
 | 
			
		||||
AI_METHOD = Register('AI Method')
 | 
			
		||||
 | 
			
		||||
from .main import BasicPlugin
 | 
			
		||||
							
								
								
									
										16
									
								
								plugins/ai_method/main.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								plugins/ai_method/main.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,16 @@
 | 
			
		||||
from rscder.plugins.basic import BasicPlugin
 | 
			
		||||
from ai_method import AI_METHOD
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class AIPlugin(BasicPlugin):
 | 
			
		||||
 | 
			
		||||
    @staticmethod
 | 
			
		||||
    def info():
 | 
			
		||||
        return {
 | 
			
		||||
            'name': 'AI 变化检测',
 | 
			
		||||
            'author': 'RSC',
 | 
			
		||||
            'version': '1.0.0',
 | 
			
		||||
            'description': 'AI 变化检测',
 | 
			
		||||
            'category': 'Ai method'
 | 
			
		||||
        }
 | 
			
		||||
    
 | 
			
		||||
@ -43,8 +43,8 @@ class RateSetdialog(QDialog):
 | 
			
		||||
        self.cancel_button.clicked.connect(self.on_cancel)
 | 
			
		||||
        self.cancel_button.setDefault(False)
 | 
			
		||||
        self.buttonbox=QDialogButtonBox(self)
 | 
			
		||||
        self.buttonbox.addButton(self.ok_button,QDialogButtonBox.Ok)
 | 
			
		||||
        self.buttonbox.addButton(self.cancel_button,QDialogButtonBox.Cancel)
 | 
			
		||||
        self.buttonbox.addButton(self.ok_button,QDialogButtonBox.NoRole)
 | 
			
		||||
        self.buttonbox.addButton(self.cancel_button,QDialogButtonBox.NoRole)
 | 
			
		||||
        self.buttonbox.setCenterButtons(True)
 | 
			
		||||
        vlayout=QVBoxLayout()
 | 
			
		||||
        vlayout.addLayout(h1)
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,5 @@
 | 
			
		||||
from misc import AlgFrontend
 | 
			
		||||
from misc.utils import format_now
 | 
			
		||||
from osgeo import gdal, gdal_array
 | 
			
		||||
from skimage.filters import rank
 | 
			
		||||
from skimage.morphology import  rectangle
 | 
			
		||||
@ -77,7 +78,7 @@ class MeanFilter(AlgFrontend):
 | 
			
		||||
        ds = gdal.Open(pth)
 | 
			
		||||
        band_count = ds.RasterCount
 | 
			
		||||
 | 
			
		||||
        out_path = os.path.join(Project().other_path, 'mean_filter_{}.tif'.format(int(datetime.now().timestamp() * 1000)))
 | 
			
		||||
        out_path = os.path.join(Project().other_path, 'mean_filter_{}.tif'.format(format_now()))
 | 
			
		||||
        out_ds = gdal.GetDriverByName('GTiff').Create(out_path, ds.RasterXSize, ds.RasterYSize, band_count, ds.GetRasterBand(1).DataType)
 | 
			
		||||
        out_ds.SetProjection(ds.GetProjection())
 | 
			
		||||
        out_ds.SetGeoTransform(ds.GetGeoTransform())
 | 
			
		||||
 | 
			
		||||
@ -8,7 +8,7 @@ from rscder.utils.project import BasicLayer, ResultPointLayer
 | 
			
		||||
from misc.utils import format_now
 | 
			
		||||
 | 
			
		||||
def table_layer(pth:str,layer:BasicLayer, name, cdpath=None,
 | 
			
		||||
            th=0, method_info=dict(), send_message = None):
 | 
			
		||||
            th=0, method_info:dict=dict(), send_message = None):
 | 
			
		||||
    if send_message is not None:
 | 
			
		||||
        send_message.emit('正在计算表格结果...')
 | 
			
		||||
    cell_size = layer.layer_parent.cell_size
 | 
			
		||||
@ -17,7 +17,7 @@ def table_layer(pth:str,layer:BasicLayer, name, cdpath=None,
 | 
			
		||||
    ysize = ds.RasterYSize
 | 
			
		||||
    geo = ds.GetGeoTransform()
 | 
			
		||||
 | 
			
		||||
    out_csv = os.path.join(Project().other_path, f'{name}_table_result_{ format_now() }.csv')
 | 
			
		||||
    out_csv = os.path.join(Project().other_path, f'{name}_{ "_".join(method_info.values()) }_{ format_now() }.csv')
 | 
			
		||||
    yblocks = ysize // cell_size[1] + 1
 | 
			
		||||
    xblocks = xsize // cell_size[0] + 1
 | 
			
		||||
    with open(out_csv, 'w') as f:
 | 
			
		||||
 | 
			
		||||
@ -6,7 +6,7 @@ import datetime
 | 
			
		||||
 | 
			
		||||
def format_now():
 | 
			
		||||
 | 
			
		||||
    datetime.datetime.now().strftime('')
 | 
			
		||||
    return datetime.datetime.now().strftime('%Y_%m_%d_%H_%M_%S')
 | 
			
		||||
 | 
			
		||||
class Register:
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -232,9 +232,7 @@ class UnsupervisedPlugin(BasicPlugin):
 | 
			
		||||
            pth1 = falg.run_alg(pth1, name=name, send_message=self.send_message, **fparams)
 | 
			
		||||
            pth2 = falg.run_alg(pth2, name=name, send_message=self.send_message, **fparams)
 | 
			
		||||
            method_info['滤波算法'] = falg.get_name()
 | 
			
		||||
        else:
 | 
			
		||||
            method_info['滤波算法'] = '无'
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        cdpth = cdalg.run_alg(pth1, pth2, layer1.layer_parent,  send_message=self.send_message,**cdparams)
 | 
			
		||||
 | 
			
		||||
        if falg is not None:
 | 
			
		||||
 | 
			
		||||
@ -12,6 +12,7 @@ from .scripts import VEG_CD
 | 
			
		||||
from thres import THRES
 | 
			
		||||
from misc import table_layer, AlgSelectWidget
 | 
			
		||||
from follow import FOLLOW
 | 
			
		||||
import os
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class VegtationCDMethod(QDialog):
 | 
			
		||||
@ -149,19 +150,41 @@ class VegetationCDFollow(AlgFrontend):
 | 
			
		||||
            return
 | 
			
		||||
 | 
			
		||||
        name = layer1.name
 | 
			
		||||
        method_info = dict()
 | 
			
		||||
 | 
			
		||||
        if falg is not None:
 | 
			
		||||
            pth1 = falg.run_alg(
 | 
			
		||||
                pth1, name=name, send_message=send_message, **fparams)
 | 
			
		||||
            pth2 = falg.run_alg(
 | 
			
		||||
                pth2, name=name, send_message=send_message, **fparams)
 | 
			
		||||
 | 
			
		||||
            method_info['滤波算法'] = falg.get_name()
 | 
			
		||||
        if falg is not None:
 | 
			
		||||
            try:
 | 
			
		||||
                os.remove(pth1)
 | 
			
		||||
                os.remove(pth2)
 | 
			
		||||
                # send_message.emit('删除临时文件')
 | 
			
		||||
            except:
 | 
			
		||||
                # send_message.emit('删除临时文件失败!')
 | 
			
		||||
                pass
 | 
			
		||||
        cdpth = cdalg.run_alg(pth1, pth2, layer1.layer_parent,
 | 
			
		||||
                              send_message=send_message, **cdparams)
 | 
			
		||||
        thpth = thalg.run_alg(
 | 
			
		||||
        if falg is not None:
 | 
			
		||||
            try:
 | 
			
		||||
                os.remove(pth1)
 | 
			
		||||
                os.remove(pth2)
 | 
			
		||||
                # send_message.emit('删除临时文件')
 | 
			
		||||
            except:
 | 
			
		||||
                # send_message.emit('删除临时文件失败!')
 | 
			
		||||
                pass
 | 
			
		||||
        if cdpth is None:
 | 
			
		||||
            return
 | 
			
		||||
        thpth, th = thalg.run_alg(
 | 
			
		||||
            cdpth, name=name, send_message=send_message, **thparams)
 | 
			
		||||
 | 
			
		||||
        table_layer(thpth, layer1, name, send_message)
 | 
			
		||||
        method_info['变化检测算法'] = cdalg.get_name()
 | 
			
		||||
        method_info['二值化算法'] = thalg.get_name()
 | 
			
		||||
        # table_layer(thpth, layer1, name, send_message)
 | 
			
		||||
        table_layer(thpth, layer1, name, cdpath=cdpth, th=th,
 | 
			
		||||
                    method_info=method_info, send_message=send_message)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class VegtationPlugin(BasicPlugin):
 | 
			
		||||
@ -177,6 +200,7 @@ class VegtationPlugin(BasicPlugin):
 | 
			
		||||
 | 
			
		||||
    def set_action(self):
 | 
			
		||||
        veg_menu = ActionManager().veg_menu
 | 
			
		||||
        veg_toolbar = ActionManager().add_toolbar('Veg Change')
 | 
			
		||||
        # veg_menu.setIcon(IconInstance().UNSUPERVISED)
 | 
			
		||||
        # ActionManager().veg_menu.addMenu(veg_menu)
 | 
			
		||||
 | 
			
		||||
@ -186,11 +210,12 @@ class VegtationPlugin(BasicPlugin):
 | 
			
		||||
                name = key
 | 
			
		||||
            else:
 | 
			
		||||
                name = alg.get_name()
 | 
			
		||||
 | 
			
		||||
            
 | 
			
		||||
        
 | 
			
		||||
            action = QAction(name, veg_menu)
 | 
			
		||||
            func = partial(self.run_cd, alg)
 | 
			
		||||
            action.triggered.connect(func)
 | 
			
		||||
 | 
			
		||||
            veg_toolbar.addAction(action)
 | 
			
		||||
            veg_menu.addAction(action)
 | 
			
		||||
 | 
			
		||||
    def run_cd(self, alg):
 | 
			
		||||
@ -210,21 +235,36 @@ class VegtationPlugin(BasicPlugin):
 | 
			
		||||
 | 
			
		||||
        falg, fparams = w.filter_select.get_alg_and_params()
 | 
			
		||||
        cdalg = w.alg
 | 
			
		||||
        cdparams = w.alg.get_params()
 | 
			
		||||
        cdparams = w.alg.get_params(w.param_widget)
 | 
			
		||||
        thalg, thparams = w.thres_select.get_alg_and_params()
 | 
			
		||||
 | 
			
		||||
        if cdalg is None or thalg is None:
 | 
			
		||||
            return
 | 
			
		||||
        method_info = dict()
 | 
			
		||||
 | 
			
		||||
        if falg is not None:
 | 
			
		||||
            pth1 = falg.run_alg(
 | 
			
		||||
                pth1, name=name, send_message=self.send_message, **fparams)
 | 
			
		||||
            pth2 = falg.run_alg(
 | 
			
		||||
                pth2, name=name, send_message=self.send_message, **fparams)
 | 
			
		||||
            method_info['滤波算法'] = falg.get_name()
 | 
			
		||||
 | 
			
		||||
        cdpth = cdalg.run_alg(pth1, pth2, layer1.layer_parent,
 | 
			
		||||
                              send_message=self.send_message, **cdparams)
 | 
			
		||||
        thpth = thalg.run_alg(
 | 
			
		||||
        if cdpth is None:
 | 
			
		||||
            return
 | 
			
		||||
        if falg is not None:
 | 
			
		||||
            try:
 | 
			
		||||
                os.remove(pth1)
 | 
			
		||||
                os.remove(pth2)
 | 
			
		||||
                # send_message.emit('删除临时文件')
 | 
			
		||||
            except:
 | 
			
		||||
                # send_message.emit('删除临时文件失败!')
 | 
			
		||||
                pass
 | 
			
		||||
        thpth, th = thalg.run_alg(
 | 
			
		||||
            cdpth, name=name, send_message=self.send_message, **thparams)
 | 
			
		||||
 | 
			
		||||
        table_layer(thpth, layer1, name, self.send_message)
 | 
			
		||||
        method_info['变化检测算法'] = cdalg.get_name()
 | 
			
		||||
        method_info['二值化算法'] = thalg.get_name()
 | 
			
		||||
        # table_layer(thpth, layer1, name, self.send_message)
 | 
			
		||||
        table_layer(thpth, layer1, name, cdpath=cdpth, th=th,
 | 
			
		||||
                    method_info=method_info, send_message=self.send_message)
 | 
			
		||||
 | 
			
		||||
@ -100,7 +100,7 @@ class VFCCD(AlgFrontend):
 | 
			
		||||
 | 
			
		||||
        max_diff = 0
 | 
			
		||||
        min_diff = math.inf
 | 
			
		||||
        
 | 
			
		||||
        # print('xxxxxxxxx')
 | 
			
		||||
        start1x,start1y=geo2imageRC(ds1.GetGeoTransform(),layer_parent.mask.xy[0],layer_parent.mask.xy[1])
 | 
			
		||||
        end1x,end1y=geo2imageRC(ds1.GetGeoTransform(),layer_parent.mask.xy[2],layer_parent.mask.xy[3])
 | 
			
		||||
 | 
			
		||||
@ -124,19 +124,25 @@ class VFCCD(AlgFrontend):
 | 
			
		||||
                block_size1 = (xsize,end1y - block_xy1[1])
 | 
			
		||||
            if block_xy2[1] + block_size2[1] > end2y:
 | 
			
		||||
                block_size2 = (xsize, end2y - block_xy2[1]) 
 | 
			
		||||
            
 | 
			
		||||
            if block_size1[0] * block_size1[1] == 0 or block_size2[0] * block_size2[1] == 0:
 | 
			
		||||
                continue
 | 
			
		||||
            block_data1 = ds1.ReadAsArray(*block_xy1, *block_size1)
 | 
			
		||||
            block_data2 = ds2.ReadAsArray(*block_xy2, *block_size2)
 | 
			
		||||
            ndvi1 = (block_data1[nir] - block_data1[red])/((block_data1[nir] + block_data1[red]) + 1e-6)
 | 
			
		||||
            ndvi2 = (block_data2[nir] - block_data2[red])/((block_data2[nir] + block_data2[red]) + 1e-6)
 | 
			
		||||
            ndvi1[ndvi1 < 0] = 0
 | 
			
		||||
            ndvi1[ndvi1 > 1] = 1
 | 
			
		||||
            ndvi2[ndvi2 > 1] = 1
 | 
			
		||||
            ndvi2[ndvi2 < 0] = 0
 | 
			
		||||
            # pdb.set_trace()
 | 
			
		||||
            block_diff = ndvi1 - ndvi2
 | 
			
		||||
            block_diff = block_diff.astype(np.float32)
 | 
			
		||||
            block_diff = np.abs(block_diff)
 | 
			
		||||
            
 | 
			
		||||
            
 | 
			
		||||
            min_diff = min(min_diff, block_diff[block_diff > 0].min())
 | 
			
		||||
            max_diff = max(max_diff, block_diff.max())
 | 
			
		||||
            max_diff = max(max_diff, block_diff[block_diff <= 1].max())
 | 
			
		||||
            out_ds.GetRasterBand(1).WriteArray(block_diff, *block_xy)
 | 
			
		||||
            if send_message is not None:
 | 
			
		||||
 | 
			
		||||
@ -147,6 +153,8 @@ class VFCCD(AlgFrontend):
 | 
			
		||||
        del out_ds
 | 
			
		||||
        if send_message is not None:
 | 
			
		||||
            send_message.emit('归一化概率中...')
 | 
			
		||||
            send_message.emit(f'max pixel {max_diff}')
 | 
			
		||||
            send_message.emit(f'min pixel {min_diff}')
 | 
			
		||||
        temp_in_ds = gdal.Open(out_tif) 
 | 
			
		||||
        
 | 
			
		||||
        out_normal_tif = os.path.join(Project().cmi_path, '{}_{}_cmi.tif'.format(layer_parent.name, int(np.random.rand() * 100000)))
 | 
			
		||||
 | 
			
		||||
@ -106,7 +106,7 @@ class ActionManager(QtCore.QObject):
 | 
			
		||||
        if path is not None:
 | 
			
		||||
            Settings.General().history = path
 | 
			
		||||
        history = Settings.General().history
 | 
			
		||||
        print(history)
 | 
			
		||||
        # print(history)
 | 
			
		||||
        def reopen(p):
 | 
			
		||||
            if Project().is_init:
 | 
			
		||||
                Project().save()
 | 
			
		||||
 | 
			
		||||
@ -92,7 +92,7 @@ class Settings(QSettings):
 | 
			
		||||
 | 
			
		||||
        @history.setter
 | 
			
		||||
        def history(self, v:str):
 | 
			
		||||
            print(v)
 | 
			
		||||
            # print(v)
 | 
			
		||||
            with Settings(Settings.General.PRE) as s:
 | 
			
		||||
                history:list = s.value('history', [])
 | 
			
		||||
            if v in history:
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user