def simSpc(mat, e0, det, dose, ntraj, simDir): """ simSpc(mat, e0, det, dose, ntraj, simDir) simulate a spectrum from a material and write it out. """ xrts = [] trs = mc3.suggestTransitions(mat, e0) for tr in trs: xrts.append(tr) xtraParams = {} xtraParams.update(mc3.configureXRayAccumulators(xrts, True, True, True)) xtraParams.update(mc3.configureOutput(simDir)) spc = mc3.simulate(mat, det, e0, dose, True, nTraj, True, True, xtraParams) fmtS = "%s-at-%g-kV" sName = fmtS % (mat.getName(), e0) spc.rename(sName) spc.display() fi = simDir + "/" fi += sName fi += "-%g-Traj.msa" % (nTraj) spc.save(fi) return spc
def simBulkStd(mat, det, e0, nTraj, lt=100, pc=1.0, ctd=True): """simBulkStd(mat, det, e0, nTraj, lt=100, pc=1.0) Use mc3 simulation to simulate an uncoated standard specimen Parameters ---------- mat - a dtsa material. Note the material must have an associated density. It should have a useful name. det - a dtsa detector Here is where we get the detector properties and calibration e0 - float The accelerating voltage in kV nTraj - integer The number of trajectories to run lt - integer (100) The live time (sec) pc - float (1.0) The probe current in nA ctd - Boolean (True) - is C coated Returns ------- sim - DTSA scriptable spectrum The simulated standard spectrum Example ------- import dtsa2.jmMC3 as jm3 det = findDetector("Oxford p4 05eV 2K") cu = material("Cu", density=8.92) a = jm3.simBulkStd(cu, det, 20.0, 100, 100, 1.0) a.display() """ dose = pc * lt # na-sec" xrts = [] trs = mc3.suggestTransitions(mat, e0) for tr in trs: xrts.append(tr) xtraParams = {} xtraParams.update(mc3.configureXRayAccumulators(xrts, True, True, True)) sim = mc3.simulate(mat, det, e0, dose, withPoisson=True, nTraj=nTraj, sf=True, bf=True, xtraParams=xtraParams) sName = "%s-%g-kV" % (mat, e0) sim.rename(sName) sim.setAsStandard(mat) return sim
def simSpc(mat, e0, det, dose, ntraj, simDir): """ simSpc(mat, e0, det, dose, ntraj, simDir) simulate a spectrum from a material and write it out. """ xrts = [] trs = mc3.suggestTransitions(mat, e0) for tr in trs: xrts.append(tr) xtraParams={} xtraParams.update(mc3.configureXRayAccumulators(xrts,True, True, True)) xtraParams.update(mc3.configureOutput(simDir)) spc = mc3.simulate(mat, det, e0, dose, True, nTraj, True, True, xtraParams) fmtS = "%s-at-%g-kV" sName = fmtS % (mat.getName(), e0) spc.rename(sName) spc.display() fi = simDir + "/" fi += sName fi += "-%g-Traj.msa" % (nTraj) spc.save(fi) return spc
def simBulkStd(mat, det, e0, nTraj, lt=100, pc=1.0, ctd=True): """simBulkStd(mat, det, e0, nTraj, lt=100, pc=1.0) Use mc3 simulation to simulate an uncoated standard specimen Parameters ---------- mat - a dtsa material. Note the material must have an associated density. It should have a useful name. det - a dtsa detector Here is where we get the detector properties and calibration e0 - float The accelerating voltage in kV nTraj - integer The number of trajectories to run lt - integer (100) The live time (sec) pc - float (1.0) The probe current in nA ctd - Boolean (True) - is C coated Returns ------- sim - DTSA scriptable spectrum The simulated standard spectrum Example ------- import dtsa2.jmMC3 as jm3 det = findDetector("Oxford p4 05eV 2K") cu = material("Cu", density=8.92) a = jm3.simBulkStd(cu, det, 20.0, 100, 100, 1.0) a.display() """ dose = pc * lt # na-sec" xrts = [] trs = mc3.suggestTransitions(mat, e0) for tr in trs: xrts.append(tr) xtraParams={} xtraParams.update(mc3.configureXRayAccumulators(xrts,True, True, True)) sim = mc3.simulate(mat, det, e0, dose, withPoisson=True, nTraj=nTraj, sf=True, bf=True, xtraParams=xtraParams) sName = "%s-%g-kV" % (mat, e0) sim.rename(sName) sim.setAsStandard(mat) return sim
def simulate_spectrum(mat, e0, det, nTraj, dose, spcDir): """ simulate_spectrum(mat, e0, det, nTraj, dose, spcDir) """ xrts = [] trs = mc3.suggestTransitions(mat, e0) for tr in trs: xrts.append(tr) xtraParams={} xtraParams.update(mc3.configureXRayAccumulators(xrts,True, True, True)) # xtraParams.update(mc3.configureOutput(simDir)) spc = mc3.simulate(mat, det, e0, dose, True, nTraj, True, True, xtraParams) sName = "%s std-%g-kV" % (mat.getName(), e0) spc.rename(sName) spc.setAsStandard(mat) spc.display() # Save the spectra if NTraj > 500 if nTraj > 500: fi = spcDir + "/" fi += sName fi += "-%g-Traj.msa" % (nTraj) spc.save(fi) return (spc)
def sim_amc_coated_mat(mat, det, e0, nTraj, lt=100, pc=1.0, tc=20.0): """sim_amc_coated_mat(mat, det, e0, nTraj, lt=100, pc=1.0, tc=20.0) Use mc3 multilayer simulation to simulate an am-C-ctd specimen Parameters ---------- mat - a dtsa material. Note the material must have an associated density. It should have a useful name. det - a dtsa detector Here is where we get the detector properties and calibration e0 - float The accelerating voltage in kV nTraj - integer The number of trajectories to run lt - integer (100) The live time (sec) pc - float (1.0) The probe current in nA tc - float (20.0) C thickness in nm Returns ------- sim - DTSA scriptable spectrum The simulated spectrum Example ------- import dtsa2.jmMC3 as jm3 det = findDetector("Oxford p4 05eV 2K") si = material("Si", density=2.3296) a = jm3.simCarbonCoatedStd(mgo, det, 5.0, 100, 100, 1.0, 20.0) a.display() """ dose = pc * lt # na-sec" amc = material("C", density=1.35) amcThickComment = "amC Thickness = %g nm %g trajectories" % (tc, nTraj) layers = [[amc, tc * 1.0e-9], [mat, 50.0e-6]] xrts = [] trs = mc3.suggestTransitions(amc, e0) for tr in trs: xrts.append(tr) trs = mc3.suggestTransitions(mat, e0) for tr in trs: xrts.append(tr) xtraParams = {} xtraParams.update(mc3.configureXRayAccumulators(xrts, True, True, True)) sim = mc3.multiFilm(layers, det, e0, withPoisson=True, nTraj=nTraj, dose=dose, sf=True, bf=True, xtraParams=xtraParams) sName = "%g-nm-amC-on-%s-%g-kV" % (tc, mat, e0) sim.rename(sName) sim.getProperties().setTextProperty(epq.SpectrumProperties.SpectrumComment, amcThickComment) return sim
def simCarbonCoatedStd(mat, det, e0, nTraj, lt=100, pc=1.0, tc=20.0): """simCarbonCoatedStd(mat, det, e0, nTraj, lt=100, pc=1.0, tc=20.0) Use mc3 multilayer simulation to simulate a C-ctd standard specimen Parameters ---------- mat - a dtsa material. Note the material must have an associated density. It should have a useful name. det - a dtsa detector Here is where we get the detector properties and calibration e0 - float The accelerating voltage in kV nTraj - integer The number of trajectories to run lt - integer (100) The live time (sec) pc - float (1.0) The probe current in nA tc - float (20.0) C thickness in nm Returns ------- sim - DTSA scriptable spectrum The simulated standard spectrum Example ------- import dtsa2.jmMC3 as jm3 det = findDetector("Si(Li)") mgo = material("MgO", density=3.58) a = jm3.simCarbonCoatedStd(mgo, det, 20.0, 100, 100, 1.0, 20.0) a.display() """ dose = pc * lt # na-sec" c = dt2.material("C", density=2.1) layers = [[c, tc * 1.0e-9], [mat, 50.0e-6]] xrts = [] trs = mc3.suggestTransitions(c, e0) for tr in trs: xrts.append(tr) trs = mc3.suggestTransitions(mat, e0) for tr in trs: xrts.append(tr) xtraParams = {} xtraParams.update(mc3.configureXRayAccumulators(xrts, True, True, True)) sim = mc3.multiFilm(layers, det, e0, withPoisson=True, nTraj=nTraj, dose=dose, sf=True, bf=True, xtraParams=xtraParams) sName = "%g-nm-C-on-%s-%g-kV-%g-Traj" % (tc, mat, e0, nTraj) sim.rename(sName) sim.setAsStandard(mat) return sim
def uncoatedSimBulkStd(mat, det, e0, nTraj, outPath, dim=5.0e-6, lt=100, pc=1.0, emiSize=512): """ uncoatedSimBulkStd(mat, det, e0, nTraj, outPath, dim=5.0e-6, lt=100, pc=1.0, emiSize=512) Use mc3 simulation to simulate an uncoated standard specimen Parameters ---------- mat - a dtsa material. Note the material must have an associated density. It should have a useful name. det - a dtsa detector Here is where we get the detector properties and calibration e0 - float The accelerating voltage in kV nTraj - integer The number of trajectories to run outPath - string The path to the directory for output dim - float (5.0e-6) The size of the emission images in um lt - integer (100) The live time (sec) pc - float (1.0) The probe current in nA emiSize - int (default 512) The width and depth of the emission images. Returns ------- sim - DTSA scriptable spectrum The simulated standard spectrum Example ------- import dtsa2 as dtsa2 import dtsa2.jmMC3 as jm3 outPath = "path/to/yours/spc" cu = material("Cu", density=8.92) det = findDetector("Si(Li)") a = jm3.uncoatedSimBulkStd(cu, det, 15.0, 100, outPath, dim=5.0e-6, lt=100, pc=1.0, emiSize=512) a.display() """ start = time.time() strMat = mat.getName() dose = pc * lt # na-sec" # specify the transitions to generate xrts = [] trs = mc3.suggestTransitions(mat, e0) for tr in trs: xrts.append(tr) # At 20 kV the images are best at 2.0e-6 xtraParams = {} xtraParams.update(mc3.configureXRayAccumulators(xrts, True, True, True)) # note that the image size on the specimen is in meters... xtraParams.update(mc3.configureEmissionImages(xrts, dim, emiSize)) xtraParams.update(mc3.configurePhiRhoZ(dim)) xtraParams.update(mc3.configureTrajectoryImage(dim, emiSize)) xtraParams.update(mc3.configureVRML(nElectrons=100)) xtraParams.update(mc3.configureOutput(outPath)) print("Output sent to %s") % (outPath) sim = mc3.simulate(mat, det, e0, lt * pc, True, nTraj, True, True, xtraParams) sName = "%s-%g-kV" % (strMat, e0) sim.rename(sName) sim.setAsStandard(mat) sim.display() end = time.time() delta = end - start msg = "This simulation required %.f sec" % (delta) print(msg) msg = " %.f min" % (delta / 60.0) print(msg) msg = " %.f hr" % (delta / 360.0) print("") return (sim)
def simCoatedSubstrate(mat, ctg, thNm, det, e0, nTraj, lt=100, pc=1.0): """simCoatedSubstrate(mat, ctg, thNm, det, e0, nTraj, lt=100, pc=1.0) Use mc3 multilayer simulation to simulate an coated substrate specimen This ONLY generates a spectrum Parameters ---------- mat - a dtsa material for the substrate. Note the material must have an associated density. It should have a useful name. ctg - a dtsa material for the coating thNm - coating thickness in nm det - a dtsa detector Here is where we get the detector properties and calibration e0 - float The accelerating voltage in kV nTraj - integer The number of trajectories to run lt - integer (100) The live time (sec) pc - float (1.0) The probe current in nA tc - float (20.0) C thickness in nm Returns ------- sim - DTSA scriptable spectrum The simulated spectrum Example ------- import dtsa2 as dtsa2 import dtsa2.jmMC3 as jm3 det = findDetector("Si(Li)") sio2 = material("SiO2", 2.65) si = material("Si", 2.3296) a = jm3.simCoatedSubstrate(si, sio2, 10.0, det, e0, nTraj, 100, 1.0) a.display() """ dose = pc * lt # na-sec" layers = [[ctg, thNm * 1.0e-9], [mat, 50.0e-6]] xrts = [] trs = mc3.suggestTransitions(ctg, e0) for tr in trs: xrts.append(tr) trs = mc3.suggestTransitions(mat, e0) for tr in trs: xrts.append(tr) xtraParams = {} xtraParams.update(mc3.configureXRayAccumulators(xrts, True, True, True)) sim = mc3.multiFilm(layers, det, e0, True, nTraj, dose, True, True, xtraParams) sName = "%g-nm-%s-on-%s-%g-kV" % (thNm, ctg, mat, e0) sim.rename(sName) return sim
def simCtdOxOnSi(det, e0, nTraj, lt=100, pc=1.0, tox=10.0, tc=20.0): """ simCtdOxOnSi(det, e0, nTraj, lt=100, pc=1.0, tox = 10.0, tc=20.0) Use mc3 multilayer simulation to simulate a C-ctd silicon specimen with a native oxide layer. det - a dtsa detector Here is where we get the detector properties and calibration e0 - float The accelerating voltage in kV nTraj - integer The number of trajectories to run lt - integer (100) The live time (sec) pc - float (1.0) The probe current in nA tox - float (10.0) The thickness of the native oxide in nm tc - float (20.0) C thickness in nm Returns ------- sim - DTSA scriptable spectrum The simulated spectrum Example ------- import dtsa2.jmMC3 as jm3 det = findDetector("Si(Li)") a = jm3.simCtdOxOnSi(det, 3.0, 100, 100, 1.0, 10.0, 20.0) a.display() """ c = dt2.material("C", density=2.1) si = dt2.material("Si", density=2.329) sio2 = dt2.material("SiO2", density=2.65) dose = pc * lt # na-sec" layers = [[c, tc * 1.0e-9], [sio2, tox * 1.0e-9], [si, 50.0e-6]] xrts = [] trs = mc3.suggestTransitions(c, e0) for tr in trs: xrts.append(tr) trs = mc3.suggestTransitions(sio2, e0) for tr in trs: xrts.append(tr) xtraParams = {} xtraParams.update(mc3.configureXRayAccumulators(xrts, True, True, True)) sim = mc3.multiFilm(layers, det, e0, withPoisson=True, nTraj=nTraj, dose=dose, sf=True, bf=True, xtraParams=xtraParams) sName = "%g-nm-C-on-%g-nm-SiO2-on-Si-%g-kV-%g-Traj" % (tc, tox, e0, nTraj) sim.rename(sName) return sim
def sim_amc_coated_mat(mat, det, e0, nTraj, lt=100, pc=1.0, tc=20.0): """sim_amc_coated_mat(mat, det, e0, nTraj, lt=100, pc=1.0, tc=20.0) Use mc3 multilayer simulation to simulate an am-C-ctd specimen Parameters ---------- mat - a dtsa material. Note the material must have an associated density. It should have a useful name. det - a dtsa detector Here is where we get the detector properties and calibration e0 - float The accelerating voltage in kV nTraj - integer The number of trajectories to run lt - integer (100) The live time (sec) pc - float (1.0) The probe current in nA tc - float (20.0) C thickness in nm Returns ------- sim - DTSA scriptable spectrum The simulated spectrum Example ------- import dtsa2.jmMC3 as jm3 det = findDetector("Oxford p4 05eV 2K") si = material("Si", density=2.3296) a = jm3.simCarbonCoatedStd(mgo, det, 20.0, 100, 100, 1.0, 20.0) a.display() """ dose = pc * lt # na-sec" amc = material("C", density=1.35) amcThickComment = "amC Thickness = %g nm %g trajectories" % (tc, nTraj) layers = [ [amc, tc*1.0e-9], [mat, 50.0e-6] ] xrts = [] trs = mc3.suggestTransitions(amc, e0) for tr in trs: xrts.append(tr) trs = mc3.suggestTransitions(mat, e0) for tr in trs: xrts.append(tr) xtraParams={} xtraParams.update(mc3.configureXRayAccumulators(xrts,True, True, True)) sim = mc3.multiFilm(layers, det, e0, withPoisson=True, nTraj=nTraj, dose=dose, sf=True, bf=True, xtraParams=xtraParams) sName = "%g-nm-amC-on-%s-%g-kV" % (tc, mat, e0) sim.rename(sName) sim.getProperties().setTextProperty(epq.SpectrumProperties.SpectrumComment, amcThickComment) return sim
def simLineInMatrixLimScan(lin, linMat, blk, blkMat, nmLinWid, umBlock, nmScan, nPts, trs, outDir, hdr, det, e0, lt, pc, withPoisson=True, nTraj=100, sf=True, bf=True, iDigits=5, bVerbose=False, xtraParams={}): """simLineInMatrixLimScan(lin, linMat, blk, blkMat, nmLinWid, umBlock, nmScan, nPts, trs, outDir, hdr, det, e0, lt, pc, withPoisson=True, nTraj=nTraj, sf=True, bf=True, iDigits=5, bVerbose=False, xtraParams={}) Simulate a line of width `nmLinWid' nm at the center of a block of `umBlock' microns. The line is of material `lin' with a name `linMat'. The block is of material `blk' with a name `blkMat'. We step a total distance of nmScan across the center of the line. We analyze an list `trs' of transitions, writing the K-ratios to a .csv file with a header `hdr'. We use the detector `det', voltage `e0' (kV) and live time `lt' sec and probe current `pc' nA. This will compute the standard spectra, compute the spectra the scanned region. It will then compute the K-ratios for each spectrum and write them to a file `name' in outDir with a header `hdr' that matches the transition order. """ # order is order of trs.. sc = 1.0e-6 # scale from microns to meters for positions dose = lt * pc lX = [] # an array for postions lKlin = [] # an array for the K-ratio of the line lKblk = [ ] # an array for the K-ratio of the block. Title correspond to hdr string umLine = nmLinWid * 1.0e-3 # start clean dt2.DataManager.clearSpectrumList() # create the standards linStd = simulateBulkStandard(lin, linMat, det, e0, lt, pc, withPoisson=withPoisson, nTraj=nTraj, sf=sf, bf=bf, xtraParams={}) dt2.display(linStd) blkStd = simulateBulkStandard(blk, blkMat, det, e0, lt, pc, withPoisson=withPoisson, nTraj=nTraj, sf=sf, bf=sf, xtraParams={}) dt2.display(blkStd) lStd = {"El": dt2.element(linMat), "Spc": linStd} bStd = {"El": dt2.element(blkMat), "Spc": blkStd} stds = [lStd, bStd] # note: put the transitions in this order iCount = 0 for x in range(-nPts / 2, (nPts / 2) + 1, 1): xPosNm = x * nmScan / nPts lX.append(round(xPosNm, iDigits)) xtraParams = {} xtraParams.update( mc3.configureXRayAccumulators(trs, charAccum=sf, charFluorAccum=sf, bremFluorAccum=bf)) xtraParams.update(mc3.configureOutput(outDir)) xtraParams.update(mc3.configureBeam(xPosNm * 1.0e-09, 0, -0.099, 1.0)) spec = mc3.embeddedRectangle(lin, [umLine * sc, umBlock * sc, umBlock * sc], blk, 0, det, e0, withPoisson=withPoisson, nTraj=nTraj, dose=dose, sf=sf, bf=bf, xtraParams=xtraParams) props = spec.getProperties() props.setNumericProperty(epq.SpectrumProperties.LiveTime, lt) props.setNumericProperty(epq.SpectrumProperties.FaradayBegin, pc) props.setNumericProperty(epq.SpectrumProperties.FaradayEnd, pc) props.setNumericProperty(epq.SpectrumProperties.BeamEnergy, e0) spcName = "x = %.3f um" % x epq.SpectrumUtils.rename(spec, spcName) spec = epq.SpectrumUtils.addNoiseToSpectrum(spec, 1.0) # display(spec) a = jmg.compKRs(spec, stds, trs, det, e0) iCount += 1 print(iCount, xPosNm) lKlin.append(round(a[0], iDigits)) lKblk.append(round(a[1], iDigits)) basFile = "%gnm-%s-in-%gum-%s-%gkV-%g-Traj.csv" % ( nmLinWid, linMat, umBlock, blkMat, e0, nTraj) strOutFile = outDir + "/" + basFile f = open(strOutFile, 'w') strLine = hdr + '\n' f.write(strLine) for i in range(iCount): strLine = "%.3f" % lX[i] + "," strLine = strLine + "%.5f" % lKlin[i] + "," strLine = strLine + "%.5f" % lKblk[i] + "\n" f.write(strLine) f.close()
e0 = 5 # kV nTraj = 10000 # trajectories lt = 60 # sec pc = 2.0 # nA imgSzUm = 5.0 # physical size of images in microns imgSizePx = 512 # size of images in pixels vmrlEl = 40 # number of el for VMRL dose = pc * lt # nA sec DataManager.clearSpectrumList() b = material("B", density=2.37) bn = material("BN", density=2.1) aln = material("AlN", density=3.26) # Sim B xrts = [transition("B K-L2"), transition("B K-L3")] xtraParams={} xtraParams.update(mc3.configureXRayAccumulators(xrts, charAccum=True, charFluorAccum=True, bremFluorAccum=True)) # note that the image size on the specimen is in meters... xtraParams.update(mc3.configureEmissionImages(xrts, imgSzUm*1.0e-6, imgSizePx)) xtraParams.update(mc3.configurePhiRhoZ(imgSzUm*1.0e-6)) xtraParams.update(mc3.configureTrajectoryImage(imgSzUm*1.0e-6, imgSizePx)) xtraParams.update(mc3.configureVRML(nElectrons = vmrlEl)) xtraParams.update(mc3.configureOutput(spcDir)) b_spc = mc3.simulate(b, det, e0, dose = pc*lt, nTraj=nTraj, sf=True, bf=True, xtraParams = xtraParams) b_spc.rename("B") # b_spec.setAsStandard(b) display(b_spc) fi = spcDir + "/B-%g-kV-%g-Traj.msa" % (e0, nTraj) b_spc.save(fi) # Sim BN xrts = [transition("B K-L2"), transition("B K-L3"), transition("N K-L2"), transition("N K-L3")]
pyrDir = prjDir + "/mc3SphereOnSubstrate Results" al2o3 = epq.Material( epq.Composition([epq.Element.Al, epq.Element.O], [0.5293, 0.4707]), epq.ToSI.gPerCC(3.95)) al2o3.setName("Al2O3") c = epq.Material(epq.Composition([epq.Element.C], [1.0]), epq.ToSI.gPerCC(2.62)) c.setName("C") xrts = [transition("Al K-L3"), transition("O K-L3"), transition("C K-L3")] xtraParams = {} xtraParams.update( mc3.configureXRayAccumulators(xrts, charAccum=True, charFluorAccum=True, bremFluorAccum=True)) # note that the image size on the specimen is in meters... xtraParams.update( mc3.configureEmissionImages(xrts, imgSzUm * 1.0e-6, imgSizePx)) xtraParams.update(mc3.configurePhiRhoZ(imgSzUm * 1.0e-6)) xtraParams.update(mc3.configureTrajectoryImage(imgSzUm * 1.0e-6, imgSizePx)) xtraParams.update(mc3.configureVRML(nElectrons=vmrlEl)) xtraParams.update(mc3.configureOutput(simDir)) spc = mc3.sphere(al2o3, radUm * 1.0e-6, det, e0, withPoisson=True, nTraj=nTraj,
def fullSimBulkStd(mat, det, e0, nTraj, outPath, dim=5.0e-6, lt=100, pc=1.0, emiSize=512, ctd=False): """ fullSimBulkStd(mat, det, e0, nTraj, outPath, dim=5.0e-6, lt=100, pc=1.0, emiSize=512, ctd=False) Use mc3 simulation to simulate an uncoated standard specimen Parameters ---------- mat - a dtsa material. Note the material must have an associated density. It should have a useful name. det - a dtsa detector Here is where we get the detector properties and calibration e0 - float The accelerating voltage in kV nTraj - integer The number of trajectories to run outPath - string The path to the directory for output dim - float (5.0e-6) The size of the emission images lt - integer (100) The live time (sec) pc - float (1.0) The probe current in nA emiSize - int (default 512) The width and depth of the emission images. ctd - Boolean (False) - is C coated Returns ------- sim - DTSA scriptable spectrum The simulated standard spectrum Example ------- import dtsa2 as dtsa2 import dtsa2.mcSimulate3 as mc3 det = findDetector("Oxford p4 05eV 2K") cu = material("Cu", density=8.92) a = fullSimBulkStd(cu, det, 20.0, 100, 100, 1.0) a.display() """ dose = pc * lt # na-sec" xrts = [] trs = mc3.suggestTransitions(mat, e0) for tr in trs: xrts.append(tr) mc3.configureEmissionImages(xrts, dim, emiSize) xtraParams={} xtraParams.update(mc3.configureXRayAccumulators(xrts,True, True, True)) # note that the image size on the specimen is in meters... xtraParams.update(mc3.configureEmissionImages(xrts, 5.0e-6, 512)) xtraParams.update(mc3.configurePhiRhoZ(5.0e-6)) xtraParams.update(mc3.configureTrajectoryImage(5.0e-6, 512)) xtraParams.update(mc3.configureVRML(nElectrons=100)) xtraParams.update(mc3.configureOutput(outPath)) mc3.configureOutput(outPath) print("Output sent to %s") % (outPath) dose = lt*pc sim = mc3.simulate(mat, det, e0, dose, withPoisson=True, nTraj=nTraj, sf=True, bf=True, xtraParams=xtraParams) sName = "%s-%g-kV" % (mat, e0) sim.rename(sName) sim.setAsStandard(mat) sim.display() fi = outPath + "/" fi += sName fi += "-%g-Traj.msa" % (nTraj) print(fi) sim.save(fi) return(sim)
def fullSimBulkStd(mat, ctg, ctgThickNm, det, e0, nTraj, outPath, dim=5.0e-6, lt=100, pc=1.0, emiSize=512, ctd=False): """ fullSimBulkStd(mat, ctg, ctgThickNm, det, e0, nTraj, outPath, dim=5.0e-6, lt=100, pc=1.0, emiSize=512, ctd=False) Use mc3 simulation to simulate an uncoated standard specimen Parameters ---------- mat - a dtsa material. Note the material must have an associated density. It should have a useful name. ctg - a dtsa2 material for the coating det - a dtsa detector Here is where we get the detector properties and calibration e0 - float The accelerating voltage in kV nTraj - integer The number of trajectories to run outPath - string The path to the directory for output dim - float (5.0e-6) The size of the emission images lt - integer (100) The live time (sec) pc - float (1.0) The probe current in nA emiSize - int (default 512) The width and depth of the emission images. ctd - Boolean (False) - is C coated Returns ------- sim - DTSA scriptable spectrum The simulated standard spectrum Example ------- import dtsa2 as dtsa2 import dtsa2.mcSimulate3 as mc3 det = findDetector("Oxford p4 05eV 4K") cu = material("Cu", density=8.92) outPath = "C:/Users/johnr/Documents/git/dtsa2Scripts/ben-buse/out" a = fullSimBulkStd(cu, det, 15.0, 100, outPath, dim=5.0e-6, lt=100, pc=1.0, emiSize=512, ctd=False) a.display() """ strCtg = ctg.getName() strMat = mat.getName() dose = pc * lt # na-sec" # specify the transitions to generate xrts = [] trs = mc3.suggestTransitions(mat, e0) for tr in trs: xrts.append(tr) trs = mc3.suggestTransitions(ctg, e0) for tr in trs: xrts.append(tr) # At 20 kV the images are best at 2.0e-6 xtraParams={} xtraParams.update(mc3.configureXRayAccumulators(xrts,True, True, True)) # note that the image size on the specimen is in meters... xtraParams.update(mc3.configureEmissionImages(xrts, 2.0e-6, 512)) xtraParams.update(mc3.configurePhiRhoZ(2.0e-6)) xtraParams.update(mc3.configureTrajectoryImage(2.0e-6, 512)) xtraParams.update(mc3.configureVRML(nElectrons=100)) xtraParams.update(mc3.configureOutput(outPath)) print("Output sent to %s") % (outPath) layers = [ [ctg, ctgThickNm*1.0e-9], [mat, 1.0e-3]] sim = mc3.multiFilm(layers, det, e0, withPoisson=True, nTraj=nTraj, dose=dose, sf=True, bf=True, xtraParams=xtraParams) sName = "%g-nm-%s-on-%s" % (tNmC, strCtg, strMat) sim.rename(sName) sim.setAsStandard(mat) sim.display() return(sim)
# start clean DataManager.clearSpectrumList() # define the desired transitions (most intense for each line...) # Ka1 Ka1 Ka1 La1 xrts = [ transition("C K-L3"), transition("O K-L3"), transition("Al K-L3"), transition("Ag L3-M5") ] # print(xrts) # set up the extra parameters xtraParams = {} xtraParams.update( mc3.configureXRayAccumulators(xrts, charAccum=charF, charFluorAccum=charF, bremFluorAccum=bremF)) # note that the image size on the specimen is in meters... xtraParams.update(mc3.configureEmissionImages(xrts, imgSzUm * 1.0e-6, imgSize)) xtraParams.update(mc3.configurePhiRhoZ(imgSzUm * 1.0e-6)) xtraParams.update(mc3.configureTrajectoryImage(imgSzUm * 1.0e-6, imgSize)) xtraParams.update(mc3.configureVRML(nElectrons=vmrlEl)) xtraParams.update(mc3.configureOutput(simDir)) print(xtraParams) spc = jm3.coatedOverBlock(ag, tBlk * 1.0e-6, wBlk * 1.0e-6, al2o3, tFlm * 1.0e-6,
def simCtdOxOnSi(det, e0, nTraj, lt=100, pc=1.0, tox = 10.0, tc=20.0): """ simCtdOxOnSi(det, e0, nTraj, lt=100, pc=1.0, tox = 10.0, tc=20.0) Use mc3 multilayer simulation to simulate a C-ctd silicon specimen with a native oxide layer. det - a dtsa detector Here is where we get the detector properties and calibration e0 - float The accelerating voltage in kV nTraj - integer The number of trajectories to run lt - integer (100) The live time (sec) pc - float (1.0) The probe current in nA tox - float (10.0) The thickness of the native oxide in nm tc - float (20.0) C thickness in nm Returns ------- sim - DTSA scriptable spectrum The simulated spectrum Example ------- import dtsa2.jmMC3 as jm3 det = findDetector("Oxford p4 05eV 2K") a = jm3.simCtdOxOnSi(det, 3.0, 100, 100, 1.0, 10.0, 20.0) a.display() """ c = dt2.material("C", density=2.1) si = dt2.material("Si", density=2.329) sio2 = dt2.material("SiO2", density=2.65) dose = pc * lt # na-sec" layers = [ [ c, tc*1.0e-9], [sio2, tox*1.0e-9], [si, 50.0e-6] ] xrts = [] trs = mc3.suggestTransitions(c, e0) for tr in trs: xrts.append(tr) trs = mc3.suggestTransitions(sio2, e0) for tr in trs: xrts.append(tr) xtraParams={} xtraParams.update(mc3.configureXRayAccumulators(xrts,True, True, True)) sim = mc3.multiFilm(layers, det, e0, withPoisson=True, nTraj=nTraj, dose=dose, sf=True, bf=True, xtraParams=xtraParams) sName = "%g-nm-C-on-%g-nm-SiO2-on-Si-%g-kV-%g-Traj" % (tc, tox, e0, nTraj) sim.rename(sName) return sim
cTS = epq.XRayTransitionSet(epq.Element.C, epq.XRayTransitionSet.K_FAMILY) cTrs = cTS.getTransitions() for tr in cTrs: xrts.append(tr) # get and add the Cu-L family siTS = epq.XRayTransitionSet(epq.Element.Si, epq.XRayTransitionSet.K_FAMILY) siTrs = siTS.getTransitions() for tr in siTrs: xrts.append(tr) xp.update(mc3.configureXRayAccumulators(xrts, charAccum=True, charFluorAccum=True, bremFluorAccum=True)) # xp.update(mc3.configureEmissionImages(xrts,imgSzUm*1.0e-6, imgSzPx)) # xp.update(mc3.configurePhiRhoZ(imgSzUm*1.0e-6)) # xp.update(mc3.configureTrajectoryImage(imgSzUm*1.0e-6, imgSzPx)) # xp.update(mc3.configureVRML(nElectrons = 40)) xp.update(mc3.configureOutput(outDir)) xp.update(mc3.configureGun(beamSzNm*1.0e-9)) ts = time.time() # first sim bare Si spc = mc3.simulate(si, det, e0, dose, True, nTraj, True, True, xp) spc = epq.SpectrumUtils.addNoiseToSpectrum(spc, 1.0) spc = wrap(spc)
rptDir = wrkDir + '/testMC3AdmiraltyBrass Results/' simDir = homDir + "/Documents/git/dtsa2Scripts/sim-Admiralty-Brass" dt2c.ensureDir(simDir) DataManager.clearSpectrumList() xrts = [] trs = mc3.suggestTransitions(mix, e0) for tr in trs: xrts.append(tr) # print(xrts) xtraParams={} xtraParams.update(mc3.configurePhiRhoZ(przDepUm*1.0e-6)) xtraParams.update(mc3.configureXRayAccumulators(xrts,True, True, True)) # note that the image size on the specimen is in meters... xtraParams.update(mc3.configureEmissionImages(xrts, imgSzUm*1.0e-6, imgSize)) xtraParams.update(mc3.configureTrajectoryImage(imgSzUm*1.0e-6, imgSize)) xtraParams.update(mc3.configureVRML(nElectrons = vmrlEl)) xtraParams.update(mc3.configureOutput(simDir)) print(xtraParams) sim = mc3.simulate(mix, det, e0, dose, True, nTraj, True, True, xtraParams) fmtS = "Admiralty-Brass-at-%g-kV" sName = fmtS % (e0) sim.rename(sName) sim.display()
layers = [[c, tCNm * 1.0e-9], [eagleXG, 50.0e-6]] xrts = [] trs = mc3.suggestTransitions(eagleXG, e0) for tr in trs: xrts.append(tr) trs = mc3.suggestTransitions(c, e0) for tr in trs: xrts.append(tr) xtraParams = {} xtraParams.update(mc3.configurePhiRhoZ(przDepUm * 1.0e-6)) xtraParams.update(mc3.configureXRayAccumulators(xrts, True, True, True)) # note that the image size on the specimen is in meters... xtraParams.update(mc3.configureEmissionImages(xrts, imgSzUm * 1.0e-6, imgSize)) xtraParams.update(mc3.configureTrajectoryImage(imgSzUm * 1.0e-6, imgSize)) xtraParams.update(mc3.configureVRML(nElectrons=vmrlEl)) xtraParams.update(mc3.configureOutput(simDir)) print(xtraParams) fmtS = "%g-nm-C-on-EagleXG-at-%g-kV" print("Starting simulation") multiLaySim = mc3.multiFilm(layers, det, e0, True, nTraj, dose, True, True, xtraParams) sName = fmtS % (tCNm, e0)
jmg.ensureDir(csvDir) # wd = homDir + relPrj + "/py/dtsa" wd = homDir + relPrj + "/py/dtsa" os.chdir(wd) pyrDir = wd + "/simPdLineInCuMatrix Results" #start clean DataManager.clearSpectrumList() # xrts=mc3.suggestTransitions("PdCu") xrts = [epq.XRayTransition(epq.Element.Cu, epq.XRayTransition.LA1), epq.XRayTransition(epq.Element.Pd, epq.XRayTransition.LA1)] xtraParams={} xtraParams.update(mc3.configureXRayAccumulators(xrts, charAccum=charF, charFluorAccum=charF, bremFluorAccum=bremF)) xtraParams.update(mc3.configureOutput(simDir)) xtraParams.update(mc3.configureBeam(0.5*nmLinWid*1.0e-9, 0, -0.099, 1.0)) # xtraParams.update(mc3.configureGun(gun)) # mc3.useHeatMapPalette() print(xtraParams) # spc = jm3.lineInMatrix(lin, blk, nmLinWid, umBlock, det, e0, withPoisson=True, nTraj=nTraj, dose=dose, sf=charF, bf=bremF, xtraParams=xtraParams) # spc = jm3.lineInMatrix(lin, blk, nmLinWid, umBlock, det, e0, poisN, nTraj, dose, charF, bremF, xtraParams) #e0=20.0, dose=defaultDose, withPoisson=poisN, nTraj=defaultNumTraj, sf=defaultCharFluor, bf=defaultBremFluor, xtraParams=defaultXtraParams): # spc = mc3.simulate(blk, det, e0, dose, poisN, nTraj, charF, bremF, xtraParams) # # Embedded Rectangle # # This works as expected.
def simLineInMatrixLimScan(lin, linMat, blk, blkMat, nmLinWid, umBlock,nmScan, nPts, trs, outDir, hdr, det, e0, lt, pc, withPoisson=True, nTraj=100, sf=True, bf=True, iDigits=5, bVerbose=False, xtraParams={}): """simLineInMatrixLimScan(lin, linMat, blk, blkMat, nmLinWid, umBlock, nmScan, nPts, trs, outDir, hdr, det, e0, lt, pc, withPoisson=True, nTraj=nTraj, sf=True, bf=True, iDigits=5, bVerbose=False, xtraParams={}) Simulate a line of width `nmLinWid' nm at the center of a block of `umBlock' microns. The line is of material `lin' with a name `linMat'. The block is of material `blk' with a name `blkMat'. We step a total distance of nmScan across the center of the line. We analyze an list `trs' of transitions, writing the K-ratios to a .csv file with a header `hdr'. We use the detector `det', voltage `e0' (kV) and live time `lt' sec and probe current `pc' nA. This will compute the standard spectra, compute the spectra the scanned region. It will then compute the K-ratios for each spectrum and write them to a file `name' in outDir with a header `hdr' that matches the transition order. """ # order is order of trs.. sc = 1.0e-6 # scale from microns to meters for positions dose = lt*pc lX = [] # an array for postions lKlin = [] # an array for the K-ratio of the line lKblk = [] # an array for the K-ratio of the block. Title correspond to hdr string umLine = nmLinWid * 1.0e-3 # start clean dt2.DataManager.clearSpectrumList() # create the standards linStd = simulateBulkStandard(lin, linMat, det, e0, lt, pc, withPoisson=withPoisson, nTraj=nTraj, sf=sf, bf=bf, xtraParams={}) dt2.display(linStd) blkStd = simulateBulkStandard(blk, blkMat, det, e0, lt, pc, withPoisson=withPoisson, nTraj=nTraj, sf=sf, bf=sf, xtraParams={}) dt2.display(blkStd) lStd = {"El":dt2.element(linMat), "Spc":linStd} bStd = {"El":dt2.element(blkMat), "Spc":blkStd} stds = [lStd, bStd] # note: put the transitions in this order iCount = 0 for x in range(-nPts/2, (nPts/2)+1, 1): xPosNm = x * nmScan / nPts lX.append(round(xPosNm, iDigits)) xtraParams={} xtraParams.update(mc3.configureXRayAccumulators(trs, charAccum=sf, charFluorAccum=sf, bremFluorAccum=bf)) xtraParams.update(mc3.configureOutput(outDir)) xtraParams.update(mc3.configureBeam(xPosNm*1.0e-09, 0, -0.099, 1.0)) spec = mc3.embeddedRectangle(lin, [umLine*sc, umBlock*sc, umBlock*sc], blk, 0, det, e0, withPoisson=withPoisson, nTraj=nTraj, dose=dose, sf=sf, bf=bf, xtraParams=xtraParams) props = spec.getProperties() props.setNumericProperty(epq.SpectrumProperties.LiveTime, lt) props.setNumericProperty(epq.SpectrumProperties.FaradayBegin, pc) props.setNumericProperty(epq.SpectrumProperties.FaradayEnd, pc) props.setNumericProperty(epq.SpectrumProperties.BeamEnergy, e0) spcName = "x = %.3f um" % x epq.SpectrumUtils.rename(spec, spcName) spec = epq.SpectrumUtils.addNoiseToSpectrum(spec, 1.0) # display(spec) a = jmg.compKRs(spec, stds, trs, det, e0) iCount += 1 print(iCount, xPosNm) lKlin.append(round(a[0], iDigits)) lKblk.append(round(a[1], iDigits)) basFile ="%gnm-%s-in-%gum-%s-%gkV-%g-Traj.csv" % (nmLinWid, linMat, umBlock, blkMat, e0, nTraj) strOutFile = outDir + "/" + basFile f=open(strOutFile, 'w') strLine = hdr + '\n' f.write(strLine) for i in range(iCount): strLine = "%.3f" % lX[i] + "," strLine = strLine + "%.5f" % lKlin[i] + "," strLine = strLine + "%.5f" % lKblk[i] + "\n" f.write(strLine) f.close()