Author Topic: EPQ library interface  (Read 1980 times)

John Donovan

  • Administrator
  • Emeritus
  • *****
  • Posts: 2426
  • Other duties as assigned...
    • Probe Software
EPQ library interface
« on: May 19, 2016, 03:31:43 am »
Hi Nicholas,
You mentioned that there might be an product that provides an interface between VB.net and Java...  if you can provide any details about it, I would be quite interested.

I'm particularly interested in your peak stripping routines that you mentioned are in the EPQ library, and wonder if you could provide a short list of the functions one would need to do this.  Basically I think there would need to be functions for loading spectra and specifying the elements and x-ray lines for the desired net intensities, loading standard profiles and anything else you think might be useful.

Thanks in advance.
john
John J. Donovan, Pres. 
(541) 343-3400

"Not Absolutely Certain, Yet Reliable"

NicholasRitchie

  • Moderator
  • Post Doc
  • *****
  • Posts: 21
    • NIST DTSA-II
Re: EPQ library interface
« Reply #1 on: May 20, 2016, 01:07:32 pm »
John,
   DTSA-II is divided into two pieces - epq.jar which provides algorithms and dtsa2.jar which provides the GUI.  Both of them are Java libraries.  Java is designed to be cross-platform and so doesn't tend to play friendly with operating system / CPU architecture specific code.  However, there are bridges that permit using Java libraries in other programming environments.  One that I know others have used with some success is the IKVM (http://www.ikvm.net/), a mechanism to use Java libraries in Microsoft's .NET environment.  I'm sure there are other bridges like IKVM for other platforms but I'm not familiar with them.
   I understand that you have plans to port the Probe software to the .NET BASIC variant.  IKVM might allow you to call the epq.jar library as though it was a native .NET library.
   As to quantifying with DTSA-II, the best examples are from the Jython code integrated into the command line console. (Look in the \Libs\dtsa2\_init_.py file)

def multiQuant(det, e0, stds, refs={}, preferred=(), elmByDiff=None, oByStoic=False, oxidizer=None, xtraKRatios=None):
   """multiQuant(det, e0, stds, refs={}, preferred=(), oByStoic=False, oxidizer=None, xtraKRatios=None)
Configure a QuantifyUsingStandards object which can be then used to quantifying multiple spectra.
Example:
    qus=multiQuant(det,e0,stds,refs)
    for spec in map:
        res=qus.compute(unknown)
        print res.getComposition()
       
+ det - The epq.EDSDetector
+ e0 - The beam energy in keV
+ stds - A dictionary mapping epq.Element into an ISpectrumData derived object
+ refs - (optional) A dictionary mapping an x-ray transition or x-ray transition set into an ISpectrumData object
+ preferred - (optional) A collection of XRayTransition objects specifying the preferred line for quantification
+ elmByDiff - (optional) Element to compute by difference from 100%
+ oByStoic - (optional) True to calculate oxygen by stoichiometry, False otherwise
+ oxidizer - (optional) An epq.Oxidizer object to use in place of the default epq.Oxidizer()
+ xtraKRatios - (optional) A list of elements each of which looks like (xrt , kratio, stdMat, props)
   where xrt is an XRayTransition(Set), kratio is a double/UncertainValue2, stdMat is a Composition and props is SpectrumProperties."""
   qus = epq.QuantifyUsingStandards(det, epq.ToSI.keV(e0))
   for elm, spec in stds.iteritems():
      elm = element(elm)
      sp = spec.getProperties()
      sp.setDetector(det)
      comp = sp.getCompositionProperty(epq.SpectrumProperties.StandardComposition)
      qus.addStandard(elm, comp, spec)
   for xrt, spec in refs.iteritems():
      xrt = transition(xrt)
      elm = xrt.getElement()
      for roi in qus.getStandardROIS(elm):
         if roi.contains(xrt):
            comp = epq.SpectrumUtils.getComposition(spec)             
            if not comp:
                comp = spec.getProperties().getElements()
            if not comp:
                comp = epq.Composition(elm)
            qus.addReference(roi, spec, comp)
   for xrt in preferred:
      xrt = transition(xrt)
      elm = xrt.getElement()
      for roi in qus.getStandardROIS(elm):
         if roi.contains(xrt):
            qus.setPreferredROI(roi)
   if isinstance(elmByDiff, epq.Element) or isinstance(elmByDiff, str):
      elmByDiff = element(elmByDiff)
      qus.addUnmeasuredElementRule(epq.CompositionFromKRatios.ElementByDifference(elmByDiff))
   if oByStoic:
      uer = epq.CompositionFromKRatios.OxygenByStoichiometry(map(element, stds.keys()))
      if not oxidizer:
          oxidizer=epq.Oxidizer()
      uer.setOxidizer(oxidizer)
      qus.addUnmeasuredElementRule(uer)
   if xtraKRatios:
       for xrt, kr, comp, props in xtraKRatios:
           qus.addExtraKRatio(transition(xrt), kr, material(comp), props)     
   return qus   

def quantify(unknown, stds, refs={}, preferred=(), elmByDiff=None, oByStoic=False, oxidizer=None, extraKRatios=None):
    """quantify(unk, stds, refs={}, preferred=(), elmByDiff = None, oByStoic=False, oxidizer=None, extraKRatios=None)
    Quantify an unknown spectrum against a set of standard spectra.  You can optionally provide a set of \
references to use for shape information. 
+ unknown - An ISpectrumData derived object with EDSDetector defined
+ stds - A dictionary mapping epq.Element into an ISpectrumData derived object
+ refs - (optional) A dictionary mapping an x-ray transition or x-ray transition set into an ISpectrumData object
+ preferred - (optional) A collection of XRayTransition objects specifying the preferred line for quantification
+ elmByDiff - (optional) Element to compute by difference from 100%
+ oByStoic - (optional) True to calculate oxygen by stoichiometry, False otherwise
+ oxidizer - (optional) An epq.Oxidizer object to use in place of the default set
+ xtraKRatios - (optional) A list of elements each of which looks like (xrt , kratio, stdMat, props)
   where xrt is an XRayTransition(Set), kratio is a double/UncertainValue2, stdMat is a Composition and props is SpectrumProperties."""
    det = unknown.getProperties().getDetector()
    e0 = unknown.getProperties().getNumericProperty(epq.SpectrumProperties.BeamEnergy)
    qus = multiQuant(det, e0, stds, refs, preferred, elmByDiff, oByStoic, oxidizer, extraKRatios)
    return qus.compute(unknown)
   


multiQuant sets up an object that can then be used to quantify multiple spectra (all against the same standards using the same references.)

quant is a  wrapper for quantifying one spectrum.  It calls multiQuant to set up the quantification and then passes the unknown and returns an object representing the result (Composition, residuals, ....)

My suggestion is to learn how to use epq.jar within the Jython environment first.  You can use Jython to explore the library.  Every class and public method is exposed through Jython.  On the documentation page on the DTSA-II web site, you will find help with scripting in the form of two presentations - one focuses on quantification and the other on basic scripting.

Nicholas

John Donovan

  • Administrator
  • Emeritus
  • *****
  • Posts: 2426
  • Other duties as assigned...
    • Probe Software
Re: EPQ library interface
« Reply #2 on: May 20, 2016, 05:48:13 pm »
John,
   DTSA-II is divided into two pieces - epq.jar which provides algorithms and dtsa2.jar which provides the GUI.  Both of them are Java libraries.  Java is designed to be cross-platform and so doesn't tend to play friendly with operating system / CPU architecture specific code.  However, there are bridges that permit using Java libraries in other programming environments.  One that I know others have used with some success is the IKVM (http://www.ikvm.net/), a mechanism to use Java libraries in Microsoft's .NET environment.  I'm sure there are other bridges like IKVM for other platforms but I'm not familiar with them.
   I understand that you have plans to port the Probe software to the .NET BASIC variant.  IKVM might allow you to call the epq.jar library as though it was a native .NET library.
   As to quantifying with DTSA-II, the best examples are from the Jython code integrated into the command line console. (Look in the \Libs\dtsa2\_init_.py file)


Hi Nicholas,
Thank-you so much for all this info, I really appreciate it.

Wasn't the EPMA 2016 TC this week wonderful?  We're heading to Julien's lab in Boulder to do his 8230 install and then back to good ol' Oregon!
john
John J. Donovan, Pres. 
(541) 343-3400

"Not Absolutely Certain, Yet Reliable"