예제 #1
0
 def empiricalDistributionPlot(self, sample, bounds=None):
     if bounds:
         lower = bounds[0]
         upper = bounds[1]
     else:
         lower = min(sample)
         upper = max(sample)
     plotDomain = linspace(lower, upper, len(sample))
     empiricalCDF = ECDF([uniform(0, 1) for i in range(len(sample))])
     empiricalCDF.observations = sample
     obs = []
     for j in range(len(sample)):
         obs.append(empiricalCDF(plotDomain[j]))
     ecdf_sample = array(obs)
     plt.plot(plotDomain, ecdf_sample)
     plt.show()
예제 #2
0
def quantile_mapping(obs_cube, mod_cube, sce_cubes, *args, **kwargs):
    """
    Quantile Mapping
    apply quantile mapping to all scenario cubes using the distributions
    of obs_cube and mod_cube
    Args:
    * obs_cube (:class:`iris.cube.Cube`):
        the observational data
    * mod_cube (:class:`iris.cube.Cube`):
        the model data at the reference period
    * sce_cubes (:class:`iris.cube.CubeList`):
        the scenario data that shall be corrected
    """
    from ecdf import ECDF

    cell_iterator = np.nditer(obs_cube.data[0], flags=['multi_index'])
    while not cell_iterator.finished:
        index_list = list(cell_iterator.multi_index)
        cell_iterator.iternext()

        index_list.insert(0, 0)
        index = tuple(index_list)
        if isinstance(obs_cube.data, np.ma.MaskedArray) \
           and obs_cube.data.mask[index]:
            continue

        index_list[0] = slice(0, None, 1)
        index = tuple(index_list)
        obs_data = obs_cube.data[index]
        mod_data = mod_cube.data[index]
        mod_ecdf = ECDF(mod_data)

        for sce_cube in sce_cubes:
            sce_data = sce_cube[index].data
            p = mod_ecdf(sce_data) * 100
            corr = np.percentile(obs_data, p) - \
                np.percentile(mod_data, p)
            sce_cube.data[index] += corr
예제 #3
0
                    E_hertz_far(r, p, R, pha, f, t=0, epsr=1.) for r in rs
                ])  # calculate sum E-fields at obsevation points
                Emags2 = abs(numpy.array([numpy.dot(a, a) for a in Es]))
                av = sum(Emags2) / N_obs_points  # the average of |E|**2
                ma = max(Emags2)  # the maximum of |E|**2
                D = ma / av  # directivity
                #print mc, ma, av, D
                Ds.append(D)
                Eslist.append(Es)
            D_max_list.append(numpy.mean(Ds))
            #ED=EDmax_hansen(ka, mu=1., Ns=Ns)
            # print
            #print f, ka, sum(Ds)/N_MC, ED
            print f
            #sys.stdout.flush()
            ecdfD = ECDF(Ds)

        #pylab.plot(deval, [FD_hertz_one_cut(d) for d in deval], label="Theoretical CDF (a=0 m)")
        #pylab.plot(deval, [FD_hertz_one_cut_costheta(d) for d in deval], label="Theoretical CDF cos(theta)(a=0 m)")
        pylab.figure(1)
        pylab.plot(N_obs_points_list,
                   D_max_list,
                   '%s+-' % clr,
                   label="f= %dGHz" % (f / 1e9))
    pylab.axis([N_obs_points_list[0], N_obs_points_list[-1], 1, 4])
    pylab.grid()
    pylab.legend(loc=4)
    pylab.xlabel("$N_{dipoles}$")
    pylab.ylabel("$<D_{max}^{R}>$")
    pylab.title(" MC runs=%d, $a_{EUT}=%.4fm$, $R=%dm$,$N_{dipole}=%d$" %
                (N_MC, a_EUT, distance, N_dipole))
예제 #4
0
     pha=2*pi*numpy.random.random(N_dipole) # generate random phases
     Es=numpy.array([E_hertz_far(r, p, R, pha, f, t=0, epsr=1.) for r in rs]) # calculate sum E-fields at obsevation points
     Emags2=abs(numpy.array([numpy.dot(a,a) for a in Es]))     
     av=sum(Emags2)/N_obs_points # the average of |E|**2
     ma=max(Emags2) # the maximum of |E|**2
     D=ma/av # directivity
     print mc, ma, av, D
     Ds.append(D)
     Eslist.append(Es)
         
 ED=EDmax_hansen(ka, mu=1., Ns=Ns)
 print    
 print f, ka, sum(Ds)/N_MC, ED
 print
 sys.stdout.flush()
 ecdfD=ECDF(Ds)
 pylab.figure(1)
 pylab.plot(deval,ecdfD(deval), '%s+-'%clr, label="$D_{max}^{R}")
 output_data.append(remove_nan(ecdfD(deval)))
 #pylab.plot(deval, [FD_hertz_one_cut(d) for d in deval], label="Theoretical CDF (a=0 m)")
 #pylab.plot(deval, [FD_hertz_one_cut_costheta(d) for d in deval], label="Theoretical CDF cos(theta)(a=0 m)")
 
 
 distance = 10  # measurement distance
 a_EUT=0.27# radius of EUT
 N_dipole = 50    # number of random dipoles
 N_obs_points=50 #number of observation points (randomly distributed) on Ring around EUT
 N_MC=1000       # number of MC runs -> average over different random configurations
 freqs=numpy.array([30,150,300])*1e6#[30,50,80,100,150, 200,250, 300,350, 400,450, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500])*1e6#numpy.array(range(30,301,30))*1000000#numpy.logspace(10,11,3)  # generate frequencies
 #kas=a_EUTs*2*pi*freqs/c # vector with k*a values (a: EUT radius)
 deval=numpy.linspace(1,12,100)
예제 #5
0
        Es = numpy.array([
            E_hertz_far(r, p, R, pha, f, t=0, epsr=1.) for r in rs
        ])  # calculate sum E-fields at obsevation points

        Emags2 = abs(numpy.array([numpy.dot(a, a) for a in Es]))

        av = sum(Emags2) / N_obs_points  # the average of |E|**2
        ma = max(Emags2)  # the maximum of |E|**2
        D = ma / av  # directivity
        #print mc, ma, av, D
        Ds_K.append(D)
        Es2_list_av_K.append(av)
        print "K", mc
    Es2_ratio = numpy.divide(Es2_list_max_R, Es2_list_av_K)
    ecdfD = ECDF(Es2_ratio)
    pylab.figure(1)
    pylab.plot(deval, ecdfD(deval), '%s+-' % clr, label="ECDF (Dipoles)")
    output_data.append(remove_nan(ecdfD(deval)))
    #pylab.plot(deval, [FD_hertz_one_cut(d) for d in deval], label="Theoretical CDF (a=0 m)")
    #pylab.plot(deval, [FD_hertz_one_cut_costheta(d) for d in deval], label="Theoretical CDF cos(theta)(a=0 m)")
    pylab.axis([deval[0], deval[-1], 0, 1])
    pylab.grid()
    pylab.legend(loc=4)
    pylab.xlabel(r"$\frac{E^{R^{2}}_{max}}{E^{K^{2}}}$")
    pylab.ylabel(r"F($\frac{E^{R^{2}}_{max}}{E^{K^{2}}}$)")
    pylab.title("$N_{dipoles}=%d$, MC runs=%d, $Frequency=%dGHz$, $R=%dm$" %
                (N_dipole, N_MC, f / 1e9, distance))
    #pylab.show()
    fig = matplotlib.pyplot.gcf()
    fig.set_size_inches(18.5, 10.5)
예제 #6
0
defosequence = []
for t in range(sampleSize):
    defosequence.append(defo_ad_pf(initial_land, costshocks[t]) - initial_land)

defosequence_ad = array(defosequence) * landtoemissions / 1e6

defosequence = []
for t in range(sampleSize):
    defosequence.append(defo_pf(initial_land, costshocks[t]) - initial_land)

defosequence_defo = array(defosequence) * landtoemissions / 1e6

lower = min(min(defosequence_defo), min(defosequence_ad))
upper = max(max(defosequence_defo), max(defosequence_ad))
plotDomain = linspace(lower, upper, len(costshocks))
empiricalCDF = ECDF([uniform(0, 1) for i in range(len(costshocks))])
empiricalCDF.observations = defosequence_ad
obs = []
for j in range(sampleSize):
    obs.append(empiricalCDF(plotDomain[j]))
ecdf_sample_ad = array(obs)
plt.plot(plotDomain, ecdf_sample_ad, label='AD')
empiricalCDF.observations = defosequence_defo
obs = []
for j in range(sampleSize):
    obs.append(empiricalCDF(plotDomain[j]))
ecdf_sample_defo = array(obs)
plt.plot(plotDomain, ecdf_sample_defo, label='Defo')
plt.legend()
plt.show()