Beispiel #1
0
def main():
    """
    NAME 
        dipole_pinc.py

    DESCRIPTION	
        gives GAD inclination at specified (paleo) latitude

    SYNTAX
        dipole_pinc.py [command line options]<filename

    OPTIONS
        -h prints help message and quits
        -i allows interactive entry of latitude
        -f file, specifies file name on command line
    """
    if '-h' in sys.argv:
        print main.__doc__
        sys.exit()
    elif '-f' in sys.argv:
       ind=sys.argv.index('-f')
       file=sys.argv[ind+1]
       f=open(file,'rU')
       data=f.readlines()
    elif '-i' not in sys.argv:
       data=sys.stdin.readlines()
    if '-i' not in sys.argv:
        for line in data:
            rec=line.split()
            print '%7.1f'%(pmag.pinc(float(rec[0])))
    else: 
       while 1:
           try:
               lat=raw_input("Paleolat for converting to inclination: <cntl-D> to quit ")
               print '%7.1f'%(pmag.pinc(float(lat)))
           except EOFError:
               print '\n Good-bye \n'
               sys.exit()
Beispiel #2
0
def main():
    """
    NAME 
        strip_magic.py

    DESCRIPTION
        plots various parameters versus depth or age

    SYNTAX
        strip_magic.py [command line optins]

    OPTIONS
        -h prints help message and quits
        -f FILE: specify input magic format file from magic,default='pmag_results.txt'
         supported types=[pmag_specimens, pmag_samples, pmag_sites, pmag_results, magic_web]
        -obj [sit,sam,all]: specify object to site,sample,all for pmag_result table, default is all
        -fmt [svg,png,jpg], format for images - default is svg
        -x [age,pos]:  specify whether age or stratigraphic position
        -y [dec,inc,int,chi,lat,lon,vdm,vadm]
           (lat and lon are VGP lat and lon)
        -Iex: plot the expected inc at lat - only available for results with lat info in file
        -ts TS amin amax: plot the GPTS for the time interval between amin and amax (numbers in Ma)
           TS: [ck95, gts04] 
        -mcd method_code, specify method code, default is first one encountered
    NOTES
        when x and/or y are not specified, a list of possibilities will be presented to the user for choosing

    """
    xaxis,xplotind,yplotind="",0,0 # (0 for strat pos)
    yaxis,Xinc="", "" 
    obj='all'
    supported=['pmag_specimens', 'pmag_samples', 'pmag_sites', 'pmag_results','magic_web']
    Depth_keys=['specimen_core_depth','specimen_height','specimen_elevation','specimen_composite_depth', 'sample_core_depth','sample_height','sample_elevation','sample_composite_depth', 'site_core_depth','site_height','site_elevation','site_composite_depth','average_height']
    Age_keys=['specimen_inferred_age','sample_inferred_age','site_inferred_age','average_age']
    Unit_keys={'specimen_inferred_age':'specimen_inferred_age_unit','sample_inferred_age':'sample_inferred_age_unit','site_inferred_age':'site_inferred_age_unit','average_age':'average_age_unit'}
    Dec_keys=['measurement_dec','specimen_dec','sample_dec','site_dec','average_dec']
    Inc_keys=['measurement_inc','specimen_inc','sample_inc','site_inc','average_inc']
    Int_keys=['measurement_magnitude','measurement_magn_moment','measurement_magn_volume','measurement_magn_mass','specimen_int','specimen_int_rel','sample_int','sample_int_rel','site_int','site_int_rel','average_int','average_int_rel']
    Chi_keys=['measurement_chi_volume','measurement_chi_mass']
    Lat_keys=['sample_lat','site_lat','average_lat']
    VLat_keys=['vgp_lat']
    VLon_keys=['vgp_lon']
    Vdm_keys=['vdm']
    Vadm_keys=['vadm']
    X_keys=[Age_keys,Depth_keys]
    Y_keys=[Dec_keys,Inc_keys,Int_keys,Chi_keys,VLat_keys,VLon_keys,Vdm_keys,Vadm_keys]
    method,fmt="",'svg'
    FIG={'strat':1}
    plotexp,pTS=0,0
    dir_path="./"
    if '-WD' in sys.argv: 
        ind=sys.argv.index('-WD')
        dir_path=sys.argv[ind+1]
    res_file=dir_path+'/pmag_results.txt'
    if '-h' in sys.argv:
        print main.__doc__
        sys.exit()
    if '-f' in sys.argv:
        ind=sys.argv.index('-f')
        res_file=dir_path+'/'+sys.argv[ind+1]
    if '-fmt' in sys.argv:
        ind=sys.argv.index('-fmt')
        fmt=sys.argv[ind+1]
    if '-obj' in sys.argv:
        ind=sys.argv.index('-obj')
        obj=sys.argv[ind+1]
    if '-x' in sys.argv:
        ind=sys.argv.index('-x')
        xaxis=sys.argv[ind+1]
    if '-y' in sys.argv:
        ind=sys.argv.index('-y')
        yaxis=sys.argv[ind+1]
        if yaxis=='dec':ykeys=Dec_keys
        if yaxis=='inc':ykeys=Inc_keys
        if yaxis=='int':ykeys=Int_keys
        if yaxis=='chi':ykeys=Chi_keys
        if yaxis=='lat':ykeys=VLat_keys
        if yaxis=='lon':ykeys=VLon_keys
        if yaxis=='vdm':ykeys=Vdm_keys
        if yaxis=='vadm':ykeys=Vadm_keys
    if '-mcd' in sys.argv:
        ind=sys.argv.index('-mcd')
        method=sys.argv[ind+1]
    if '-ts' in sys.argv:
        ind=sys.argv.index('-ts')
        ts=sys.argv[ind+1]
        amin=float(sys.argv[ind+2])
        amax=float(sys.argv[ind+3])
        pTS=1
    if '-Iex' in sys.argv: plotexp=1
    #
    #
    # get data read in
    Results,file_type=pmag.magic_read(res_file) 
    if file_type not in supported:
        print "Unsupported file type, try again"
        sys.exit()
    PltObjs=['all']
    if file_type=='pmag_results': # find out what to plot
        for rec in Results:
            resname=rec['pmag_result_name'].split()
            if 'Sample' in resname and 'sam' not in PltObjs:PltObjs.append('sam')
            if 'Site' in resname and 'sit' not in PltObjs:PltObjs.append('sit')
    methcodes=[]
    if "magic_method_codes" in Results[0].keys(): # need to know all the measurement types from method_codes
        for rec in Results:
            meths=rec["magic_method_codes"].split(":")
            for meth in meths:
                if meth.strip() not in methcodes and 'LP' in meth: methcodes.append(meth.strip()) # look for the lab treatments
    #
    # initialize some variables
    X_unit="" # Unit for age or depth plotting (meters if depth)
    Xplots,Yplots=[],[]
    Xunits=[]
    yplotind,xplotind=0,0
    #
    # step through possible plottable keys
    #
    if xaxis=="" or yaxis=="":
        for key in Results[0].keys():
            for keys in  X_keys:
                for xkeys in keys: 
                    if key in xkeys:
                        for ResRec in Results:
                            if ResRec[key]!="":
                                Xplots.append(key) # only plot something if there is something to plot!
                                break
            for keys in  Y_keys:
                for pkeys in keys: 
                    if key in pkeys:
                        for ResRec in Results:
                            if ResRec[key]!="":
                                Yplots.append(key)
                                break
        X,Y=[],[]
        for plt in Xplots:
            if plt in Age_keys and 'age' not in X: X.append('age')
            if plt in Depth_keys and 'pos' not in X:X.append('pos')
        for plt in Yplots:
            if plt in Dec_keys and 'dec' not in Y:Y.append('dec')
            if plt in Inc_keys and 'inc' not in Y:Y.append('inc')
            if plt in Int_keys and 'int' not in Y:Y.append('int')
            if plt in Chi_keys and 'chi' not in Y:Y.append('chi')
            if plt in VLat_keys and 'lat' not in Y:Y.append('lat')
            if plt in VLon_keys and 'lon' not in Y:Y.append('lon')
            if plt in Vadm_keys and 'vadm' not in Y:Y.append('vadm')
            if plt in Vdm_keys and 'vdm' not in Y:Y.append('vdm')
        if file_type=='pmag_results':
            print 'available objects for plotting: ',PltObjs
        print 'available X plots: ',X
        print 'available Y plots: ',Y
        print 'available method codes: ',methcodes
        f=open(dir_path+'/.striprc','w')
        for x in X:
           f.write('x:'+x+'\n') 
        for y in Y:
           f.write('y:'+y+'\n') 
        for m in methcodes:
           f.write('m:'+m+'\n') 
        for obj in PltObjs:
           f.write('obj:'+obj+'\n') 
        sys.exit()
    if plotexp==1:
        for lkey in Lat_keys:
            for key in Results[0].keys():
                if key==lkey:    
                    lat=float(Results[0][lkey])
                    Xinc=[pmag.pinc(lat),-pmag.pinc(lat)]
                    break
        if Xinc=="":
            print 'can not plot expected inc for site - lat unknown'
    if method!="" and method not in methcodes:
        print 'your method not available, but these are:  '
        print methcodes
        print 'use ',methocodes[0],'? ^D to quit' 
    if xaxis=='age':
        for akey in Age_keys:
            for key in Results[0].keys():
                if key==akey:
                    Xplots.append(key)
                    Xunits.append(Unit_keys[key])
    if xaxis=='pos':
        for dkey in Depth_keys:
            for key in Results[0].keys():
                if key==dkey: 
                    Xplots.append(key)
    if len(Xplots)==0:
        print 'desired X axis  information not found'
        sys.exit()
    if xaxis=='age':age_unit=Results[0][Xunits[0]]
    if len(Xplots)>1:
        print 'multiple X axis  keys found, using: ',Xplots[xplotind]
    for ykey in ykeys: 
        for key in Results[0].keys():
            if key==ykey:Yplots.append(key)
    if len(Yplots)==0:
        print 'desired Y axis  information not found'
        sys.exit()
    if len(Yplots)>1:
        print 'multiple Y axis  keys found, using: ',Yplots[yplotind]
    
    # check if age or depth info        
    if len(Xplots)==0:
        print "Must have either age or height info to plot "
        sys.exit()
    #
    # check for variable to plot
    #
    #
    # determine X axis (age or depth)
    #
    if xaxis=="age": plotind="1"
    if method=="":method=methcodes[0]
    if xaxis=='pos':
        xlab="Stratigraphic Height (meters)" 
    else:
        xlab="Age ("+age_unit+")"
    Xkey=Xplots[xplotind]
    Ykey=Yplots[yplotind]
    ylab=Ykey
    #
    # collect the data for plotting
    XY=[]
    isign=1.
#    if float(Results[0][Xkey])/float(Results[-1][Xkey])>0 and float(Results[0][Xkey])<0: 
#        isign=-1. # x axis all same sign and negative, take positive (e.g.,for depth in core)
#        xlab="Stratigraphic Position (meters)" 
#    else:
#        isign=1.
    for rec in Results:
        if "magic_method_codes" in rec.keys():
            meths=rec["magic_method_codes"].split(":")
            if method in meths: # make sure it is desired lab treatment step
                if obj=='all' and rec[Xkey].strip()!="":
                    XY.append([isign*float(rec[Xkey]),float(rec[Ykey])])
                elif rec[Xkey].strip()!="":
                    name=rec['pmag_result_name'].split()
                    if obj=='sit' and "Site" in name: XY.append([isign*float(rec[Xkey]),float(rec[Ykey])])
                    if obj=='sam' and "Sample" in name: XY.append([isign*float(rec[Xkey]),float(rec[Ykey])])
        elif method =="":
            if obj=='all' and rec[Xkey].strip()!="":
                XY.append([isign*float(rec[Xkey]),float(rec[Ykey])])
            elif rec[Xkey].strip()!="":
                name=rec['pmag_result_name'].split()
                if obj=='sit' and "Site" in name: XY.append([isign*float(rec[Xkey]),float(rec[Ykey])])
                if obj=='sam' and "Sample" in name: XY.append([isign*float(rec[Xkey]),float(rec[Ykey])])
        else:  
            print "Something wrong with your plotting choices"
            break
    XY.sort()
    title=""
    if "er_locations_names" in Results[0].keys(): title=Results[0]["er_location_names"]
    if "er_locations_name" in Results[0].keys(): title=Results[0]["er_location_name"]
    labels=[xlab,ylab,title]
    pmagplotlib.plot_init(FIG['strat'],10,5)
    pmagplotlib.plotSTRAT(FIG['strat'],XY,labels) # plot them
    if plotexp==1: pmagplotlib.plotHs(FIG['strat'],Xinc,'b','--')
    if yaxis=='inc' or yaxis=='lat':
        pmagplotlib.plotHs(FIG['strat'],[0],'b','-')
        pmagplotlib.plotHs(FIG['strat'],[-90,90],'g','-')
    if pTS==1: 
        FIG['ts']=2
        pmagplotlib.plot_init(FIG['ts'],10,5)
        pmagplotlib.plotTS(FIG['ts'],[amin,amax],ts)
    files={}
    for key in FIG.keys():
        files[key]=key+'.'+fmt 
    if pmagplotlib.isServer: 
        black     = '#000000'
        purple    = '#800080'
        files={}
        files['strat']=xaxis+'_'+yaxis+'_.'+fmt
        files['ts']='ts.'+fmt
        titles={}
        titles['strat']='Depth/Time Series Plot'
        titles['ts']='Time Series Plot'
        FIG = pmagplotlib.addBorders(FIG,titles,black,purple)
        pmagplotlib.saveP(FIG,files)
    else:
        ans=raw_input(" S[a]ve to save plot, [q]uit without saving:  ")
        if ans=="a": pmagplotlib.saveP(FIG,files) 
Beispiel #3
0
def main():
    """
    NAME 
        magstrat_magic.py

    DESCRIPTION
        plots various parameters versus depth or age with optional time scale

    SYNTAX
        magstrat_magic.py [-h] [-i] [command line optins]

    OPTIONS
        -h prints help message and quits
        -i allows interactive entry of options
        -f FILE: specify input magic  format file from magic,default='pmag_results.txt'
         supported types=[pmag_specimens, pmag_samples, pmag_sites, pmag_results]
        -X [age,pos]:  specify whether age or stratigraphic position
        -Y [dec,inc,int,lat,lon,vdm,vadm]
           (lat and lon are VGP lat and lon)
        -Iex: plot the expected inc at average_lat - only available for pmag_results
        -ts TS: plot the GPTS for the time interval shown (only for age option)
           TS: [ck95, gts04] 
        -mcd method_code, specify method code, default is first one encountered
    NOTES
        when X and/or Y are not specified, a list of possibilities will be presented to the user for choosing

    """
    res_file='pmag_results.txt'
    xaxis,xplotind,yplotind="",0,"" # (0 for strat pos)
    yaxis=""  
    supported=['pmag_specimens', 'pmag_samples', 'pmag_sites', 'pmag_results','magic_web']
    method,fignum="",1
    plotexp,pTS=0,0
    if '-h' in sys.argv:
        print main.__doc__
        sys.exit()
    if '-f' in sys.argv:
        ind=sys.argv.index('-f')
        res_file=sys.argv[ind+1]
    if '-X' in sys.argv:
        ind=sys.argv.index('-X')
        xaxis=sys.argv[ind+1]
    if '-Y' in sys.argv:
        ind=sys.argv.index('-Y')
        yaxis=sys.argv[ind+1]
    if '-mcd' in sys.argv:
        ind=sys.argv.index('-mcd')
        method=sys.argv[ind+1]
    if '-ts' in sys.argv:
        ind=sys.argv.index('-ts')
        ts=sys.argv[ind+1]
        pTS=1
        if xaxis=='pos':
            print "Time scale option for age only, time scale will not be plotted"
            pTS=0
    if '-Iex' in sys.argv: plotexp=1
    if '-i' in sys.argv:
        yaxis,xaxis=="",""
    #
    # get name of file from command line
    #
        res_file=raw_input("Input pmag_results  file name? [pmag_results.txt]   ")
        if res_file=="":res_file="pmag_results.txt"
    #
    #
    # get data read in
    Results,file_type=pmag.magic_read(res_file) 
    if file_type not in supported:
        print "Unsupported file type, try again"
        sys.exit()
    methcodes=[]
    if "magic_method_codes" in Results[0].keys(): # need to know all the measurement types from method_codes
        for rec in Results:
            meths=rec["magic_method_codes"]
            if meths not in methcodes: methcodes.append(meths.strip()) # look for the lab treatments
    #
    # initialize some variables
    age_unit="" # Unit for age or depth plotting (meters if depth)
    Xplots,Yplots,Xplotind,Yplotind=[],[],0,""
    #
    # step through possible file formats
    #
    if file_type=="pmag_results":
        if "average_age" in Results[0].keys():
            Xplots.append("average_age")
            age_unit=Results[0]["average_age_unit"]
        if "average_height" in Results[0].keys(): Xplots.append("average_height")
        if plotexp==1:
             if "average_lat" in Results[0].keys():
                 lat=float(Results[0]['average_lat'])
                 Xinc=[pmag.pinc(lat),-pmag.pinc(lat)]
             else:
                 print 'can not plot expected inc for site - lat unknown'
        if xaxis=="pos":
            xplotind=Xplots.index("average_height")
        else: 
            xplotind=Xplots.index("average_age")
        if "average_dec" in Results[0].keys():Yplots.append("average_dec")
        if "average_inc" in Results[0].keys():Yplots.append("average_inc")
        if "average_int" in Results[0].keys():Yplots.append("average_int")
        if "average_int_rel" in Results[0].keys():Yplots.append("average_int_rel")
        if "vgp_lat" in Results[0].keys():Yplots.append("vgp_lat")
        if "vgp_lon" in Results[0].keys():Yplots.append("vgp_lon")
        if "vdm" in Results[0].keys():Yplots.append("vdm")
        if "vadm" in Results[0].keys():Yplots.append("vadm")
        if yaxis=="dec" and "average_dec" in Yplots:yplotind=Yplots.index("average_dec")
        if yaxis=="inc" and "average_inc" in Yplots:yplotind=Yplots.index("average_inc")
        if yaxis=="int" and "average_int_rel" in Yplots:yplotind=Yplots.index("average_int_rel")
        if yaxis=="int" and "average_int" in Yplots:yplotind=Yplots.index("average_int")
        if yaxis=="lat" and "vgp_lat" in Yplots:yplotind=Yplots.index("vgp_lat")
        if yaxis=="lon" and "vgp_lon" in Yplots:yplotind=Yplots.index("vgp_lon")
        if yaxis=="vdm" and "vdm" in Yplots:yplotind=Yplots.index("vdm")
        if yaxis=="vadm" and "vadm" in Yplots:yplotind=Yplots.index("vadm")
        if yplotind=="":
            print 'your choice not available, but these are: '
            print Yplots
            sys.exit()
    else:
        xplotind,plotexp=0,0
        if xaxis=="pos":
            print "Only age available for these types of files - try pmag_results "
            sys.exit()
    if file_type=="pmag_sites":
        if "site_inferred_age" in Results[0].keys():
            Xplots.append("site_inferred_age")
            age_unit=Results[0]["site_inferred_age_unit"]
        if "site_dec" in Results[0].keys():Yplots.append("site_dec")
        if "site_inc" in Results[0].keys():Yplots.append("site_inc")
        if "site_int" in Results[0].keys():Yplots.append("site_int")
        if "site_int_rel" in Results[0].keys():Yplots.append("site_int_rel")
        if yaxis=="dec" and "site_dec" in Yplots:yplotind=Yplots.index("site_dec")
        if yaxis=="inc" and "site_inc" in Yplots:yplotind=Yplots.index("site_inc")
        if yaxis=="int" and "site_int_rel" in Yplots:yplotind=Yplots.index("site_int_rel")
        if yaxis=="int" and "site_int" in Yplots:yplotind=Yplots.index("site_int")
    if file_type=="pmag_samples":
        if "sample_inferred_age" in Results[0].keys():
            Xplots.append("sample_inferred_age")
            age_unit=Results[0]["sample_inferred_age_unit"]
        if "sample_dec" in Results[0].keys():Yplots.append("sample_dec")
        if "sample_inc" in Results[0].keys():Yplots.append("sample_inc")
        if "sample_int" in Results[0].keys():Yplots.append("sample_int")
        if "sample_int_rel" in Results[0].keys():Yplots.append("sample_int_rel")
        if yaxis=="dec" and "sample_dec" in Yplots:yplotind=Yplots.index("sample_dec")
        if yaxis=="inc" and "sample_inc" in Yplots:yplotind=Yplots.index("sample_inc")
        if yaxis=="int" and "sample_int_rel" in Yplots:yplotind=Yplots.index("sample_int_rel")
        if yaxis=="int" and "sample_int" in Yplots:yplotind=Yplots.index("sample_int")
    if file_type=="pmag_specimens":
        if "specimen_inferred_age" in Results[0].keys():
            Xplots.append("specimen_inferred_age")
            age_unit=Results[0]["specimen_inferred_age_unit"]
        if "specimen_dec" in Results[0].keys():Yplots.append("specimen_dec")
        if "specimen_inc" in Results[0].keys():Yplots.append("specimen_inc")
        if "specimen_int" in Results[0].keys():Yplots.append("specimen_int")
        if "specimen_int_rel" in Results[0].keys():Yplots.append("specimen_int_rel")
        if yaxis=="dec" and "specimen_dec" in Yplots:yplotind=Yplots.index("specimen_dec")
        if yaxis=="inc" and "specimen_inc" in Yplots:yplotind=Yplots.index("specimen_inc")
        if yaxis=="int" and "specimen_int_rel" in Yplots:yplotind=Yplots.index("specimen_int_rel")
        if yaxis=="int" and "specimen_int" in Yplots:yplotind=Yplots.index("specimen_int")
    if yplotind=="":
        print 'your choice not available, but these are: '
        print Yplots
        sys.exit()
    #
    # check if age or depth info        
    if len(Xplots)==0:
        print "Must have either age or height info to plot "
        sys.exit()
    #
    # check for variable to plot
    #
    if len(Yplots)==0:
        print "Must have something to plot! "
        sys.exit()
    #
    # determine X axis (age or depth)
    #
    if '-i' in sys.argv:
        if len(Xplots)==2:
            print "0: ",Xplots[0],"1: ",Xplots[1]
            plotind=raw_input("Which type of plot [0]/1 " )
            xplotind=int(plotind)
            if xplotind==1:xaxis='age'
    # inquire about which lab treatment step desired
        method=methcodes[0]
        if len(methcodes)>1:
            print " There are several different  experiments. " 
            print " Select type you want to plot. "
            for k in range(len(methcodes)):
                print methcodes[k], " [",k,"] "
            ans=int(raw_input())
            method=methcodes[ans]
    # now get Y axis (whatever)
        if len(Yplots)>1:
            for yplotind in range(len(Yplots)):
                print yplotind, Yplots[yplotind]
    #        if len(methcodes)>1: print "Be careful to select the one that goes with your lab treatment! "
            yplotind=raw_input("Which type of plot [0] " )
            if yplotind=="":yplotind=0
            yplotind=int(yplotind)
    else:
        if xaxis=="age": plotind="1"
        if method=="":method=methcodes[0]
    if xaxis=='pos':
        xlab="Stratigraphic Height (meters)" 
    else:
        xlab="Age ("+age_unit+")"
    Xkey=Xplots[xplotind]
    Ykey=Yplots[yplotind]
    ylab=Ykey
         
    #
    # collect the data for plotting
    X,Y=[],[]
    if float(Results[0][Xkey])/float(Results[-1][Xkey])>0 and float(Results[0][Xkey])<0: 
        isign=-1. # x axis all same signa and negative, take positive (e.g.,for depth in core)
        xlab="Stratigraphic Depth (meters)" 
    else:
        isign=1.
    for rec in Results:
        if "magic_method_codes" in rec.keys():
            meths=rec["magic_method_codes"]
            if method == meths: # make sure it is desired lab treatment step
                X.append(isign*float(rec[Xkey]))
                Y.append(float(rec[Ykey]))
        elif method =="":
            X.append(isign*float(rec[Xkey]))
            Y.append(float(rec[Ykey]))
        else:  
            print "Something wrong with your plotting choices"
            break
    data=[X,Y]   # pack them up for shipping
    title=""
    if "er_locations_names" in Results[0].keys(): title=Results[0]["er_location_names"]
    if "er_locations_name" in Results[0].keys(): title=Results[0]["er_location_name"]
    labels=[xlab,ylab,title]
    pmagplotlib.plotSTRAT(fignum,data,labels) # plot them
    if plotexp==1: pmagplotlib.plotHs(fignum,Xinc,'b','--')
    if yaxis=='inc' or yaxis=='lat':
        pmagplotlib.plotHs(fignum,[0],'b','-')
        pmagplotlib.plotHs(fignum,[-90,90],'g','-')
    if pTS==1: pmagplotlib.plotTS(fignum+1,[X[0],X[-1]],ts)
    raw_input()
Beispiel #4
0
def main():
    """
    NAME 
        ODP_incplot.py

    DESCRIPTION
        plots various measurements versus core_depth

    SYNTAX
        ODP_incplot.py [command line optins]

    OPTIONS
        -h prints help message and quits
        -f FILE: specify input magic_measurments format file from magic
        -fsa FILE: specify input er_samples format file from magic
        -AF step [in mT] to plot 
        -T step [in C] to plot 
        -d min max [in m] depth range to plot
        -Iex: plot the expected inc at lat - only available for results with lat info in file
        -ts TS amin amax: plot the GPTS for the time interval between amin and amax (numbers in Ma)
           TS: [ck95, gts04] 

     DEFAULTS:
         Measurements file: magic_measurements.txt
         Samples file: er_samples.txt
         NRM step
    """
    method,fmt="LT-NO",'.svg'
    step=0
    pcol=3
    plotexp,pTS=0,0
    dir_path="./"
    if '-WD' in sys.argv: 
        ind=sys.argv.index('-WD')
        dir_path=sys.argv[ind+1]
    meas_file=dir_path+'/magic_measurements.txt'
    samp_file=dir_path+'/er_samples.txt'
    if '-h' in sys.argv:
        print main.__doc__
        sys.exit()
    if '-f' in sys.argv:
        ind=sys.argv.index('-f')
        meas_file=dir_path+'/'+sys.argv[ind+1]
    if '-fsa' in sys.argv:
        ind=sys.argv.index('-fsa')
        samp_file=dir_path+'/'+sys.argv[ind+1]
    if '-fmt' in sys.argv:
        ind=sys.argv.index('-fmt')
        fmt='.'+sys.argv[ind+1]
    if '-AF' in sys.argv:
        ind=sys.argv.index('-AF')
        step=float(sys.argv[ind+1])*1e-3
        method='LT-AF-Z'
    if '-T' in sys.argv:
        ind=sys.argv.index('-T')
        step=float(sys.argv[ind+1])+273
        method='LT-T-Z'
    dmin,dmax=-1,1e6
    if '-d' in sys.argv:
        ind=sys.argv.index('-d')
        dmin=float(sys.argv[ind+1])
        dmax=float(sys.argv[ind+2])
    if '-ts' in sys.argv:
        ind=sys.argv.index('-ts')
        ts=sys.argv[ind+1]
        amin=float(sys.argv[ind+2])
        amax=float(sys.argv[ind+3])
        pTS,pcol=1,4
    if '-Iex' in sys.argv: plotexp=1
    #
    #
    # get data read in
    Meas,file_type=pmag.magic_read(meas_file) 
    Samps,file_type=pmag.magic_read(samp_file) 
    Data=[]
    for rec in Meas:
        for samp in Samps:
            if samp['er_sample_name']== rec['er_sample_name'] and 'core_depth' in samp.keys() and samp['core_depth']!="":
                rec['core_depth'] = samp['core_depth']
                Data.append(rec) # fish out data with core_depth
    if plotexp==1:
        for lkey in Lat_keys:
            for key in Results[0].keys():
                if key==lkey:    
                    lat=float(Results[0][lkey])
                    Xinc=[pmag.pinc(lat),-pmag.pinc(lat)]
                    break
        if Xinc=="":
            print 'can not plot expected inc for site - lat unknown'
    xlab="Core Depth (m)"
    # collect the data for plotting declination
    XY=[]
    maxInt=-1000
    samples=[]
    for rec in Data:
        if "magic_method_codes" in rec.keys():
            meths=rec["magic_method_codes"].split(":")
            if method in meths: # make sure it is desired lab treatment step
                if float(rec['core_depth'])<dmax and float(rec['core_depth'])>dmin and ('LT-AF-Z' in method and float(rec['treatment_ac_field'])==step) or ('LT-NO' in method and step == 0) or ('LT-T-Z' in method and float(rec['treatment_temp'])==step):
                    XY.append([float(rec['core_depth']),float(rec['measurement_inc'])])
    if len(XY)>0 :
        FIG={'strat':1,'ts':2}
        pmagplotlib.plot_init(FIG['strat'],10,5)
        labels=['Depth below sea floor (m)','Inclination','']
        pmagplotlib.plotSTRAT(FIG['strat'],XY,labels)
        if pTS==1:
            pmagplotlib.plot_init(FIG['ts'],10,5)
            pmagplotlib.plotTS(FIG['ts'],[amin,amax],ts)
    else:
        print "No data points met your criteria - try again"
        sys.exit()
    files,fmt={},'svg'
    for key in FIG.keys():
        files[key]=key+'.'+fmt
    if pmagplotlib.isServer:
        black     = '#000000'
        purple    = '#800080'
        files={}
        files['strat']=xaxis+'_'+yaxis+'_'+fmt
        files['ts']='ts'+fmt
        titles={}
        titles['strat']='Depth/Time Series Plot'
        titles['ts']='Time Series Plot'
        FIG = pmagplotlib.addBorders(FIG,titles,black,purple)
        pmagplotlib.saveP(FIG,files)
    else:
        ans=raw_input(" S[a]ve to save plot, [q]uit without saving:  ")
        if ans=="a": pmagplotlib.saveP(FIG,files)
Beispiel #5
0
def main():
    """
    NAME 
        Core_depthplot.py

    DESCRIPTION
        plots various measurements versus core_depth

    SYNTAX
        Core_depthplot.py [command line optins]

    OPTIONS
        -h prints help message and quits
        -f FILE: specify input magic_measurments format file from magic
        -fsa FILE: specify input er_samples format file from magic
        -AF step [in mT] to plot 
        -T step [in C] to plot 
        -d min max [in m] depth range to plot
        -Iex: plot the expected inc at lat - only available for results with lat info in file
        -ts TS amin amax: plot the GPTS for the time interval between amin and amax (numbers in Ma)
           TS: [ck95, gts04] 

     DEFAULTS:
         Measurements file: magic_measurements.txt
         Samples file: er_samples.txt
         NRM step
    """
    method,fmt="LT-NO",'.svg'
    step=0
    pcol=3
    plotexp,pTS=0,0
    dir_path="./"
    if '-WD' in sys.argv: 
        ind=sys.argv.index('-WD')
        dir_path=sys.argv[ind+1]
    meas_file=dir_path+'/magic_measurements.txt'
    samp_file=dir_path+'/er_samples.txt'
    if '-h' in sys.argv:
        print main.__doc__
        sys.exit()
    if '-f' in sys.argv:
        ind=sys.argv.index('-f')
        meas_file=dir_path+'/'+sys.argv[ind+1]
    if '-fsa' in sys.argv:
        ind=sys.argv.index('-fsa')
        samp_file=dir_path+'/'+sys.argv[ind+1]
    if '-fmt' in sys.argv:
        ind=sys.argv.index('-fmt')
        fmt='.'+sys.argv[ind+1]
    if '-AF' in sys.argv:
        ind=sys.argv.index('-AF')
        step=float(sys.argv[ind+1])*1e-3
        method='LT-AF-Z'
    if '-T' in sys.argv:
        ind=sys.argv.index('-T')
        step=float(sys.argv[ind+1])+273
        method='LT-T-Z'
    dmin,dmax=-1,-1
    if '-d' in sys.argv:
        ind=sys.argv.index('-d')
        dmin=float(sys.argv[ind+1])
        dmax=float(sys.argv[ind+2])
    if '-ts' in sys.argv:
        ind=sys.argv.index('-ts')
        ts=sys.argv[ind+1]
        amin=float(sys.argv[ind+2])
        amax=float(sys.argv[ind+3])
        pTS,pcol=1,4
    if '-Iex' in sys.argv: plotexp=1
    #
    #
    # get data read in
    Meas,file_type=pmag.magic_read(meas_file) 
    Samps,file_type=pmag.magic_read(samp_file) 
    Data=[]
    for rec in Meas:
        for samp in Samps:
            if samp['er_sample_name']== rec['er_sample_name'] and 'core_depth' in samp.keys() and samp['core_depth']!="":
                rec['core_depth'] = samp['core_depth']
                Data.append(rec) # fish out data with core_depth
    if plotexp==1:
        for lkey in Lat_keys:
            for key in Results[0].keys():
                if key==lkey:    
                    lat=float(Results[0][lkey])
                    Xinc=[pmag.pinc(lat),-pmag.pinc(lat)]
                    break
        if Xinc=="":
            print 'can not plot expected inc for site - lat unknown'
    xlab="Core Depth (m)"
    # collect the data for plotting declination
    Depths,Decs,Incs,Ints=[],[],[],[]
    maxInt=-1000
    samples=[]
    for rec in Data:
        if "magic_method_codes" in rec.keys():
            meths=rec["magic_method_codes"].split(":")
            if method in meths: # make sure it is desired lab treatment step
                if ('LT-AF-Z' in method and float(rec['treatment_ac_field'])==step) or ('LT-NO' in method and step == 0) or ('LT-T-Z' in method and float(rec['treatment_temp'])==step):
                    Depths.append(float(rec['core_depth']))
                    Decs.append(float(rec['measurement_dec']))
                    Incs.append(float(rec['measurement_inc']))
                    Ints.append(float(rec['measurement_magn_moment']))
                    if len(Ints)>1 and Ints[-1]>maxInt:maxInt=Ints[-1]
    if dmin==-1:
        dmin,dmax=Depths[0],Depths[-1]
    if len(Decs)>0 and len(Depths)>0:
        for pow in range(-10,10):
            if maxInt*10**pow>1:break
        for k in range(len(Ints)):
            Ints[k]=Ints[k]*10**pow
        pylab.figure(1,figsize=(10,8))
        pylab.subplot(1,pcol,1)
        pylab.plot(Decs,Depths,'ro',Decs,Depths,'k') 
        pylab.axis([0,360,dmax,dmin])
        pylab.xlabel('Declination')
        pylab.ylabel('Depth in core (m)')
        pylab.subplot(1,pcol,2)
        pylab.plot(Incs,Depths,'bo',Incs,Depths,'k') 
        pylab.axis([-90,90,dmax,dmin])
        pylab.xlabel('Inclination')
        pylab.ylabel('')
        pylab.subplot(1,pcol,3)
        pylab.plot(Ints,Depths,'ko',Ints,Depths,'k') 
        pylab.axis([0,maxInt*10**pow+.1,dmax,dmin])
        pylab.xlabel('%s %i %s'%('Intensity (x 10^',pow,' Am^2)'))
        if pTS==1:
            pylab.subplot(1,pcol,4)
            TS,Chrons=pmag.get_TS(ts)
            p=1
            X,Y=[],[]
            for d in TS:
                if d<=amax:
                    if d>=amin:
                        if len(X)==0:
                            ind=TS.index(d)
                            X.append(TS[ind-1])
                            Y.append(p%2)
                        X.append(d)
                        Y.append(p%2)
                        p+=1
                        X.append(d)
                        Y.append(p%2)
                else: 
                    X.append(amax)
                    Y.append(p%2)
                    pylab.plot(Y,X,'k')
                    pylab.axvline(x=0,ymin=amin,ymax=amax,linewidth=1,color='w',linestyle='-')
#                    pylab.axhline(y=1.1,xmin=0,xmax=1,linewidth=1,color='w',linestyle='-')
#                    pylab.axvline(y=-.1,xmin=0,xmax=1,linewidth=1,color='w',linestyle='-')
#                    pylab.xlabel("Age (Ma): "+ts) 
                    isign=-1
                    for c in Chrons:
                        off=-.1
                        isign=-1*isign 
                        if isign>0: off=1.05
                        if c[1]>=X[0] and c[1]<X[-1]:
                            pylab.text(c[1]-.2,off,c[0])
                    pylab.axis([-.25,1.25,amax,amin])
        pylab.draw()
        ans=raw_input("Press return to quit  ")
        sys.exit()
    else:
        print "No data points met your criteria - try again"