def main(): """ NAME lowrie.py DESCRIPTION plots intensity decay curves for Lowrie experiments SYNTAX lowrie -h [command line options] INPUT takes SIO formatted input files OPTIONS -h prints help message and quits -f FILE: specify input file -N do not normalize by maximum magnetization -fmt [svg, pdf, eps, png] specify fmt, default is svg """ fmt='svg' FIG={} # plot dictionary FIG['lowrie']=1 # demag is figure 1 pmagplotlib.plot_init(FIG['lowrie'],6,6) norm=1 # default is to normalize by maximum axis if len(sys.argv)>1: if '-h' in sys.argv: print main.__doc__ sys.exit() if '-N' in sys.argv: norm=0 # don't normalize if '-f' in sys.argv: # sets input filename ind=sys.argv.index("-f") in_file=sys.argv[ind+1] else: print main.__doc__ print 'you must supply a file name' sys.exit() else: print main.__doc__ print 'you must supply a file name' sys.exit() data=open(in_file).readlines() # open the SIO format file PmagRecs=[] # set up a list for the results keys=['specimen','treatment','csd','M','dec','inc'] for line in data: PmagRec={} rec=line.replace('\n','').split() for k in range(len(keys)): PmagRec[keys[k]]=rec[k] PmagRecs.append(PmagRec) specs=pmag.get_dictkey(PmagRecs,'specimen','') sids=[] for spec in specs: if spec not in sids:sids.append(spec) # get list of unique specimen names for spc in sids: # step through the specimen names print spc specdata=pmag.get_dictitem(PmagRecs,'specimen',spc,'T') # get all this one's data DIMs,Temps=[],[] for dat in specdata: # step through the data DIMs.append([float(dat['dec']),float(dat['inc']),float(dat['M'])*1e-3]) Temps.append(float(dat['treatment'])) carts=pmag.dir2cart(DIMs).transpose() #if norm==1: # want to normalize # nrm=max(max(abs(carts[0])),max(abs(carts[1])),max(abs(carts[2]))) # by maximum of x,y,z values # ylab="M/M_max" if norm==1: # want to normalize nrm=(DIMs[0][2]) # normalize by NRM ylab="M/M_o" else: nrm=1. # don't normalize ylab="Magnetic moment (Am^2)" xlab="Temperature (C)" pmagplotlib.plotXY(FIG['lowrie'],Temps,abs(carts[0])/nrm,sym='r-') pmagplotlib.plotXY(FIG['lowrie'],Temps,abs(carts[0])/nrm,sym='ro') # X direction pmagplotlib.plotXY(FIG['lowrie'],Temps,abs(carts[1])/nrm,sym='c-') pmagplotlib.plotXY(FIG['lowrie'],Temps,abs(carts[1])/nrm,sym='cs') # Y direction pmagplotlib.plotXY(FIG['lowrie'],Temps,abs(carts[2])/nrm,sym='k-') pmagplotlib.plotXY(FIG['lowrie'],Temps,abs(carts[2])/nrm,sym='k^',title=spc,xlab=xlab,ylab=ylab) # Z direction pmagplotlib.drawFIGS(FIG) ans=raw_input('S[a]ve figure? [q]uit, <return> to continue ') if ans=='a': files={'lowrie':'lowrie:_'+spc+'_.'+fmt} pmagplotlib.saveP(FIG,files) elif ans=='q': sys.exit() pmagplotlib.clearFIG(FIG['lowrie'])
def main(): """ NAME lowrie_magic.py DESCRIPTION plots intensity decay curves for Lowrie experiments SYNTAX lowrie -h [command line options] INPUT takes magic_measurements formatted input files OPTIONS -h prints help message and quits -f FILE: specify input file, default is magic_measurements.txt -N do not normalize by maximum magnetization -fmt [svg, pdf, eps, png] specify fmt, default is svg """ fmt='svg' FIG={} # plot dictionary FIG['lowrie']=1 # demag is figure 1 pmagplotlib.plot_init(FIG['lowrie'],6,6) norm=1 # default is to normalize by maximum axis in_file,dir_path='magic_measurements.txt','.' if len(sys.argv)>1: 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 '-N' in sys.argv: norm=0 # don't normalize if '-f' in sys.argv: # sets input filename ind=sys.argv.index("-f") in_file=sys.argv[ind+1] else: print main.__doc__ print 'you must supply a file name' sys.exit() in_file=dir_path+'/'+in_file print in_file PmagRecs,file_type=pmag.magic_read(in_file) if file_type!="magic_measurements": print 'bad input file' sys.exit() PmagRecs=pmag.get_dictitem(PmagRecs,'magic_method_codes','LP-IRM-3D','has') # get all 3D IRM records if len(PmagRecs)==0: print 'no records found' sys.exit() specs=pmag.get_dictkey(PmagRecs,'er_specimen_name','') sids=[] for spec in specs: if spec not in sids:sids.append(spec) # get list of unique specimen names for spc in sids: # step through the specimen names print spc specdata=pmag.get_dictitem(PmagRecs,'er_specimen_name',spc,'T') # get all this one's data DIMs,Temps=[],[] for dat in specdata: # step through the data DIMs.append([float(dat['measurement_dec']),float(dat['measurement_inc']),float(dat['measurement_magn_moment'])]) Temps.append(float(dat['treatment_temp'])-273.) carts=pmag.dir2cart(DIMs).transpose() if norm==1: # want to normalize nrm=(DIMs[0][2]) # normalize by NRM ylab="M/M_o" else: nrm=1. # don't normalize ylab="Magnetic moment (Am^2)" xlab="Temperature (C)" pmagplotlib.plotXY(FIG['lowrie'],Temps,abs(carts[0])/nrm,sym='r-') pmagplotlib.plotXY(FIG['lowrie'],Temps,abs(carts[0])/nrm,sym='ro') # X direction pmagplotlib.plotXY(FIG['lowrie'],Temps,abs(carts[1])/nrm,sym='c-') pmagplotlib.plotXY(FIG['lowrie'],Temps,abs(carts[1])/nrm,sym='cs') # Y direction pmagplotlib.plotXY(FIG['lowrie'],Temps,abs(carts[2])/nrm,sym='k-') pmagplotlib.plotXY(FIG['lowrie'],Temps,abs(carts[2])/nrm,sym='k^',title=spc,xlab=xlab,ylab=ylab) # Z direction pmagplotlib.drawFIGS(FIG) ans=raw_input('S[a]ve figure? [q]uit, <return> to continue ') if ans=='a': files={'lowrie':'lowrie:_'+spc+'_.'+fmt} pmagplotlib.saveP(FIG,files) elif ans=='q': sys.exit() pmagplotlib.clearFIG(FIG['lowrie'])
def main(): """ NAME ani_depthplot.py DESCRIPTION plots tau, V3_inc, P and chi versus core_depth SYNTAX ani_depthplot.py [command line optins] OPTIONS -h prints help message and quits -f FILE: specify input rmag_anisotropy format file from magic -fb FILE: specify input magic_measurements format file from magic -fsa FILE: specify input er_samples format file from magic -fa FILE: specify input er_ages format file from magic -d min max [in m] depth range to plot -ds [mcd,mbsf], specify depth scale, default is mbsf -sav save plot without review -fmt specfiy format for figures - default is svg DEFAULTS: Anisotropy file: rmag_anisotropy.txt Bulk susceptibility file: magic_measurements.txt Samples file: er_samples.txt """ fmt='.svg' dir_path="./" pcol=3 verbose=pmagplotlib.verbose plots=0 age_file="" if '-WD' in sys.argv: ind=sys.argv.index('-WD') dir_path=sys.argv[ind+1] ani_file=dir_path+'/rmag_anisotropy.txt' 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') ani_file=dir_path+'/'+sys.argv[ind+1] if '-fb' in sys.argv: ind=sys.argv.index('-fb') 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 '-fa' in sys.argv: print main.__doc__ print 'only -fsa OR -fa - not both' sys.exit() elif '-fa' in sys.argv: ind=sys.argv.index('-fa') age_file=dir_path+"/"+sys.argv[ind+1] if '-fmt' in sys.argv: ind=sys.argv.index('-fmt') fmt='.'+sys.argv[ind+1] 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 '-ds' in sys.argv and 'mcd' in sys.argv: # sets depth scale to meters composite depth (as opposed to meters below sea floor) depth_scale='sample_composite_depth' elif age_file=="": depth_scale='sample_core_depth' else: depth_scale='age' if '-sav' in sys.argv: plots=1 verbose=0 # # get data read in isbulk=0 # tests if there are bulk susceptibility measurements AniData,file_type=pmag.magic_read(ani_file) # read in tensor elements if age_file=="": Samps,file_type=pmag.magic_read(samp_file) # read in sample depth info from er_sample.txt format file else: Samps,file_type=pmag.magic_read(age_file) # read in sample age info from er_ages.txt format file age_unit=Samps[0]['age_unit'] for s in Samps:s['er_sample_name']=s['er_sample_name'].upper() # change to upper case for every sample name Meas,file_type=pmag.magic_read(meas_file) if file_type=='magic_measurements':isbulk=1 Data=[] Bulks=[] BulkDepths=[] for rec in AniData: samprecs=pmag.get_dictitem(Samps,'er_sample_name',rec['er_sample_name'].upper(),'T') # look for depth record for this sample sampdepths=pmag.get_dictitem(samprecs,depth_scale,'','F') # see if there are non-blank depth data if dmax!=-1: sampdepths=pmag.get_dictitem(sampdepths,depth_scale,dmax,'max') # fishes out records within depth bounds sampdepths=pmag.get_dictitem(sampdepths,depth_scale,dmin,'min') if len(sampdepths)>0: # if there are any.... rec['core_depth'] = sampdepths[0][depth_scale] # set the core depth of this record Data.append(rec) # fish out data with core_depth if isbulk: # if there are bulk data chis=pmag.get_dictitem(Meas,'er_specimen_name',rec['er_specimen_name'],'T') chis=pmag.get_dictitem(chis,'measurement_chi_volume','','F') # get the non-zero values for this specimen if len(chis)>0: # if there are any.... Bulks.append(1e6*float(chis[0]['measurement_chi_volume'])) # put in microSI BulkDepths.append(float(sampdepths[0][depth_scale])) if len(Bulks)>0: # set min and max bulk values bmin=min(Bulks) bmax=max(Bulks) xlab="Depth (m)" if len(Data)>0: location=Data[0]['er_location_name'] else: print 'no data to plot' sys.exit() # collect the data for plotting tau and V3_inc Depths,Tau1,Tau2,Tau3,V3Incs,P=[],[],[],[],[],[] Axs=[] # collect the plot ids if len(Bulks)>0: pcol+=1 s1=pmag.get_dictkey(Data,'anisotropy_s1','f') # get all the s1 values from Data as floats s2=pmag.get_dictkey(Data,'anisotropy_s2','f') s3=pmag.get_dictkey(Data,'anisotropy_s3','f') s4=pmag.get_dictkey(Data,'anisotropy_s4','f') s5=pmag.get_dictkey(Data,'anisotropy_s5','f') s6=pmag.get_dictkey(Data,'anisotropy_s6','f') Depths=pmag.get_dictkey(Data,'core_depth','f') Ss=numpy.array([s1,s4,s5,s4,s2,s6,s5,s6,s3]).transpose() # make an array Ts=numpy.reshape(Ss,(len(Ss),3,-1)) # and re-shape to be n-length array of 3x3 sub-arrays for k in range(len(Depths)): tau,Evecs= pmag.tauV(Ts[k]) # get the sorted eigenvalues and eigenvectors v3=pmag.cart2dir(Evecs[2])[1] # convert to inclination of the minimum eigenvector V3Incs.append(v3) Tau1.append(tau[0]) Tau2.append(tau[1]) Tau3.append(tau[2]) P.append(tau[0]/tau[2]) if len(Depths)>0: if dmax==-1: dmax=max(Depths) dmin=min(Depths) tau_max=max(Tau1) tau_min=min(Tau3) P_max=max(P) P_min=min(P) #dmax=dmax+.05*dmax #dmin=dmin-.05*dmax pylab.figure(1,figsize=(10,8)) # make the figure version_num=pmag.get_version() pylab.figtext(.02,.01,version_num) # attach the pmagpy version number ax=pylab.subplot(1,pcol,1) # make the first column Axs.append(ax) ax.plot(Tau1,Depths,'rs') ax.plot(Tau2,Depths,'b^') ax.plot(Tau3,Depths,'ko') ax.axis([tau_min,tau_max,dmax,dmin]) ax.set_xlabel('Eigenvalues') if depth_scale=='sample_core_depth': ax.set_ylabel('Depth (mbsf)') elif depth_scale=='age': ax.set_ylabel('Age ('+age_unit+')') else: ax.set_ylabel('Depth (mcd)') ax2=pylab.subplot(1,pcol,2) # make the second column ax2.plot(P,Depths,'rs') ax2.axis([P_min,P_max,dmax,dmin]) ax2.set_xlabel('P') ax2.set_title(location) Axs.append(ax2) ax3=pylab.subplot(1,pcol,3) Axs.append(ax3) ax3.plot(V3Incs,Depths,'ko') ax3.axis([0,90,dmax,dmin]) ax3.set_xlabel('V3 Inclination') if pcol==4: ax4=pylab.subplot(1,pcol,4) Axs.append(ax4) ax4.plot(Bulks,BulkDepths,'bo') ax4.axis([bmin-1,bmax+1,dmax,dmin]) ax4.set_xlabel('Bulk Susc. (uSI)') for x in Axs:pmagplotlib.delticks(x) # this makes the x-tick labels more reasonable - they were overcrowded using the defaults figname=location+'_ani-depthplot'+fmt if verbose: pylab.draw() ans=raw_input("S[a]ve plot? Return to quit ") if ans=='a': pylab.savefig(figname) print 'Plot saved as ',figname elif plots: pylab.savefig(figname) print 'Plot saved as ',figname sys.exit() else: print "No data points met your criteria - try again"
def main(): """ NAME sites_locations.py DESCRIPTION reads in er_sites.txt file and finds all locations and bounds of locations outputs er_locations.txt file SYNTAX sites_locations.py [command line options] OPTIONS -h prints help message and quits -f: specimen input er_sites format file, default is "er_sites.txt" -F: locations table: default is "er_locations.txt" """ # set defaults site_file = "er_sites.txt" loc_file = "er_locations.txt" Names, user = [], "unknown" Done = [] version_num = pmag.get_version() args = sys.argv dir_path = "." # get command line stuff if "-WD" in args: ind = args.index("-WD") dir_path = args[ind + 1] if "-h" in args: print main.__doc__ sys.exit() if "-f" in args: ind = args.index("-f") site_file = args[ind + 1] if "-F" in args: ind = args.index("-F") loc_file = args[ind + 1] # site_file = dir_path + "/" + site_file loc_file = dir_path + "/" + loc_file Sites, file_type = pmag.magic_read(site_file) if file_type != "er_sites": print file_type print file_type, "This is not a valid er_sites file " sys.exit() # read in site data # LocNames, Locations = [], [] for site in Sites: if site["er_location_name"] not in LocNames: # new location name LocNames.append(site["er_location_name"]) sites_locs = pmag.get_dictitem( Sites, "er_location_name", site["er_location_name"], "T" ) # get all sites for this loc lats = pmag.get_dictkey(sites_locs, "site_lat", "f") # get all the latitudes as floats lons = pmag.get_dictkey(sites_locs, "site_lon", "f") # get all the longitudes as floats LocRec = { "er_citation_names": "This study", "er_location_name": site["er_location_name"], "location_type": "", } LocRec["location_begin_lat"] = str(min(lats)) LocRec["location_end_lat"] = str(max(lats)) LocRec["location_begin_lon"] = str(min(lons)) LocRec["location_end_lon"] = str(max(lons)) Locations.append(LocRec) if len(Locations) > 0: pmag.magic_write(loc_file, Locations, "er_locations") print "Locations written to: ", loc_file
def main(): """ NAME plot_mapPTS.py DESCRIPTION plots points on map SYNTAX plot_mapPTS.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,'rU').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: f=open(file,'rU') 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={} for key in FIG.keys(): files[key]='Map_PTS'+'.'+fmt if pmagplotlib.isServer or plot: black = '#000000' purple = '#800080' titles={} titles['eq']='PT 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)