News:

:) If you are a member, please feel free to add your website URL to your forum profile

Main Menu

Error from EPQLibrary.QuantifyUsingStandards()

Started by Clueless Micky, November 06, 2025, 06:18:31 AM

Previous topic - Next topic

Clueless Micky

Hello forum participants,

I'm encountering an error when trying to use the function EPQLibrary.QuantifyUsingStandards().

The following minimum code example
e0 = 15
detx = Database.findDetector('SDD (Medium, 4096)')
qus = epq.QuantifyUsingStandards(detx, epq.ToSI.keV(e0))

results in the error
TypeError: gov.nist.microanalysis.EPQLibrary.QuantifyUsingStandards(): expected 4 args; got 2

From the documentation of the function it seems that providing two arguments should be correct. What am I doing wrong?


Background to my question:

Using the DTSA-II GUI, I ran a quantification on the "K240 example" data set from the DTSA-II homepage, with the resulting composition closely matching that reported in the literature.

Now I want to learn how to reproduce this quantification using a Python script.

After dutifully reading in all the standard and reference spectra, and associating them with compositions as follows:
file_Benitoite = 'Benitoite 15 keV[Wed May  4 140614 2016][all].msa'
comp_Benitoite = 'BaTiSi3O9'

spec_Benitoite = wrap( readSpectrum( dir_spectra + '\\' + file_Benitoite ) )
spec_Benitoite.setAsMicroanalyticalComposition( comp_Benitoite )

and alike for all other materials, my script goes on like this:
detx = Database.findDetector('SDD (Medium, 4096)')

prop_unk = spec_unk.getProperties()
prop_unk.setDetector( detx )

quantification = quantify( spec_unk, { "Ti":spec_Benitoite, "Ba":spec_Sanbornite, "Si":spec_Sanbornite, "O":spec_Sanbornite, "Mg":spec_Mg, "Zn":spec_Zn, "Zr":spec_Zr }, refs = { "Si":spec_SiO2, "O":spec_SiO2, "Ti":spec_Ti } )

which results in the error message
File "myscript.py", line 73, in <module>
    quantification = quantify( spec_unk, { "Ti":spec_Benitoite, "Ba":spec_Sanbornite, "Si":spec_Sanbornite, "O":spec_Sanbornite, "Mg":spec_Mg, "Zn":spec_Zn, "Zr":spec_Zr }, refs = { "Si":spec_SiO2, "O":spec_SiO2, "Ti":spec_Ti } )

File "C:\Program Files\NIST\NIST DTSA-II Oberon 2024-11-22\Lib\dtsa2\__init__.py", line 1324, in quantify
    qus = multiQuant(det, e0, stds, refs, preferred, elmByDiff, oByStoic, oxidizer, extraKRatios, fiat)

File "C:\Program Files\NIST\NIST DTSA-II Oberon 2024-11-22\Lib\dtsa2\__init__.py", line 1262, in multiQuant
    qus = epq.QuantifyUsingStandards(det, epq.ToSI.keV(e0))

TypeError: gov.nist.microanalysis.EPQLibrary.QuantifyUsingStandards(): expected 4 args; got 2

i.e. the built-in function quantify() calls the function EPQLibrary.QuantifyUsingStandards() and results in the same error as the code example quoted at the beginning of my post.

Many thanks for any insights you can provide!

Clueless Micky

Looking at the Nicholas Ritchie's Github repository with the Java source code of the function QuantifyUsingStandards(), it appears from the "Blame" timeline that some time in June 2025, he already fixed the problem with this function that I described in my original post, by adding the missing definition
public QuantifyUsingStandards(final EDSDetector det, final double beamEnergy)
that takes only two arguments. So I presume this problem will be gone in the next release of DTSA II.

For now, I'm bypassing the issue by defining my own versions of the functions quantify() and multiQuant(), copying the code from the file "__init__.py", but replacing the line
qus = epq.QuantifyUsingStandards(det, epq.ToSI.keV(e0))
by
qus = epq.QuantifyUsingStandards(det, epq.ToSI.keV(e0), False, True)
which seems to work correctly for the moment.

Nicholas Ritchie

"Do what you can, with what you have, where you are"
  - Teddy Roosevelt