예제 #1
0
def plotMFIdistsRho(bclust=2.2, rhorange=[0.1, 1.0, 0.2], kmaxFP=10 ** 6, nMax=200, pim=4.9, fpmodel=1, fignums=[0, 1]):
    # rhorange = [minrho, maxrho, dRho]
    bofpim = []
    for fignum in fignums:
        plt.figure(fignum)
        plt.clf()
        plt.xlabel("$log_{10}(k)$", size=18)
        plt.ylabel("$log_{10}(N(k))$", size=18)

        #
    primeRhos = [0.1, 0.3, 0.5, 0.7, 0.9, 1.0]
    thisrho = rhorange[0]
    icount = 0
    while thisrho <= rhorange[1]:
        X = getMFIsquarePropModel(bclust, thisrho, pim, kmaxFP, nMax, fpmodel)
        x = []
        y1 = []
        y2 = []
        xstart = 25
        for rw in X:
            # print rw
            x += [math.log10(rw[2])]
            # print rw[3]
            y1 += [math.log10(rw[3])]
            y2 += [math.log10(rw[4])]
        lf1 = yp.linefit([x[xstart:], y1[xstart:]])
        lf2 = yp.linefit([x[xstart:], y2[xstart:]])
        lf1.doFit()
        lf2.doFit()
        # lf1.doFit(None, None, 3)
        # lf2.doFit(None, None, 3)
        #
        bofpim += [[pim, lf1.a, -lf1.b, lf1.meanVar(), lf2.a, -lf2.b, lf2.meanVar()]]
        plt.figure(fignums[0])
        plt.title("$\\beta=2.2$")
        plt.plot(
            x,
            y1,
            "%s.-" % yp.pycolor(icount),
            label="$\\rho = %s, \\epsilon=%s, b=%s$" % (str(thisrho), str(pim), str(-lf1.b)),
            lw=2,
        )  # beta!=2
        plt.plot(
            [x[0], x[xstart], x[-1]],
            [lf1.a + lf1.b * x[0], lf1.a + lf1.b * x[xstart], lf1.a + lf1.b * x[-1]],
            "%s|-" % yp.pycolor(icount),
            ms=15,
        )
        plt.figure(fignums[1])
        plt.title("$\\beta=2.0$")
        plt.plot(
            x,
            y2,
            "%s.-" % yp.pycolor(icount),
            label="$\\rho = %s, \\epsilon=%s, b=%s$" % (str(thisrho), str(pim), str(-lf2.b)),
            lw=2,
        )  # beta=2 approximation
        plt.plot(
            [x[0], x[xstart], x[-1]],
            [lf2.a + lf2.b * x[0], lf2.a + lf2.b * x[xstart], lf2.a + lf2.b * x[-1]],
            "%s|-" % yp.pycolor(icount),
            ms=15,
        )
        icount += 1
        #
        thisrho += rhorange[2]
    plt.show()
    #
    for fignum in fignums:
        plt.figure(fignum)
        plt.legend(loc="best")
    return bofpim
예제 #2
0
def plotMFIdistsBetaEps(bclust=2.2, kmaxFP=10 ** 9, nMax=200, pimrange=[0.0, 5.0, 1.0], beta=1.25, fignums=[0, 1]):
    # def plotMFIdistsBetaEps(bclust=2.2, kmaxFP=10**9, nMax=200, pimlist=[0.0,1.0, 2.0, 3.0, 4.0, 4.9], beta=1.25, fignums=[0,1]):
    # (this function is probably redundant. same as ...Beta(), but fix beta and range over pim.) we know we get nice PL
    # when we vary the shape dimension. what about if we fix D (beta) and vary eps. with the fractal-footprint?
    #
    # fig 5 in PRE pub.
    #
    # pimrange=[0.0,4.9,1.]
    # "beta" version, use footprint ~ n**beta 1<beta<2.0 (or maybe 2.25 or something).
    # for now, fixed epsilon (pim), fixed rho.
    # rhorange = [minrho, maxrho, dRho]
    # note: bcluse is slope of b-distribution, beta is the exponent for shape area/raduis (n) scaling.
    fsize = 20
    thisfont = pltf.FontProperties(size=fsize)
    thisfont2 = pltf.FontProperties(size=fsize - 2)
    #
    fpmodel = 2  # aka, MFI with fractal dimension treatment (as opposed to solid shapes, etc.)
    rho = 1.0  # basically, this puts all the empty sites into the fractal/branching structure.
    thisrho = rho
    bofpim = []
    for fignum in fignums:
        plt.figure(fignum)
        plt.clf()
        plt.xlabel("$log_{10}(k)$", size=fsize + 2)
        plt.ylabel("$log_{10}(N(k))$", size=fsize + 2)
        #
        # starts=[]
        #
    primeRhos = [0.1, 0.3, 0.5, 0.7, 0.9, 1.0]
    # thisrho=rhorange[0]
    icount = 0
    # while thisrho<=rhorange[1]:
    # for beta in betas:
    pim = pimrange[0]
    pim0 = pim
    while pim0 <= pimrange[1]:
        # for pim in pimlist:
        # X=getMFIsquarePropModel(bclust, thisrho, pim, kmaxFP, nMax, fpmodel)
        pim = pim0
        if pim > 4.9:
            pim = 4.9
        print "prams: %s, %s, %s, %s, %s, %s, %s" % (bclust, thisrho, pim, kmaxFP, nMax, fpmodel, beta)
        # pim=pimrange[0]+float(icount)*pimrange[2]
        X = getMFIsquarePropModel(bclust, thisrho, pim, kmaxFP, nMax, fpmodel, beta)
        print "beta=%f, len=%d" % (beta, len(X))
        x = []
        y1 = []
        y2 = []
        # xstart=25
        xstart = 15
        sxtop = 500
        for rw in X:
            # print rw
            x += [math.log10(rw[2])]
            # print rw[3]
            y1 += [math.log10(rw[3])]
            y2 += [math.log10(rw[4])]
        lf1 = yp.linefit([x[xstart:], y1[xstart:]])
        lf2 = yp.linefit([x[xstart:], y2[xstart:]])
        lf1.doFit()
        lf2.doFit()
        # lf1.doFit(None, None, 3)
        # lf2.doFit(None, None, 3)
        #
        dotsies = yp.integerSpacedPoints([x[1:], y1[1:]], 0.5)
        dotsies[0] += [x[-1]]
        dotsies[1] += [y1[-1]]
        if fpmodel > 1:
            bofpim += [[pim, beta, lf1.a, -lf1.b, lf1.meanVar(), lf2.a, -lf2.b, lf2.meanVar()]]
        else:
            bofpim += [[pim, lf1.a, -lf1.b, lf1.meanVar(), lf2.a, -lf2.b, lf2.meanVar()]]
        plt.figure(fignums[0])
        # plt.title('$\\beta=2.2$')
        # plt.plot(x[1:],y1[1:],'%s.-' % yp.pycolor(icount), label='$\\rho = %s, \\epsilon=%s, D=%s, b=%s$' % (str(thisrho), str(pim), str(beta), str(-lf1.b)[0:5]), lw=2)		# beta!=2
        plt.plot(
            dotsies[0],
            dotsies[1],
            "%s%s" % (yp.pycolor(icount), yp.fitMarkerShortList[icount % len(yp.fitMarkerShortList)]),
            label="$\\epsilon=%s, b=%s$" % (str(pim), str(-lf1.b)[0:5]),
            ms=10,
        )
        plt.plot(x[1:], y1[1:], "%s-" % yp.pycolor(icount), lw=2, ms=10)  # beta!=2
        plt.plot(
            [x[0], x[xstart], x[-1]],
            [lf1.a + lf1.b * x[0], lf1.a + lf1.b * x[xstart], lf1.a + lf1.b * x[-1]],
            "%s|-" % yp.pycolor(icount),
            ms=15,
        )
        plt.figure(fignums[1])
        # plt.title('$\\beta=2.0$')
        # plt.plot(x[1:], y2[1:], '%s.-' % yp.pycolor(icount), label='$\\rho = %s, \\epsilon=%s, D=%s, b=%s$' % (str(thisrho), str(pim), str(beta), str(-lf2.b)[0:5]), lw=2)		# beta=2 approximation
        plt.plot(
            x[1:],
            y2[1:],
            "%s.-" % yp.pycolor(icount),
            label="$\\epsilon=%s, b=%s$" % (str(pim), str(-lf2.b)[0:5]),
            lw=2,
            ms=10,
        )  # beta=2
        plt.plot(
            [x[0], x[xstart], x[-1]],
            [lf2.a + lf2.b * x[0], lf2.a + lf2.b * x[xstart], lf2.a + lf2.b * x[-1]],
            "%s|-" % yp.pycolor(icount),
            ms=15,
        )
        icount += 1
        pim0 += pimrange[2]
        #
        # thisrho+=rhorange[2]
        #
    for fignum in fignums:
        plt.figure(fignum)
        ax = plt.gca()
        plt.subplots_adjust(bottom=0.15)
        plt.setp(ax.get_xticklabels(), fontsize=fsize)
        plt.setp(ax.get_yticklabels(), fontsize=fsize)

        # lgd=plt.legend(loc='best', numpoints=1, title='$D=1.25$', prop=thisfont2, ncol=1)
        lgd = plt.legend(loc="best", numpoints=1, prop=thisfont2, ncol=1)
        lgd.set_title("$D=1.25$")
        plt.setp(lgd.get_title(), fontsize=fsize)
        if fignum > 0:
            continue
        plt.savefig(
            "writeup/mfi-aps/mfi-PRE-letter/figs/mfi-fractalType-varEps-bc%s-D125.png" % str(bclust).replace(".", "")
        )
        plt.savefig(
            "writeup/mfi-aps/mfi-PRE-letter/figs/mfi-fractalType-varEps-bc%s-D125.eps" % str(bclust).replace(".", "")
        )
    plt.show()

    return bofpim
예제 #3
0
def plotMFIdistsBeta(
    bclust=2.2,
    kmaxFP=10 ** 9,
    nMax=200,
    pim=4.9,
    betas=[0.9, 1.0, 1.25, 1.5, 1.75, 2.0, 2.5],
    fignums=[0, 1],
    dosave=False,
):
    # "Fig-4" in PRE publication.
    #
    # "beta" version, use footprint ~ n**beta 1<beta<2.0 (or maybe 2.25 or something).
    # for now, fixed epsilon (pim), fixed rho.
    # rhorange = [minrho, maxrho, dRho]
    # note: bcluse is slope of b-distribution, beta is the exponent for shape area/raduis (n) scaling.
    fpmodel = 2
    rho = 1.0  # basically, this puts all the empty sites into the fractal/branching structure.
    thisrho = rho
    #
    fsize = 20
    thisfont = pltf.FontProperties(size=fsize)
    thisfont2 = pltf.FontProperties(size=fsize - 2)
    #
    bofpim = []
    for fignum in fignums:
        plt.figure(fignum)
        plt.clf()
        plt.xlabel("$log_{10}(k)$", size=fsize + 2)
        plt.ylabel("$log_{10}(N(k))$", size=fsize + 2)
        #
        # starts=[]
        #
    primeRhos = [0.1, 0.3, 0.5, 0.7, 0.9, 1.0]
    # thisrho=rhorange[0]
    icount = 0
    # while thisrho<=rhorange[1]:
    fitMarkerShortList = ["o", "^", "s", "p", "*", "h", "+", "H", "D", "x"]
    for beta in betas:
        # X=getMFIsquarePropModel(bclust, thisrho, pim, kmaxFP, nMax, fpmodel)
        print "prams: %s, %s, %s, %s, %s, %s, %s" % (bclust, thisrho, pim, kmaxFP, nMax, fpmodel, beta)
        X = getMFIsquarePropModel(bclust, thisrho, pim, kmaxFP, nMax, fpmodel, beta)
        print "beta=%f, len=%d" % (beta, len(X))
        x = []
        y1 = []
        y2 = []
        # xstart=25
        xstart = 2
        sxtop = 500
        for rw in X:
            # print rw
            x += [math.log10(rw[2])]
            # print rw[3]
            y1 += [math.log10(rw[3])]
            y2 += [math.log10(rw[4])]
        lf1 = yp.linefit([x[xstart:], y1[xstart:]])
        lf2 = yp.linefit([x[xstart:], y2[xstart:]])
        lf1.doFit()
        lf2.doFit()
        # lf1.doFit(None, None, 3)
        # lf2.doFit(None, None, 3)
        #
        if fpmodel > 1:
            bofpim += [[pim, beta, lf1.a, -lf1.b, lf1.meanVar(), lf2.a, -lf2.b, lf2.meanVar()]]
        else:
            bofpim += [[pim, lf1.a, -lf1.b, lf1.meanVar(), lf2.a, -lf2.b, lf2.meanVar()]]
        plt.figure(fignums[0])
        # plt.title('$\\beta=2.2$')
        # plt.plot(x[1:],y1[1:],'%s.-' % yp.pycolor(icount), label='$\\rho = %s, \\epsilon=%s, \\beta_s=%s, b=%s$' % (str(thisrho), str(pim), str(beta), str(-lf1.b)[0:5]), lw=2)		# beta!=2
        dotsies = yp.integerSpacedPoints([x[1:], y1[1:]], 0.5)
        dotsies[0] += [x[-1]]
        dotsies[1] += [y1[-1]]  # add end-bits for completeness.
        plt.plot(x[1:], y1[1:], "%s-" % yp.pycolor(icount), lw=2, ms=10)  # beta!=2
        plt.plot(
            dotsies[0],
            dotsies[1],
            "%s%s" % (yp.pycolor(icount), fitMarkerShortList[icount % len(fitMarkerShortList)]),
            label="$D=%s, b=%s$" % (str(beta), str(-lf1.b)[0:5]),
            ms=10,
        )
        plt.plot(
            [x[0], x[xstart], x[-1]],
            [lf1.a + lf1.b * x[0], lf1.a + lf1.b * x[xstart], lf1.a + lf1.b * x[-1]],
            "%s|-" % yp.pycolor(icount),
            ms=20,
            lw=2,
        )
        #
        plt.figure(fignums[1])
        # plt.title('$\\beta=2.0$')
        # plt.plot(x[1:], y2[1:], '%s.-' % yp.pycolor(icount), label='$\\rho = %s, \\epsilon=%s, \\beta_s=%s, b=%s$' % (str(thisrho), str(pim), str(beta), str(-lf2.b)[0:5]), lw=2)		# beta=2 approximation
        plt.plot(
            x[1:],
            y2[1:],
            "%s.-" % yp.pycolor(icount),
            label="$D=%s, b=%s$" % (str(beta), str(-lf2.b)[0:5]),
            lw=2,
            ms=10,
        )  # beta=2 approximation
        plt.plot(
            [x[0], x[xstart], x[-1]],
            [lf2.a + lf2.b * x[0], lf2.a + lf2.b * x[xstart], lf2.a + lf2.b * x[-1]],
            "%s|-" % yp.pycolor(icount),
            ms=15,
            lw=2,
        )
        icount += 1
        #
        # thisrho+=rhorange[2]
        #
    for fignum in fignums:
        plt.figure(fignum)
        ax = plt.gca()
        plt.subplots_adjust(bottom=0.15)
        plt.setp(ax.get_xticklabels(), fontsize=fsize)
        plt.setp(ax.get_yticklabels(), fontsize=fsize)

        # plt.legend(loc='best', numpoints=1, prop=thisfont2, ncol=1, title='$\\epsilon=4.9$')
        lgd = plt.legend(loc="best", numpoints=1, prop=thisfont2, ncol=1)
        lgd.set_title("$\\epsilon=4.9$")
        plt.setp(lgd.get_title(), fontsize=fsize)
        # mfi-fractalType-varEps-bc22-D125
        if fignum > 0:
            continue
        if dosave:
            plt.savefig(
                "writeup/mfi-aps/mfi-PRE-letter/figs/mfi-fractalType-eps49-bc%s-varD.png" % str(bclust).replace(".", "")
            )
            plt.savefig(
                "writeup/mfi-aps/mfi-PRE-letter/figs/mfi-fractalType-eps49-bc%s-varD.eps" % str(bclust).replace(".", "")
            )
    plt.show()
    return bofpim
예제 #4
0
def plotMFIdists(
    bclust=2.2, rho=0.59, kmaxFP=10 ** 6, nMax=200, pimrange=[0.0, 4.9], doClf=[True, True, False], fpmodel=1, lineNum=0
):
    # pim=0.0
    # lineNum is the index of the line on the plot when we plot multiple lines on a single canvas.
    beta = 1.5
    print "lineNum: %d" % lineNum
    xstart = 15
    pim = pimrange[0]
    bofpim = []
    plt.figure(0)
    if doClf[0]:
        plt.clf()
    plt.figure(1)
    if doClf[1]:
        plt.clf()

    plt.figure(3)
    plt.clf()
    plt.figure(4)
    plt.clf()
    # primePims=[0.0, .4, 1.0, 1.4, 2.0, 2.4, 3.0, 3.4, 4.0, 4.6, 4.8]
    # primePims=[0, 4, 10, 14, 20, 24, 30, 34, 40, 46, 49]
    primePims = [0, 10, 20, 30, 40, 48]

    icount = -1
    icount2 = 0
    while pim <= (pimrange[1] + 0.0001):
        print pim
        icount += 1
        X = getMFIsquarePropModel(bclust, rho, pim, kmaxFP, nMax, fpmodel, beta)
        x = []
        y1 = []
        y2 = []
        for rw in X:
            # print rw
            x += [math.log10(rw[2])]
            # print rw[3]
            y1 += [math.log10(rw[3])]
            y2 += [math.log10(rw[4])]
        lf1 = yp.linefit([x[xstart:], y1[xstart:]])
        lf2 = yp.linefit([x[xstart:], y2[xstart:]])
        lf1.doFit()
        lf2.doFit()
        # lf1.doFit(None, None, 3)
        # lf2.doFit(None, None, 3)
        #
        bofpim += [[pim, lf1.a, -lf1.b, lf1.meanVar(), lf2.a, -lf2.b, lf2.meanVar()]]
        a1 = bofpim[-1][1]
        b1 = bofpim[-1][2]
        a2 = bofpim[-1][4]
        b2 = bofpim[-1][5]

        plt.figure(0)
        # plt.loglog(map(operator.itemgetter(2), X), map(operator.itemgetter(3), X), '.-')
        plt.plot(x, y1, "%s.-" % yp.pycolor(icount), label="$\\epsilon=%s, b=%s$" % (str(pim), str(-lf1.b)))  # beta!=2
        # plt.plot([x[0], x[-1]], [a1-b1*x[0], a1-b1*x[-1]], '%s*-' % yp.pycolor(icount))
        #
        plt.figure(1)
        # plt.loglog(map(operator.itemgetter(2), X), map(operator.itemgetter(4), X), '.-')
        plt.plot(
            x, y2, "%s.-" % yp.pycolor(icount), label="$\\epsilon=%s, b=%s$" % (str(pim), str(-lf2.b))
        )  # beta=2 approximation
        # plt.plot([x[0], x[-1]], [a2-b2*x[0], a2-b2*x[-1]], '%s*-' % yp.pycolor(icount))
        #
        # plt.loglog(map(operator.itemgetter(2), X), map(operator.itemgetter(3), X), '.-')
        if int(10.0 * pim) in primePims:
            plt.figure(3)
            plt.plot(
                x,
                y1,
                "%s.-" % yp.pycolor(icount2),
                label="$\\epsilon=%s, b=%s$" % (str(pim), str(-round(lf1.b, 2))),
                lw=2,
            )
            plt.plot(
                [x[0], x[xstart], x[-1]],
                [a1 - b1 * x[0], a1 - b1 * x[xstart], a1 - b1 * x[-1]],
                "%s*-" % yp.pycolor(icount2),
            )
            plt.figure(4)
            plt.plot(
                x,
                y2,
                "%s.-" % yp.pycolor(icount2),
                label="$\\epsilon=%s, b=%s$" % (str(pim), str(-round(lf2.b, 2))),
                lw=2,
            )
            plt.plot(
                [x[0], x[xstart], x[-1]],
                [a2 - b2 * x[0], a2 - b2 * x[xstart], a2 - b2 * x[-1]],
                "%s*-" % yp.pycolor(icount2),
            )
            icount2 += 1
        pim += 0.2

        plt.figure(0)
    plt.legend(loc="upper right")
    plt.figure(1)
    plt.legend(loc="upper right")
    plt.figure(3)
    plt.legend(loc="lower left")
    plt.xlabel("$log(k)$", size=18)
    plt.ylabel("$log(N(k))$", size=18)
    plt.figure(4)
    plt.legend(loc="lower left")
    plt.xlabel("$log(k)$", size=18)
    plt.ylabel("$log(N(k))$", size=18)
    for i in xrange(5):
        plt.figure(i)
        plt.title("$\\rho=%f$" % rho)

    plt.figure(2)
    if doClf[2]:
        plt.clf()
    # if int(10.0*pim) in primePims:
    plt.plot(
        map(operator.itemgetter(0), bofpim),
        map(operator.itemgetter(2), bofpim),
        "%s.-" % yp.pycolor(lineNum),
        label="$ \\beta = 2.2, \\rho = %s $" % str(rho),
        lw=2,
    )
    plt.plot(
        map(operator.itemgetter(0), bofpim),
        map(operator.itemgetter(5), bofpim),
        "%s>-" % yp.pycolor(lineNum),
        label="$ \\beta = 2.0,  \\rho = %s $" % str(rho),
        lw=2,
    )
    plt.xlabel("$\\epsilon$", size=18)
    plt.ylabel("$b_{fires}$", size=18)
    plt.show()
    #
    return bofpim
예제 #5
0
파일: sopac.py 프로젝트: markyoder/sopac
def plotDonsTriangle(stations=['farb', 'diab', 'ohln'], startDate=dtm.datetime(2000, 1,1), endDate=dtm.datetime.now(), deltaT=None):
	# deltaT=dtm.timedelta(days=1)
	plt.ion()
	timelen=10**8.0	# length magnifier for velocity vectors.
	timelenmap=10**0.0
	if deltaT==None:
		# instead of a proper trace, just get the first and last positions (start date, end date).
		# but, the easiest way to do this programatically is to use the getTraces() function.
		thistdelta=endDate-startDate
		traces=getStationTraces(stations, startDate, endDate, thistdelta)
	else:
		traces=getStationTraces(stations, startDate, endDate, deltaT)
		# and next, figure out if we ended on endDate. if so, add it (or just add it and delete it if it's the same).
		#if traces[-1][0]!=endDate.toordinal(): traces+=getStationTraces(stations, endDate, endDate)[1]
	#
	lfVelocities=getMeanStationVelocities1(traces)	# returns [[station, lon0, lat0, v_lon, vlat, siglon, siglat, sigVel_lon, sigVel_lat], []..]
	#
	#times=map(operator.itemgetter(0, traces))
	#stations=[]
	#for i in xrange(len(traces[0])):
	#	stations+=[map(operator.itemgetter(i), traces)]
	#
	polys=[]	# in general, we want polygons; one for each time-step of stations. these will be [[time, [[x,y], [x,y], ...]] ]
	for stas in traces:	# row of stations
		if stas[0]=='time':
			# header row
			continue
		# otherwise, we get [time, [position-sta1], [position-sta2], ...]
		polys+=[[stas[0], []]]	# new polygon; start with time. so a row is like [time, [positions]]
		#for sta in stas[1]:
		for i in xrange(1, len(stas)):
			sta=stas[i]
			# each station...
			#print polys, sta
			polys[-1][1]+=[[sta[1], sta[0]]]	# lon, lat 
		# and close the loop:
		polys[-1][1]+=[polys[-1][1][0]]
		#
	vels=[]
	for i in xrange(len(polys[0][1])-1):
		#vels+=[[polys[-1][1][i][0]-polys[0][1][i][0], polys[-1][1][i][1]-polys[0][1][i][1]] ]
		vels+=[[lfVelocities[i][3], lfVelocities[i][4]]] 
		#
	#
	# plotting:
	plt.figure(1)
	plt.clf()
	plt.figure(0)
	plt.clf()
	#
	for ply in polys:
	#while iply<len(polys):
		#ply=polys[iply]
		Xs=map(operator.itemgetter(0), ply[1])
		Ys=map(operator.itemgetter(1), ply[1])
		plt.fill(Xs, Ys, alpha=.25)
		#
	#
	for iply in xrange(len(polys[0][1])-1):
		thiscolor=yp.pycolor(iply)
		#print "iply: %d" % iply
		#plt.plot([Xs[iply], Xs[iply]+vels[iply][0]*timelen], [Ys[iply], Ys[iply]+vels[iply][1]*timelen], color=thiscolor)
		#plt.arrow(startPoints[i][1], startPoints[i][0], meanVels[i][2]*vectorTime, meanVels[i][1]*vectorTime, \
#lw=2, ec=thiscolor, fc=thiscolor, head_width=.05, head_length=.05 )
		plt.arrow(Xs[iply], Ys[iply], vels[iply][0]*timelen, vels[iply][1]*timelen, \
lw=2, ec=thiscolor, fc=thiscolor, head_width=.05, head_length=.05 )
	#
	# now the map plot:
	# set up a map:
	###############
	plt.figure(1)
	lats=Ys
	lons=Xs
	vlats=map(operator.itemgetter(1), vels)
	vlons=map(operator.itemgetter(0), vels)
	
	#lats+=(scipy.array(lats)+scipy.array(vlats)*timelen).tolist()
	#lons+=(scipy.array(lons)+scipy.array(vlons)*timelen).tolist()
	
	#print lats, lons
	llpad=.25
	llr=[[min(lats)-llpad, min(lons)-llpad], [max(lats)+llpad, max(lons)+llpad]]
	print llr
	cntr=[float(llr[0][0])+(llr[1][0]-float(llr[0][0]))/2.0, float(llr[0][1])+(llr[1][1]-float(llr[0][1]))/2.0]
	catmap=mpbm.Basemap(llcrnrlon=llr[0][1], llcrnrlat=llr[0][0], urcrnrlon=llr[1][1], urcrnrlat=llr[1][0], resolution ='l', projection='tmerc', lon_0=cntr[1], lat_0=cntr[0])
	#
	thisax=plt.gca()
	catmap.ax=thisax
	#
	catmap.drawcoastlines(color='gray')
	catmap.drawcountries(color='gray')
	catmap.drawstates(color='gray')
	catmap.drawrivers(color='gray')
	catmap.fillcontinents(color='beige')
	
	catmap.drawmeridians(range(int(llr[0][1]-2.0), int(llr[1][1]+2.0)), color='k', labels=[1,1,1,1])
	catmap.drawparallels(range(int(llr[0][0]-2.0), int(llr[1][0]+2.0)), color='k', labels=[1, 1, 1, 1])
	#
	iply=0	# just a polygon index tracker.
	for ply in polys:
	#while iply<len(polys):
		#ply=polys[iply]
		iply+=1
		Xs=map(operator.itemgetter(0), ply[1])
		Ys=map(operator.itemgetter(1), ply[1])
		mapXs, mapYs=catmap(Xs, Ys)
		
		if iply==1: plt.fill(mapXs, mapYs, alpha=.25)	# here, iply is the index of the polygon.
		#
	#
	# here, iply is the index of a single vertex of one (first or last) polygon.
	for iply in xrange(len(polys[-1][1])-1):
		thiscolor=yp.pycolor(iply)
		#print "iply: %d" % iply
		#plt.plot([Xs[iply], Xs[iply]+vels[iply][0]*timelen], [Ys[iply], Ys[iply]+vels[iply][1]*timelen], color=thiscolor)
		#plt.arrow(startPoints[i][1], startPoints[i][0], meanVels[i][2]*vectorTime, meanVels[i][1]*vectorTime, \
#lw=2, ec=thiscolor, fc=thiscolor, head_width=.05, head_length=.05 )
		mapX, mapY = catmap(Xs[iply], Ys[iply])
		#plt.arrow(Xs[iply], Ys[iply], vels[iply][0]*timelen, vels[iply][1]*timelen, lw=2, ec=thiscolor, fc=thiscolor, head_width=.05, head_length=.05 )
		#
		# and arrows for the map too. first, get the end positions and projected lengths.
		aryXs=scipy.array(Xs[iply])
		aryYs=scipy.array(Ys[iply])
		mapx1, mapy1 = catmap(aryXs+scipy.array(vels[iply][0])*timelen, aryYs + scipy.array(vels[iply][1])*timelen)
		mapVelX=scipy.array(mapx1)-mapX
		mapVelY=scipy.array(mapy1)-mapY	# projected lengths.
		# and get arrow head lengths:
		arrow_head_scaling=.03
		map_head_X, map_head_Y=catmap(aryXs+arrow_head_scaling, aryYs+arrow_head_scaling)
		map_head_w=map_head_X-scipy.array(mapX)
		map_head_l=map_head_Y-scipy.array(mapY)	# so the width/length might look weird if the projections are not square, since some "lengths" are x-like
																# and other "lengths" are y-like (and vice versa of course for "width"/y.
		#plt.arrow(mapX, mapY, vels[iply][0]*timelen, vels[iply][1]*timelen, lw=2, ec=thiscolor, fc=thiscolor, head_width=.05, head_length=.05 )
		#plt.arrow(mapX, mapY, mapVelX*timelenmap, mapVelY*timelenmap, lw=2, ec=thiscolor, fc=thiscolor, head_width=.05, head_length=.05 )
		plt.arrow(mapX, mapY, mapVelX*timelenmap, mapVelY*timelenmap, lw=2, ec=thiscolor, fc=thiscolor, head_width=map_head_w, head_length=map_head_l )
	#
	# and plot the last polygon as well:
	plt.fill(mapXs, mapYs, alpha=.25)
	###############
	pangles=getpolyangles(polys)
	plotpolyangles(pangles, 'asecs')
	#
	return [polys, vels]
예제 #6
0
파일: sopac.py 프로젝트: markyoder/sopac
def plotMeanStationVelocities(vels, pos, vectorTime=1000000., llrange=None):
	# velocities and positions. really, we only need the first row for each position (we'll strip the first 2 rows for each set of station positions, so we can
	# take the whole enchilada as well).
	#
	# get mean velocities; draw vectors from the first position of each station, then draw error-ellipses.
	# how do we scale the vectors (and error-ellipses)? we'll sort out something. maybe find the max/min velocity vectors and scale the representaiton to alpha*map extents.
	#
	#  llrange -> [lrlon, lrlat, urlon, urlat]
	# vectorTime: time to determine vector length.
	#
	myheaders=pos[0]
	startPoints=[]
	for i in xrange(1, len(pos[1])):
		startPoints+=[pos[1][i]]
	#print "start points: %s" % str(startPoints)
	#
	meanVels=getMeanStationVelocities(vels)
	#print "mean vels: %s" % str(meanVels)
	#
	#endPoints=[]
	#for istation in xrange(len(startPoints)):
	#	endPoints+=[[]]
	#	for i in xrange(3):
	#		endPoints[-1]+=[startPoints[istation][i] + vectorTime*meanVels[istation][i] ]
	
	#return [meanVels, startPoints]
	#
	# and plot the vectors:
	plt.ion()
	plt.figure(0)
	plt.clf()
	
	for i in xrange(len(startPoints)):
		#print "arrow prams: %f, %f, %e, %e" % (startPoints[i][0], startPoints[i][1], meanVels[i][1]*vectorTime, meanVels[i][2]*vectorTime)
		thiscolor=yp.pycolor(i)
		#plt.arrow(startPoints[i][0], startPoints[i][1], meanVels[i][1]*vectorTime, meanVels[i][2]*vectorTime, \
		#lw=3, ec=thiscolor, fc=thiscolor)
		plt.arrow(startPoints[i][1], startPoints[i][0], meanVels[i][2]*vectorTime, meanVels[i][1]*vectorTime, \
		lw=2, ec=thiscolor, fc=thiscolor, head_width=.05, head_length=.05 )
		#width=100, head_width=500, head_length=50)
		#plt.plot([startPoints[i][0], startPoints[i][0]+meanVels[i][1]*vectorTime], [startPoints[i][1], startPoints[i][1]+meanVels[i][2]*vectorTime] )
		plt.plot([startPoints[i][1], startPoints[i][1]+meanVels[i][2]*vectorTime], [startPoints[i][0], startPoints[i][0]+meanVels[i][1]*vectorTime], color=thiscolor)
	
	plt.figure(1)
	plt.clf()
	#
	# make basemap stuff
	# we'll need max extents:
	lats=map(operator.itemgetter(0), startPoints)
	lons=map(operator.itemgetter(1), startPoints)
	vlats=map(operator.itemgetter(1), meanVels)
	vlons=map(operator.itemgetter(2), meanVels)
	
	lats+=(scipy.array(lats)+scipy.array(vlats)*vectorTime).tolist()
	lons+=(scipy.array(lons)+scipy.array(vlons)*vectorTime).tolist()
	
	print lats, lons
	llpad=.25
	llr=[[min(lats)-llpad, min(lons)-llpad], [max(lats)+llpad, max(lons)+llpad]]
	print llr
	cntr=[float(llr[0][0])+(llr[1][0]-float(llr[0][0]))/2.0, float(llr[0][1])+(llr[1][1]-float(llr[0][1]))/2.0]
	catmap=mpbm.Basemap(llcrnrlon=llr[0][1], llcrnrlat=llr[0][0], urcrnrlon=llr[1][1], urcrnrlat=llr[1][0], resolution ='l', projection='tmerc', lon_0=cntr[1], lat_0=cntr[0])
	#
	thisax=plt.gca()
	catmap.ax=thisax
	#
	catmap.drawcoastlines(color='gray')
	catmap.drawcountries(color='gray')
	catmap.drawstates(color='gray')
	catmap.drawrivers(color='gray')
	catmap.fillcontinents(color='beige')
	
	catmap.drawmeridians(range(int(llr[0][1]-2.0), int(llr[1][1]+2.0)), color='k', labels=[1,1,1,1])
	catmap.drawparallels(range(int(llr[0][0]-2.0), int(llr[1][0]+2.0)), color='k', labels=[1, 1, 1, 1])
	#
	#return None
	for i in xrange(len(startPoints)):
		#print "arrow prams: %f, %f, %f, %f" % (startPoints[i][0], startPoints[i][1], meanVels[i][1], meanVels[i][2])
		thiscolor=yp.pycolor(i)

		# the arrow is more complicated here. get the dx, dy from X,Y below.
		X, Y=catmap([startPoints[i][1], startPoints[i][1]+meanVels[i][2]*vectorTime], [startPoints[i][0], startPoints[i][0]+meanVels[i][1]*vectorTime])
		arrowHeadX, arrowHeadY=catmap([startPoints[i][1]+meanVels[i][2]*vectorTime+.05], [startPoints[i][0]+meanVels[i][1]*vectorTime+.05])
		plt.plot(X,Y, color=thiscolor, lw=2, label='%s' % meanVels[i][0])
		plt.arrow(X[0], Y[0], (X[1]-X[0]), (Y[1]-Y[0]), lw=2, ec=thiscolor, fc=thiscolor, head_width=arrowHeadX[0]-X[1], head_length=arrowHeadY[0]-Y[1], )
	#print llrange
	plt.legend(loc='lower left', numpoints=1)
	#plt.show()
	
	return None