-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmean_filter_3x3.py
50 lines (38 loc) · 1.37 KB
/
mean_filter_3x3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
from os.path import *
#from osgeo import gdal, ogr,osr
import numpy as np
import scipy
import rasterio as rio
work_dir = r'E:\work\change_detect_solo'
gran = "T18SUJ"
gran_dir = join(work_dir, gran)
temp_slope_dir = join(gran_dir,'temp_slope')
chang_dir = join(gran_dir,'change')
time_stats_dir = join(gran_dir,'time_stats')
vec_dir = join(gran_dir,'vec')
bnum = '1'
date_num = join(chang_dir, f'{gran}_b{bnum}_date_num.tif')
ts_std = join(chang_dir,f'{gran}_b{bnum}_stacktempslope_std.tif')
out_name = f'{gran}_b{bnum}_tempslope_std_focal_filter.tif'
out_path = join(chang_dir,out_name)
src = rio.open(ts_std)
arr_ch = src.read()
ch_pro = src.profile
#output_raster = np.full_like(arr_ch, -32767)
#thank you Geoprocessing with Python
arr_avg_std = scipy.ndimage.uniform_filter(arr_ch,size=3,mode='nearest')
print(f'Writing {out_name}')
with rio.open(out_path, "w", **ch_pro) as dst:
dst.write(arr_avg_std)
out_name = f'{gran}_b{bnum}_date_num_focal_filter.tif'
out_path = join(chang_dir, out_name)
src = rio.open(date_num)
arr_ch = src.read()
ch_pro = src.profile
# output_raster = np.full_like(arr_ch, -32767)
# thank you Geoprocessing with Python
arr_avg_std = scipy.ndimage.uniform_filter(arr_ch, size=3, mode='nearest')
print(f'Writing {out_name}')
with rio.open(out_path, "w", **ch_pro) as dst:
dst.write(arr_avg_std)