def main(): #%%################### ## PREPROCESSING #%% #Load Context damp = 1.0 Context = L_Context.Load_Context(wdir) #Load ellipses and compute synthetic observation Observation, tita = L_ReadObs.Load_PKL_Obs( HDFfilename, Context, Band) #Load Observations & Kernels #Compute cell in the grid considered as MARGIN-CELLS (for correct error estimation) L_Syn_Img.Set_Margins(Context) for i in range(10): #Create Synthetic Image TbH = L_Syn_Img.Create_Random_Synth_Img(Context, sgm=10) TbV = L_Syn_Img.Create_Random_Synth_Img(Context, sgm=100) Observation = L_Syn_Img.Simulate_PMW( TbH, TbV, Context, Observation, Obs_error_std=damp) #Simulate SynObs #Print Synth Image stats tita = L_ParamEst.recompute_param([TbH, TbV], Observation, tita) L_ParamEst.pr(tita, 'Synthetic Image') #%################################################### ## SOLVE SYSTEM with real parameters Sol = L_Solvers.Solve(Context, Observation, Method, tita, damp=damp) #%################################################## #% #Compare Original and Reconstructed tita = L_ParamEst.recompute_param([TbH, TbV], Observation, tita) L_ParamEst.pr(tita, 'Synthetic Image') sH0_o = np.sqrt(tita['H']['sigma2'][0]) sH1_o = np.sqrt(tita['H']['sigma2'][1]) sV0_o = np.sqrt(tita['V']['sigma2'][0]) sV1_o = np.sqrt(tita['V']['sigma2'][1]) tita = L_ParamEst.recompute_param(Sol, Observation, tita) L_ParamEst.pr(tita, 'Reconstructed Image') sH0_c = np.sqrt(tita['H']['sigma2'][0]) sH1_c = np.sqrt(tita['H']['sigma2'][1]) sV0_c = np.sqrt(tita['V']['sigma2'][0]) sV1_c = np.sqrt(tita['V']['sigma2'][1]) print("\nSummary:\n--------") print("RMSE H: %.3f" % (L_Syn_Img.RMSE_M(TbH, Sol[0], Context))) print("RMSE V: %.3f" % (L_Syn_Img.RMSE_M(TbV, Sol[1], Context))) MSG = "Orig: %.2f, \t%.2f, \t%.2f, \t%.2f" % (sH0_o, sH1_o, sV0_o, sV1_o) print(MSG) logging.info(MSG) MSG = "Comp: %.2f, \t%.2f, \t%.2f, \t%.2f" % (sH0_c, sH1_c, sV0_c, sV1_c) print(MSG) logging.info(MSG) MSG = "Quot: %.2f, \t%.2f, \t%.2f, \t%.2f" % ( sH0_c / sH0_o, sH1_c / sH1_o, sV0_c / sV0_o, sV1_c / sV1_o) print(MSG) logging.info(MSG)
import L_ParamEst import L_Syn_Img import numpy as np import pandas as pd import time import matplotlib.pyplot as plt # INICIALIZO LOS VALORES A EXPERIMENTAR: #%% HDFfilename = 'GW1AM2_201207310439_227D_L1SGBTBR_2210210' Bands = ['X', 'K', 'KU', 'KA', 'C'] Bands = ['KA', 'KU', 'K', 'X', 'C'] Context = L_Context.Load_Context(wdir) L_Syn_Img.Set_Margins(Context) np.random.seed(1) #%% #FIND Ws #%% BestW = {} BestG = {} BestRH = {} BestRV = {} MaxObsS = [3, 4, 6, 9, 12, 16, 20, 25] OUT_FN = wdir + "Best_GammaW_ManyObs.txt" for MaxObs in MaxObsS: BestW[MaxObs] = {} BestG[MaxObs] = {}
def main(): #%%################### ## PREPROCESSING #%% #Load Context damp = 1.0 Context = L_Context.Load_Context(wdir) #Create Synthetic Image TbH = Create_Random_Synth_Img(Context, sgm=10) TbV = Create_Random_Synth_Img(Context, sgm=.6) #[5,2,1,...] #Export Synthetic Image Map #L_Output.Export_Solution([TbH,TbV], Context, Band, "SynthImg") #Load ellipses and compute synthetic observation Observation, tita = L_ReadObs.Load_Band_Kernels( HDFfilename, Context, Band) #Load Observations & Kernels Observation = L_Syn_Img.Simulate_PMW(TbH, TbV, Context, Observation, Obs_error_std=damp) #Simulate SynObs #print("LandType approximation error:%.2f, %.2f"%(Observation['LSQRSols']['H']['norm'],Observation['LSQRSols']['V']['norm'])) #Observation['LSQRSols']={'H':lsqr(M,Observation['Tb']['H']),'V':lsqr(M,Observation['Tb']['V'])} #Compute cell in the grid considered as MARGIN-CELLS (for correct error estimation) L_Syn_Img.Set_Margins(Context) titaOrig = copy.deepcopy( L_ParamEst.recompute_param([TbH, TbV], Observation, tita)) L_ParamEst.pr(titaOrig, 'Synthetic Image') K = Observation['Wt'] Tbh = Observation['Tb']['H'] Tbv = Observation['Tb']['V'] VType = Observation['VType'] #%% STDs = np.exp( np.arange(-10, 8.001, .1) ) #[np.exp(-10),np.exp(-5),np.exp(-4),np.exp(-2),np.exp(-1),np.exp(0),np.exp(1),np.exp(2),np.exp(3),np.exp(4),np.exp(5)]#,3,5,7,9,11,13,15] STDh0 = [] STDv0 = [] STDh1 = [] STDv1 = [] RSEh = [] PEh = [] RSEv = [] PEv = [] LLh = [] LLv = [] ll = [] for std in STDs: tita = copy.deepcopy(titaOrig) for pol in ['H', 'V']: for lt in [0, 1]: tita[pol]['sigma2'][lt] = std * std Sol = L_Solvers.Solve(Context, Observation, "Rodgers", tita, damp=damp) tita = copy.deepcopy(titaOrig) for pol in ['H', 'V']: for lt in [0, 1]: tita[pol]['sigma2'][lt] = std * std difH = Tbh - K.dot(Sol[0]) difV = Tbv - K.dot(Sol[1]) #sn=np.sqrt(Tbh.shape[0]) RSEh.append(-np.linalg.norm(difH)**2) RSEv.append(-np.linalg.norm(difV)**2) err_str = "RMSE, H:%.2f, V:%.2f " % (RSEh[-1], RSEv[-1]) #RSE.append([RSEh,RSEv]) ONE = 0 * TbH + 1 mu = ONE * ((VType == 0) * tita['H']['mu'][0] + (VType == 1) * tita['H']['mu'][1]) std = ONE * np.sqrt((VType == 0) * tita['H']['sigma2'][0] + (VType == 1) * tita['H']['sigma2'][1]) l = np.log(std).sum() PEh.append(-np.linalg.norm((Sol[0] - mu) / std)**2 - l) mu = ONE * ((VType == 0) * tita['V']['mu'][0] + (VType == 1) * tita['V']['mu'][1]) std = ONE * np.sqrt((VType == 0) * tita['V']['sigma2'][0] + (VType == 1) * tita['V']['sigma2'][1]) l = np.log(std).sum() PEv.append(-np.linalg.norm((Sol[1] - mu) / std)**2 - l) LLh.append(RSEh[-1] + PEh[-1]) LLv.append(RSEv[-1] + PEv[-1]) #PE.append([PEh,PEv]) tita = L_ParamEst.recompute_param(Sol, Observation, tita) STDh0.append(np.sqrt(tita['H']['sigma2'][0])) STDh1.append(np.sqrt(tita['H']['sigma2'][1])) STDv0.append(np.sqrt(tita['V']['sigma2'][0])) STDv1.append(np.sqrt(tita['V']['sigma2'][1])) L_ParamEst.pr(tita, 'Reconstructed Image') #%% import matplotlib.pyplot as plt plt.clf() llplot(STDs, STDs) llplot(STDs, STDh0) llplot(STDs, STDh1) llplot_diag_crux(np.sqrt(titaOrig['H']['sigma2'][0]), e=2) llplot_diag_crux(np.sqrt(titaOrig['H']['sigma2'][1]), e=2) plt.figure() llplot(STDs, STDs) llplot(STDs, STDv0) llplot(STDs, STDv1) llplot_diag_crux(np.sqrt(titaOrig['V']['sigma2'][0]), e=2) llplot_diag_crux(np.sqrt(titaOrig['V']['sigma2'][1]), e=2) #% plt.figure() lplot(STDs, PEh) lplot(STDs, RSEh) lplot(STDs, LLh) #% plt.figure() lplot(STDs, PEv) lplot(STDs, RSEv) lplot(STDs, LLv) #%% plt.figure() llplot(STDs, STDs) llplot(STDs, STDh0) lplot(STDs, [l / 10000 for l in LLh])
def main(): #%%################### ## PREPROCESSING #Load Context Context = L_Context.Load_Context(wdir) #Load Observation Observation, tita = L_ReadObs.Load_PKL_Obs(HDFfilename, Context, Band) #Lee obs y nucleos #Create Synthetic Image TbH = L_Syn_Img.Create_Trig_Synth_Img(Context) TbV = L_Syn_Img.Create_Random_Synth_Img(Context) #Export Synthetic Image Map L_Output.Export_Solution([TbH, TbV], Context, Band, "SynthImg") #Print Synth Image stats tita = L_ParamEst.recompute_param([TbH, TbV], Observation, tita) L_ParamEst.pr(tita, 'Synthetic Image') Observation = L_Syn_Img.Simulate_PMW(TbH, TbV, Context, Observation, error_var=1.0) #Compute cell in the grid considered as MARGIN-CELLS L_Syn_Img.Set_Margins(Context) #%%################################################## ## SOLVE SYSTEM with real parameters #%%################################################## ## Export solution L_Output.Export_Solution(SolR, Context, Band, "SolSynthImg_%s" % Method) #Evaluate error (with and without margins) print("RMSE H: %.3f,%.3f" % (L_Syn_Img.RMSE_M( TbH, SolR[0], Context), L_Syn_Img.RMSE(TbH, SolR[0]))) print("RMSE V: %.3f,%.3f" % (L_Syn_Img.RMSE_M( TbV, SolR[1], Context), L_Syn_Img.RMSE(TbV, SolR[1]))) #%%################################################## ## EROR ANALYSIS for Rodgers Method #Error covariance SH = L_Solvers.Rodgers_Compute_Covarince(Context, Observation, tita, 'H') EH = np.sqrt(SH.diagonal()) SV = L_Solvers.Rodgers_Compute_Covarince(Context, Observation, tita, 'V') EV = np.sqrt(SV.diagonal()) L_Output.Export_Solution([EH, EV], Context, Band, "SolSynthImg_Std") #Export 5 first error eigenvectors EigH = np.linalg.eig(SH) EigV = np.linalg.eig(SV) for i in range(5): #(EigH[0].shape[0]): ViH = EigH[1][:, i] * EigH[0][i] ViV = EigV[1][:, i] * EigV[0][i] L_Output.Export_Solution([ViH, ViV], Context, Band, "SolSynthImg_Pattern_" + str(i)) #%%################################################################# ## SOLVE SYSTEM WITH ITERATIVE METHOD #Print Synth Image stats tita = L_ParamEst.recompute_param([TbH, TbV], Observation, tita) L_ParamEst.pr(tita) #Solve system SolR = L_Solvers.Solve(Context, Observation, "Rodgers_IT", tita) #Evaluate error (with and without margins) print("RMSE H: %.3f,%.3f" % (L_Syn_Img.RMSE_M( TbH, SolR[0], Context), L_Syn_Img.RMSE(TbH, SolR[0]))) print("RMSE V: %.3f,%.3f" % (L_Syn_Img.RMSE_M( TbV, SolR[1], Context), L_Syn_Img.RMSE(TbV, SolR[1]))) #Export solution L_Output.Export_Solution(SolR, Context, Band, "Sol20120811_SynthImg_Rod_IT_1noise") #%% #main()