def BG(gamma=np.pi / 4, MaxObs=4, w=0.001, V=1): if V == 4: BG_Coef = L_Solvers.BG_Precomp_MaxObs_V4(Context, Observation, gamma=gamma, w=w, MaxObs=MaxObs) elif V == 3: BG_Coef = L_Solvers.BG_Precomp_MaxObs_V3_b(Context, Observation, gamma=gamma, w=w, MaxObs=MaxObs) elif V == 2: BG_Coef = L_Solvers.BG_Precomp_MaxObs_V2(Context, Observation, gamma=gamma, w=w, MaxObs=MaxObs) else: BG_Coef = L_Solvers.BG_Precomp_MaxObs(Context, Observation, gamma=gamma, w=w, MaxObs=MaxObs) Sol = [ BG_Coef.dot(Observation['Tb']['H']), BG_Coef.dot(Observation['Tb']['V']) ] RMSE = L_Syn_Img.RMSE_M(TbV, Sol[1], Context) print("RMSE: %.5f\n*****************************************" % RMSE) return Sol, RMSE
def main(): Method='Rodgers' #Load Context Context=L_Context.Load_Context(wdir) print('######################################') print('## PRECOMPUTING K for BAND',Band,'#####') print('######################################') Observation, tita = L_ReadObs.Load_PKL_or_Compute_Kernels(HDFfilename,Context,Band,GC=True) print('######################################') print('## SOLVING BAND',Band,' Method',Method) print('######################################') #%% ls=[] lp=[] lpyx=[] lpxt=[] ex=[] ey=[] lso=[] lsi=[] pol='H' for std in np.arange(.01,20,1): print ("std:", end=' ') print(std, end='\t\t') #Solve system tita[pol]['sigma2']=np.array([std*std,std*std]) Sol=L_Solvers.Solve(Context, Observation, Method, tita) lsi.append(std) sstd=Sol[0][VType==0].std() lso.append(sstd) print(std,sstd) LP, LPyx, LPxt , Ex, Ey = compute_LP(Sol[0],pol,tita,Observation) lp.append(LP) lpyx.append(LPyx) lpxt.append(LPxt) ex.append(Ex) ey.append(Ey) #print ("P:%.10f"%p) import matplotlib.pyplot as plt plt.clf() plt.plot(ls,lp) plt.plot(ls,lpyx) plt.plot(ls,lpxt) plt.plot(ls,ex) plt.plot(ls,ey) SolIt=L_Solvers.Solve(Context, Observation, "Rodgers_IT", tita)
def main(): global wdir #PROCESS PARAMETERS HDFfilename = 'GW1AM2_201208110420_224D_L1SGBTBR_2210210' arg_HDF = False #True #process argument file (or fixed example file)? if arg_HDF: #infut HDF is given by argument? HDFfilename = sys.argv[1] Context = L_Context.Load_Context(wdir) print( '############################################################################' ) print('## Processing file %s' % HDFfilename) Band = 'ka' #Dict_Bands=L_ReadObs.Load_PKL_or_HDF_Ells(HDFfilename, Context,GC=True) print('######################################') print('## PRECOMPUTING K for BAND', Band, '#####') print('######################################') Observation, tita = L_ReadObs.Load_PKL_or_Compute_Kernels(HDFfilename, Context, Band, GC=True) #Solve system Method = 'Rodgers' print('######################################') print('## SOLVING BAND', Band, ' Method', Method) print('######################################') SolR = L_Solvers.Solve(Context, Observation, Method, tita) tita = L_ParamEst.recompute_param(SolR, Observation, tita) tita = L_ParamEst.minSigma2(tita, .99) L_ParamEst.pr1(tita, "Post-Rodgers") Method = 'BGP' print('######################################') print('## SOLVING BAND', Band, ' Method', Method) print('######################################') Sol = L_Solvers.Solve(Context, Observation, Method, tita) #Write images with solution L_Output.Export_Solution(Sol, Context, Band, Observation['FileName'] + '_' + Method) print('## Donde processing file') print( '############################################################################\n' )
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)
def main(): global wdir #PROCESS PARAMETERS HDFfilename='AMSR_E_L2A_BrightnessTemperatures_V12_200601010409_D' HDFfilename='GW1AM2_201408210358_220D_L1SGBTBR_2220220' HDFfilename='GW1AM2_201406020358_220D_L1SGBTBR_2220220' HDFfilename='GW1AM2_201207310439_227D_L1SGBTBR_2210210' arg_HDF=False #True #process argument file (or fixed example file)? if arg_HDF: #infut HDF is given by argument? HDFfilename=sys.argv[1] #Method = 'GCV_Tichonov' #Method = 'BGC' #Method = 'Tichonov' #Method = 'SimpleEM' #Method = "OHB" #Method = "MCEM" Method = 'Weights' Method = 'LSQR' Method = 'Global_GCV_Tichonov' #Method = 'K_Global_GCV_Tichonov' Method = 'Rodgers_IT' Context=L_Context.Load_Context(wdir) print('############################################################################') print('## Processing file %s' %HDFfilename) Bands=['KA','K','KU','C','X']#Context['Bands'] Methods=['Global_GCV_Tichonov','Rodgers_IT','LSQR','Weights'] Bands=['KA']#Context['Bands'] Methods=['Rodgers_IT'] for Band in Bands: Observation, tita=L_ReadObs.Load_Band_Kernels(HDFfilename, Context, Band) #%%Solve system for Method in Methods: print('######################################') print('## SOLVING BAND',Band,'#################') print('######################################') Sol=L_Solvers.Solve(Context, Observation, Method, tita) #Write images with solution L_Output.Export_Solution(Sol, Context, Band, Observation['FileName']+'_'+Method) #%% print('## Donde processing file') print('############################################################################\n')
def BG(gamma=0, MaxObs=4, w=0.001): print("Computing %.5f" % gamma) X.append(gamma) BG_Coef = L_Solvers.BG_Precomp_MaxObs(Context, Observation, gamma=gamma, w=w, MaxObs=MaxObs) Sol = [ BG_Coef.dot(Observation['Tb']['H']), BG_Coef.dot(Observation['Tb']['V']) ] RMSE = L_Syn_Img.RMSE_M(TbH, Sol[0], Context) print("RMSE: %.5f\n*****************************************" % RMSE) return RMSE
def BG(Context, Observation, omega=0.001, gamma=np.pi / 4, error_std=1, max_obs=4): BG_Coef = L_Solvers.BG_Precomp_MaxObs_Cell(distances, Context, Observation, gamma=gamma, w=omega, error_std=error_std, MaxObs=max_obs) Sol = [ BG_Coef.dot(Observation['Tb']['H']), BG_Coef.dot(Observation['Tb']['V']) ] return Sol
np.random.seed(1) #cols = ['km','Band','MaxObs','w','Gamma','RMSE'] cols = ['km', 'Band', 'MaxObs', 'w', 'Gamma', 'RMSE', 'Error'] df = pd.DataFrame(columns=cols) i = 0 for MAPA in MAPAS: wdir = BASE_DIR + 'Mapas/%s/' % MAPA Context = L_Context.Load_Context(wdir, NeighborsBehaviour) L_Syn_Img.Set_Margins(Context) km = int(MAPA[4:6]) omega = dic_omega[km] distances_path = wdir + 'distance' if not L_Files.exists(distances_path): distances = L_Solvers.precompute_all_optimized(Context) L_Solvers.save_distances(distances_path, distances) distances = L_Solvers.load_distances(distances_path) for rep in range(tot_img_samples): TbH = L_Syn_Img.Create_Random_Synth_Img(Context) TbV = L_Syn_Img.Create_Trig_Synth_Img(Context) titaReal = copy.deepcopy(L_ParamEst.Compute_param([TbH, TbV], Context)) for Band in Bands: Observation, tita = L_ReadObs.Load_Band_Kernels( HDFfilename, Context, Band) Observation = L_Syn_Img.Simulate_PMW(TbH, TbV, Context, Observation,
#%% np.random.seed(1) #cols = ['km','Band','MaxObs','w','Gamma','RMSE'] i = 0 for MAPA in MAPAS: wdir = BASE_DIR + 'Mapas/%s/' % MAPA Context = L_Context.Load_Context(wdir, NeighborsBehaviour) L_Syn_Img.Set_Margins(Context) km = int(MAPA[4:6]) omega = dic_omega[km] distances_path = wdir + 'distance' if not L_Files.exists(distances_path): distances = L_Solvers.precompute_all_optimized(Context) L_Solvers.save_distances(distances_path, distances) distances = L_Solvers.load_distances(distances_path) for Band in Bands: Observation, tita = L_ReadObs.Load_Band_Kernels( HDFfilename, Context, Band) key = Band + str(km) max_obs = dic_maxObs[key] omega = dic_omega[km] gamma = dict_gamma[key] #usar diccionarios con KEY para max_obs + omega + gamma para calcular kernel print("Computando coeficientes para banda ", Band, " y Mapa ", MAPA) COEF = L_Solvers.BG_Precomp_MaxObs_Cell(distances,
D['STDVi1'].append(np.sqrt(tita['V']['sigma2'][1])) STDs = [10**i for i in np.arange(-1, 0.71, .01)] for std in STDs: D['ObsErr'].append(std) for Band in Bands: Observations[Band] = L_Syn_Img.Simulate_PMW(TbH, TbV, Context, Observations[Band], Obs_error_std=std) L_ParamEst.compute_param([TbH, TbV], Observations[Band]) #STAT Sol = L_Solvers.Solve_Rodgers_IT_NB(Context, Observations[Band], tita, obsvar=std * std, tol=0.00005, max_iter=50) RMSEH = L_Syn_Img.RMSE_M(TbH, Sol[0], Context) RMSEV = L_Syn_Img.RMSE_M(TbV, Sol[1], Context) print(" -done") print("RMSEsHw: %.3f" % RMSEH) print("RMSEsVw: %.3f" % RMSEV) tita = L_ParamEst.recompute_param(Sol, Observations[Band], tita) D[Band]['RMSEHs'].append(RMSEH) D[Band]['RMSEVs'].append(RMSEV) D[Band]['STDHo0'].append(np.sqrt(tita['H']['sigma2'][0])) D[Band]['STDHo1'].append(np.sqrt(tita['H']['sigma2'][1])) D[Band]['STDVo0'].append(np.sqrt(tita['V']['sigma2'][0]))
L_Syn_Img.Set_Margins(Context) #%% TbH = L_Syn_Img.Create_Random_Synth_Img(Context, sgm0=1.0, sgm1=1.0) TbV = L_Syn_Img.Create_Trig_Synth_Img(Context) Observation = L_Syn_Img.Simulate_PMW(TbH, TbV, Context, Observation, Obs_error_std=1.0) L_ParamEst.compute_param([TbH, TbV], Observation) #L_Output.Export_Solution([TbH,TbV], Context, Band, "SynthImg") #%% #Rodgers no bound #%% Sol = L_Solvers.Solve_Rodgers_IT_NB(Context, Observation, tita, damp=1.0, tol=0.00005, max_iter=50) RMSEsHw = L_Syn_Img.RMSE_M(TbH, Sol[0], Context) RMSEsVw = L_Syn_Img.RMSE_M(TbV, Sol[1], Context) print(" -done") print("RMSEsHw: %.3f" % RMSEsHw) print("RMSEsVw: %.3f" % RMSEsVw)
import time import matplotlib.pyplot as plt # INICIALIZO LOS VALORES A EXPERIMENTAR: #%% HDFfilename='GW1AM2_201207310439_227D_L1SGBTBR_2210210' Band='K' Context=L_Context.Load_Context(wdir) Observation, tita=L_ReadObs.Load_Band_Kernels(HDFfilename,Context,Band) TbH = L_Syn_Img.Create_Random_Synth_Img(Context) TbV = L_Syn_Img.Create_Trig_Synth_Img(Context) Observation=L_Syn_Img.Simulate_PMW(TbH,TbV,Context,Observation,Obs_error_std=1.0) L_Syn_Img.Set_Margins(Context) L_Output.Export_Solution([TbH,TbV], Context, Band, "SynthImg") #%% #FIND Ws #%% gamma = np.pi/4 w=0.001 BG_Coef=L_Solvers.BG_Precomp(Context, Observation, gamma=gamma,w=w) Sol=[BG_Coef.dot(Observation['Tb']['H']), BG_Coef.dot(Observation['Tb']['V'])] RMSEsHw=L_Syn_Img.RMSE_M(TbH,Sol[0],Context) RMSEsVw=L_Syn_Img.RMSE_M(TbV,Sol[1],Context) print(" -done") print("RMSEsHw: %.3f"%RMSEsHw) print("RMSEsVw: %.3f"%RMSEsVw)
pickle.dump(distances_matrix_list, f, pickle.HIGHEST_PROTOCOL) # Abrir with open('data_25km.pickle', 'rb') as f: # The protocol version used is detected automatically, so we do not # have to specify it. distances_matrix_list_recovered = pickle.load(f) with open('/home/rgrimson/data_10km.pickle', 'rb') as f: # The protocol version used is detected automatically, so we do not # have to specify it. distances_matrix_list_recovered = pickle.load(f) BG_Coef = L_Solvers.BG_Precomp_MaxObs_V3_c(distances_matrix_list_recovered, Context, Observation, gamma=np.pi / 4, w=0.001, MaxObs=4) Sol = [ BG_Coef.dot(Observation['Tb']['H']), BG_Coef.dot(Observation['Tb']['V']) ] RMSE = L_Syn_Img.RMSE_M(TbV, Sol[1], Context) print("RMSE: %.5f\n*****************************************" % RMSE) # Ver si no es J al cuadrado. #Sol,RMSE = BG(V=3) sys.exit(1) #%% GAMMAS = np.linspace(0, np.pi / 2, 20)
#%% #FIND Ws #%% gamma = np.pi / 4 w_min = 10**-50 RMSEsVw = 1000 RMSE_gain = 1.0 w = 10 while ((w > w_min) and (RMSE_gain > 0)): w_anterior = w w = w / 10 RMSEsVw_anterior = RMSEsVw Sol = L_Solvers.BGF(Context, Observation, gamma=gamma, w=w) RMSEsHw = L_Syn_Img.RMSE_M(TbH, Sol[0], Context) RMSEsVw = L_Syn_Img.RMSE_M(TbV, Sol[1], Context) print(" -done") print("RMSEsHw: %.3f" % RMSEsHw) print("RMSEsVw: %.3f" % RMSEsVw) RMSE_gain = RMSEsVw_anterior - RMSEsVw w = w_anterior print("Best w: %.3f" % w) #%% #GAMMAS #%% gammas = np.linspace(0, np.pi / 2, 10)
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()
Observation, Obs_error_std=1.0) #L_Output.Export_Solution([TbH,TbV], Context, Band, "SynthImg") gamma = np.pi / 4 w_min = 10**-50 w_max = 10**50 RMSEsVw = 1000 RMSE_gain = 1.0 w1 = 1.0 w0 = 0.1 BG_Coef = L_Solvers.BG_Precomp_MaxObs(Context, Observation, gamma=gamma, w=w0, MaxObs=MaxObs) Sol = [ BG_Coef.dot(Observation['Tb']['H']), BG_Coef.dot(Observation['Tb']['V']) ] RMSEsHw0 = L_Syn_Img.RMSE_M(TbH, Sol[0], Context) RMSEsVw0 = L_Syn_Img.RMSE_M(TbV, Sol[1], Context) print("RMSEsHw: %.10f" % RMSEsHw0) print("RMSEsVw: %.10f" % RMSEsVw0) BG_Coef = L_Solvers.BG_Precomp_MaxObs(Context, Observation, gamma=gamma, w=w1,
#%% main() #%% converged = False last_std = np.exp(-4) new_std = last_std IN_STD = [last_std] while not converged: tita = copy.deepcopy(titaOrig) for pol in POL: for lt in LT: tita[pol]['sigma2'][lt] = last_std * last_std Sol = L_Solvers.Solve(Context, Observation, "Rodgers", tita, damp=damp) tita = L_ParamEst.recompute_param(Sol, Observation, tita) #L_ParamEst.pr(tita,'Reconstructed Image') for pol in POL: for lt in LT: new_std = np.sqrt(tita[pol]['sigma2'][lt]) IN_STD.append(new_std) if np.abs(new_std - last_std) < 0.005: converged = True else: last_std = new_std #%% for i in range(len(IN_STD) - 1): s0 = IN_STD[i] s1 = IN_STD[i + 1]
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(): global wdir #PROCESS PARAMETERS #Method = 'Rodgers_IT' #Method = 'Weights' #Method = 'Tichonov' #Method = 'GCV_Tichonov' Method = 'Rodgers_IT' Context = L_Context.Load_Context(wdir) FileList = L_Files.listFilesWithExtension(wdir + 'HDF/', '.h5') nF = len(FileList) iF = 0 for HDFfilename in FileList: print( '############################################################################' ) print('## Processing file %s, method = %s' % (HDFfilename, Method)) iF += 1 print('## %d of %d' % (iF, nF)) Bands = Context['Bands'] for Band in Bands: Error = False try: Observation, tita = L_ReadObs.Load_Band_Kernels( HDFfilename, Context, Band) except: Error = True logging.info("Error - Could not load file") if not Error: try: L_Output.Export_Observation(Observation, Context, Band, HDFfilename) except: Error = True logging.info("Error - Could not export observation") if not Error: try: #Solve system print('######################################') print('## SOLVING BAND', Band, '#################') print('######################################') Sol = L_Solvers.Solve(Context, Observation, Method, tita) FileName = Method + '_' + HDFfilename + '_' except: Error = True logging.info("Error - Could not solve system") if not Error: try: L_Output.Export_Solution(Sol, Context, Band, FileName) except: Error = True logging.info("Error - Could not export solution") if Error: print('## Could not process file band --- see log file') print( '############################################################################\n' ) else: print('## Donde processing band') print( '############################################################################\n' )