Ejemplo n.º 1
0
def compareMedianBalanceVsRegressionGivenGroundTruth(
                list_of_power, 
                num_time_sample=2000,
                origin_time_sample = 0.01,
                delta_time_sample = 0.002,  
                num_point_ricker_wavelet=100, 
                width_parameter_ricker_wavelet=10, 
                noise_level=1,
                initial_exponent_power=2, 
                max_iteration=60, 
                delta_exponent_power_tolerance=1e-12,
                output_directory='/tmp'):
    
    output = collections.namedtuple('compareMedianBalanceVsRegression', 
                                          ['list_median_balance_recovered_power', 
                                           'list_regression_recovered_power',
                                           'data_by_trace_time'
                                           'domain_time_sample']) 
    output.domain_time_sample = math_op.calculateLinearlySpacedValues(origin_time_sample, 
                                                               delta_time_sample, 
                                                               num_time_sample)
    output.data_by_trace_time = get_ricker_data(list_of_power, 
                                         num_time_sample, 
                                         num_point_ricker_wavelet, 
                                         width_parameter_ricker_wavelet, 
                                         output.domain_time_sample, 
                                         noise_level)
    output.list_median_balance_recovered_power = []
    output.list_regression_recovered_power = []
    for power, trace in zip(list_of_power, output.data_by_trace_time):    
                        #median_balance
        normalized_trace = np.squeeze(math_op.divideEachRowByItsMaxAbsValue(np.array([trace])))                       
        median_result = mb.recoverDomainWeightedGainViaMedianBalancing( normalized_trace, 
                        output.domain_time_sample,
                        initial_exponent_power,
                        max_iteration,
                        delta_exponent_power_tolerance,
                        output_directory,
                        print_to_stdout = 0,
                        logging_level=logging.CRITICAL)
        output.list_median_balance_recovered_power.append(median_result.domain_exponent_power)
                        #regression
        output_logloglinear = lll.findDomainPowerViaLogLogLinearRegresstion(
                                                                    np.abs(trace),
                                                                    output.domain_time_sample)
        output.list_regression_recovered_power.append(-output_logloglinear.slope)
    
    l2_median_balance_powers_error = np.linalg.norm(output.list_median_balance_recovered_power - list_of_power)
    l2_regression_powers_error = np.linalg.norm(output.list_regression_recovered_power - list_of_power)
    print 'l2_median_balance_powers_error= %g' % l2_median_balance_powers_error
    print 'l2_regression_powers_error = %g' % l2_regression_powers_error
    print 'l2_median_balance_powers_error / l2_regression_powers_error = %g' % (l2_median_balance_powers_error/l2_regression_powers_error)


    
    return output
Ejemplo n.º 2
0
             data_by_trace_time[idx_power,:] =  \
                 attenuation_by_time_sample * true_data_by_trace_time[idx_power,:]
         break
     if case(): # default, could also just omit condition or 'if True'
         print "unknown input_data_type = %s \n" % input_data_type     
 
 processed_data_by_trace_time = np.zeros((num_trace,num_time_sample),'f')
 if (treat_traces_individually):
     list_power_by_traceindex = np.zeros(num_trace)
     list_iterationcount_by_traceindex = np.zeros(num_trace)
     list_traceindex = range(num_trace)
     for trace_index in list_traceindex:
         trace = data_by_trace_time[[trace_index],:]
                     
                     #normalize values
         normalized_trace = math_op.divideEachRowByItsMaxAbsValue(trace)                      
         
                     #setup output directory
         local_output_directory = output_directory + os.sep + "data" + str(trace_index)
         file_operation.makeDirectoryIfNotExist(local_output_directory) 
                    
         median_balance_output = \
           mb.recoverDomainWeightedGainViaMedianBalancing( normalized_trace, 
                                                           domain_time_sample,
                                                           initial_exponent_power,
                                                           max_iteration,
                                                           delta_exponent_power_tolerance,
                                                           local_output_directory,
                                                           print_to_stdout = 1,
                                                           logging_level=logging.DEBUG)
         weighted_trace = math_op.weightSignalByDomainExponentiated(