def get_padded_feature_stack(window_size, correction_switch, degree, pad=-1): eigen_full=extract_polarimetric.eigen_raster_full(window_size, correction_switch, degree) #9 is the window size cov_arr=extract_polarimetric.extract_covariance_arr(window_size, correction_switch, degree) #padding=int(np.floor(window_size/2)) padding=window_size//2 if pad!=0 else 0 Ihh=np.pad(cov_arr[...,0,0], padding, 'constant') Ihv=np.pad(cov_arr[...,1,1], padding, 'constant') Ivv=np.pad(cov_arr[...,2,2], padding, 'constant') arr_lamb1=np.pad(eigen_full[:,:,2], padding, 'constant') arr_lamb2=np.pad(eigen_full[:,:,1], padding, 'constant') arr_lamb3=np.pad(eigen_full[:,:,0], padding, 'constant') co_pol_dif=np.pad(extract_polarimetric.co_pol_diff(cov_arr), padding, 'constant') arr_det_cov=np.pad(np.absolute(extract_polarimetric.determinant_cov_conj(cov_arr)), padding, 'constant') R_co = Rco_X = np.pad(np.real(cov_arr[...,0,2]), padding, 'constant') Ico_X = np.pad(np.absolute(np.imag(cov_arr[...,0,2])), padding, 'constant') #return np.dstack((np.real(Ihh),np.real(Ihv),np.real(Ivv),np.real(arr_lamb1), np.real(arr_lamb2), np.real(arr_lamb3), np.absolute(co_pol_dif),R_co, Ico_X, np.absolute(arr_det_cov))) return np.dstack((np.real(Ihh),np.real(Ihv),np.real(Ivv),np.real(arr_lamb1), np.real(arr_lamb2), np.real(arr_lamb3), np.absolute(co_pol_dif), np.absolute(arr_det_cov)))#,R_co, Ico_X
def plot_feature_space_test(window_size): eigen_arr = extract_polarimetric.eigen_raster_full(window_size) cov_arr = extract_polarimetric.extract_covariance_arr(window_size, False) cppr = np.absolute(extract_polarimetric.co_pol_power_ratio_1(cov_arr)) co_pol_diff = np.absolute(extract_polarimetric.co_pol_diff(cov_arr)) lambda_3 = np.absolute(eigen_arr[:, :, 0]) plot_feature_space(co_pol_diff, lambda_3)
def polarimetric_features(window_size): fig, ax = plt.subplots(nrows=2, ncols=3) #arr=extract_polarimetric.eigen_raster_full(window_size) cov_arr = extract_polarimetric.extract_covariance_arr(window_size, False) plt.subplot(2, 3, 1) plt.imshow(np.absolute(extract_polarimetric.co_pol_power_ratio_1(cov_arr)), cmap='gray') plt.xlabel('Range') plt.ylabel('Azimuth') plt.title('Ivv/Ihh (Co-pol power ratio)') plt.colorbar() plt.subplot(2, 3, 2) plt.imshow(np.absolute(extract_polarimetric.determinant_cov(cov_arr)), cmap='gray') plt.xlabel('Range') plt.ylabel('Azimuth') plt.title('Det(Cov)') plt.colorbar() plt.subplot(2, 3, 3) plt.imshow(np.absolute(extract_polarimetric.co_pol_diff(cov_arr)), cmap='gray') plt.xlabel('Range') plt.ylabel('Azimuth') plt.title('Co-pol diff (Ihh-Ivv)') plt.colorbar() plt.subplot(2, 3, 4) plt.imshow(np.real(extract_polarimetric.co_pol_cross_product(cov_arr)), cmap='gray') plt.xlabel('Range') plt.ylabel('Azimuth') plt.title('Real(ShhSvv) co-pol cross_product') plt.colorbar() plt.subplot(2, 3, 5) plt.imshow(np.imag(extract_polarimetric.co_pol_cross_product(cov_arr)), cmap='gray') plt.xlabel('Range') plt.ylabel('Azimuth') plt.title('Imag(ShhSvv) Co-pol cross_product') plt.colorbar() plt.show()
def read_Pol_features(window_size, correction_switch, degree, rescale_switch = False, log_Transform_switch = False): #os.chdir('../') eigen_full = extract_polarimetric.eigen_raster_full(window_size, correction_switch, degree) #9 is the window size cov_arr = extract_polarimetric.extract_covariance_arr(window_size, correction_switch, degree) arr_lamb1=np.absolute(eigen_full[:,:,2]) arr_lamb2=np.absolute(eigen_full[:,:,1]) arr_lamb3=np.absolute(eigen_full[:,:,0]) co_pol_dif=np.absolute(extract_polarimetric.co_pol_diff(cov_arr)) arr_det_cov=np.absolute(extract_polarimetric.determinant_cov_conj(cov_arr)) Rco_X = np.real(cov_arr[...,0,2]) Ico_X = abs(np.imag(cov_arr[...,0,2])) I_hh = np.absolute(cov_arr[...,0,0]) I_hv = np.absolute(cov_arr[...,1,1]) I_vv = np.absolute(cov_arr[...,2,2]) if (log_Transform_switch ==True): arr_lamb1 = np.log10(arr_lamb1) arr_lamb2 = np.log10(arr_lamb2) arr_lamb3 = np.log10(arr_lamb3) co_pol_dif = np.log10(co_pol_dif) arr_det_cov = np.log10(arr_det_cov) Rco_X = np.log10(Rco_X) Ico_X = np.log10(Ico_X) I_hh = np.log10(I_hh) I_hv = np.log10(I_hv) I_vv = np.log10(I_vv) if(rescale_switch == True): arr_lamb1=rescale(arr_lamb1) arr_lamb2=rescale(arr_lamb2) arr_lamb3=rescale(arr_lamb3) co_pol_dif = rescale(co_pol_dif) arr_det_cov = rescale(arr_det_cov) Rco_X = rescale(Rco_X) Ico_X = rescale(Ico_X) I_hh = rescale(I_hh) I_hv = rescale(I_hv) I_vv = rescale(I_vv) #if(log_Transform_switch ==True): #return 10*np.log10(np.dstack((arr_lamb1, arr_lamb2, arr_lamb3, co_pol_dif, arr_det_cov, Rco_X, Ico_X, I_hh, I_hv, I_vv))) #else: return np.dstack((arr_lamb1, arr_lamb2, arr_lamb3, co_pol_dif, arr_det_cov, Rco_X, Ico_X, I_hh, I_hv, I_vv))
def polarimetric_features(window_size, correction_switch): #fig, ax = plt.subplots(nrows=2, ncols=3) #arr=extract_polarimetric.eigen_raster_full(window_size) cov_arr = extract_polarimetric.extract_covariance_arr( window_size, correction_switch) #plt.subplot(2,3,1) plt.imshow(np.absolute(extract_polarimetric.co_pol_power_ratio_1(cov_arr)), cmap='gray') plt.xlabel('Range') plt.ylabel('Azimuth') plt.title('Ivv/Ihh (Co-pol power ratio)') plt.colorbar() plt.savefig('/home/anurag/Documents/MScProject/Meetings_ITC/Results/' + 'Ivv-Ihh_(Co-pol power ratio)' + '.tiff', dpi=300) plt.clf() #plt.subplot(2,3,2) plt.imshow(incidence_angle_corr.hist_stretch( np.absolute(extract_polarimetric.determinant_cov(cov_arr)), 6), cmap='gray') plt.xlabel('Range') plt.ylabel('Azimuth') plt.title('Det(Cov)') plt.colorbar() plt.savefig('/home/anurag/Documents/MScProject/Meetings_ITC/Results/' + 'Det(Cov)_stretched' + '.tiff', dpi=300) plt.clf() #plt.subplot(2,3,2) plt.imshow(np.absolute(extract_polarimetric.determinant_cov(cov_arr)), cmap='gray') plt.xlabel('Range') plt.ylabel('Azimuth') plt.title('Det(Cov)') plt.colorbar() plt.savefig('/home/anurag/Documents/MScProject/Meetings_ITC/Results/' + 'Det(Cov)' + '.tiff', dpi=300) plt.clf() #plt.subplot(2,3,3) plt.imshow(np.absolute(extract_polarimetric.co_pol_diff(cov_arr)), cmap='gray') plt.xlabel('Range') plt.ylabel('Azimuth') plt.title('Co-pol diff (Ihh-Ivv)') plt.colorbar() plt.savefig('/home/anurag/Documents/MScProject/Meetings_ITC/Results/' + 'Co-pol diff(Ihh-Ivv)' + '.tiff', dpi=300) plt.clf() #plt.subplot(2,3,4) plt.imshow(np.real(extract_polarimetric.co_pol_cross_product(cov_arr)), cmap='gray') plt.xlabel('Range') plt.ylabel('Azimuth') plt.title('Real(ShhSvv) co-pol cross_product') plt.colorbar() plt.savefig('/home/anurag/Documents/MScProject/Meetings_ITC/Results/' + 'Real(ShhSvv) co-pol cross_product' + '.tiff', dpi=300) plt.clf() #plt.subplot(2,3,5) plt.imshow(np.imag(extract_polarimetric.co_pol_cross_product(cov_arr)), cmap='gray') plt.xlabel('Range') plt.ylabel('Azimuth') plt.title('Imag(ShhSvv) Co-pol cross_product') plt.colorbar() plt.savefig('/home/anurag/Documents/MScProject/Meetings_ITC/Results/' + 'Imag(ShhSvv) Co-pol cross_product', dpi=300) plt.clf()
def main(): plot_all_UAVSAR_data_takes() sys.exit() #UAVSAR_directory_name_prep base_dir = '../North_Sea_UAVSAR/UAV_norway' file_ext = [ '.ann', '.dat', '.gif', '.hgt', '.inc', '.kmz', '.slope', '_hgt.tif', '_pauli.tif' ] #folders=['_mlc','_grd'] dType = 'grd' Region = 'norway' Heading = '007' Counter_num = '09' Year = '15' Num_flights_year = '092' Data_take = '000' Day = '10' Month = '06' Band = 'L' Steering_angle = '090' Cross_talk = 'CX' Processing_version = '01' Polarization = 'HHHV' #==================================================== Is_List_Ratio = False Cropping_switch = True Reproject_switch = False Plotting_switch = True Convolution_switch = False Inc_correction_switch = False Window_size_fea = 9 Inc_correction_sin_degree = 3 #==================================================== wd = getdir(region=Region, heading=Heading, counter_num=Counter_num, year=Year, num_flights_year=Num_flights_year, data_take=Data_take, day=Day, month=Month, band=Band, steering_angle=Steering_angle, cross_talk=Cross_talk, processing_version=Processing_version) base_file_name = get_base_file_name(region=Region, heading=Heading, counter_num=Counter_num, year=Year, num_flights_year=Num_flights_year, data_take=Data_take, day=Day, month=Month, band=Band, steering_angle=Steering_angle, cross_talk=Cross_talk, processing_version=Processing_version) os.chdir(wd) #print(os.getcwd()) #=======+Get Matadata======== meta = metadata_dict(base_file_name) #===============SLC======================== #directory_SLC='/home/anurag/Documents/MScProject/SAR/OilSpill/North_Sea_UAVSAR/UAV_norway/UA_norway_00709_15092_000_150610_L090_CX_02' #print(slc_file_name) #print(os.getcwd()) #print(meta) #print(os.getcwd()) #os.chdir(directory_SLC) #slc_VV=get_SLC(meta,base_file_name, polarization='VV', dType='slc') #slc_HH=get_SLC(meta,base_file_name, polarization='HH', dType='slc') #=============Defining the subset===================== if dType == 'mlc': grd_cropping_list_00709 = [521, 1543, 4049, 5233] #[2000,3500,2500,4000] grd_cropping_list_18709 = [1000, 2300, 3250, 4450] elif dType == 'grd': grd_cropping_list_00709 = [2000, 3500, 2500, 4000] grd_cropping_list_18709 = [900, 2400, 3150, 4650] if Heading == '007': cropping_list_GRD = grd_cropping_list_00709 if (Counter_num == '10'): cropping_list_GRD = [2500, 4000, 2500, 4000] elif Heading == '187': cropping_list_GRD = grd_cropping_list_18709 if (Counter_num == '10'): cropping_list_GRD = [1400, 2900, 3150, 4650] elif Heading == '142': cropping_list_GRD = [2500, 4000, 2500, 4000] #===========Defining Convolution keranl=========== Convolution_kernal = kernal(Window_size_fea) #============incidence angle================= grd_lines = int(meta['grd_pwr.set_rows']) grd_samples = int(meta['grd_pwr.set_cols']) inc_ang_arr = get_inc_angle(grd_lines, grd_samples, base_file_name, cropping_list_GRD, cropping_switch=Cropping_switch, is_List_Ratio=Is_List_Ratio) #plt.imshow(inc_ang_arr) #plt.show() #=============Extract GRD Component===================== get_GRD_MLC(dType, meta, base_file_name, Convolution_kernal, inc_ang_arr, component=Polarization, grd_cropping_list=cropping_list_GRD, is_List_Ratio=False, cropping_switch=True, reproject_switch=False, plotting_switch=True, convolution_switch=True, inc_correction_switch=True) #=============Plot all data takes======================= #==================Get covariance matrix=============== cov_arr = get_covariance_matrix_grd( dType, meta, base_file_name, Convolution_kernal, inc_ang_arr, inc_correction_sin_degree=Inc_correction_sin_degree, cropping_list_GRD=cropping_list_GRD, is_List_Ratio=Is_List_Ratio, cropping_switch=Cropping_switch, convolution_switch=Convolution_switch, inc_correction_switch=Inc_correction_switch) #=============Convert to T3========= coh_arr = get_coherecy_matrix_grd(cov_arr) ######################################### #============Extraction of Pol. Features=========== ######################################### eigen_raster = eigen_raster_full(coh_arr) arr_lamb1 = eigen_raster[:, :, 2] arr_lamb2 = eigen_raster[:, :, 1] arr_lamb3 = eigen_raster[:, :, 0] #============get_co_pol_diff============ co_pol_diff = extract_polarimetric.co_pol_diff(cov_arr) #================Plotting lambda 3 and co_pol diff=============== #import sys #sys.exit() plt.subplot(221) plt.imshow(10 * np.log10(np.absolute(arr_lamb1))) plt.colorbar() plt.subplot(222) plt.imshow(10 * np.log10(np.absolute(arr_lamb2))) plt.colorbar() plt.subplot(223) plt.imshow(10 * np.log10(np.absolute(arr_lamb3))) plt.colorbar() plt.subplot(224) plt.imshow(np.log10(np.absolute(co_pol_diff))) plt.colorbar() plt.show() ###################################### #=================EPFS=============== ###################################### ncomp = 3 tolerance = 0.0001 num_initialization = 1 max_iteration = 200 correction_switch = True window_size_fea = 9 window_size_smoo = 1 #35 window_size_boun = 3 bin_size = 400 font_size = 15 #-------Plot histogram-------- arr_1 = EPFS.rescale(np.log10(np.absolute(arr_lamb3)), clip_extremes=False) arr_3 = EPFS.rescale(np.log10(np.absolute(arr_lamb2)), clip_extremes=False) arr_4 = EPFS.rescale(np.log10(np.absolute(arr_lamb1)), clip_extremes=False) arr_2 = EPFS.rescale(np.log10(np.absolute(co_pol_diff)), clip_extremes=False) plt.hist(arr_1.flatten(), bins=bin_size, rwidth=0.5, histtype='step', label='$\lambda_{3}$') plt.hist(arr_3.flatten(), bins=bin_size, rwidth=0.5, histtype='step', label='$\lambda_{2}$') plt.hist(arr_4.flatten(), bins=bin_size, rwidth=0.5, histtype='step', label='$\lambda_{1}$') plt.hist(arr_2.flatten(), bins=bin_size, rwidth=0.5, histtype='step', label='PD') plt.xlabel('Normalized values', fontsize=font_size) plt.ylabel('Frequency', fontsize=font_size) plt.legend() plt.show() #==========Stack of features=============== feature_stack = np.dstack((arr_1, arr_2, arr_3, arr_4, cov_arr[..., 2, 2])) #-------Perform EPFS----------- gmm = EPFS.gmm_fitting_1(feature_stack, ncomp, tolerance=tolerance, num_initial=num_initialization, max_iteration=max_iteration) EPFS.plot_result(feature_stack, gmm, ncomp) #plt.show() #=========Co-pol_phase_diff=========== '''
def plot_all_UAVSAR_data_takes(): matplotlib.rcParams.update({'font.size': 3}) #files = ['UA_norway_00709_15091_000_150610_L090_CX_01', 'UA_norway_18709_15091_001_150610_L090_CX_01', #'UA_norway_00710_15091_002_150610_L090_CX_01', 'UA_norway_18710_15091_003_150610_L090_CX_01', #'UA_norway_00709_15091_004_150610_L090_CX_01', 'UA_norway_18709_15091_005_150610_L090_CX_01', #'UA_norway_00710_15091_006_150610_L090_CX_01', 'UA_norway_18709_15091_007_150610_L090_CX_01', #'UA_norway_00709_15091_008_150610_L090_CX_01', 'UA_norway_18709_15091_009_150610_L090_CX_01', #'UA_norway_00709_15091_010_150610_L090_CX_01', 'UA_norway_18709_15091_011_150610_L090_CX_01', #'UA_norway_00709_15091_012_150610_L090_CX_01', 'UA_norway_18709_15091_013_150610_L090_CX_01', #'UA_norway_00709_15091_014_150610_L090_CX_01', 'UA_norway_14203_15091_015_150610_L090_CX_01', #'UA_norway_00709_15092_000_150610_L090_CX_01', 'UA_norway_18709_15092_001_150610_L090_CX_01', #'UA_norway_00709_15092_002_150610_L090_CX_01', 'UA_norway_18709_15092_003_150610_L090_CX_01', #'UA_norway_00709_15092_004_150610_L090_CX_01', 'UA_norway_18709_15092_005_150610_L090_CX_01'] files = [ 'UA_norway_00709_15091_000_150610_L090_CX_01', 'UA_norway_00709_15091_004_150610_L090_CX_01', 'UA_norway_00709_15091_008_150610_L090_CX_01', 'UA_norway_00709_15091_010_150610_L090_CX_01', 'UA_norway_00709_15091_012_150610_L090_CX_01', 'UA_norway_00709_15091_014_150610_L090_CX_01', 'UA_norway_00709_15092_000_150610_L090_CX_01', 'UA_norway_00709_15092_002_150610_L090_CX_01', 'UA_norway_00709_15092_004_150610_L090_CX_01' ] for i, dir_base_file_name in enumerate(files): #dType = 'grd' dType = 'mlc' Region = 'norway' Heading = dir_base_file_name[10:13] Counter_num = dir_base_file_name[13:15] Year = '15' Num_flights_year = dir_base_file_name[18:21] Data_take = dir_base_file_name[22:25] Day = '10' Month = '06' Band = 'L' Steering_angle = '090' Cross_talk = 'CX' Processing_version = '01' Polarization = 'VVVV' #==================================================== Is_List_Ratio = False Cropping_switch = True Reproject_switch = False Plotting_switch = True Convolution_switch = True Inc_correction_switch = True Window_size_fea = 9 Inc_correction_sin_degree = 2 #==================================================== ncomp = 6 tolerance = 0.0001 num_initialization = 1 max_iteration = 200 window_size_smoo = 35 bin_size = 400 #===================================================== wd = getdir(region=Region, heading=Heading, counter_num=Counter_num, year=Year, num_flights_year=Num_flights_year, data_take=Data_take, day=Day, month=Month, band=Band, steering_angle=Steering_angle, cross_talk=Cross_talk, processing_version=Processing_version) base_file_name = get_base_file_name( region=Region, heading=Heading, counter_num=Counter_num, year=Year, num_flights_year=Num_flights_year, data_take=Data_take, day=Day, month=Month, band=Band, steering_angle=Steering_angle, cross_talk=Cross_talk, processing_version=Processing_version) os.chdir(wd) #print(os.getcwd()) #=======+Get Matadata======== meta = metadata_dict(base_file_name) #=============Defining the subset===================== if dType == 'mlc': grd_cropping_list_00709 = [521, 1543, 4049, 5233] #[2000,3500,2500,4000] grd_cropping_list_18709 = [1000, 2300, 3250, 4450] elif dType == 'grd': grd_cropping_list_00709 = [2000, 3500, 2500, 4000] grd_cropping_list_18709 = [900, 2400, 3150, 4650] if Heading == '007': cropping_list_GRD = grd_cropping_list_00709 if (Counter_num == '10'): cropping_list_GRD = [2500, 4000, 2500, 4000] elif Heading == '187': cropping_list_GRD = grd_cropping_list_18709 if (Counter_num == '10'): cropping_list_GRD = [1400, 2900, 3150, 4650] elif Heading == '142': cropping_list_GRD = [2500, 4000, 2500, 4000] #===========Defining Convolution keranl=========== Convolution_kernal = kernal(Window_size_fea) #============incidence angle================= grd_lines = int(meta['grd_pwr.set_rows']) grd_samples = int(meta['grd_pwr.set_cols']) inc_ang_arr = get_inc_angle(grd_lines, grd_samples, base_file_name, cropping_list_GRD, cropping_switch=Cropping_switch, is_List_Ratio=Is_List_Ratio) #inc_ang_arr = 0 #plt.imshow(inc_ang_arr) #plt.show() #=============Extract GRD Component and plotting===================== plt.subplot(4, 6, i + 1) #grd_data = get_GRD_MLC(dType,meta, base_file_name,Convolution_kernal, inc_ang_arr, component = Polarization,grd_cropping_list=cropping_list_GRD, is_List_Ratio=False, cropping_switch=True, reproject_switch=False, plotting_switch=True, convolution_switch = True, inc_correction_switch=False, save_plot_switch = False) #time_stamp = meta['Date of Acquisition'][12:17] #plt.title(time_stamp + ['AM' if int(time_stamp[:2])<12 else ' PM' ][0], fontsize = 4) #plt.ylabel('Longitude' if((i)%6==0) else '', fontsize = 7) #plt.xlabel('Latitude' if (i>=18) else '', fontsize = 7) #plt.savefig('/home/anurag/Documents/MScProject/Meetings_ITC/Results/All_UAVSAR_plot_grd.tiff', dpi=300,bbox_inches='tight') #plt.show() cov_arr = get_covariance_matrix_grd( dType, meta, base_file_name, Convolution_kernal, inc_ang_arr, inc_correction_sin_degree=Inc_correction_sin_degree, cropping_list_GRD=cropping_list_GRD, is_List_Ratio=Is_List_Ratio, cropping_switch=Cropping_switch, convolution_switch=Convolution_switch, inc_correction_switch=Inc_correction_switch) #=============Convert to T3========= coh_arr = get_coherecy_matrix_grd(cov_arr) ######################################### #============Extraction of Pol. Features=========== ######################################### eigen_raster = eigen_raster_full(coh_arr) arr_lamb1 = eigen_raster[:, :, 2] arr_lamb2 = eigen_raster[:, :, 1] arr_lamb3 = eigen_raster[:, :, 0] #============get_co_pol_diff============ co_pol_diff = extract_polarimetric.co_pol_diff(cov_arr) arr_1 = 10 * np.log10(np.absolute(arr_lamb3)) arr_2 = 10 * np.log10(np.absolute(co_pol_diff)) feature_stack = np.dstack( (arr_1, arr_2)) #, arr_3, arr_4, cov_arr[...,2,2])) #-------Perform EPFS----------- gmm = EPFS.gmm_fitting_1(feature_stack, ncomp, tolerance=tolerance, num_initial=num_initialization, max_iteration=max_iteration) X = EPFS.prepare_X_all(feature_stack) shp = feature_stack.shape[:2] res = gmm.predict(X).reshape(shp[0], shp[1]) im = plt.imshow(res.reshape(shp[0], shp[1]), cmap='RdYlBu') plt.ylabel('Azimuth' if ((i) % 6 == 0) else '', fontsize=7) plt.xlabel('Range' if (i >= 18) else '', fontsize=7) time_stamp = meta['Date of Acquisition'][12:17] plt.title(time_stamp + ['AM' if int(time_stamp[:2]) < 12 else ' PM'][0], fontsize=4) plt.tight_layout() #plt.savefig('/home/anurag/Documents/MScProject/Meetings_ITC/Results/Segmentation/Multi_temporal/Segmentation_ncomp_{}_inc_corr_degree_{}_tol10E-4.tiff'.format(str(ncomp),str(Inc_correction_sin_degree)), dpi=300,bbox_inches='tight') plt.show()