示例#1
0
文件: pt_rot.py 项目: ihilburn/PmagPy
def main():
    """
    NAME 
        pt_rot.py 

    DESCRIPTION
        rotates pt according to specified age and plate
 
    SYNTAX
        pt_rot.py [command line options]

    OPTIONS
        -h prints help and quits
        -f file with lon lat plate age Dplate as space delimited input
           Dplate is the destination plate coordinates desires 
           - default is "fixed south africa"
           Dplate should be one of: [nwaf, neaf,saf,aus, eur, ind, sam, ant, grn, nam]
        -ff file Efile,   file  has lat lon data file and Efile has sequential rotation poles: Elat Elon Omega 
        -F OFILE, output pmag_results formatted file with rotated points stored in vgp_lon, vgp_lat
           default is to print out rotated lon, lat to standard output
    
    """
    dir_path='.'
    PTS=[]
    ResRecs=[]
    ofile=""
    Dplates=['nwaf', 'neaf','saf','aus', 'eur', 'ind', 'sam', 'ant', 'grn', 'nam']
    if '-WD' in sys.argv:
        ind = sys.argv.index('-WD')
        dir_path=sys.argv[ind+1]
    if '-h' in sys.argv:
        print main.__doc__
        sys.exit()
    if '-F' in sys.argv:
        ind = sys.argv.index('-F')
        ofile=dir_path+'/'+sys.argv[ind+1]
    if '-f' in sys.argv:
        ind = sys.argv.index('-f')
        file=dir_path+'/'+sys.argv[ind+1]
        f=open(file,'rU')
        data=f.readlines()
    elif '-ff' in sys.argv:
        ind = sys.argv.index('-ff')
        file=dir_path+'/'+sys.argv[ind+1]
        f=open(file,'rU')
        data=f.readlines()
        Efile=dir_path+'/'+sys.argv[ind+2]
        f=open(Efile,'rU')
        edata=f.readlines()
        Poles=[]
        for p in edata:
             rec=p.split()
             pole=[float(rec[0]),float(rec[1]),float(rec[2])]
             Poles.append(pole)
    else:
        data=sys.stdin.readlines()
    for line in data:
        PtRec={}
        rec=line.split()
        PtRec['site_lat']=rec[0]
        PtRec['site_lon']=rec[1]
        if '-ff' in sys.argv:
            pt_lat,pt_lon=float(rec[0]),float(rec[1])
            for pole in Poles:
                ptrot= pmag.PTrot(pole,[pt_lat],[pt_lon])
                pt_lat=ptrot[0][0]
                pt_lon=ptrot[1][0]
            if ofile=="":
                print ptrot[1][0], ptrot[0][0]
            else:
                ResRec={'vgp_lat': '%7.1f'%(ptrot[0][0]),'vgp_lon':'%7.1f'%( ptrot[1][0])}
                ResRecs.append(ResRec)
        else:
            PtRec['cont']=rec[2]
            if PtRec['cont']=='af':PtRec['cont']='saf' # use fixed south africa
            PtRec['age']=rec[3]
            if len(rec)>4:
               PtRec['dcont']=rec[4]
            PTS.append(PtRec)
    if '-ff' not in sys.argv:
        for pt in PTS:
            pole='not specified'
            pt_lat=float(pt['site_lat'])
            pt_lon=float(pt['site_lon'])
            age=float(pt['age'])
            ptrot=[[pt_lat],[pt_lon]]
            if pt['cont']=='ib':
                pole=frp.get_pole(pt['cont'],age)
                ptrot= pmag.PTrot(pole,[pt_lat],[pt_lon])
                pt_lat=ptrot[0][0]
                pt_lon=ptrot[1][0]
                pt['cont']='eur'
            if pt['cont']!='saf':
                pole1=frp.get_pole(pt['cont'],age)
                ptrot= pmag.PTrot(pole1,[pt_lat],[pt_lon])
                if 'dcont' in pt.keys():
                    pt_lat=ptrot[0][0]
                    pt_lon=ptrot[1][0]
                    pole=frp.get_pole(pt['dcont'],age)
                    pole[2]=-pole[2] 
                    ptrot= pmag.PTrot(pole,[pt_lat],[pt_lon])
                if ofile=="":
                    print ptrot[1][0], ptrot[0][0]
                else:
                    ResRec={'vgp_lat': '%7.1f'%(ptrot[0][0]),'vgp_lon':'%7.1f'%( ptrot[1][0])}
                    ResRecs.append(ResRec)
            else:
                if 'dcont' in pt.keys():
                    pole=frp.get_pole(pt['dcont'],age)
                    pole[2]=-pole[2] 
                    ptrot= pmag.PTrot(pole,[pt_lat],[pt_lon])
                    if ofile=="":
                        print ptrot[1][0], ptrot[0][0]
                    else:
                        ResRec={'vgp_lat': '%7.1f'%(ptrot[0][0]),'vgp_lon':'%7.1f'%( ptrot[1][0])}
                        ResRecs.append(ResRec)
                else:
                    if ofile=="":
                        print ptrot[1][0], ptrot[0][0]
                    else:
                        ResRec={'vgp_lat': '%7.1f'%(ptrot[0][0]),'vgp_lon':'%7.1f'%( ptrot[1][0])}
                        ResRecs.append(ResRec)
    if len(ResRecs)>0:
        pmag.magic_write(ofile,ResRecs,'pmag_results')
示例#2
0
def main():
    """
    NAME 
        cont_rot.py 

    DESCRIPTION
        rotates continental fragments according to specified Euler pole
 
    SYNTAX
        cont_rot.py [command line options]

    OPTIONS
        -h prints help and quits
        -con [af, congo, kala, aus, balt, eur, ind, sam, ant, grn, lau, nam, gond] , specify colon delimited list of continents to be displayed, e.g., af, af:aus], etc
        -age use finite rotations of Torsvik et al. 2008 for specific age (5 Ma increments <325Ma)
             rotates to paleomagnetic reference frame 
             available conts: [congo kala aus eur ind sam ant grn nam]
        -sac include rotation of south african craton to pmag reference
        -sym [ro, bs, g^, r., b-, etc.] [1,5,10] symbol and size for continent
           colors are r=red,b=blue,g=green, etc.
           symbols are '.' for points, ^, for triangle, s for square, etc.
            -, for lines, -- for dotted lines, see matplotlib online documentation for plot()
        -eye  ELAT ELON [specify eyeball location]
        -pfr  PLAT PLON OMEGA  [specify pole of finite rotation lat,lon and degrees]
        -ffr FFILE, specifies series of finite rotations 
           vector in tab delimited file 
        -sr treat poles as sequential rotations 
        -fpp PFILE, specifies series of paleopoles from which
           euler poles can be calculated: vector in tab delimited file 
        -pt LAT LON,  specify a point to rotate along with continent
        -fpt PTFILE, specifies file with a series of points to be plotted
        -res [c,l,i,h] specify resolution (crude, low, intermediate, high]
        -prj PROJ,  specify one of the supported projections: (see basemap.py online documentation)
            aeqd = Azimuthal Equidistant
            poly = Polyconic
            gnom = Gnomonic
            moll = Mollweide
            tmerc = Transverse Mercator
            nplaea = North-Polar Lambert Azimuthal
            mill = Miller Cylindrical
            merc = Mercator
            stere = Stereographic
            npstere = North-Polar Stereographic
            geos = Geostationary
            laea = Lambert Azimuthal Equal Area
            sinu = Sinusoidal
            spstere = South-Polar Stereographic
            lcc = Lambert Conformal
            npaeqd = North-Polar Azimuthal Equidistant
            eqdc = Equidistant Conic
            cyl = Cylindrical Equidistant
            omerc = Oblique Mercator
            aea = Albers Equal Area
            spaeqd = South-Polar Azimuthal Equidistant
            ortho = Orthographic
            cass= Cassini-Soldner
            splaea = South-Polar Lambert Azimuthal
            robin = Robinson
    
    DEFAULTS
        con: nam
        res:  c
        prj: mollweide 
        ELAT,ELON = 0,0
        NB: high resolution or lines can be very slow
    
    """
    dir_path='.'
    ocean=0
    res='c'
    proj='moll'
    euler_file=''
    Conts=[]
    Poles=[]
    PTS=[]
    lat_0,lon_0=0.,0.
    fmt='pdf'
    sym='r.'
    symsize=5
    SEQ,age,SAC=0,0,0
    rconts=['af','congo','kala','aus','eur','ind','sam','ant','grn','nam']
    if '-WD' in sys.argv:
        ind = sys.argv.index('-WD')
        dir_path=sys.argv[ind+1]
    if '-h' in sys.argv:
        print main.__doc__
        sys.exit()
    if '-con' in sys.argv:
        ind = sys.argv.index('-con')
        Conts=sys.argv[ind+1].split(':')
    if '-age' in sys.argv:
        ind = sys.argv.index('-age')
        age=int(sys.argv[ind+1])
        if age%5!=0 and age>320:
            print main.__doc__
            print 'age must be multiple of 5 less than 325'
            sys.exit()
        import frp
    if '-res' in sys.argv:
        ind = sys.argv.index('-res')
        res=sys.argv[ind+1]
        if res!= 'c' and res!='l':
            print 'this resolution will take a while - be patient'
    if '-prj' in sys.argv:
        ind = sys.argv.index('-prj')
        proj=sys.argv[ind+1]
    if '-eye' in sys.argv:
        ind = sys.argv.index('-eye')
        lat_0=float(sys.argv[ind+1])
        lon_0=float(sys.argv[ind+2])
    if '-pt' in sys.argv:
        ind = sys.argv.index('-pt')
        pt_lat=float(sys.argv[ind+1])
        pt_lon=float(sys.argv[ind+2])
        PTS.append([pt_lat,pt_lon])
    if '-sym' in sys.argv:
        ind = sys.argv.index('-sym')
        sym=sys.argv[ind+1]
        symsize=int(sys.argv[ind+2])
#    if '-rsym' in sys.argv:
#        ind = sys.argv.index('-rsym')
#        rsym=sys.argv[ind+1]
#        rsymsize=int(sys.argv[ind+2])
    if '-sr' in sys.argv: SEQ=1
    if '-sac' in sys.argv: SAC=1
    if '-pfr' in sys.argv:
        ind = sys.argv.index('-pfr')
        Poles.append([float(sys.argv[ind+1]),float(sys.argv[ind+2]),float(sys.argv[ind+3])])
    elif '-ffr' in sys.argv:
        ind = sys.argv.index('-ffr')
        file=dir_path+'/'+sys.argv[ind+1]
        f=open(file,'rU')
        edata=f.readlines()
        for line in edata:
            rec=line.split()
            Poles.append([float(rec[0]),float(rec[1]),float(rec[2])])
    elif '-fpp' in sys.argv:
        ind = sys.argv.index('-fpp')
        file=dir_path+'/'+sys.argv[ind+1]
        f=open(file,'rU')
        pdata=f.readlines()
        for line in pdata:
            rec=line.split()
# transform paleopole to Euler pole taking shortest route
            Poles.append([0.,float(rec[1])-90.,90.-float(rec[0])])
    if '-fpt' in sys.argv:
        ind = sys.argv.index('-fpt')
        file=dir_path+'/'+sys.argv[ind+1]
        f=open(file,'rU')
        ptdata=f.readlines()
        for line in ptdata:
            rec=line.split()
            PTS.append([float(rec[0]),float(rec[1])])
    FIG={'map':1}
    pmagplotlib.plot_init(FIG['map'],6,6)
    # read in er_sites file
    if res=='c':skip=8
    if res=='l':skip=5
    if res=='i':skip=2
    if res=='h':skip=1
    cnt=0
    Opts={'latmin':-90,'latmax':90,'lonmin':0.,'lonmax':360.,'lat_0':lat_0,'lon_0':lon_0,'proj':proj,'sym':sym,'symsize':3,'pltgrid':0,'res':res,'boundinglat':0.}
    if proj=='merc':
        Opts['latmin']=-70
        Opts['latmax']=70
        Opts['lonmin']=-180
        Opts['lonmax']=180
    pmagplotlib.plotMAP(FIG['map'],[],[],Opts) # plot the basemap
    Opts['pltgrid']=-1 # turn off replotting of gridlines
    if '-pt' in sys.argv:
        Opts['sym']=sym
        Opts['symsize']=symsize
        pmagplotlib.plotMAP(FIG['map'],[pt_lat],[pt_lon],Opts)
        pmagplotlib.drawFIGS(FIG)
    for cont in Conts: 
        Opts['sym']=sym
        lats,lons=[],[]
        if age!=0:
            Poles=[]
            rcont=cont
            if rcont not in rconts:
                print main.__doc__
                print rcont
                print 'continents  must be one of following: '
                print rconts
                sys.exit()
            if rcont=='congo':rcont='nwaf'
            if rcont=='kala':rcont='neaf'
            if rcont=='sam':rcont='sac'
            if rcont=='ant':rcont='eant'
            if rcont!='af':
                Poles.append(frp.get_pole(rcont,age))
            else:
                Poles.append([0,0,0])
            if SAC==1:Poles.append(frp.get_pole('saf',age))
            SEQ=1
            if Poles[-1]=='NONE':
                print 'continent does not exist for rotation, try again '
                sys.exit()
        data=continents.get_continent(cont+'.asc')
        for line in data:
            if float(line[0])==0 and float(line[1])==0:line[0]='100.' # change stupid 0,0s to delimeters with lat=100
            if float(line[0])>90:
                lats.append(float(line[0]))
                lons.append(float(line[1]))
            elif cnt%skip==0:
                lats.append(float(line[0]))
                lons.append(float(line[1]))
            cnt+=1
        if len(lats)>0 and len(Poles)==0:
            pmagplotlib.plotMAP(FIG['map'],lats,lons,Opts)
            pmagplotlib.drawFIGS(FIG)
        newlats,newlons=[],[]
        for lat in lats:newlats.append(lat)
        for lon in lons:newlons.append(lon)
        Opts['pltgrid']=-1 # turns off replotting of meridians and parallels
        for pole in Poles:
             Rlats,Rlons=pmag.PTrot(pole,newlats,newlons)
             Opts['sym']=sym
             Opts['symsize']=3
             if SEQ==0:
                 pmagplotlib.plotMAP(FIG['map'],Rlats,Rlons,Opts)
             elif pole==Poles[-1]: # plot only last pole for sequential rotations
                 pmagplotlib.plotMAP(FIG['map'],Rlats,Rlons,Opts)
             pmagplotlib.drawFIGS(FIG)
             if SEQ==1: # treat poles as sequential rotations
                 newlats,newlons=[],[]
                 for lat in Rlats:newlats.append(lat)
                 for lon in Rlons:newlons.append(lon)
    for pt in PTS:
        pt_lat=pt[0]
        pt_lon=pt[1]
        Opts['sym']='r*'
        Opts['symsize']=5
        pmagplotlib.plotMAP(FIG['map'],[pt[0]],[pt[1]],Opts)
        pmagplotlib.drawFIGS(FIG)
        Opts['pltgrid']=-1 # turns off replotting of meridians and parallels
        for pole in Poles:
            Opts['sym']=sym
            Opts['symsize']=symsize
            Rlats,Rlons=pmag.PTrot(pole,[pt_lat],[pt_lon])
            print Rlats,Rlons
            pmagplotlib.plotMAP(FIG['map'],Rlats,Rlons,Opts)
            pmagplotlib.drawFIGS(FIG)
        Opts['sym']='g^'
        Opts['symsize']=5
        pmagplotlib.plotMAP(FIG['map'],[pole[0]],[pole[1]],Opts)
        pmagplotlib.drawFIGS(FIG)
    files={}
    for key in FIG.keys():
        files[key]='Cont_rot'+'.'+fmt
    if pmagplotlib.isServer:
        black     = '#000000'
        purple    = '#800080'
        titles={}
        titles['eq']='Site Map'
        FIG = pmagplotlib.addBorders(FIG,titles,black,purple)
        pmagplotlib.saveP(FIG,files)
    else:
        ans=raw_input(" S[a]ve to save plot, Return to quit:  ")
        if ans=="a":
            pmagplotlib.saveP(FIG,files)