示例#1
0
def main():
    """
    NAME 
        basemap_magic.py
        NB:  this program no longer maintained - use plot_mapPTS.py for greater functionality

    DESCRIPTION
        makes a map of locations in er_sites.txt
 
    SYNTAX
        basemap_magic.py  [command line options]

    OPTIONS
        -h prints help message and quits
        -f SFILE, specify er_sites.txt or pmag_results.txt format file
        -res [c,l,i,h] specify resolution (crude,low,intermediate,high)
        -etp plot the etopo20 topographic mesh
        -pad [LAT LON]  pad bounding box by LAT/LON  (default is [.5 .5] degrees)
        -grd SPACE specify grid spacing
        -prj [lcc] , specify projection (lcc=lambert conic conformable), default is mercator
        -n print site names (default is not)
        -l print location names (default is not)
        -o color ocean blue/land green (default is not)
        -R don't plot details of rivers
        -B don't plot national/state  boundaries, etc.
        -sav save plot and quit quietly
        -fmt [png,svg,eps,jpg,pdf] specify format for output, default is pdf     
    DEFAULTS
        SFILE: 'er_sites.txt'
        resolution: intermediate
        saved images are in pdf
    """
    dir_path='.'
    sites_file='er_sites.txt'
    ocean=0
    res='i'
    proj='merc'
    prn_name=0
    prn_loc=0
    fancy=0
    rivers,boundaries=0,0
    padlon,padlat,gridspace,details=.5,.5,.5,1
    fmt='pdf'
    if '-h' in sys.argv:
        print main.__doc__
        sys.exit()
    if '-f' in sys.argv:
        ind = sys.argv.index('-f')
        sites_file=sys.argv[ind+1]
    if '-res' in sys.argv:
        ind = sys.argv.index('-res')
        res=sys.argv[ind+1]
    if '-etp' in sys.argv:fancy=1
    if '-n' in sys.argv:prn_name=1
    if '-l' in sys.argv:prn_loc=1
    if '-o' in sys.argv:ocean=1
    if '-R' in sys.argv:rivers=0
    if '-B' in sys.argv:boundaries=0
    if '-prj' in sys.argv:
        ind = sys.argv.index('-prj')
        proj=sys.argv[ind+1]
    if '-fmt' in sys.argv:
        ind = sys.argv.index('-fmt')
        fmt=sys.argv[ind+1]
    verbose=pmagplotlib.verbose
    if '-sav' in sys.argv: 
        verbose=0
    if '-pad' in sys.argv:
        ind = sys.argv.index('-pad')
        padlat=float(sys.argv[ind+1])
        padlon=float(sys.argv[ind+2])
    if '-grd' in sys.argv:
        ind = sys.argv.index('-grd')
        gridspace=float(sys.argv[ind+1])
    if '-WD' in sys.argv:
        ind = sys.argv.index('-WD')
        dir_path=sys.argv[ind+1]
    sites_file=dir_path+'/'+sites_file
    location=""
    FIG={'map':1}
    pmagplotlib.plot_init(FIG['map'],6,6)
    # read in er_sites file
    Sites,file_type=pmag.magic_read(sites_file)
    if 'results' in file_type:
        latkey='average_lat'
        lonkey='average_lon'
        namekey='pmag_result_name'
        lockey='er_location_names'
    else:
        latkey='site_lat'
        lonkey='site_lon'
        namekey='er_site_name'
        lockey='er_location_name'
    lats,lons=[],[]
    slats,slons=[],[]
    names,locs=[],[]
    for site in Sites:
        if prn_loc==1 and location=="":location=site['er_location_name']
        lats.append(float(site[latkey]))
        l=float(site[lonkey])
        if l<0:l=l+360. # make positive
        lons.append(l)
        if prn_name==1:names.append(site[namekey])
        if prn_loc==1:locs.append(site[lockey])
    for lat in lats:slats.append(lat)
    for lon in lons:slons.append(lon)
    Opts={'res':res,'proj':proj,'loc_name':locs,'padlon':padlon,'padlat':padlat,'latmin':numpy.min(slats)-padlat,'latmax':numpy.max(slats)+padlat,'lonmin':numpy.min(slons)-padlon,'lonmax':numpy.max(slons)+padlon,'sym':'ro','boundinglat':0.,'pltgrid':1.}
    Opts['lon_0']=0.5*(numpy.min(slons)+numpy.max(slons))
    Opts['lat_0']=0.5*(numpy.min(slats)+numpy.max(slats))
    Opts['names']=names
    Opts['gridspace']=gridspace
    Opts['details']={'coasts':1,'rivers':1,'states':1,'countries':1,'ocean':0} 
    if ocean==1:Opts['details']['ocean']=1
    if rivers==1: Opts['details']['rivers']=0
    if boundaries==1:
        Opts['details']['states']=0
        Opts['details']['countries']=0
    Opts['details']['fancy']=fancy
    pmagplotlib.plotMAP(FIG['map'],lats,lons,Opts)
    if verbose:pmagplotlib.drawFIGS(FIG)
    files={}
    for key in FIG.keys():
        files[key]='Site_map'+'.'+fmt
    if pmagplotlib.isServer:
        black     = '#000000'
        purple    = '#800080'
        titles={}
        titles['map']='Site Map'
        FIG = pmagplotlib.addBorders(FIG,titles,black,purple)
        pmagplotlib.saveP(FIG,files)
    elif verbose:
        ans=raw_input(" S[a]ve to save plot, Return to quit:  ")
        if ans=="a":
            pmagplotlib.saveP(FIG,files)
    else:
        pmagplotlib.saveP(FIG,files)
示例#2
0
def main():
    """
    NAME 
        vgpmap_magic.py 

    DESCRIPTION
        makes a map of vgps and a95/dp,dm for site means in a pmag_results table
 
    SYNTAX
        vgpmap_magic.py [command line options]

    OPTIONS
        -h prints help and quits
        -eye  ELAT ELON [specify eyeball location], default is 90., 0.
        -f FILE pmag_results format file, [default is pmag_results.txt] 
        -res [c,l,i,h] specify resolution (crude, low, intermediate, high]
        -etp plot the etopo20 topographpy data (requires high resolution data set)
        -prj PROJ,  specify one of the following:
             ortho = orthographic
             lcc = lambert conformal
             moll = molweide
             merc = mercator
        -sym SYM SIZE: choose a symbol and size, examples: 
            ro 5 : small red circles
            bs 10 : intermediate blue squares
            g^ 20 : large green triangles
        -ell  plot dp/dm or a95 ellipses
        -rev RSYM RSIZE : flip reverse poles to normal antipode 
        -S:  plot antipodes of all poles
        -age : plot the ages next to the poles
        -crd [g,t] : choose coordinate system, default is to plot all site VGPs
        -fmt [pdf, png, eps...] specify output format, default is pdf
        -sav  save and quit    
    DEFAULTS
        FILE: pmag_results.txt
        res:  c
        prj: ortho 
        ELAT,ELON = 0,0
        SYM SIZE: ro 8
        RSYM RSIZE: g^ 8
    
    """
    dir_path = '.'
    res, ages = 'c', 0
    plot = 0
    proj = 'ortho'
    results_file = 'pmag_results.txt'
    ell, flip = 0, 0
    lat_0, lon_0 = 90., 0.
    fmt = 'pdf'
    sym, size = 'ro', 8
    rsym, rsize = 'g^', 8
    anti = 0
    fancy = 0
    coord = ""
    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 '-S' in sys.argv: anti = 1
    if '-fmt' in sys.argv:
        ind = sys.argv.index('-fmt')
        fmt = sys.argv[ind + 1]
    if '-sav' in sys.argv: plot = 1
    if '-res' in sys.argv:
        ind = sys.argv.index('-res')
        res = sys.argv[ind + 1]
    if '-etp' in sys.argv: fancy = 1
    if '-prj' in sys.argv:
        ind = sys.argv.index('-prj')
        proj = sys.argv[ind + 1]
    if '-rev' in sys.argv:
        flip = 1
        ind = sys.argv.index('-rev')
        rsym = (sys.argv[ind + 1])
        rsize = int(sys.argv[ind + 2])
    if '-sym' in sys.argv:
        ind = sys.argv.index('-sym')
        sym = (sys.argv[ind + 1])
        size = int(sys.argv[ind + 2])
    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 '-ell' in sys.argv: ell = 1
    if '-age' in sys.argv: ages = 1
    if '-f' in sys.argv:
        ind = sys.argv.index('-f')
        results_file = sys.argv[ind + 1]
    if '-crd' in sys.argv:
        ind = sys.argv.index('-crd')
        crd = sys.argv[ind + 1]
        if crd == 'g': coord = '0'
        if crd == 't': coord = '100'
    results_file = dir_path + '/' + results_file
    data, file_type = pmag.magic_read(results_file)
    if file_type != 'pmag_results':
        print "bad results file"
        sys.exit()
    FIG = {'map': 1}
    pmagplotlib.plot_init(FIG['map'], 6, 6)
    # read in er_sites file
    lats, lons, dp, dm, a95 = [], [], [], [], []
    Pars = []
    dates, rlats, rlons = [], [], []
    if 'data_type' in data[0].keys():
        Results = pmag.get_dictitem(data, 'data_type', 'i',
                                    'T')  # get all site level data
    else:
        Results = data
    Results = pmag.get_dictitem(Results, 'vgp_lat', '',
                                'F')  # get all non-blank latitudes
    Results = pmag.get_dictitem(Results, 'vgp_lon', '',
                                'F')  # get all non-blank longitudes
    if coord != "":
        Results = pmag.get_dictitem(Results, 'tilt_correction', coord,
                                    'T')  # get specified coordinate system
    location = ""
    for rec in Results:
        if rec['er_location_names'] not in location:
            location = location + ':' + rec['er_location_names']
        if 'average_age' in rec.keys(
        ) and rec['average_age'] != "" and ages == 1:
            dates.append(rec['average_age'])
        lat = float(rec['vgp_lat'])
        lon = float(rec['vgp_lon'])
        if flip == 0:
            lats.append(lat)
            lons.append(lon)
        elif flip == 1:
            if lat < 0:
                rlats.append(-lat)
                lon = lon + 180.
                if lon > 360: lon = lon - 360.
                rlons.append(lon)
            else:
                lats.append(lat)
                lons.append(lon)
        elif anti == 1:
            lats.append(-lat)
            lon = lon + 180.
            if lon > 360: lon = lon - 360.
            lons.append(lon)
        ppars = []
        ppars.append(lon)
        ppars.append(lat)
        ell1, ell2 = "", ""
        if 'vgp_dm' in rec.keys() and rec['vgp_dm'] != "":
            ell1 = float(rec['vgp_dm'])
        if 'vgp_dp' in rec.keys() and rec['vgp_dp'] != "":
            ell2 = float(rec['vgp_dp'])
        if 'vgp_alpha95' in rec.keys() and rec['vgp_alpha95'] != "":
            ell1, ell2 = float(rec['vgp_alpha95']), float(rec['vgp_alpha95'])
        if ell1 != "" and ell2 != "":
            ppars = []
            ppars.append(lons[-1])
            ppars.append(lats[-1])
            ppars.append(ell1)
            ppars.append(lons[-1])
            isign = abs(lats[-1]) / lats[-1]
            ppars.append(lats[-1] - isign * 90.)
            ppars.append(ell2)
            ppars.append(lons[-1] + 90.)
            ppars.append(0.)
            Pars.append(ppars)
    location = location.strip(':')
    Opts = {
        'latmin': -90,
        'latmax': 90,
        'lonmin': 0.,
        'lonmax': 360.,
        'lat_0': lat_0,
        'lon_0': lon_0,
        'proj': proj,
        'sym': 'bs',
        'symsize': 3,
        'pltgrid': 0,
        'res': res,
        'boundinglat': 0.
    }
    Opts['details'] = {
        'coasts': 1,
        'rivers': 0,
        'states': 0,
        'countries': 0,
        'ocean': 1,
        'fancy': fancy
    }
    pmagplotlib.plotMAP(
        FIG['map'], [90.], [0.],
        Opts)  # make the base map with a blue triangle at the pole`
    Opts['pltgrid'] = -1
    Opts['sym'] = sym
    Opts['symsize'] = size
    if len(dates) > 0: Opts['names'] = dates
    if len(lats) > 0:
        pmagplotlib.plotMAP(FIG['map'], lats, lons,
                            Opts)  # add the lats and lons of the poles
    Opts['names'] = []
    if len(rlats) > 0:
        Opts['sym'] = rsym
        Opts['symsize'] = rsize
        pmagplotlib.plotMAP(FIG['map'], rlats, rlons,
                            Opts)  # add the lats and lons of the poles
    if plot == 0:
        pmagplotlib.drawFIGS(FIG)
    if ell == 1:  # add ellipses if desired.
        Opts['details'] = {
            'coasts': 0,
            'rivers': 0,
            'states': 0,
            'countries': 0,
            'ocean': 0
        }
        Opts['pltgrid'] = -1  # turn off meridian replotting
        Opts['symsize'] = 2
        Opts['sym'] = 'g-'
        for ppars in Pars:
            if ppars[2] != 0:
                PTS = pmagplotlib.plotELL(FIG['map'], ppars, 'g.', 0, 0)
                elats, elons = [], []
                for pt in PTS:
                    elons.append(pt[0])
                    elats.append(pt[1])
                pmagplotlib.plotMAP(
                    FIG['map'], elats, elons, Opts
                )  # make the base map with a blue triangle at the pole`
                if plot == 0: pmagplotlib.drawFIGS(FIG)
    files = {}
    for key in FIG.keys():
        files[key] = 'LO:_' + location + '_VGP_map.' + fmt
    if pmagplotlib.isServer:
        black = '#000000'
        purple = '#800080'
        titles = {}
        titles['eq'] = 'LO:_' + location + '_VGP_map'
        FIG = pmagplotlib.addBorders(FIG, titles, black, purple)
        pmagplotlib.saveP(FIG, files)
    elif plot == 0:
        pmagplotlib.drawFIGS(FIG)
        ans = raw_input(" S[a]ve to save plot, Return to quit:  ")
        if ans == "a":
            pmagplotlib.saveP(FIG, files)
        else:
            print "Good bye"
            sys.exit()
    else:
        pmagplotlib.saveP(FIG, files)
示例#3
0
def main():
    """
    NAME
        plot_geomagia.py

    DESCRIPTION
        makes a map  and VADM plot of geomagia download file 

    SYNTAX
        plot_geomagia.py  [command line options]

    OPTIONS
        -h prints help message and quits
        -f FILE, specify geomagia download file
        -res [c,l,i,h] specify resolution (crude,low,intermediate,high)
        -etp plot the etopo20 topographic mesh
        -pad [LAT LON]  pad bounding box by LAT/LON  (default is [.5 .5] degrees)
        -grd SPACE specify grid spacing
        -prj [lcc] , specify projection (lcc=lambert conic conformable), default is mercator
        -o color ocean blue/land green (default is not)
        -d plot details of rivers, boundaries, etc.
        -sav save plot and quit quietly
        -fmt [png,svg,eps,jpg,pdf] specify format for output, default is pdf
    DEFAULTS
        resolution: intermediate
        saved images are in pdf
    """
    dir_path='.'
    names,res,proj,locs,padlon,padlat,fancy,gridspace,details=[],'l','lcc','',0,0,0,15,1
    Age_bounds=[-5000,2000]
    Lat_bounds=[20,45]
    Lon_bounds=[15,55]
    fmt='pdf'
    if '-h' in sys.argv:
        print main.__doc__
        sys.exit()
    if '-f' in sys.argv:
        ind = sys.argv.index('-f')
        sites_file=sys.argv[ind+1]
    if '-res' in sys.argv:
        ind = sys.argv.index('-res')
        res=sys.argv[ind+1]
    if '-etp' in sys.argv:fancy=1
    if '-o' in sys.argv:ocean=1
    if '-d' in sys.argv:details=1
    if '-prj' in sys.argv:
        ind = sys.argv.index('-prj')
        proj=sys.argv[ind+1]
    if '-fmt' in sys.argv:
        ind = sys.argv.index('-fmt')
        fmt=sys.argv[ind+1]
    verbose=pmagplotlib.verbose
    if '-sav' in sys.argv:
        verbose=0
    if '-pad' in sys.argv:
        ind = sys.argv.index('-pad')
        padlat=float(sys.argv[ind+1])
        padlon=float(sys.argv[ind+2])
    if '-grd' in sys.argv:
        ind = sys.argv.index('-grd')
        gridspace=float(sys.argv[ind+1])
    if '-WD' in sys.argv:
        ind = sys.argv.index('-WD')
        dir_path=sys.argv[ind+1]
    sites_file=dir_path+'/'+sites_file
    geo_in=open(sites_file,'rU').readlines()
    Age,AgeErr,Vadm,VadmErr,slats,slons=[],[],[],[],[],[]
    for line in geo_in[2:]: # skip top two rows`
        rec=line.split()
        if float(rec[0])>Age_bounds[0] and float(rec[0])<Age_bounds[1] \
           and float(rec[12])>Lat_bounds[0] and float(rec[12]) < Lat_bounds[1]\
            and float(rec[13])>Lon_bounds[0] and float(rec[13])<Lon_bounds[1]:
            Age.append(float(rec[0]))
            AgeErr.append(float(rec[1]))
            Vadm.append(10.*float(rec[6]))
            VadmErr.append(10.*float(rec[7]))
            slats.append(float(rec[12]))
            slons.append(float(rec[13]))
    FIGS={'map':1,'vadms':2}
    pmagplotlib.plot_init(FIGS['map'],6,6)
    pmagplotlib.plot_init(FIGS['vadms'],6,6)
    Opts={'res':res,'proj':proj,'loc_name':locs,'padlon':padlon,'padlat':padlat,'latmin':numpy.min(slats)-padlat,'latmax':numpy.max(slats)+padlat,'lonmin':numpy.min(slons)-padlon,'lonmax':numpy.max(slons)+padlon,'sym':'ro','boundinglat':0.,'pltgrid':1}
    Opts['lon_0']=int(0.5*(numpy.min(slons)+numpy.max(slons)))
    Opts['lat_0']=int(0.5*(numpy.min(slats)+numpy.max(slats)))
    Opts['gridspace']=gridspace
    if details==1:
        Opts['details']={'coasts':1,'rivers':0,'states':1,'countries':1,'ocean':1}
    else:
        Opts['details']={'coasts':1,'rivers':0,'states':0,'countries':0,'ocean':1}
    Opts['details']['fancy']=fancy
    pmagplotlib.plotMAP(FIGS['map'],slats,slons,Opts)
    pmagplotlib.plotXY(FIGS['vadms'],Age,Vadm,sym='bo',xlab='Age (Years CE)',ylab=r'VADM (ZAm$^2$)')
    if verbose:pmagplotlib.drawFIGS(FIGS)
    files={}
    for key in FIGS.keys():
        files[key]=key+'.'+fmt
    if pmagplotlib.isServer:
        black     = '#000000'
        purple    = '#800080'
        titles={}
        titles['map']='Map'
        titles['vadms']='VADMs'
        FIG = pmagplotlib.addBorders(FIGS,titles,black,purple)
        pmagplotlib.saveP(FIGS,files)
    elif verbose:
        ans=raw_input(" S[a]ve to save plot, Return to quit:  ")
        if ans=="a":
            pmagplotlib.saveP(FIGS,files)
    else:
        pmagplotlib.saveP(FIGS,files)
示例#4
0
def main():
    """
    NAME 
        vgpmap_magic.py 

    DESCRIPTION
        makes a map of vgps and a95/dp,dm for site means in a pmag_results table
 
    SYNTAX
        vgpmap_magic.py [command line options]

    OPTIONS
        -h prints help and quits
        -eye  ELAT ELON [specify eyeball location], default is 90., 0.
        -f FILE pmag_results format file, [default is pmag_results.txt] 
        -res [c,l,i,h] specify resolution (crude, low, intermediate, high]
        -etp plot the etopo20 topographpy data (requires high resolution data set)
        -prj PROJ,  specify one of the following:
             ortho = orthographic
             lcc = lambert conformal
             moll = molweide
             merc = mercator
        -sym SYM SIZE: choose a symbol and size, examples: 
            ro 5 : small red circles
            bs 10 : intermediate blue squares
            g^ 20 : large green triangles
        -ell  plot dp/dm or a95 ellipses
        -rev RSYM RSIZE : flip reverse poles to normal antipode 
        -S:  plot antipodes of all poles
        -age : plot the ages next to the poles
        -crd [g,t] : choose coordinate system, default is to plot all site VGPs
        -fmt [pdf, png, eps...] specify output format, default is pdf
        -sav  save and quit    
    DEFAULTS
        FILE: pmag_results.txt
        res:  c
        prj: ortho 
        ELAT,ELON = 0,0
        SYM SIZE: ro 8
        RSYM RSIZE: g^ 8
    
    """
    dir_path='.'
    res,ages='c',0
    plot=0
    proj='ortho'
    results_file='pmag_results.txt'
    ell,flip=0,0
    lat_0,lon_0=90.,0.
    fmt='pdf'
    sym,size='ro',8
    rsym,rsize='g^',8
    anti=0
    fancy=0
    coord=""
    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 '-S' in sys.argv:anti=1
    if '-fmt' in sys.argv:
        ind = sys.argv.index('-fmt')
        fmt=sys.argv[ind+1]
    if '-sav' in sys.argv:plot=1
    if '-res' in sys.argv:
        ind = sys.argv.index('-res')
        res=sys.argv[ind+1]
    if '-etp' in sys.argv:fancy=1
    if '-prj' in sys.argv:
        ind = sys.argv.index('-prj')
        proj=sys.argv[ind+1]
    if '-rev' in sys.argv: 
        flip=1
        ind = sys.argv.index('-rev')
        rsym=(sys.argv[ind+1])
        rsize=int(sys.argv[ind+2])
    if '-sym' in sys.argv:
        ind = sys.argv.index('-sym')
        sym=(sys.argv[ind+1])
        size=int(sys.argv[ind+2])
    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 '-ell' in sys.argv: ell=1
    if '-age' in sys.argv: ages=1
    if '-f' in sys.argv:
        ind = sys.argv.index('-f')
        results_file=sys.argv[ind+1]
    if '-crd' in sys.argv:
        ind = sys.argv.index('-crd')
        crd=sys.argv[ind+1]
        if crd=='g':coord='0'
        if crd=='t':coord='100'
    results_file=dir_path+'/'+results_file
    data,file_type=pmag.magic_read(results_file)
    if file_type!='pmag_results':
        print "bad results file"
        sys.exit()
    FIG={'map':1}
    pmagplotlib.plot_init(FIG['map'],6,6)
    # read in er_sites file
    lats,lons,dp,dm,a95=[],[],[],[],[]
    Pars=[]
    dates,rlats,rlons=[],[],[]
    if 'data_type' in data[0].keys():
        Results=pmag.get_dictitem(data,'data_type','i','T') # get all site level data
    else:
        Results=data
    Results=pmag.get_dictitem(Results,'vgp_lat','','F') # get all non-blank latitudes
    Results=pmag.get_dictitem(Results,'vgp_lon','','F') # get all non-blank longitudes
    if coord!="":Results=pmag.get_dictitem(Results,'tilt_correction',coord,'T') # get specified coordinate system
    location=""
    for rec in Results:
            if rec['er_location_names'] not in location:location = location+':'+rec['er_location_names']
            if 'average_age' in rec.keys() and rec['average_age']!="" and ages==1:
                dates.append(rec['average_age'])
            lat=float(rec['vgp_lat'])
            lon=float(rec['vgp_lon'])
            if flip==0:
                lats.append(lat)
                lons.append(lon)
            elif flip==1:
                if lat<0:
                    rlats.append(-lat)
                    lon=lon+180.
                    if lon>360:lon=lon-360.
                    rlons.append(lon)
                else:
                    lats.append(lat)
                    lons.append(lon)
            elif anti==1:
                lats.append(-lat)
                lon=lon+180.
                if lon>360:lon=lon-360.
                lons.append(lon)
            ppars=[]
            ppars.append(lon)
            ppars.append(lat)
            ell1,ell2="",""
            if 'vgp_dm' in rec.keys() and rec['vgp_dm']!="":ell1=float(rec['vgp_dm'])
            if 'vgp_dp' in rec.keys() and rec['vgp_dp']!="":ell2=float(rec['vgp_dp'])
            if 'vgp_alpha95' in rec.keys() and rec['vgp_alpha95']!="":ell1,ell2=float(rec['vgp_alpha95']),float(rec['vgp_alpha95'])
            if ell1!="" and ell2!="":
                ppars=[]
                ppars.append(lons[-1])
                ppars.append(lats[-1])
                ppars.append(ell1)
                ppars.append(lons[-1])
                isign=abs(lats[-1])/lats[-1]
                ppars.append(lats[-1]-isign*90.)
                ppars.append(ell2)
                ppars.append(lons[-1]+90.)
                ppars.append(0.)
                Pars.append(ppars)
    location=location.strip(':')
    Opts={'latmin':-90,'latmax':90,'lonmin':0.,'lonmax':360.,'lat_0':lat_0,'lon_0':lon_0,'proj':proj,'sym':'bs','symsize':3,'pltgrid':0,'res':res,'boundinglat':0.}
    Opts['details']={'coasts':1,'rivers':0, 'states':0, 'countries':0,'ocean':1,'fancy':fancy}
    pmagplotlib.plotMAP(FIG['map'],[90.],[0.],Opts) # make the base map with a blue triangle at the pole`
    Opts['pltgrid']=-1
    Opts['sym']=sym
    Opts['symsize']=size
    if len(dates)>0:Opts['names']=dates
    if len(lats)>0:pmagplotlib.plotMAP(FIG['map'],lats,lons,Opts) # add the lats and lons of the poles
    Opts['names']=[]
    if len(rlats)>0:
        Opts['sym']=rsym
        Opts['symsize']=rsize
        pmagplotlib.plotMAP(FIG['map'],rlats,rlons,Opts) # add the lats and lons of the poles
    if plot==0:
        pmagplotlib.drawFIGS(FIG)
    if ell==1: # add ellipses if desired.
        Opts['details']={'coasts':0,'rivers':0, 'states':0, 'countries':0,'ocean':0}
        Opts['pltgrid']=-1 # turn off meridian replotting
        Opts['symsize']=2
        Opts['sym']='g-'
        for ppars in Pars:
            if ppars[2]!=0:
                PTS=pmagplotlib.plotELL(FIG['map'],ppars,'g.',0,0)
                elats,elons=[],[]
                for pt in PTS:
                    elons.append(pt[0])
                    elats.append(pt[1])
                pmagplotlib.plotMAP(FIG['map'],elats,elons,Opts) # make the base map with a blue triangle at the pole`
                if plot==0:pmagplotlib.drawFIGS(FIG)
    files={}
    for key in FIG.keys():
        files[key]='LO:_'+location+'_VGP_map.'+fmt
    if pmagplotlib.isServer:
        black     = '#000000'
        purple    = '#800080'
        titles={}
        titles['eq']='LO:_'+location+'_VGP_map'
        FIG = pmagplotlib.addBorders(FIG,titles,black,purple)
        pmagplotlib.saveP(FIG,files)
    elif plot==0:
        pmagplotlib.drawFIGS(FIG)
        ans=raw_input(" S[a]ve to save plot, Return to quit:  ")
        if ans=="a":
            pmagplotlib.saveP(FIG,files)
        else:
            print "Good bye"
            sys.exit()
    else:
        pmagplotlib.saveP(FIG,files)
示例#5
0
def main():
    """
    NAME 
        plot_map_pts.py 

    DESCRIPTION
        plots points on map
 
    SYNTAX
        plot_map_pts.py [command line options]

    OPTIONS
        -h prints help and quits
        -sym [ro, bs, g^, r., b-, etc.] [1,5,10] symbol and size for points
           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]
        -etp  put on topography
        -f FILE, specify input file
        -o color ocean blue/land green (default is not)
        -res [c,l,i,h] specify resolution (crude, low, intermediate, high]
        -fmt [pdf,eps, png] specify output format (default is pdf)
        -R don't plot details of rivers
        -B don't plot national/state boundaries, etc.
        -pad [LAT LON] pad bounding box by LAT/LON (default is not)
        -grd SPACE specify grid spacing
        -sav  save plot and quit
        -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
        Special codes for MagIC formatted input files:
            -n
            -l
    
    INPUTS
        space or tab delimited LON LAT data
        OR: 
           standard MagIC formatted er_sites or pmag_results table
    DEFAULTS
        res:  c
        prj: mollweide;  lcc for MagIC format files 
        ELAT,ELON = 0,0
        pad LAT,LON=0,0
        NB: high resolution or lines can be very slow
    
    """
    dir_path='.'
    plot=0
    ocean=0
    res='c'
    proj='moll'
    Lats,Lons=[],[]
    fmt='pdf'
    sym='ro'
    symsize=5
    fancy=0
    rivers,boundaries,ocean=1,1,0
    latmin,latmax,lonmin,lonmax,lat_0,lon_0=-90,90,0.,360.,0.,0.
    padlat,padlon,gridspace=0,0,30
    lat_0,lon_0="",""
    prn_name,prn_loc,names,locs=0,0,[],[]
    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 '-fmt' in sys.argv:
        ind = sys.argv.index('-fmt')
        fmt=sys.argv[ind+1]
    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 '-etp' in sys.argv: fancy=1
    if '-sav' in sys.argv: plot=1
    if '-R' in sys.argv:rivers=0
    if '-B' in sys.argv:boundaries=0
    if '-o' in sys.argv:ocean=1
    if '-grd' in sys.argv:
        ind = sys.argv.index('-grd')
        gridspace=float(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 '-sym' in sys.argv:
        ind = sys.argv.index('-sym')
        sym=sys.argv[ind+1]
        symsize=int(sys.argv[ind+2])
    if '-pad' in sys.argv:
        ind = sys.argv.index('-pad')
        padlat=float(sys.argv[ind+1])
        padlon=float(sys.argv[ind+2])
    if '-f' in sys.argv:
        ind = sys.argv.index('-f')
        file=dir_path+'/'+sys.argv[ind+1]
        header=open(file,'r').readlines()[0].split('\t')
        if 'tab' in header[0]:
            if '-n' in sys.argv:prn_name=1
            if '-l' in sys.argv:prn_loc=1
            proj='lcc'
            if 'results' in header[1]:
                latkey='average_lat'
                lonkey='average_lon'
                namekey='pmag_result_name'
                lockey='er_location_names'
            elif 'sites' in header[1]:
                latkey='site_lat'
                lonkey='site_lon'
                namekey='er_site_name'
                lockey='er_location_name'
            else:  
                print('file type not supported')
                print(main.__doc__)
                sys.exit()
            Sites,file_type=pmag.magic_read(file)
            Lats=pmag.get_dictkey(Sites,latkey,'f')
            Lons=pmag.get_dictkey(Sites,lonkey,'f')
            if prn_name==1:names=pmag.get_dictkey(Sites,namekey,'')
            if prn_loc==1:names=pmag.get_dictkey(Sites,lockey,'')
        else:
            ptdata=numpy.loadtxt(file)
            Lons=ptdata.transpose()[0]
            Lats=ptdata.transpose()[1]
        latmin=numpy.min(Lats)-padlat
        lonmin=numpy.min(Lons)-padlon
        latmax=numpy.max(Lats)+padlat
        lonmax=numpy.max(Lons)+padlon
        if lon_0=="":
            lon_0=0.5*(lonmin+lonmax)
            lat_0=0.5*(latmin+latmax)
    else:
        print("input file must be specified")
        sys.exit()
    if '-prj' in sys.argv:
        ind = sys.argv.index('-prj')
        proj=sys.argv[ind+1]
    FIG={'map':1}
    pmagplotlib.plot_init(FIG['map'],6,6)
    if res=='c':skip=8
    if res=='l':skip=5
    if res=='i':skip=2
    if res=='h':skip=1
    cnt=0
    Opts={'latmin':latmin,'latmax':latmax,'lonmin':lonmin,'lonmax':lonmax,'lat_0':lat_0,'lon_0':lon_0,'proj':proj,'sym':sym,'symsize':3,'pltgrid':1,'res':res,'boundinglat':0.,'padlon':padlon,'padlat':padlat,'gridspace':gridspace}
    Opts['details']={}
    Opts['details']['coasts']=1
    Opts['details']['rivers']=rivers
    Opts['details']['states']=boundaries
    Opts['details']['countries']=boundaries
    Opts['details']['ocean']=ocean
    Opts['details']['fancy']=fancy
    if len(names)>0:Opts['names']=names
    if len(locs)>0:Opts['loc_name']=locs
    if proj=='merc':
        Opts['latmin']=-70
        Opts['latmax']=70
        Opts['lonmin']=-180
        Opts['lonmax']=180
    print('please wait to draw points')
    Opts['sym']=sym
    Opts['symsize']=symsize
    pmagplotlib.plotMAP(FIG['map'],Lats,Lons,Opts)
    files={}
    titles={}
    titles['map']='PT Map'
    for key in list(FIG.keys()):
        files[key]='Map_PTS'+'.'+fmt
    if pmagplotlib.isServer:
        black     = '#000000'
        purple    = '#800080'
        FIG = pmagplotlib.addBorders(FIG,titles,black,purple)
        pmagplotlib.saveP(FIG,files)
    if plot==1:
        pmagplotlib.saveP(FIG,files)
    else:
        pmagplotlib.drawFIGS(FIG)
        ans=input(" S[a]ve to save plot, Return to quit:  ")
        if ans=="a": pmagplotlib.saveP(FIG,files)
示例#6
0
def main():
    """
    NAME
        vgpmap_magic.py

    DESCRIPTION
        makes a map of vgps and a95/dp,dm for site means in a sites table

    SYNTAX
        vgpmap_magic.py [command line options]

    OPTIONS
        -h prints help and quits
        -eye  ELAT ELON [specify eyeball location], default is 90., 0.
        -f FILE sites format file, [default is sites.txt]
        -res [c,l,i,h] specify resolution (crude, low, intermediate, high]
        -etp plot the etopo20 topographpy data (requires high resolution data set)
        -prj PROJ,  specify one of the following:
             ortho = orthographic
             lcc = lambert conformal
             moll = molweide
             merc = mercator
        -sym SYM SIZE: choose a symbol and size, examples:
            ro 5 : small red circles
            bs 10 : intermediate blue squares
            g^ 20 : large green triangles
        -ell  plot dp/dm or a95 ellipses
        -rev RSYM RSIZE : flip reverse poles to normal antipode
        -S:  plot antipodes of all poles
        -age : plot the ages next to the poles
        -crd [g,t] : choose coordinate system, default is to plot all site VGPs
        -fmt [pdf, png, eps...] specify output format, default is pdf
        -sav  save and quit
    DEFAULTS
        FILE: pmag_results.txt
        res:  c
        prj: ortho
        ELAT,ELON = 0,0
        SYM SIZE: ro 8
        RSYM RSIZE: g^ 8

    """
    if '-h' in sys.argv:
        print(main.__doc__)
        sys.exit()
    dir_path = pmag.get_named_arg_from_sys("-WD", ".")
    # plot: default is 0, if -sav in sys.argv should be 1
    plot = pmag.get_flag_arg_from_sys("-sav", true=1, false=0)
    fmt = pmag.get_named_arg_from_sys("-fmt", "pdf")
    res = pmag.get_named_arg_from_sys("-res", "c")
    proj = pmag.get_named_arg_from_sys("-prj", "ortho")
    anti = pmag.get_flag_arg_from_sys("-S", true=1, false=0)
    fancy = pmag.get_flag_arg_from_sys("-etp", true=1, false=0)
    ell = pmag.get_flag_arg_from_sys("-ell", true=1, false=0)
    ages = pmag.get_flag_arg_from_sys("-age", true=1, false=0)
    if '-rev' in sys.argv:
        flip = 1
        ind = sys.argv.index('-rev')
        rsym = (sys.argv[ind + 1])
        rsize = int(sys.argv[ind + 2])
    else:
        flip, rsym, rsize = 0, "g^", 8
    if '-sym' in sys.argv:
        ind = sys.argv.index('-sym')
        sym = (sys.argv[ind + 1])
        size = int(sys.argv[ind + 2])
    else:
        sym, size = 'ro', 8
    if '-eye' in sys.argv:
        ind = sys.argv.index('-eye')
        lat_0 = float(sys.argv[ind + 1])
        lon_0 = float(sys.argv[ind + 2])
    else:
        lat_0, lon_0 = 90., 0.
    crd = pmag.get_named_arg_from_sys("-crd", "")
    coord_dict = {'g': 0, 't': 100}
    coord = coord_dict[crd] if crd else ""
    results_file = pmag.get_named_arg_from_sys("-f", "sites.txt")

    con = nb.Contribution(dir_path, single_file=results_file)
    if not list(con.tables.keys()):
        print("-W - Couldn't read in data")
        return

    FIG = {'map': 1}
    pmagplotlib.plot_init(FIG['map'], 6, 6)
    # read in er_sites file
    lats, lons = [], []
    Pars = []
    dates, rlats, rlons = [], [], []

    site_container = con.tables['sites']
    site_df = site_container.df
    # use individual results
    site_df = site_df[site_df['result_type'] == 'i']
    # use records with vgp_lat and vgp_lon
    cond1, cond2 = site_df['vgp_lat'].notnull(), site_df['vgp_lon'].notnull()
    Results = site_df[cond1 & cond2]
    # use tilt correction
    if coord and 'dir_tilt_correction' in Results.columns:
        Results = Results[Results['dir_tilt_correction'] == coord]
    # get location name and average ages
    location = ":".join(Results['location'].unique())
    if 'average_age' in Results.columns and ages == 1:
        dates = Results['average_age'].unique()

    # go through rows and extract data
    for ind, row in Results.iterrows():
        lat, lon = float(row['vgp_lat']), float(row['vgp_lon'])
        if anti == 1:
            lats.append(-lat)
            lon = lon + 180.
            if lon > 360:
                lon = lon - 360.
            lons.append(lon)
        elif flip == 0:
            lats.append(lat)
            lons.append(lon)
        elif flip == 1:
            if lat < 0:
                rlats.append(-lat)
                lon = lon + 180.
                if lon > 360:
                    lon = lon - 360
                rlons.append(lon)
            else:
                lats.append(lat)
                lons.append(lon)

        ppars = []
        ppars.append(lon)
        ppars.append(lat)
        ell1, ell2 = "", ""
        if 'vgp_dm' in list(row.keys()) and row['vgp_dm']:
            ell1 = float(row['vgp_dm'])
        if 'vgp_dp' in list(row.keys()) and row['vgp_dp']:
            ell2 = float(row['vgp_dp'])
        if 'vgp_alpha95' in list(row.keys()) and row['vgp_alpha95'].notnull():
            ell1, ell2 = float(row['vgp_alpha95']), float(row['vgp_alpha95'])
        if ell1 and ell2:
            ppars = []
            ppars.append(lons[-1])
            ppars.append(lats[-1])
            ppars.append(ell1)
            ppars.append(lons[-1])
            isign = old_div(abs(lats[-1]), lats[-1])
            ppars.append(lats[-1] - isign * 90.)
            ppars.append(ell2)
            ppars.append(lons[-1] + 90.)
            ppars.append(0.)
            Pars.append(ppars)

    location = location.strip(':')
    Opts = {
        'latmin': -90,
        'latmax': 90,
        'lonmin': 0.,
        'lonmax': 360.,
        'lat_0': lat_0,
        'lon_0': lon_0,
        'proj': proj,
        'sym': 'bs',
        'symsize': 3,
        'pltgrid': 0,
        'res': res,
        'boundinglat': 0.
    }
    Opts['details'] = {
        'coasts': 1,
        'rivers': 0,
        'states': 0,
        'countries': 0,
        'ocean': 1,
        'fancy': fancy
    }
    # make the base map with a blue triangle at the pole
    pmagplotlib.plotMAP(FIG['map'], [90.], [0.], Opts)
    Opts['pltgrid'] = -1
    Opts['sym'] = sym
    Opts['symsize'] = size
    if len(dates) > 0:
        Opts['names'] = dates
    if len(lats) > 0:
        # add the lats and lons of the poles
        pmagplotlib.plotMAP(FIG['map'], lats, lons, Opts)
    Opts['names'] = []
    if len(rlats) > 0:
        Opts['sym'] = rsym
        Opts['symsize'] = rsize
        # add the lats and lons of the poles
        pmagplotlib.plotMAP(FIG['map'], rlats, rlons, Opts)
    if plot == 0:
        pmagplotlib.drawFIGS(FIG)
    if ell == 1:  # add ellipses if desired.
        Opts['details'] = {
            'coasts': 0,
            'rivers': 0,
            'states': 0,
            'countries': 0,
            'ocean': 0,
            'fancy': fancy
        }
        Opts['pltgrid'] = -1  # turn off meridian replotting
        Opts['symsize'] = 2
        Opts['sym'] = 'g-'
        for ppars in Pars:
            if ppars[2] != 0:
                PTS = pmagplotlib.plotELL(FIG['map'], ppars, 'g.', 0, 0)
                elats, elons = [], []
                for pt in PTS:
                    elons.append(pt[0])
                    elats.append(pt[1])
                # make the base map with a blue triangle at the pole
                pmagplotlib.plotMAP(FIG['map'], elats, elons, Opts)
                if plot == 0:
                    pmagplotlib.drawFIGS(FIG)
    files = {}
    for key in list(FIG.keys()):
        if pmagplotlib.isServer:  # use server plot naming convention
            files[key] = 'LO:_' + location + '_VGP_map.' + fmt
        else:  # use more readable naming convention
            files[key] = '{}_VGP_map.{}'.format(location, fmt)

    if pmagplotlib.isServer:
        black = '#000000'
        purple = '#800080'
        titles = {}
        titles['eq'] = 'LO:_' + location + '_VGP_map'
        FIG = pmagplotlib.addBorders(FIG, titles, black, purple)
        pmagplotlib.saveP(FIG, files)
    elif plot == 0:
        pmagplotlib.drawFIGS(FIG)
        ans = input(" S[a]ve to save plot, Return to quit:  ")
        if ans == "a":
            pmagplotlib.saveP(FIG, files)
        else:
            print("Good bye")
            sys.exit()
    else:
        pmagplotlib.saveP(FIG, files)
示例#7
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]
        -fmt [png,jpg,svg,pdf] format for saved figure - pdf is default
        -sav saves plots and quits
        -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
    plot=0
    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 '-fmt' in sys.argv:
        ind = sys.argv.index('-fmt')
        fmt=sys.argv[ind+1]
    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 pmagpy.frp as 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 '-sav' in sys.argv: plot=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)
        if plot==0: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)
            if plot==0: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)
             if plot==0: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)
        if plot==0: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)
            if plot==0:pmagplotlib.drawFIGS(FIG)
        Opts['sym']='g^'
        Opts['symsize']=5
        pmagplotlib.plotMAP(FIG['map'],[pole[0]],[pole[1]],Opts)
        if plot==0:pmagplotlib.drawFIGS(FIG)
    files={}
    for key in FIG.keys():
        files[key]='Cont_rot'+'.'+fmt
    if plot==1:
        pmagplotlib.saveP(FIG,files)
        sys.exit()
    if pmagplotlib.isServer:
        black     = '#000000'
        purple    = '#800080'
        titles={}
        titles['eq']='Site Map'
        FIG = pmagplotlib.addBorders(FIG,titles,black,purple)
        pmagplotlib.saveP(FIG,files)
    else:
        pmagplotlib.drawFIGS(FIG)
        ans=raw_input(" S[a]ve to save plot, Return to quit:  ")
        if ans=="a":
            pmagplotlib.saveP(FIG,files)
示例#8
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]
        -fmt [png,jpg,svg,pdf] format for saved figure - pdf is default
        -sav saves plots and quits
        -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
    plot=0
    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 '-fmt' in sys.argv:
        ind = sys.argv.index('-fmt')
        fmt=sys.argv[ind+1]
    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 pmagpy.frp as 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 '-sav' in sys.argv: plot=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)
        if plot==0: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)
            if plot==0: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)
             if plot==0: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)
        if plot==0: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)
            if plot==0:pmagplotlib.drawFIGS(FIG)
        Opts['sym']='g^'
        Opts['symsize']=5
        pmagplotlib.plotMAP(FIG['map'],[pole[0]],[pole[1]],Opts)
        if plot==0:pmagplotlib.drawFIGS(FIG)
    files={}
    for key in FIG.keys():
        files[key]='Cont_rot'+'.'+fmt
    if plot==1:
        pmagplotlib.saveP(FIG,files)
        sys.exit()
    if pmagplotlib.isServer:
        black     = '#000000'
        purple    = '#800080'
        titles={}
        titles['eq']='Site Map'
        FIG = pmagplotlib.addBorders(FIG,titles,black,purple)
        pmagplotlib.saveP(FIG,files)
    else:
        pmagplotlib.drawFIGS(FIG)
        ans=raw_input(" S[a]ve to save plot, Return to quit:  ")
        if ans=="a":
            pmagplotlib.saveP(FIG,files)
示例#9
0
def main():
    """
    NAME
        plot_geomagia.py

    DESCRIPTION
        makes a map  and VADM plot of geomagia download file 

    SYNTAX
        plot_geomagia.py  [command line options]

    OPTIONS
        -h prints help message and quits
        -f FILE, specify geomagia download file
        -res [c,l,i,h] specify resolution (crude,low,intermediate,high)
        -etp plot the etopo20 topographic mesh
        -pad [LAT LON]  pad bounding box by LAT/LON  (default is [.5 .5] degrees)
        -grd SPACE specify grid spacing
        -prj [lcc] , specify projection (lcc=lambert conic conformable), default is mercator
        -o color ocean blue/land green (default is not)
        -d plot details of rivers, boundaries, etc.
        -sav save plot and quit quietly
        -fmt [png,svg,eps,jpg,pdf] specify format for output, default is pdf
    DEFAULTS
        resolution: intermediate
        saved images are in pdf
    """
    dir_path = '.'
    names, res, proj, locs, padlon, padlat, fancy, gridspace, details = [], 'l', 'lcc', '', 0, 0, 0, 15, 1
    Age_bounds = [-5000, 2000]
    Lat_bounds = [20, 45]
    Lon_bounds = [15, 55]
    fmt = 'pdf'
    if '-h' in sys.argv:
        print(main.__doc__)
        sys.exit()
    if '-f' in sys.argv:
        ind = sys.argv.index('-f')
        sites_file = sys.argv[ind + 1]
    if '-res' in sys.argv:
        ind = sys.argv.index('-res')
        res = sys.argv[ind + 1]
    if '-etp' in sys.argv: fancy = 1
    if '-o' in sys.argv: ocean = 1
    if '-d' in sys.argv: details = 1
    if '-prj' in sys.argv:
        ind = sys.argv.index('-prj')
        proj = sys.argv[ind + 1]
    if '-fmt' in sys.argv:
        ind = sys.argv.index('-fmt')
        fmt = sys.argv[ind + 1]
    verbose = pmagplotlib.verbose
    if '-sav' in sys.argv:
        verbose = 0
    if '-pad' in sys.argv:
        ind = sys.argv.index('-pad')
        padlat = float(sys.argv[ind + 1])
        padlon = float(sys.argv[ind + 2])
    if '-grd' in sys.argv:
        ind = sys.argv.index('-grd')
        gridspace = float(sys.argv[ind + 1])
    if '-WD' in sys.argv:
        ind = sys.argv.index('-WD')
        dir_path = sys.argv[ind + 1]
    sites_file = dir_path + '/' + sites_file
    geo_in = open(sites_file, 'r').readlines()
    Age, AgeErr, Vadm, VadmErr, slats, slons = [], [], [], [], [], []
    for line in geo_in[2:]:  # skip top two rows`
        rec = line.split()
        if float(rec[0])>Age_bounds[0] and float(rec[0])<Age_bounds[1] \
           and float(rec[12])>Lat_bounds[0] and float(rec[12]) < Lat_bounds[1]\
            and float(rec[13])>Lon_bounds[0] and float(rec[13])<Lon_bounds[1]:
            Age.append(float(rec[0]))
            AgeErr.append(float(rec[1]))
            Vadm.append(10. * float(rec[6]))
            VadmErr.append(10. * float(rec[7]))
            slats.append(float(rec[12]))
            slons.append(float(rec[13]))
    FIGS = {'map': 1, 'vadms': 2}
    pmagplotlib.plot_init(FIGS['map'], 6, 6)
    pmagplotlib.plot_init(FIGS['vadms'], 6, 6)
    Opts = {
        'res': res,
        'proj': proj,
        'loc_name': locs,
        'padlon': padlon,
        'padlat': padlat,
        'latmin': numpy.min(slats) - padlat,
        'latmax': numpy.max(slats) + padlat,
        'lonmin': numpy.min(slons) - padlon,
        'lonmax': numpy.max(slons) + padlon,
        'sym': 'ro',
        'boundinglat': 0.,
        'pltgrid': 1
    }
    Opts['lon_0'] = int(0.5 * (numpy.min(slons) + numpy.max(slons)))
    Opts['lat_0'] = int(0.5 * (numpy.min(slats) + numpy.max(slats)))
    Opts['gridspace'] = gridspace
    if details == 1:
        Opts['details'] = {
            'coasts': 1,
            'rivers': 0,
            'states': 1,
            'countries': 1,
            'ocean': 1
        }
    else:
        Opts['details'] = {
            'coasts': 1,
            'rivers': 0,
            'states': 0,
            'countries': 0,
            'ocean': 1
        }
    Opts['details']['fancy'] = fancy
    pmagplotlib.plotMAP(FIGS['map'], slats, slons, Opts)
    pmagplotlib.plotXY(FIGS['vadms'],
                       Age,
                       Vadm,
                       sym='bo',
                       xlab='Age (Years CE)',
                       ylab=r'VADM (ZAm$^2$)')
    if verbose: pmagplotlib.drawFIGS(FIGS)
    files = {}
    for key in list(FIGS.keys()):
        files[key] = key + '.' + fmt
    if pmagplotlib.isServer:
        black = '#000000'
        purple = '#800080'
        titles = {}
        titles['map'] = 'Map'
        titles['vadms'] = 'VADMs'
        FIG = pmagplotlib.addBorders(FIGS, titles, black, purple)
        pmagplotlib.saveP(FIGS, files)
    elif verbose:
        ans = input(" S[a]ve to save plot, Return to quit:  ")
        if ans == "a":
            pmagplotlib.saveP(FIGS, files)
    else:
        pmagplotlib.saveP(FIGS, files)
示例#10
0
def main():
    """
    NAME 
        basemap_magic.py
        NB:  this program no longer maintained - use plot_mapPTS.py for greater functionality

    DESCRIPTION
        makes a map of locations in er_sites.txt
 
    SYNTAX
        basemap_magic.py  [command line options]

    OPTIONS
        -h prints help message and quits
        -f SFILE, specify er_sites.txt or pmag_results.txt format file
        -res [c,l,i,h] specify resolution (crude,low,intermediate,high)
        -etp plot the etopo20 topographic mesh
        -pad [LAT LON]  pad bounding box by LAT/LON  (default is [.5 .5] degrees)
        -grd SPACE specify grid spacing
        -prj [lcc] , specify projection (lcc=lambert conic conformable), default is mercator
        -n print site names (default is not)
        -l print location names (default is not)
        -o color ocean blue/land green (default is not)
        -R don't plot details of rivers
        -B don't plot national/state  boundaries, etc.
        -sav save plot and quit quietly
        -fmt [png,svg,eps,jpg,pdf] specify format for output, default is pdf     
    DEFAULTS
        SFILE: 'er_sites.txt'
        resolution: intermediate
        saved images are in pdf
    """
    dir_path = '.'
    sites_file = 'er_sites.txt'
    ocean = 0
    res = 'i'
    proj = 'merc'
    prn_name = 0
    prn_loc = 0
    fancy = 0
    rivers, boundaries = 0, 0
    padlon, padlat, gridspace, details = .5, .5, .5, 1
    fmt = 'pdf'
    if '-h' in sys.argv:
        print(main.__doc__)
        sys.exit()
    if '-f' in sys.argv:
        ind = sys.argv.index('-f')
        sites_file = sys.argv[ind + 1]
    if '-res' in sys.argv:
        ind = sys.argv.index('-res')
        res = sys.argv[ind + 1]
    if '-etp' in sys.argv: fancy = 1
    if '-n' in sys.argv: prn_name = 1
    if '-l' in sys.argv: prn_loc = 1
    if '-o' in sys.argv: ocean = 1
    if '-R' in sys.argv: rivers = 0
    if '-B' in sys.argv: boundaries = 0
    if '-prj' in sys.argv:
        ind = sys.argv.index('-prj')
        proj = sys.argv[ind + 1]
    if '-fmt' in sys.argv:
        ind = sys.argv.index('-fmt')
        fmt = sys.argv[ind + 1]
    verbose = pmagplotlib.verbose
    if '-sav' in sys.argv:
        verbose = 0
    if '-pad' in sys.argv:
        ind = sys.argv.index('-pad')
        padlat = float(sys.argv[ind + 1])
        padlon = float(sys.argv[ind + 2])
    if '-grd' in sys.argv:
        ind = sys.argv.index('-grd')
        gridspace = float(sys.argv[ind + 1])
    if '-WD' in sys.argv:
        ind = sys.argv.index('-WD')
        dir_path = sys.argv[ind + 1]
    sites_file = dir_path + '/' + sites_file
    location = ""
    FIG = {'map': 1}
    pmagplotlib.plot_init(FIG['map'], 6, 6)
    # read in er_sites file
    Sites, file_type = pmag.magic_read(sites_file)
    if 'results' in file_type:
        latkey = 'average_lat'
        lonkey = 'average_lon'
        namekey = 'pmag_result_name'
        lockey = 'er_location_names'
    else:
        latkey = 'site_lat'
        lonkey = 'site_lon'
        namekey = 'er_site_name'
        lockey = 'er_location_name'
    lats, lons = [], []
    slats, slons = [], []
    names, locs = [], []
    for site in Sites:
        if prn_loc == 1 and location == "": location = site['er_location_name']
        lats.append(float(site[latkey]))
        l = float(site[lonkey])
        if l < 0: l = l + 360.  # make positive
        lons.append(l)
        if prn_name == 1: names.append(site[namekey])
        if prn_loc == 1: locs.append(site[lockey])
    for lat in lats:
        slats.append(lat)
    for lon in lons:
        slons.append(lon)
    Opts = {
        'res': res,
        'proj': proj,
        'loc_name': locs,
        'padlon': padlon,
        'padlat': padlat,
        'latmin': numpy.min(slats) - padlat,
        'latmax': numpy.max(slats) + padlat,
        'lonmin': numpy.min(slons) - padlon,
        'lonmax': numpy.max(slons) + padlon,
        'sym': 'ro',
        'boundinglat': 0.,
        'pltgrid': 1.
    }
    Opts['lon_0'] = 0.5 * (numpy.min(slons) + numpy.max(slons))
    Opts['lat_0'] = 0.5 * (numpy.min(slats) + numpy.max(slats))
    Opts['names'] = names
    Opts['gridspace'] = gridspace
    Opts['details'] = {
        'coasts': 1,
        'rivers': 1,
        'states': 1,
        'countries': 1,
        'ocean': 0
    }
    if ocean == 1: Opts['details']['ocean'] = 1
    if rivers == 1: Opts['details']['rivers'] = 0
    if boundaries == 1:
        Opts['details']['states'] = 0
        Opts['details']['countries'] = 0
    Opts['details']['fancy'] = fancy
    pmagplotlib.plotMAP(FIG['map'], lats, lons, Opts)
    if verbose: pmagplotlib.drawFIGS(FIG)
    files = {}
    for key in list(FIG.keys()):
        files[key] = 'Site_map' + '.' + fmt
    if pmagplotlib.isServer:
        black = '#000000'
        purple = '#800080'
        titles = {}
        titles['map'] = 'Site Map'
        FIG = pmagplotlib.addBorders(FIG, titles, black, purple)
        pmagplotlib.saveP(FIG, files)
    elif verbose:
        ans = input(" S[a]ve to save plot, Return to quit:  ")
        if ans == "a":
            pmagplotlib.saveP(FIG, files)
    else:
        pmagplotlib.saveP(FIG, files)
示例#11
0
def main():
    """
    NAME
        vgpmap_magic.py

    DESCRIPTION
        makes a map of vgps and a95/dp,dm for site means in a sites table

    SYNTAX
        vgpmap_magic.py [command line options]

    OPTIONS
        -h prints help and quits
        -eye  ELAT ELON [specify eyeball location], default is 90., 0.
        -f FILE sites format file, [default is sites.txt]
        -res [c,l,i,h] specify resolution (crude, low, intermediate, high]
        -etp plot the etopo20 topographpy data (requires high resolution data set)
        -prj PROJ,  specify one of the following:
             ortho = orthographic
             lcc = lambert conformal
             moll = molweide
             merc = mercator
        -sym SYM SIZE: choose a symbol and size, examples:
            ro 5 : small red circles
            bs 10 : intermediate blue squares
            g^ 20 : large green triangles
        -ell  plot dp/dm or a95 ellipses
        -rev RSYM RSIZE : flip reverse poles to normal antipode
        -S:  plot antipodes of all poles
        -age : plot the ages next to the poles
        -crd [g,t] : choose coordinate system, default is to plot all site VGPs
        -fmt [pdf, png, eps...] specify output format, default is pdf
        -sav  save and quit
    DEFAULTS
        FILE: pmag_results.txt
        res:  c
        prj: ortho
        ELAT,ELON = 0,0
        SYM SIZE: ro 8
        RSYM RSIZE: g^ 8

    """
    if "-h" in sys.argv:
        print main.__doc__
        sys.exit()
    dir_path = pmag.get_named_arg_from_sys("-WD", ".")
    # plot: default is 0, if -sav in sys.argv should be 1
    plot = pmag.get_flag_arg_from_sys("-sav", true=1, false=0)
    fmt = pmag.get_named_arg_from_sys("-fmt", "pdf")
    res = pmag.get_named_arg_from_sys("-res", "c")
    proj = pmag.get_named_arg_from_sys("-prj", "ortho")
    anti = pmag.get_flag_arg_from_sys("-S", true=1, false=0)
    fancy = pmag.get_flag_arg_from_sys("-etp", true=1, false=0)
    ell = pmag.get_flag_arg_from_sys("-ell", true=1, false=0)
    ages = pmag.get_flag_arg_from_sys("-age", true=1, false=0)
    if "-rev" in sys.argv:
        flip = 1
        ind = sys.argv.index("-rev")
        rsym = sys.argv[ind + 1]
        rsize = int(sys.argv[ind + 2])
    else:
        flip, rsym, rsize = 0, "g^", 8
    if "-sym" in sys.argv:
        ind = sys.argv.index("-sym")
        sym = sys.argv[ind + 1]
        size = int(sys.argv[ind + 2])
    else:
        sym, size = "ro", 8
    if "-eye" in sys.argv:
        ind = sys.argv.index("-eye")
        lat_0 = float(sys.argv[ind + 1])
        lon_0 = float(sys.argv[ind + 2])
    else:
        lat_0, lon_0 = 90.0, 0.0
    crd = pmag.get_named_arg_from_sys("-crd", "")
    coord_dict = {"g": 0, "t": 100}
    coord = coord_dict[crd] if crd else ""
    results_file = pmag.get_named_arg_from_sys("-f", "sites.txt")

    con = nb.Contribution(dir_path, single_file=results_file)
    if not con.tables.keys():
        print "-W - Couldn't read in data"
        return

    FIG = {"map": 1}
    pmagplotlib.plot_init(FIG["map"], 6, 6)
    # read in er_sites file
    lats, lons = [], []
    Pars = []
    dates, rlats, rlons = [], [], []

    site_container = con.tables["sites"]
    site_df = site_container.df
    # use individual results
    site_df = site_df[site_df["result_type"] == "i"]
    # use records with vgp_lat and vgp_lon
    cond1, cond2 = site_df["vgp_lat"].notnull(), site_df["vgp_lon"].notnull()
    Results = site_df[cond1 & cond2]
    # use tilt correction
    if coord and "dir_tilt_correction" in Results.columns:
        Results = Results[Results["dir_tilt_correction"] == coord]
    # get location name and average ages
    location = ":".join(Results["location"].unique())
    if "average_age" in Results.columns and ages == 1:
        dates = Results["average_age"].unique()

    # go through rows and extract data
    for ind, row in Results.iterrows():
        lat, lon = float(row["vgp_lat"]), float(row["vgp_lon"])
        if anti == 1:
            lats.append(-lat)
            lon = lon + 180.0
            if lon > 360:
                lon = lon - 360.0
            lons.append(lon)
        elif flip == 0:
            lats.append(lat)
            lons.append(lon)
        elif flip == 1:
            if lat < 0:
                rlats.append(-lat)
                lon = lon + 180.0
                if lon > 360:
                    lon = lon - 360
                rlons.append(lon)
            else:
                lats.append(lat)
                lons.append(lon)

        ppars = []
        ppars.append(lon)
        ppars.append(lat)
        ell1, ell2 = "", ""
        if "vgp_dm" in row.keys() and row["vgp_dm"]:
            ell1 = float(row["vgp_dm"])
        if "vgp_dp" in row.keys() and row["vgp_dp"]:
            ell2 = float(row["vgp_dp"])
        if "vgp_alpha95" in row.keys() and row["vgp_alpha95"].notnull():
            ell1, ell2 = float(row["vgp_alpha95"]), float(row["vgp_alpha95"])
        if ell1 and ell2:
            ppars = []
            ppars.append(lons[-1])
            ppars.append(lats[-1])
            ppars.append(ell1)
            ppars.append(lons[-1])
            isign = abs(lats[-1]) / lats[-1]
            ppars.append(lats[-1] - isign * 90.0)
            ppars.append(ell2)
            ppars.append(lons[-1] + 90.0)
            ppars.append(0.0)
            Pars.append(ppars)

    location = location.strip(":")
    Opts = {
        "latmin": -90,
        "latmax": 90,
        "lonmin": 0.0,
        "lonmax": 360.0,
        "lat_0": lat_0,
        "lon_0": lon_0,
        "proj": proj,
        "sym": "bs",
        "symsize": 3,
        "pltgrid": 0,
        "res": res,
        "boundinglat": 0.0,
    }
    Opts["details"] = {"coasts": 1, "rivers": 0, "states": 0, "countries": 0, "ocean": 1, "fancy": fancy}
    # make the base map with a blue triangle at the pole
    pmagplotlib.plotMAP(FIG["map"], [90.0], [0.0], Opts)
    Opts["pltgrid"] = -1
    Opts["sym"] = sym
    Opts["symsize"] = size
    if len(dates) > 0:
        Opts["names"] = dates
    if len(lats) > 0:
        # add the lats and lons of the poles
        pmagplotlib.plotMAP(FIG["map"], lats, lons, Opts)
    Opts["names"] = []
    if len(rlats) > 0:
        Opts["sym"] = rsym
        Opts["symsize"] = rsize
        # add the lats and lons of the poles
        pmagplotlib.plotMAP(FIG["map"], rlats, rlons, Opts)
    if plot == 0:
        pmagplotlib.drawFIGS(FIG)
    if ell == 1:  # add ellipses if desired.
        Opts["details"] = {"coasts": 0, "rivers": 0, "states": 0, "countries": 0, "ocean": 0, "fancy": fancy}
        Opts["pltgrid"] = -1  # turn off meridian replotting
        Opts["symsize"] = 2
        Opts["sym"] = "g-"
        for ppars in Pars:
            if ppars[2] != 0:
                PTS = pmagplotlib.plotELL(FIG["map"], ppars, "g.", 0, 0)
                elats, elons = [], []
                for pt in PTS:
                    elons.append(pt[0])
                    elats.append(pt[1])
                # make the base map with a blue triangle at the pole
                pmagplotlib.plotMAP(FIG["map"], elats, elons, Opts)
                if plot == 0:
                    pmagplotlib.drawFIGS(FIG)
    files = {}
    for key in FIG.keys():
        files[key] = "LO:_" + location + "_VGP_map." + fmt
    if pmagplotlib.isServer:
        black = "#000000"
        purple = "#800080"
        titles = {}
        titles["eq"] = "LO:_" + location + "_VGP_map"
        FIG = pmagplotlib.addBorders(FIG, titles, black, purple)
        pmagplotlib.saveP(FIG, files)
    elif plot == 0:
        pmagplotlib.drawFIGS(FIG)
        ans = raw_input(" S[a]ve to save plot, Return to quit:  ")
        if ans == "a":
            pmagplotlib.saveP(FIG, files)
        else:
            print "Good bye"
            sys.exit()
    else:
        pmagplotlib.saveP(FIG, files)
示例#12
0
def main():
    """
    NAME
        vgpmap_magic.py

    DESCRIPTION
        makes a map of vgps and a95/dp,dm for site means in a sites table

    SYNTAX
        vgpmap_magic.py [command line options]

    OPTIONS
        -h prints help and quits
        -eye  ELAT ELON [specify eyeball location], default is 90., 0.
        -f FILE sites format file, [default is sites.txt]
        -res [c,l,i,h] specify resolution (crude, low, intermediate, high]
        -etp plot the etopo20 topographpy data (requires high resolution data set)
        -prj PROJ,  specify one of the following:
             ortho = orthographic
             lcc = lambert conformal
             moll = molweide
             merc = mercator
        -sym SYM SIZE: choose a symbol and size, examples:
            ro 5 : small red circles
            bs 10 : intermediate blue squares
            g^ 20 : large green triangles
        -ell  plot dp/dm or a95 ellipses
        -rev RSYM RSIZE : flip reverse poles to normal antipode
        -S:  plot antipodes of all poles
        -age : plot the ages next to the poles
        -crd [g,t] : choose coordinate system, default is to plot all site VGPs
        -fmt [pdf, png, eps...] specify output format, default is pdf
        -sav  save and quit
    DEFAULTS
        FILE: pmag_results.txt
        res:  c
        prj: ortho
        ELAT,ELON = 0,0
        SYM SIZE: ro 8
        RSYM RSIZE: g^ 8

    """
    if '-h' in sys.argv:
        print(main.__doc__)
        sys.exit()
    dir_path = pmag.get_named_arg_from_sys("-WD", ".")
    # plot: default is 0, if -sav in sys.argv should be 1
    plot = pmag.get_flag_arg_from_sys("-sav", true=1, false=0)
    fmt = pmag.get_named_arg_from_sys("-fmt", "pdf")
    res = pmag.get_named_arg_from_sys("-res", "c")
    proj = pmag.get_named_arg_from_sys("-prj", "ortho")
    anti = pmag.get_flag_arg_from_sys("-S", true=1, false=0)
    fancy = pmag.get_flag_arg_from_sys("-etp", true=1, false=0)
    ell = pmag.get_flag_arg_from_sys("-ell", true=1, false=0)
    ages = pmag.get_flag_arg_from_sys("-age", true=1, false=0)
    if '-rev' in sys.argv:
        flip = 1
        ind = sys.argv.index('-rev')
        rsym = (sys.argv[ind + 1])
        rsize = int(sys.argv[ind + 2])
    else:
        flip, rsym, rsize = 0, "g^", 8
    if '-sym' in sys.argv:
        ind = sys.argv.index('-sym')
        sym = (sys.argv[ind + 1])
        size = int(sys.argv[ind + 2])
    else:
        sym, size = 'ro', 8
    if '-eye' in sys.argv:
        ind = sys.argv.index('-eye')
        lat_0 = float(sys.argv[ind + 1])
        lon_0 = float(sys.argv[ind + 2])
    else:
        lat_0, lon_0 = 90., 0.
    crd = pmag.get_named_arg_from_sys("-crd", "")
    coord_dict = {'g': 0, 't': 100}
    coord = coord_dict[crd] if crd else ""
    results_file = pmag.get_named_arg_from_sys("-f", "sites.txt")

    con = nb.Contribution(dir_path, single_file=results_file)
    if not list(con.tables.keys()):
        print("-W - Couldn't read in data")
        return

    FIG = {'map': 1}
    pmagplotlib.plot_init(FIG['map'], 6, 6)
    # read in er_sites file
    lats, lons = [], []
    Pars = []
    dates, rlats, rlons = [], [], []

    site_container = con.tables['sites']
    site_df = site_container.df
    # use individual results
    site_df = site_df[site_df['result_type'] == 'i']
    # use records with vgp_lat and vgp_lon
    cond1, cond2 = site_df['vgp_lat'].notnull(), site_df['vgp_lon'].notnull()
    Results = site_df[cond1 & cond2]
    # use tilt correction
    if coord and 'dir_tilt_correction' in Results.columns:
        Results = Results[Results['dir_tilt_correction'] == coord]
    # get location name and average ages
    location = ":".join(Results['location'].unique())
    if 'average_age' in Results.columns and ages == 1:
        dates = Results['average_age'].unique()

    # go through rows and extract data
    for ind, row in Results.iterrows():
        lat, lon = float(row['vgp_lat']), float(row['vgp_lon'])
        if anti == 1:
            lats.append(-lat)
            lon = lon + 180.
            if lon > 360:
                lon = lon - 360.
            lons.append(lon)
        elif flip == 0:
            lats.append(lat)
            lons.append(lon)
        elif flip == 1:
            if lat < 0:
                rlats.append(-lat)
                lon = lon + 180.
                if lon > 360:
                    lon = lon - 360
                rlons.append(lon)
            else:
                lats.append(lat)
                lons.append(lon)

        ppars = []
        ppars.append(lon)
        ppars.append(lat)
        ell1, ell2 = "", ""
        if 'vgp_dm' in list(row.keys()) and row['vgp_dm']:
            ell1 = float(row['vgp_dm'])
        if 'vgp_dp' in list(row.keys()) and row['vgp_dp']:
            ell2 = float(row['vgp_dp'])
        if 'vgp_alpha95' in list(row.keys()) and row['vgp_alpha95'].notnull():
            ell1, ell2 = float(row['vgp_alpha95']), float(row['vgp_alpha95'])
        if ell1 and ell2:
            ppars = []
            ppars.append(lons[-1])
            ppars.append(lats[-1])
            ppars.append(ell1)
            ppars.append(lons[-1])
            isign = old_div(abs(lats[-1]), lats[-1])
            ppars.append(lats[-1] - isign * 90.)
            ppars.append(ell2)
            ppars.append(lons[-1] + 90.)
            ppars.append(0.)
            Pars.append(ppars)

    location = location.strip(':')
    Opts = {'latmin': -90, 'latmax': 90, 'lonmin': 0., 'lonmax': 360.,
            'lat_0': lat_0, 'lon_0': lon_0, 'proj': proj, 'sym': 'bs',
            'symsize': 3, 'pltgrid': 0, 'res': res, 'boundinglat': 0.}
    Opts['details'] = {'coasts': 1, 'rivers': 0, 'states': 0,
                       'countries': 0, 'ocean': 1, 'fancy': fancy}
    # make the base map with a blue triangle at the pole
    pmagplotlib.plotMAP(FIG['map'], [90.], [0.], Opts)
    Opts['pltgrid'] = -1
    Opts['sym'] = sym
    Opts['symsize'] = size
    if len(dates) > 0:
        Opts['names'] = dates
    if len(lats) > 0:
        # add the lats and lons of the poles
        pmagplotlib.plotMAP(FIG['map'], lats, lons, Opts)
    Opts['names'] = []
    if len(rlats) > 0:
        Opts['sym'] = rsym
        Opts['symsize'] = rsize
        # add the lats and lons of the poles
        pmagplotlib.plotMAP(FIG['map'], rlats, rlons, Opts)
    if plot == 0:
        pmagplotlib.drawFIGS(FIG)
    if ell == 1:  # add ellipses if desired.
        Opts['details'] = {'coasts': 0, 'rivers': 0, 'states': 0,
                           'countries': 0, 'ocean': 0, 'fancy': fancy}
        Opts['pltgrid'] = -1  # turn off meridian replotting
        Opts['symsize'] = 2
        Opts['sym'] = 'g-'
        for ppars in Pars:
            if ppars[2] != 0:
                PTS = pmagplotlib.plotELL(FIG['map'], ppars, 'g.', 0, 0)
                elats, elons = [], []
                for pt in PTS:
                    elons.append(pt[0])
                    elats.append(pt[1])
                # make the base map with a blue triangle at the pole
                pmagplotlib.plotMAP(FIG['map'], elats, elons, Opts)
                if plot == 0:
                    pmagplotlib.drawFIGS(FIG)
    files = {}
    for key in list(FIG.keys()):
        if pmagplotlib.isServer:  # use server plot naming convention
            files[key] = 'LO:_' + location + '_VGP_map.' + fmt
        else:  # use more readable naming convention
            files[key] = '{}_VGP_map.{}'.format(location, fmt)

    if pmagplotlib.isServer:
        black = '#000000'
        purple = '#800080'
        titles = {}
        titles['eq'] = 'LO:_' + location + '_VGP_map'
        FIG = pmagplotlib.addBorders(FIG, titles, black, purple)
        pmagplotlib.saveP(FIG, files)
    elif plot == 0:
        pmagplotlib.drawFIGS(FIG)
        ans = input(" S[a]ve to save plot, Return to quit:  ")
        if ans == "a":
            pmagplotlib.saveP(FIG, files)
        else:
            print("Good bye")
            sys.exit()
    else:
        pmagplotlib.saveP(FIG, files)