def main(): """ NAME uniform.py DESCRIPTION draws N directions from uniform distribution on a sphere SYNTAX uniform.py [-h][command line options] -h prints help message and quits -n N, specify N on the command line (default is 100) -F file, specify output file name, default is standard output """ outf = "" N = 100 if "-h" in sys.argv: print main.__doc__ sys.exit() if "-F" in sys.argv: ind = sys.argv.index("-F") outf = sys.argv[ind + 1] if outf != "": out = open(outf, "w") if "-n" in sys.argv: ind = sys.argv.index("-n") N = int(sys.argv[ind + 1]) dirs = pmag.get_unf(N) if outf == "": for dir in dirs: print "%7.1f %7.1f" % (dir[0], dir[1]) else: numpy.savetxt(outf, dirs, fmt="%7.1f %7.1f")
def main(): """ NAME probRo.py DESCRIPTION Calculates Ro as a test for randomness - if R exceeds Ro given N, then set is not random at 95% level of confindence SYNTAX probRo.py [command line options] OPTIONS -h prints this help message -Nm number of Monte Carlo simulations (default is 10000) -Nmax maximum number for dataset (default is 10) """ Ns,Nm=range(4,11),10000 files,fmt={},'svg' if '-h' in sys.argv: # check if help is needed print main.__doc__ sys.exit() # graceful quit if '-Nm' in sys.argv: ind=sys.argv.index('-Nm') Nm=int(sys.argv[ind+1]) if '-Nmax' in sys.argv: ind=sys.argv.index('-Nmax') Nmax=int(sys.argv[ind+1]) Ns=range(3,Nmax+1) PLT={'plt':1} pmagplotlib.plot_init(PLT['plt'],5,5) Ro=[] for N in Ns: Rs=[] n=0 while n<Nm: dirs=pmag.get_unf(N) pars=pmag.fisher_mean(dirs) Rs.append(pars['r']) n+=1 Rs.sort() crit=int(.95*Nm) Ro.append(Rs[crit]) pmagplotlib.plotXY(PLT['plt'],Ns,Ro,'-','N','Ro','') pmagplotlib.plotXY(PLT['plt'],Ns,Ro,'ro','N','Ro','') pmagplotlib.drawFIGS(PLT) for key in PLT.keys(): files[key]=key+'.'+fmt ans=raw_input(" S[a]ve to save plot, [q]uit without saving: ") if ans=="a": pmagplotlib.saveP(PLT,files)
def main(): f = .9 while 1: stdev = 0 size = raw_input("mean width of smallest edge in nanometers: ") std = raw_input( " std deviation of length of smallest edge in nanometers: [return for single xtal] " ) if std == "": std = "0" dmean = float(size) * 1e-9 # convert to meters if std != "0": stdev = float(std) * 1e-9 abc = raw_input(" dimensions in colon delimited list [2:1:1] ") if abc == "": abc = "2:1:1" abcsplit = abc.split(':') a, b, c = float(abcsplit[0]), float(abcsplit[1]), float(abcsplit[2]) a, b, c = a / c, b / c, c / c # c = 1 Na = (1. / 3.) * (1. - (2. / 5.) * (2. - b / a - c / a)) # get demag factor Nb = (1. - Na) / 2. dN = Nb - Na Ndirs = 1000 dirs = pmag.get_unf(Ndirs) # get a uniform distribution of theta T, M = get_trm(dmean, stdev, dN, a * b, dirs) outstring = size + ' nm ' + '+/-' + std + '; shape: ' + abc text(.3, f, outstring) f -= .05 xlabel('Field (uT)') ylabel('TRM/sIRM') plot(T, M) bounds = axis() v = [bounds[0], bounds[1], 0, 1.] axis(v) draw() ans = raw_input( "[s]ave to save data, Return to continue, <^D> to quit ") if ans == "s": file = size + '_pm_' + std + '_' + '%i' % (a) + '_' + '%i' % ( b) + '_' + '%i' % (c) + '.out' f = open(file, 'w') for k in range(len(T)): outstring = '%i %7.5f\n' % (T[k], M[k]) f.write(outstring) f.close()
def main(): f=.9 while 1: stdev=0 size=raw_input("mean width of smallest edge in nanometers: ") std=raw_input(" std deviation of length of smallest edge in nanometers: [return for single xtal] ") if std=="":std="0" dmean=float(size)*1e-9 # convert to meters if std!="0": stdev=float(std)*1e-9 abc=raw_input(" dimensions in colon delimited list [2:1:1] ") if abc=="":abc="2:1:1" abcsplit=abc.split(':') a,b,c=float(abcsplit[0]),float(abcsplit[1]),float(abcsplit[2]) a,b,c=a/c,b/c,c/c # c = 1 Na=(1./3.)*(1.-(2./5.)*(2.-b/a-c/a)) # get demag factor Nb=(1.-Na)/2. dN=Nb-Na Ndirs=1000 dirs=pmag.get_unf(Ndirs)# get a uniform distribution of theta T,M=get_trm(dmean,stdev,dN,a*b,dirs) outstring=size+' nm '+'+/-'+std+'; shape: '+abc text(.3,f,outstring) f-=.05 xlabel('Field (uT)') ylabel('TRM/sIRM') plot(T,M) bounds=axis() v=[bounds[0],bounds[1],0,1.] axis(v) draw() ans=raw_input("[s]ave to save data, Return to continue, <^D> to quit ") if ans=="s": file=size+'_pm_'+std+'_'+'%i'%(a)+'_'+'%i'%(b)+'_'+'%i'%(c)+'.out' f=open(file,'w') for k in range(len(T)): outstring='%i %7.5f\n'%(T[k],M[k]) f.write(outstring) f.close()
def main(): """ NAME uniform.py DESCRIPTION draws N directions from uniform distribution on a sphere SYNTAX uniform.py [-h][command line options] -h prints help message and quits -i interactive entry of N and output file -n N, specify N on the command line (default is 100) -F file, specify output file name, default is standard output """ outf="" N=100 if '-h' in sys.argv: print main.__doc__ sys.exit() if '-i' in sys.argv: N=int(raw_input("Desired number of uniform directions ")) outf=raw_input("Output file for saving? ") if '-F' in sys.argv: ind=sys.argv.index('-F') outf=sys.argv[ind+1] if outf!="": out=open(outf,'w') if '-N' in sys.argv: ind=sys.argv.index('-N') N=int(sys.argv[ind+1]) dirs=pmag.get_unf(N) for dir in dirs: if outf!="": out.write('%7.1f %7.1f \n'%(dir[0],dir[1])) else: print '%7.1f %7.1f'%(dir[0],dir[1])