Ejemplo n.º 1
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)
Ejemplo n.º 2
0
def main():
    """
    NAME
       plotdi_a.py

    DESCRIPTION
       plots equal area projection  from dec inc data and fisher mean, cone of confidence

    INPUT FORMAT
       takes dec, inc, alpha95 as first three columns in space delimited file

    SYNTAX
       plotdi_a.py [-i][-f FILE] 

    OPTIONS
        -f FILE to read file name from command line
        -fmt [png,jpg,eps,pdf,svg] set plot file format ['svg' is default]
        -sav save plot and quit

    """
    fmt,plot='svg',0
    if len(sys.argv) > 0:
        if '-h' in sys.argv: # check if help is needed
            print(main.__doc__)
            sys.exit() # graceful quit
        if '-fmt' in sys.argv:
            ind=sys.argv.index('-fmt')
            fmt=sys.argv[ind+1]
        if '-sav' in sys.argv:plot=1
        if '-f' in sys.argv:
            ind=sys.argv.index('-f')
            file=sys.argv[ind+1]
            f=open(file,'r')
            data=f.readlines()
        else:
            data=sys.stdin.readlines() # read in data from standard input
    DIs,Pars=[],[]
    for line in data:   # read in the data from standard input
        pars=[]
        rec=line.split() # split each line on space to get records
        DIs.append([float(rec[0]),float(rec[1])])
        pars.append(float(rec[0]))
        pars.append(float(rec[1]))
        pars.append(float(rec[2]))
        pars.append(float(rec[0]))
        isign=old_div(abs(float(rec[1])),float(rec[1]))
        pars.append(float(rec[1])-isign*90.) #Beta inc
        pars.append(float(rec[2])) # gamma
        pars.append(float(rec[0])+90.) # Beta dec
        pars.append(0.) #Beta inc
        Pars.append(pars)
#
    EQ={'eq':1} # make plot dictionary
    pmagplotlib.plot_init(EQ['eq'],5,5)
    title='Equal area projection'
    pmagplotlib.plotEQ(EQ['eq'],DIs,title)# plot directions
    for k in range(len(Pars)):
        pmagplotlib.plotELL(EQ['eq'],Pars[k],'b',0,1) # plot ellipses
    files={}
    for key in list(EQ.keys()):
        files[key]=key+'.'+fmt 
    titles={}
    titles['eq']='Equal Area Plot'
    if pmagplotlib.isServer:
        black     = '#000000'
        purple    = '#800080'
        EQ = pmagplotlib.addBorders(EQ,titles,black,purple)
        pmagplotlib.saveP(EQ,files)
    elif plot==0:
        pmagplotlib.drawFIGS(EQ)
        ans=input(" S[a]ve to save plot, [q]uit, Return to continue:  ")
        if ans=="q": sys.exit()
        if ans=="a": 
            pmagplotlib.saveP(EQ,files) 
    else:
        pmagplotlib.saveP(EQ,files) 
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)
Ejemplo n.º 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)
Ejemplo n.º 7
0
def main():
    """
    NAME
       plotdi_a.py

    DESCRIPTION
       plots equal area projection  from dec inc data and fisher mean, cone of confidence

    INPUT FORMAT
       takes dec, inc, alpha95 as first three columns in space delimited file

    SYNTAX
       plotdi_a.py [-i][-f FILE] 

    OPTIONS
        -f FILE to read file name from command line
        -fmt [png,jpg,eps,pdf,svg] set plot file format ['svg' is default]
        -sav save plot and quit

    """
    fmt, plot = 'svg', 0
    if len(sys.argv) > 0:
        if '-h' in sys.argv:  # check if help is needed
            print(main.__doc__)
            sys.exit()  # graceful quit
        if '-fmt' in sys.argv:
            ind = sys.argv.index('-fmt')
            fmt = sys.argv[ind + 1]
        if '-sav' in sys.argv: plot = 1
        if '-f' in sys.argv:
            ind = sys.argv.index('-f')
            file = sys.argv[ind + 1]
            f = open(file, 'r')
            data = f.readlines()
        else:
            data = sys.stdin.readlines()  # read in data from standard input
    DIs, Pars = [], []
    for line in data:  # read in the data from standard input
        pars = []
        rec = line.split()  # split each line on space to get records
        DIs.append([float(rec[0]), float(rec[1])])
        pars.append(float(rec[0]))
        pars.append(float(rec[1]))
        pars.append(float(rec[2]))
        pars.append(float(rec[0]))
        isign = old_div(abs(float(rec[1])), float(rec[1]))
        pars.append(float(rec[1]) - isign * 90.)  #Beta inc
        pars.append(float(rec[2]))  # gamma
        pars.append(float(rec[0]) + 90.)  # Beta dec
        pars.append(0.)  #Beta inc
        Pars.append(pars)


#
    EQ = {'eq': 1}  # make plot dictionary
    pmagplotlib.plot_init(EQ['eq'], 5, 5)
    title = 'Equal area projection'
    pmagplotlib.plotEQ(EQ['eq'], DIs, title)  # plot directions
    for k in range(len(Pars)):
        pmagplotlib.plotELL(EQ['eq'], Pars[k], 'b', 0, 1)  # plot ellipses
    files = {}
    for key in list(EQ.keys()):
        files[key] = key + '.' + fmt
    titles = {}
    titles['eq'] = 'Equal Area Plot'
    if pmagplotlib.isServer:
        black = '#000000'
        purple = '#800080'
        EQ = pmagplotlib.addBorders(EQ, titles, black, purple)
        pmagplotlib.saveP(EQ, files)
    elif plot == 0:
        pmagplotlib.drawFIGS(EQ)
        ans = input(" S[a]ve to save plot, [q]uit, Return to continue:  ")
        if ans == "q": sys.exit()
        if ans == "a":
            pmagplotlib.saveP(EQ, files)
    else:
        pmagplotlib.saveP(EQ, files)