def iplotDImean(Dec,Inc,a95,color='k',marker='o',label=''):
    """
    Plot a mean declination, inclination with alpha_95 ellipse on an equal area plot.

    Before this function is called a plot needs to be initialized with code that looks 
    something like:
    >fignum = 1
    >plt.figure(num=fignum,figsize=(10,10),dpi=160)
    >IPmag.iplotNET(fignum)

    Parameters
    ----------

    Dec : declination of mean being plotted
    Inc : inclination of mean being plotted
    a95 : a95 confidence ellipse of mean being plotted
    color : the default color is black. Other colors can be chosen (e.g. 'r')
    marker : the default is a circle. Other symbols can be chose (e.g. 's')
    label : the default is no label. Labels can be assigned
    """
    DI_dimap=pmag.dimap(Dec,Inc)
    if Inc < 0:
        pylab.plot(DI_dimap[0],DI_dimap[1],markeredgecolor=color , markerfacecolor='white', marker=marker,label=label)
    if Inc >= 0:
        pylab.plot(DI_dimap[0],DI_dimap[1],color=color,marker=marker,label=label)
    Xcirc,Ycirc=[],[]
    Da95,Ia95=pmag.circ(Dec,Inc,a95)
    pylab.legend(loc=2)
    for k in  range(len(Da95)):
        XY=pmag.dimap(Da95[k],Ia95[k])
        Xcirc.append(XY[0])
        Ycirc.append(XY[1])
    pylab.plot(Xcirc,Ycirc,color)
    pylab.tight_layout()
Esempio n. 2
0
def main():
    """
    NAME
        di_eq.py
    
    DESCRIPTION
      converts dec, inc pairs to  x,y pairs using equal area projection
      NB: do only upper or lower  hemisphere at a time: does not distinguish between up and down.
    
    SYNTAX
        di_eq.py [command line options] [< filename]
    
    OPTIONS
        -f FILE, input file
    """
    out=""
    UP=0
    if '-h' in sys.argv:
        print main.__doc__
        sys.exit()
    if '-f' in sys.argv:
        dat=[]
        ind=sys.argv.index('-f')
        file=sys.argv[ind+1]  
        f=open(file,'rU')
        input=f.readlines()
    else:
        input = sys.stdin.readlines()  # read from standard input
    for line in input:
        rec=line.split()
        d,i=float(rec[0]),float(rec[1]) 
        XY=pmag.dimap(d,i)
        print XY[0],XY[1] # 
Esempio n. 3
0
def plot_AMS(sdata,pointsize=50,errors='None',bedding=[],incolor='N',):
    """
    adapted from pmagplotlib.plotANIS
    set errors to 'h' for hext ellipses, 'b' for bootstrap, 'p' for parametric bootstrap
    bootstrap trials currently hard-coded as 1000
    for bedding, give as [strike,dip] ;
    """
    subplot_net() #set up stereonet
    if incolor=='N': colours=['0.4','0.6','0.5'] #specify greyscale colours
    else: colours=['lightcoral','lightskyblue','lightgreen']
    #if bedding plot bedding plane
    if bedding !=[]:
        # hard-coded version of pmag.plotC
        D_c,I_c=pmag.circ(bedding[0]-90.,90.-bedding[1],90.)
        X_c_d,Y_c_d=[],[]
        for k in range(len(D_c)):
            XY=pmag.dimap(D_c[k],I_c[k])
            if I_c[k]>0:
                X_c_d.append(XY[0])
                Y_c_d.append(XY[1])
        plt.plot(X_c_d,Y_c_d,color='grey',dashes=[10,2],linewidth=3,zorder=1)
    Vs=[]
    #plot individual sample data
    for s in sdata:
        tau,V=pmag.doseigs(s)
        Vs.append(V)
    plotEVEC(Vs,pointsize,colours)
    #plot mean eigenvectors
    nf,sigma,avs=pmag.sbar(sdata)
    Vs=[]
    mtau,mV=pmag.doseigs(avs)
    Vs.append(mV)
    plotEVEC(Vs,pointsize*4,['w','w','w'], 'black',7)
    #plot confidence limits
    hpars=pmag.dohext(nf,sigma,avs)
    if errors=='h':
        ellpars=[hpars["v1_dec"],hpars["v1_inc"],hpars["e12"],hpars["v2_dec"],hpars["v2_inc"],hpars["e13"],hpars["v3_dec"],hpars["v3_inc"]]
        plotELL(ellpars,'black',1,1)
        ellpars=[hpars["v2_dec"],hpars["v2_inc"],hpars["e23"],hpars["v3_dec"],hpars["v3_inc"],hpars["e12"],hpars["v1_dec"],hpars["v1_inc"]]
        plotELL(ellpars,'black',1,1)
        ellpars=[hpars["v3_dec"],hpars["v3_inc"],hpars["e13"],hpars["v1_dec"],hpars["v1_inc"],hpars["e23"],hpars["v2_dec"],hpars["v2_inc"]]
        plotELL(ellpars,'black',1,1)
    elif errors=='b' or errors=='p':
        if errors=='p': ipar=1
        else: ipar=0
        Tmean,Vmean,Taus,BVs=pmag.s_boot(sdata,ipar,1000) # get eigenvectors of mean tensor
        # the problem with the bootstrap is that for fabrics where one or more eigenvectors is close to the horizontal,
        # you end up with dipolar data        
                        
        bpars=pmag.sbootpars(Taus,BVs,Vmean)
        bpars['t1']=hpars['t1']
        bpars['t2']=hpars['t2']
        bpars['t3']=hpars['t3']
        #have to pair zeta value with eta dec/inc, and vice-versa, to align error ellipses correctly.
        ellpars=[bpars["v1_dec"],bpars["v1_inc"],bpars["v1_eta"],bpars["v1_eta_dec"],bpars["v1_eta_inc"],bpars["v1_zeta"],bpars["v1_zeta_dec"],bpars["v1_zeta_inc"]]
        plotELL(ellpars,'black',1,1)
        ellpars=[bpars["v2_dec"],bpars["v2_inc"],bpars["v2_eta"],bpars["v2_eta_dec"],bpars["v2_eta_inc"],bpars["v2_zeta"],bpars["v2_zeta_dec"],bpars["v2_zeta_inc"]]
        plotELL(ellpars,'black',1,1)
        ellpars=[bpars["v3_dec"],bpars["v3_inc"],bpars["v3_eta"],bpars["v3_eta_dec"],bpars["v3_eta_inc"],bpars["v3_zeta"],bpars["v3_zeta_dec"],bpars["v3_zeta_inc"]]
        plotELL(ellpars,'black',1,1) 
def iplotDI(DIblock,color='k',label=''):
    """
    Plot declination, inclination data on an equal area plot

    This function modifies the plotDI function of PmagPy for use in the IPython notebook environment

    Parameters
    ----------

    DIblock : a DIblock is comprise of a list of unit vectors [dec,inc,1.]
    color : the default color is black. Other colors can be chosen (e.g. 'r')
    """
    # initialize the variables
    X_down,X_up,Y_down,Y_up=[],[],[],[]
    for rec in DIblock:
        Up,Down=0,0
        XY=pmag.dimap(rec[0],rec[1])
        if rec[1] >= 0:         
            X_down.append(XY[0])
            Y_down.append(XY[1])
        else:
            X_up.append(XY[0])
            Y_up.append(XY[1])

    if len(X_up)>0:
        pylab.scatter(X_up,Y_up,facecolors='none', edgecolors=color)

    if len(X_down)>0: 
        pylab.scatter(X_down,Y_down,facecolors=color, edgecolors=color)
    pylab.legend(loc=2)
    pylab.tight_layout()
Esempio n. 5
0
def subplot_net(title="", quadrant='all'):
    ax=plt.gca()
    # modified from plotNET to look nicer, play more nicely with subfigures; 
    # also modified to allow quadrants/halves only to be plotted
    """
    draws circle and tick marks for equal area projection
    can zoom in on quadrant/half of stereonet using quadrant='NE','E','S' etc.
    """
    quadrants= {'all': [-1.1,1.1,-1.1,1.1],'N': [-1.1,1.1,-0.1,1.1], 'E': [-0.1,1.1,-1.1,1.1], 
            'S': [-1.1,1.1,-1.1,0.1],'W': [-1.1,0.1,-1.1,1.1], 'NE': [-0.1,1.1,-0.1,1.1],
            'SE': [-0.1,1.1,-1.1,0.1],'SW': [-1.1,0.1,-1.1,0.1], 'NW': [-0.1,1.1,-1.1,0.1]}
     
    # make the perimeter
    ax.axis("off")
    Dcirc=np.arange(0,361.)
    Icirc=np.zeros(361,'f')
    Xcirc,Ycirc=[],[]
    for k in range(361):
        XY= pmag.dimap(Dcirc[k],Icirc[k])
        Xcirc.append(XY[0])
        Ycirc.append(XY[1])
    ax.plot(Xcirc,Ycirc,'k', linewidth=2, zorder=2)
    ax.set_xlim(quadrants[quadrant][:2])
    ax.set_ylim(quadrants[quadrant][-2:])
    # put on the tick marks
    Xsym,Ysym=[],[]
    for I in range(10,100,10):
        XY=pmag.dimap(0.,I)
        Xsym.append(XY[0])
        Ysym.append(XY[1])
    ax.scatter(Xsym,Ysym, color='lightgrey', marker='+', s=20)
    Xsym,Ysym=[],[]
    for I in range(10,90,10):
        XY=pmag.dimap(90.,I)
        Xsym.append(XY[0])
        Ysym.append(XY[1])
    ax.scatter(Xsym,Ysym,color='lightgrey', marker='+', s=20)
    Xsym,Ysym=[],[]
    for I in range(10,90,10):
        XY=pmag.dimap(180.,I)
        Xsym.append(XY[0])
        Ysym.append(XY[1])
    ax.scatter(Xsym,Ysym,color='lightgrey', marker='+', s=20)
    Xsym,Ysym=[],[]
    for I in range(10,90,10):
        XY=pmag.dimap(270.,I)
        Xsym.append(XY[0])
        Ysym.append(XY[1])
    ax.scatter(Xsym,Ysym,color='lightgrey', marker='+', s=20)
    for D in range(0,360,10):
        Xtick,Ytick=[],[]
        for I in range(4):
            XY=pmag.dimap(D,I)
            Xtick.append(XY[0])
            Ytick.append(XY[1])
        ax.plot(Xtick,Ytick,color='grey', linewidth=1.5,zorder=1) 
    ax.set_title(title)
    ax.set(aspect=1)
Esempio n. 6
0
def plotEVEC(Vs,symsize=40,colours=['lightcoral','lightskyblue','lightgreen'],symboledgecolor='none',level=5):
    """
    plots eigenvector directions of S vectors
    adapted from pmagplotlib.plotEVEC
    """
    symb,symkey=['s','v','o'],0 # plot V1s as squares, V2s as triangles and V3s as circles
    for VEC in range(3):
        X,Y=[],[]
        for Vdirs in Vs:
    #  plot the V1 data  first
            XY=pmag.dimap(Vdirs[VEC][0],Vdirs[VEC][1])
            X.append(XY[0])
            Y.append(XY[1])
        plt.scatter(X,Y,s=symsize,marker=symb[VEC],c=colours[VEC],edgecolors=symboledgecolor, zorder=level)
Esempio n. 7
0
def draw_net(FIG):
    FIG.clear()
    eq = FIG
    eq.axis((-1, 1, -1, 1))
    eq.axis("off")
    theta = arange(0.0, 2 * pi, 2 * pi / 1000)
    eq.plot(cos(theta), sin(theta), "k", clip_on=False, lw=1)
    # eq.vlines((0,0),(0.9,-0.9),(1.0,-1.0),'k')
    # eq.hlines((0,0),(0.9,-0.9),(1.0,-1.0),'k')
    # eq.plot([0.0],[0.0],'+k')

    Xsym, Ysym = [], []
    for I in range(10, 100, 10):
        XY = dimap(0.0, I)
        Xsym.append(XY[0])
        Ysym.append(XY[1])
    for I in range(10, 90, 10):
        XY = dimap(90.0, I)
        Xsym.append(XY[0])
        Ysym.append(XY[1])
    for I in range(10, 90, 10):
        XY = dimap(180.0, I)
        Xsym.append(XY[0])
        Ysym.append(XY[1])
    for I in range(10, 90, 10):
        XY = dimap(270.0, I)
        Xsym.append(XY[0])
        Ysym.append(XY[1])
    eq.plot(Xsym, Ysym, "k+", clip_on=False, mew=0.5)
    for D in range(0, 360, 10):
        Xtick, Ytick = [], []
        for I in range(4):
            XY = dimap(D, I)
            Xtick.append(XY[0])
            Ytick.append(XY[1])
        eq.plot(Xtick, Ytick, "k", clip_on=False, lw=0.5)
    eq.axes.set_aspect("equal")
def iplotNET(fignum):
    """
    draws circle and tick marks for equal area projection
    """
#
# make the perimeter
#
    pylab.figure(num=fignum)
    pylab.clf()
    pylab.axis("off")
    Dcirc=np.arange(0,361.)
    Icirc=np.zeros(361,'f')
    Xcirc,Ycirc=[],[]
    for k in range(361):
        XY= pmag.dimap(Dcirc[k],Icirc[k])
        Xcirc.append(XY[0])
        Ycirc.append(XY[1])
    pylab.plot(Xcirc,Ycirc,'k')
#
# put on the tick marks
    Xsym,Ysym=[],[]
    for I in range(10,100,10):
        XY=pmag.dimap(0.,I)
        Xsym.append(XY[0])
        Ysym.append(XY[1])
    pylab.plot(Xsym,Ysym,'k+')
    Xsym,Ysym=[],[]
    for I in range(10,90,10):
        XY=pmag.dimap(90.,I)
        Xsym.append(XY[0])
        Ysym.append(XY[1])
    pylab.plot(Xsym,Ysym,'k+')
    Xsym,Ysym=[],[]
    for I in range(10,90,10):
        XY=pmag.dimap(180.,I)
        Xsym.append(XY[0])
        Ysym.append(XY[1])
    pylab.plot(Xsym,Ysym,'k+')
    Xsym,Ysym=[],[]
    for I in range(10,90,10):
        XY=pmag.dimap(270.,I)
        Xsym.append(XY[0])
        Ysym.append(XY[1])
    pylab.plot(Xsym,Ysym,'k+')
    for D in range(0,360,10):
        Xtick,Ytick=[],[]
        for I in range(4):
            XY=pmag.dimap(D,I)
            Xtick.append(XY[0])
            Ytick.append(XY[1])
        pylab.plot(Xtick,Ytick,'k')
    pylab.axis("equal")
    pylab.tight_layout()
Esempio n. 9
0
def plotCONF(pars): #Modified from PmagPy (Tauxe et al., 2016)
	"""
	plots directions and confidence ellipses 
	"""


	#
	# put on the mean direction
	#
	x,y=[],[]
	XY=pmag.dimap(float(pars[0]),float(pars[1]))
	x.append(XY[0])
	y.append(XY[1])
	#pylab.figure(num=1)
	
	if pars[1]<1:plt.scatter(x, y, edgecolors='m',facecolors='w',marker='*',s=100,zorder=5)
	else:plt.scatter(x, y, edgecolors='w',facecolors='m',marker='*',s=100,zorder=5)
	#pylab.scatter(x,y,marker='^',s=80,c='g',zorder=2)
	#pylab.title(s)
	#
	# plot the ellipse
	#
	plotELL(pars,'m',0,1)
Esempio n. 10
0
def iplotDI(DIblock,color='k',marker='o',legend='no',label=''):
    """
    Plot declination, inclination data on an equal area plot

    This function modifies the plotDI function of PmagPy for use in the IPython notebook environment

    Required Parameters
    -----------
    DIblock : a DIblock is comprised of a list of unit vectors [dec,inc,1.]

    Optional Parameters
    -----------
    color : the default color is black. Other colors can be chosen (e.g. 'r')
    marker : the default marker is a circle ('o')
    label : the default label is blank ('')
    legend : the default is no legend ('no'). Putting 'yes' will plot a legend.
    """
    # initialize the variables
    X_down,X_up,Y_down,Y_up=[],[],[],[]
    for rec in DIblock:
        Up,Down=0,0
        XY=pmag.dimap(rec[0],rec[1])
        if rec[1] >= 0:         
            X_down.append(XY[0])
            Y_down.append(XY[1])
        else:
            X_up.append(XY[0])
            Y_up.append(XY[1])

    if len(X_up)>0:
        pylab.scatter(X_up,Y_up,facecolors='none', edgecolors=color, marker=marker, label=label)

    if len(X_down)>0: 
        pylab.scatter(X_down,Y_down,facecolors=color, edgecolors=color, marker=marker, label=label)
    if legend=='yes':
        pylab.legend(loc=2)
    pylab.tight_layout()
Esempio n. 11
0
def main():
    """
    NAME
        di_eq.py
    
    DESCRIPTION
      converts dec, inc pairs to  x,y pairs using equal area projection
      NB: do only upper or lower  hemisphere at a time: does not distinguish between up and down.
    
    SYNTAX
        di_eq.py [command line options] [< filename]
    
    OPTIONS
        -h  prints help message and quits
        -f FILE, input file
    """
    out=""
    UP=0
    if '-h' in sys.argv:
        print main.__doc__
        sys.exit()
    if '-f' in sys.argv:
        ind=sys.argv.index('-f')
        file=sys.argv[ind+1]  
        DI=numpy.loadtxt(file,dtype=numpy.float)
    else:
        DI = numpy.loadtxt(sys.stdin,dtype=numpy.float)  # read from standard input
    Ds=DI.transpose()[0]
    Is=DI.transpose()[1]
    if len(DI)>1: #array of data
       XY=pmag.dimap_V(Ds,Is)
       for xy in XY:
           print '%f %f'%(xy[0],xy[1])
    else: # single data point
       XY=pmag.dimap(Ds,Is)
       print '%f %f'%(XY[0],XY[1])
Esempio n. 12
0
def subplot_net(title="", quadrant='all'):
    ax = plt.gca()
    # modified from plotNET to look nicer, play more nicely with subfigures;
    # also modified to allow quadrants/halves only to be plotted
    """
    draws circle and tick marks for equal area projection
    can zoom in on quadrant/half of stereonet using quadrant='NE','E','S' etc.
    """
    quadrants = {
        'all': [-1.1, 1.1, -1.1, 1.1],
        'N': [-1.1, 1.1, -0.1, 1.1],
        'E': [-0.1, 1.1, -1.1, 1.1],
        'S': [-1.1, 1.1, -1.1, 0.1],
        'W': [-1.1, 0.1, -1.1, 1.1],
        'NE': [-0.1, 1.1, -0.1, 1.1],
        'SE': [-0.1, 1.1, -1.1, 0.1],
        'SW': [-1.1, 0.1, -1.1, 0.1],
        'NW': [-0.1, 1.1, -1.1, 0.1]
    }

    # make the perimeter
    ax.axis("off")
    Dcirc = np.arange(0, 361.)
    Icirc = np.zeros(361, 'f')
    Xcirc, Ycirc = [], []
    for k in range(361):
        XY = pmag.dimap(Dcirc[k], Icirc[k])
        Xcirc.append(XY[0])
        Ycirc.append(XY[1])
    ax.plot(Xcirc, Ycirc, 'k', linewidth=2, zorder=2)
    ax.set_xlim(quadrants[quadrant][:2])
    ax.set_ylim(quadrants[quadrant][-2:])
    # put on the tick marks
    Xsym, Ysym = [], []
    for I in range(10, 100, 10):
        XY = pmag.dimap(0., I)
        Xsym.append(XY[0])
        Ysym.append(XY[1])
    ax.scatter(Xsym, Ysym, color='lightgrey', marker='+', s=20)
    Xsym, Ysym = [], []
    for I in range(10, 90, 10):
        XY = pmag.dimap(90., I)
        Xsym.append(XY[0])
        Ysym.append(XY[1])
    ax.scatter(Xsym, Ysym, color='lightgrey', marker='+', s=20)
    Xsym, Ysym = [], []
    for I in range(10, 90, 10):
        XY = pmag.dimap(180., I)
        Xsym.append(XY[0])
        Ysym.append(XY[1])
    ax.scatter(Xsym, Ysym, color='lightgrey', marker='+', s=20)
    Xsym, Ysym = [], []
    for I in range(10, 90, 10):
        XY = pmag.dimap(270., I)
        Xsym.append(XY[0])
        Ysym.append(XY[1])
    ax.scatter(Xsym, Ysym, color='lightgrey', marker='+', s=20)
    for D in range(0, 360, 10):
        Xtick, Ytick = [], []
        for I in range(4):
            XY = pmag.dimap(D, I)
            Xtick.append(XY[0])
            Ytick.append(XY[1])
        ax.plot(Xtick, Ytick, color='grey', linewidth=1.5, zorder=1)
    ax.set_title(title)
    ax.set(aspect=1)
Esempio n. 13
0
def plot_AMS(
    sdata,
    pointsize=50,
    errors='None',
    bedding=[],
    incolor='N',
):
    """
    adapted from pmagplotlib.plotANIS
    set errors to 'h' for hext ellipses, 'b' for bootstrap, 'p' for parametric bootstrap
    bootstrap trials currently hard-coded as 1000
    for bedding, give as [strike,dip] ;
    """
    subplot_net()  #set up stereonet
    if incolor == 'N':
        colours = ['0.4', '0.6', '0.5']  #specify greyscale colours
    else:
        colours = ['lightcoral', 'lightskyblue', 'lightgreen']
    #if bedding plot bedding plane
    if bedding != []:
        # hard-coded version of pmag.plotC
        D_c, I_c = pmag.circ(bedding[0] - 90., 90. - bedding[1], 90.)
        X_c_d, Y_c_d = [], []
        for k in range(len(D_c)):
            XY = pmag.dimap(D_c[k], I_c[k])
            if I_c[k] > 0:
                X_c_d.append(XY[0])
                Y_c_d.append(XY[1])
        plt.plot(X_c_d,
                 Y_c_d,
                 color='grey',
                 dashes=[10, 2],
                 linewidth=3,
                 zorder=1)
    Vs = []
    #plot individual sample data
    for s in sdata:
        tau, V = pmag.doseigs(s)
        Vs.append(V)
    plotEVEC(Vs, pointsize, colours)
    #plot mean eigenvectors
    nf, sigma, avs = pmag.sbar(sdata)
    Vs = []
    mtau, mV = pmag.doseigs(avs)
    Vs.append(mV)
    plotEVEC(Vs, pointsize * 4, ['w', 'w', 'w'], 'black', 7)
    #plot confidence limits
    hpars = pmag.dohext(nf, sigma, avs)
    if errors == 'h':
        ellpars = [
            hpars["v1_dec"], hpars["v1_inc"], hpars["e12"], hpars["v2_dec"],
            hpars["v2_inc"], hpars["e13"], hpars["v3_dec"], hpars["v3_inc"]
        ]
        plotELL(ellpars, 'black', 1, 1)
        ellpars = [
            hpars["v2_dec"], hpars["v2_inc"], hpars["e23"], hpars["v3_dec"],
            hpars["v3_inc"], hpars["e12"], hpars["v1_dec"], hpars["v1_inc"]
        ]
        plotELL(ellpars, 'black', 1, 1)
        ellpars = [
            hpars["v3_dec"], hpars["v3_inc"], hpars["e13"], hpars["v1_dec"],
            hpars["v1_inc"], hpars["e23"], hpars["v2_dec"], hpars["v2_inc"]
        ]
        plotELL(ellpars, 'black', 1, 1)
    elif errors == 'b' or errors == 'p':
        if errors == 'p': ipar = 1
        else: ipar = 0
        Tmean, Vmean, Taus, BVs = pmag.s_boot(
            sdata, ipar, 1000)  # get eigenvectors of mean tensor
        # the problem with the bootstrap is that for fabrics where one or more eigenvectors is close to the horizontal,
        # you end up with dipolar data

        bpars = pmag.sbootpars(Taus, BVs, Vmean)
        bpars['t1'] = hpars['t1']
        bpars['t2'] = hpars['t2']
        bpars['t3'] = hpars['t3']
        #have to pair zeta value with eta dec/inc, and vice-versa, to align error ellipses correctly.
        ellpars = [
            bpars["v1_dec"], bpars["v1_inc"], bpars["v1_eta"],
            bpars["v1_eta_dec"], bpars["v1_eta_inc"], bpars["v1_zeta"],
            bpars["v1_zeta_dec"], bpars["v1_zeta_inc"]
        ]
        plotELL(ellpars, 'black', 1, 1)
        ellpars = [
            bpars["v2_dec"], bpars["v2_inc"], bpars["v2_eta"],
            bpars["v2_eta_dec"], bpars["v2_eta_inc"], bpars["v2_zeta"],
            bpars["v2_zeta_dec"], bpars["v2_zeta_inc"]
        ]
        plotELL(ellpars, 'black', 1, 1)
        ellpars = [
            bpars["v3_dec"], bpars["v3_inc"], bpars["v3_eta"],
            bpars["v3_eta_dec"], bpars["v3_eta_inc"], bpars["v3_zeta"],
            bpars["v3_zeta_dec"], bpars["v3_zeta_inc"]
        ]
        plotELL(ellpars, 'black', 1, 1)
Esempio n. 14
0
def main():
    """
    NAME
        site_edit_magic.py

    DESCRIPTION
       makes equal area projections site by site
         from pmag_specimens.txt file with
         Fisher confidence ellipse using McFadden and McElhinny (1988)
         technique for combining lines and planes
         allows testing and reject specimens for bad orientations

    SYNTAX
        site_edit_magic.py [command line options]

    OPTIONS
       -h: prints help and quits
       -f: specify pmag_specimen format file, default is pmag_specimens.txt
       -fsa: specify er_samples.txt file
       -exc: use existing pmag_criteria.txt file
       -N: reset all sample flags to good
    
    OUPUT
       edited er_samples.txt file

    """
    dir_path='.'
    FIG={} # plot dictionary
    FIG['eqarea']=1 # eqarea is figure 1
    in_file='pmag_specimens.txt'
    sampfile='er_samples.txt'
    out_file=""
    fmt,plot='svg',1
    Crits=""
    M,N=180.,1
    repeat=''
    renew=0
    if '-h' in sys.argv:
        print main.__doc__
        sys.exit()
    if '-WD' in sys.argv:
        ind=sys.argv.index('-WD')
        dir_path=sys.argv[ind+1]
    if '-f' in sys.argv:
        ind=sys.argv.index("-f")
        in_file=sys.argv[ind+1]
    if '-fsa' in sys.argv:
        ind=sys.argv.index("-fsa")
        sampfile=sys.argv[ind+1]
    if '-exc' in sys.argv:
        Crits,file_type=pmag.magic_read(dir_path+'/pmag_criteria.txt')
        for crit in Crits:
            if crit['pmag_criteria_code']=='DE-SPEC':
                M=float(crit['specimen_mad'])
                N=float(crit['specimen_n'])
    if '-fmt' in sys.argv:
        ind=sys.argv.index("-fmt")
        fmt=sys.argv[ind+1]
    if '-N' in sys.argv: renew=1
# 
    if in_file[0]!="/":in_file=dir_path+'/'+in_file
    if sampfile[0]!="/":sampfile=dir_path+'/'+sampfile
    crd='s'
    Specs,file_type=pmag.magic_read(in_file)
    if file_type!='pmag_specimens':
        print ' bad pmag_specimen input file'
        sys.exit()
    Samps,file_type=pmag.magic_read(sampfile)
    if file_type!='er_samples':
        print ' bad er_samples input file'
        sys.exit()
    SO_methods=[]
    for rec in Samps:
       if 'sample_orientation_flag' not in rec.keys(): rec['sample_orientation_flag']='g'
       if 'sample_description' not in rec.keys(): rec['sample_description']=''
       if renew==1:
          rec['sample_orientation_flag']='g'
          description=rec['sample_description']
          if '#' in description:
               newdesc=""
               c=0
               while description[c]!='#' and c<len(description)-1: # look for first pound sign
                   newdesc=newdesc+description[c]
                   c+=1
               while description[c]=='#': 
                   c+=1# skip first set of pound signs
               while description[c]!='#':c+=1 # find second set of pound signs
               while description[c]=='#' and c<len(description)-1:c+=1 # skip second set of pound signs
               while c<len(description)-1: # look for first pound sign
                   newdesc=newdesc+description[c]
                   c+=1
               rec['sample_description']=newdesc # edit out old comment about orientations
       if "magic_method_codes" in rec:
           methlist=rec["magic_method_codes"]
           for meth in methlist.split(":"):
               if "SO" in meth.strip() and "SO-POM" not in meth.strip():
                   if meth.strip() not in SO_methods: SO_methods.append(meth.strip())
    pmag.magic_write(sampfile,Samps,'er_samples')
    SO_priorities=pmag.set_priorities(SO_methods,0)
    sitelist=[]
    for rec in Specs:
        if rec['er_site_name'] not in sitelist: sitelist.append(rec['er_site_name'])
    sitelist.sort()
    EQ={} 
    EQ['eqarea']=1
    pmagplotlib.plot_init(EQ['eqarea'],5,5)
    k=0
    while k<len(sitelist):
        site=sitelist[k]
        print site
        data=[]
        ThisSiteSpecs=pmag.get_dictitem(Specs,'er_site_name',site,'T')
        ThisSiteSpecs=pmag.get_dictitem(ThisSiteSpecs,'specimen_tilt_correction','-1','T') # get all the unoriented data
        for spec in ThisSiteSpecs:
                if spec['specimen_mad']!="" and spec['specimen_n']!="" and float(spec['specimen_mad'])<=M and float(spec['specimen_n'])>=N: 
# good spec, now get orientation....
                    redo,p=1,0
                    if len(SO_methods)<=1:
                        az_type=SO_methods[0]
                        orient=pmag.find_samp_rec(spec["er_sample_name"],Samps,az_type)
                        redo=0
                    while redo==1:
                        if p>=len(SO_priorities):
                            print "no orientation data for ",spec['er_sample_name']
                            orient["sample_azimuth"]=""
                            orient["sample_dip"]=""
                            redo=0
                        else:
                            az_type=SO_methods[SO_methods.index(SO_priorities[p])]
                            orient=pmag.find_samp_rec(spec["er_sample_name"],Samps,az_type)
                            if orient["sample_azimuth"]  !="":
                                redo=0
                        p+=1
                    if orient['sample_azimuth']!="":
                        rec={}
                        for key in spec.keys():rec[key]=spec[key]
                        rec['dec'],rec['inc']=pmag.dogeo(float(spec['specimen_dec']),float(spec['specimen_inc']),float(orient['sample_azimuth']),float(orient['sample_dip']))
                        rec["tilt_correction"]='1'
                        crd='g'
                        rec['sample_azimuth']=orient['sample_azimuth']
                        rec['sample_dip']=orient['sample_dip']
                        data.append(rec)
        if len(data)>2:
            print 'specimen, dec, inc, n_meas/MAD,| method codes '
            for i  in range(len(data)):
                print '%s: %7.1f %7.1f %s / %s | %s' % (data[i]['er_specimen_name'], data[i]['dec'], data[i]['inc'], data[i]['specimen_n'], data[i]['specimen_mad'], data[i]['magic_method_codes'])

            fpars=pmag.dolnp(data,'specimen_direction_type')
            print "\n Site lines planes  kappa   a95   dec   inc"
            print site, fpars["n_lines"], fpars["n_planes"], fpars["K"], fpars["alpha95"], fpars["dec"], fpars["inc"], fpars["R"]
            if out_file!="":
                if float(fpars["alpha95"])<=acutoff and float(fpars["K"])>=kcutoff:
                    out.write('%s %s %s\n'%(fpars["dec"],fpars['inc'],fpars['alpha95']))
            pmagplotlib.plotLNP(EQ['eqarea'],site,data,fpars,'specimen_direction_type')
            pmagplotlib.drawFIGS(EQ)
            if k!=0 and repeat!='y':
                ans=raw_input("s[a]ve plot, [q]uit, [e]dit specimens, [p]revious site, <return> to continue:\n ")
            elif k==0 and repeat!='y':
                ans=raw_input("s[a]ve plot, [q]uit, [e]dit specimens, <return> to continue:\n ")
            if ans=="p": k-=2
            if ans=="a":
                files={}
                files['eqarea']=site+'_'+crd+'_eqarea'+'.'+fmt
                pmagplotlib.saveP(EQ,files)
            if ans=="q": sys.exit()
            if ans=="e" and Samps==[]:
                print "can't edit samples without orientation file, sorry"
            elif ans=="e": 
#                k-=1
                testspec=raw_input("Enter name of specimen to check: ")
                for spec in data:
                    if spec['er_specimen_name']==testspec:
# first test wrong direction of drill arrows (flip drill direction in opposite direction and re-calculate d,i
                        d,i=pmag.dogeo(float(spec['specimen_dec']),float(spec['specimen_inc']),float(spec['sample_azimuth'])-180.,-float(spec['sample_dip']))
                        XY=pmag.dimap(d,i)
                        pmagplotlib.plotXY(EQ['eqarea'],[XY[0]],[XY[1]],sym='g^')
# first test wrong end of compass (take az-180.)
                        d,i=pmag.dogeo(float(spec['specimen_dec']),float(spec['specimen_inc']),float(spec['sample_azimuth'])-180.,float(spec['sample_dip']))
                        XY=pmag.dimap(d,i)
                        pmagplotlib.plotXY(EQ['eqarea'],[XY[0]],[XY[1]],sym='kv')
# did the sample spin in the hole?  
# now spin around specimen's z
                        X_up,Y_up,X_d,Y_d=[],[],[],[]
                        for incr in range(0,360,5):
                            d,i=pmag.dogeo(float(spec['specimen_dec'])+incr,float(spec['specimen_inc']),float(spec['sample_azimuth']),float(spec['sample_dip']))
                            XY=pmag.dimap(d,i)
                            if i>=0:
                                X_d.append(XY[0])
                                Y_d.append(XY[1])
                            else:
                                X_up.append(XY[0])
                                Y_up.append(XY[1])
                        pmagplotlib.plotXY(EQ['eqarea'],X_d,Y_d,sym='b.')
                        pmagplotlib.plotXY(EQ['eqarea'],X_up,Y_up,sym='c.')
                        pmagplotlib.drawFIGS(EQ)
                        break
                print "Triangle: wrong arrow for drill direction."
                print "Delta: wrong end of compass."
                print "Small circle:  wrong mark on sample. [cyan upper hemisphere]"
                deleteme=raw_input("Mark this sample as bad? y/[n]  ")
                if deleteme=='y':
                    reason=raw_input("Reason: [1] broke, [2] wrong drill direction, [3] wrong compass direction, [4] bad mark, [5] displaced block [6] other ")
                    if reason=='1':
                       description=' sample broke while drilling'
                    if reason=='2':
                       description=' wrong drill direction '
                    if reason=='3':
                       description=' wrong compass direction '
                    if reason=='4':
                       description=' bad mark in field'
                    if reason=='5':
                       description=' displaced block'
                    if reason=='6':
                       description=raw_input('Enter brief reason for deletion:   ')
                    for samp in Samps:
                        if samp['er_sample_name']==spec['er_sample_name']:
                            samp['sample_orientation_flag']='b'
                            samp['sample_description']=samp['sample_description']+' ## direction deleted because: '+description+'##' # mark description
                    pmag.magic_write(sampfile,Samps,'er_samples')
                repeat=raw_input("Mark another sample, this site? y/[n]  ")
                if repeat=='y': k-=1
        else:
            print 'skipping site - not enough data with specified coordinate system'
        k+=1 
    print "sample flags stored in ",sampfile
Esempio n. 15
0
def main():
    """
    NAME
        site_edit_magic.py

    DESCRIPTION
       makes equal area projections site by site
         from zeq_specimens_g.txt file with
         Fisher confidence ellipse using McFadden and McElhinny (1988)
         technique for combining lines and planes
         allows testing and reject specimens for bad orientations

    SYNTAX
        site_edit_magic.py [command line options]

    OPTIONS
       -h: prints help and quits
       -f: specify pmag_specimen format file, default is zeq_specimens_s.txt
       -fsa: specify er_samples.txt file
       -exc: use existing pmag_criteria.txt file
       -N: reset all sample flags to good
    
    OUPUT
       edited er_samples.txt file

    """
    dir_path = "."
    FIG = {}  # plot dictionary
    FIG["eqarea"] = 1  # eqarea is figure 1
    in_file = "zeq_specimens_s.txt"
    sampfile = "er_samples.txt"
    out_file = ""
    fmt, plot = "svg", 1
    Crits = ""
    M, N = 180.0, 1
    repeat = ""
    renew = 0
    if "-h" in sys.argv:
        print main.__doc__
        sys.exit()
    if "-WD" in sys.argv:
        ind = sys.argv.index("-WD")
        dir_path = sys.argv[ind + 1]
    if "-f" in sys.argv:
        ind = sys.argv.index("-f")
        in_file = sys.argv[ind + 1]
    if "-fsa" in sys.argv:
        ind = sys.argv.index("-fsa")
        sampfile = sys.argv[ind + 1]
    if "-exc" in sys.argv:
        Crits, file_type = pmag.magic_read(dir_path + "/pmag_criteria.txt")
        for crit in Crits:
            if crit["pmag_criteria_code"] == "DE-SPEC":
                M = float(crit["specimen_mad"])
                N = float(crit["specimen_n"])
    if "-fmt" in sys.argv:
        ind = sys.argv.index("-fmt")
        fmt = sys.argv[ind + 1]
    if "-N" in sys.argv:
        renew = 1
    #
    in_file = dir_path + "/" + in_file
    sampfile = dir_path + "/" + sampfile
    Specs, file_type = pmag.magic_read(in_file)
    if file_type != "pmag_specimens":
        print " bad pmag_specimen input file"
        sys.exit()
    Samps, file_type = pmag.magic_read(sampfile)
    if file_type != "er_samples":
        print " bad er_samples input file"
        sys.exit()
    SO_methods = []
    for rec in Samps:
        if "sample_orientation_flag" not in rec.keys():
            rec["sample_orientation_flag"] = "g"
        if "sample_description" not in rec.keys():
            rec["sample_description"] = ""
        if renew == 1:
            rec["sample_orientation_flag"] = "g"
            description = rec["sample_description"]
            if "#" in description:
                newdesc = ""
                c = 0
                while description[c] != "#" and c < len(description) - 1:  # look for first pound sign
                    newdesc = newdesc + description[c]
                    c += 1
                while description[c] == "#":
                    c += 1  # skip first set of pound signs
                while description[c] != "#":
                    c += 1  # find second set of pound signs
                while description[c] == "#" and c < len(description) - 1:
                    c += 1  # skip second set of pound signs
                while c < len(description) - 1:  # look for first pound sign
                    newdesc = newdesc + description[c]
                    c += 1
                rec["sample_description"] = newdesc  # edit out old comment about orientations
        if "magic_method_codes" in rec:
            methlist = rec["magic_method_codes"]
            for meth in methlist.split(":"):
                if "SO" in meth.strip() and "SO-POM" not in meth.strip():
                    if meth.strip() not in SO_methods:
                        SO_methods.append(meth.strip())
    pmag.magic_write(sampfile, Samps, "er_samples")
    SO_priorities = pmag.set_priorities(SO_methods, 0)
    sitelist = []
    for rec in Specs:
        if rec["er_site_name"] not in sitelist:
            sitelist.append(rec["er_site_name"])
    sitelist.sort()
    EQ = {}
    EQ["eqarea"] = 1
    pmagplotlib.plot_init(EQ["eqarea"], 5, 5)
    k = 0
    while k < len(sitelist):
        site = sitelist[k]
        print site
        data = []
        for spec in Specs:
            if spec["er_site_name"] == site:
                if (
                    spec["specimen_mad"] != ""
                    and spec["specimen_n"] != ""
                    and float(spec["specimen_mad"]) <= M
                    and float(spec["specimen_n"]) >= N
                ):
                    # good spec, now get orientation....
                    redo, p = 1, 0
                    if len(SO_methods) <= 1:
                        az_type = SO_methods[0]
                        orient = pmag.find_samp_rec(spec["er_sample_name"], Samps, az_type)
                        redo = 0
                    while redo == 1:
                        if p >= len(SO_priorities):
                            print "no orientation data for ", spec["er_sample_name"]
                            orient["sample_azimuth"] = ""
                            orient["sample_dip"] = ""
                            redo = 0
                        else:
                            az_type = SO_methods[SO_methods.index(SO_priorities[p])]
                            orient = pmag.find_samp_rec(spec["er_sample_name"], Samps, az_type)
                            if orient["sample_azimuth"] != "":
                                redo = 0
                        p += 1
                    if orient["sample_azimuth"] != "":
                        rec = {}
                        for key in spec.keys():
                            rec[key] = spec[key]
                        rec["dec"], rec["inc"] = pmag.dogeo(
                            float(spec["specimen_dec"]),
                            float(spec["specimen_inc"]),
                            float(orient["sample_azimuth"]),
                            float(orient["sample_dip"]),
                        )
                        rec["tilt_correction"] = "1"
                        rec["sample_azimuth"] = orient["sample_azimuth"]
                        rec["sample_dip"] = orient["sample_dip"]
                        data.append(rec)
        if len(data) > 2:
            print "specimen, dec, inc, n_meas/MAD,| method codes "
            for i in range(len(data)):
                print "%s: %7.1f %7.1f %s / %s | %s" % (
                    data[i]["er_specimen_name"],
                    data[i]["dec"],
                    data[i]["inc"],
                    data[i]["specimen_n"],
                    data[i]["specimen_mad"],
                    data[i]["magic_method_codes"],
                )

            fpars = pmag.dolnp(data, "specimen_direction_type")
            print "\n Site lines planes  kappa   a95   dec   inc"
            print site, fpars["n_lines"], fpars["n_planes"], fpars["K"], fpars["alpha95"], fpars["dec"], fpars[
                "inc"
            ], fpars["R"]
            if out_file != "":
                if float(fpars["alpha95"]) <= acutoff and float(fpars["K"]) >= kcutoff:
                    out.write("%s %s %s\n" % (fpars["dec"], fpars["inc"], fpars["alpha95"]))
            pmagplotlib.plotLNP(EQ["eqarea"], site, data, fpars, "specimen_direction_type")
            if k != 0 and repeat != "y":
                ans = raw_input("s[a]ve plot, [q]uit, [e]dit specimens, [p]revious site, <return> to continue:\n ")
            elif k == 0 and repeat != "y":
                ans = raw_input("s[a]ve plot, [q]uit, [e]dit specimens, <return> to continue:\n ")
            if ans == "p":
                k -= 2
            if ans == "a":
                files = {}
                files["eqarea"] = site + "_" + crd + "_" + "eqarea" + "." + fmt
                pmagplotlib.saveP(EQ, files)
            if ans == "q":
                sys.exit()
            if ans == "e" and Samps == []:
                print "can't edit samples without orientation file, sorry"
            elif ans == "e":
                #                k-=1
                testspec = raw_input("Enter name of specimen to check: ")
                for spec in data:
                    if spec["er_specimen_name"] == testspec:
                        # first test wrong direction of drill arrows (flip drill direction in opposite direction and re-calculate d,i
                        d, i = pmag.dogeo(
                            float(spec["specimen_dec"]),
                            float(spec["specimen_inc"]),
                            float(spec["sample_azimuth"]) - 180.0,
                            -float(spec["sample_dip"]),
                        )
                        XY = pmag.dimap(d, i)
                        pmagplotlib.plotXY(EQ["eqarea"], [XY[0]], [XY[1]], "g^", "", "", "")
                        # first test wrong end of compass (take az-180.)
                        d, i = pmag.dogeo(
                            float(spec["specimen_dec"]),
                            float(spec["specimen_inc"]),
                            float(spec["sample_azimuth"]) - 180.0,
                            float(spec["sample_dip"]),
                        )
                        XY = pmag.dimap(d, i)
                        pmagplotlib.plotXY(EQ["eqarea"], [XY[0]], [XY[1]], "kv", "", "", "")
                        # did the sample spin in the hole?
                        # now spin around specimen's z
                        X_up, Y_up, X_d, Y_d = [], [], [], []
                        for incr in range(0, 360, 5):
                            d, i = pmag.dogeo(
                                float(spec["specimen_dec"]) + incr,
                                float(spec["specimen_inc"]),
                                float(spec["sample_azimuth"]),
                                float(spec["sample_dip"]),
                            )
                            XY = pmag.dimap(d, i)
                            if i >= 0:
                                X_d.append(XY[0])
                                Y_d.append(XY[1])
                            else:
                                X_up.append(XY[0])
                                Y_up.append(XY[1])
                        pmagplotlib.plotXY(EQ["eqarea"], X_d, Y_d, "b.", "", "", "")
                        pmagplotlib.plotXY(EQ["eqarea"], X_up, Y_up, "c.", "", "", "")
                        pmagplotlib.drawFIGS(EQ)
                        break
                print "Triangle: wrong arrow for drill direction."
                print "Delta: wrong end of compass."
                print "Small circle:  wrong mark on sample. [cyan upper hemisphere]"
                deleteme = raw_input("Mark this sample as bad? y/[n]  ")
                if deleteme == "y":
                    reason = raw_input(
                        "Reason: [1] broke, [2] wrong drill direction, [3] wrong compass direction, [4] bad mark, [5] displaced block [6] other "
                    )
                    if reason == "1":
                        description = " sample broke while drilling"
                    if reason == "2":
                        description = " wrong drill direction "
                    if reason == "3":
                        description = " wrong compass direction "
                    if reason == "4":
                        description = " bad mark in field"
                    if reason == "5":
                        description = " displaced block"
                    if reason == "6":
                        description = raw_input("Enter brief reason for deletion:   ")
                    for samp in Samps:
                        if samp["er_sample_name"] == spec["er_sample_name"]:
                            samp["sample_orientation_flag"] = "b"
                            samp["sample_description"] = (
                                samp["sample_description"] + " ## direction deleted because: " + description + "##"
                            )  # mark description
                    pmag.magic_write(sampfile, Samps, "er_samples")
                repeat = raw_input("Mark another sample, this site? y/[n]  ")
                if repeat == "y":
                    k -= 1
        else:
            print "skipping site - not enough data with specified coordinate system"
        k += 1
    print "sample flags stored in ", sampfile
Esempio n. 16
0
def plot_di_mean(dec,
                 inc,
                 a95,
                 color='k',
                 marker='o',
                 markersize=20,
                 label='',
                 legend='no',
                 zorder=3):  #Modified from PmagPy (Tauxe et al., 2016)
    """
	Plot a mean direction (declination, inclination) with alpha_95 ellipse on
	an equal area plot.

	Before this function is called, a plot needs to be initialized with code
	that looks something like:
	>fignum = 1
	>plt.figure(num=fignum,figsize=(10,10),dpi=160)
	>ipmag.plot_net(fignum)

	Required Arguments
	-----------
	dec : declination of mean being plotted
	inc : inclination of mean being plotted
	a95 : a95 confidence ellipse of mean being plotted

	Optional Keywords
	-----------
	color : the default color is black. Other colors can be chosen (e.g. 'r').
	marker : the default is a circle. Other symbols can be chosen (e.g. 's').
	markersize : the default is 20. Other sizes can be chosen.
	label : the default is no label. Labels can be assigned.
	legend : the default is no legend ('no'). Putting 'yes' will plot a legend.
	"""
    DI_dimap = pmag.dimap(dec, inc)
    if inc < 0:
        plt.scatter(DI_dimap[0],
                    DI_dimap[1],
                    edgecolors=color,
                    facecolors='white',
                    marker=marker,
                    s=markersize,
                    label=label,
                    zorder=4)
    if inc >= 0:
        plt.scatter(DI_dimap[0],
                    DI_dimap[1],
                    edgecolors=color,
                    facecolors=color,
                    marker=marker,
                    s=markersize,
                    label=label,
                    zorder=zorder)
    Xcirc, Ycirc = [], []
    Da95, Ia95 = pmag.circ(dec, inc, a95)
    if legend == 'yes':
        plt.legend(loc=2)
    for k in range(len(Da95)):
        XY = pmag.dimap(Da95[k], Ia95[k])
        Xcirc.append(XY[0])
        Ycirc.append(XY[1])
    plt.plot(Xcirc, Ycirc, c=color, linewidth=0.5, zorder=3)
    plt.tight_layout()