def compareCompositions(specs, comp, withSigma=False, normalize=False, prop=epq.SpectrumProperties.MicroanalyticalComposition): """Syntax: compareCompositions(specs, comp=createMaterial(), [withSigma=False], [normalize=False], [prop=epq.SpectrumProperties.MicroanalyticalComposition] Tabulate the comparison between the compositions of the specified spectra with the specified composition.""" res = {} elms = ju.TreeSet() for spec in specs: c = spec.getProperties().getObjectWithDefault(prop, None) if c != None: res[spec] = c elms.addAll(c.getElementSet()) str = "Name" for elm in elms: str = "%s\t%s-diff\t%s-frac" % (str, elm.toAbbrev(), elm.toAbbrev()) if withSigma: str = "%s\t%s-sig" % (str, elm.toAbbrev()) print str str="Nominal" for elm in elms: str = "%s\t%g\t" % (str, comp.weightFraction(elm,normalize)*100) if withSigma: str="%s\t" % str print str for spec in res: c = res[spec] str = "%s" % spec for elm in elms: u = c.weightFractionU(elm, normalize) err = 100 *(u.doubleValue()-comp.weightFraction(elm,normalize)) str = "%s\t%g\t%g" % (str, err, err/comp.weightFraction(elm,normalize)) if withSigma: if u.uncertainty()>0: str = "%s\t%g" % (str, err / (100.0 * u.uncertainty())) else: str = "%s\t-" % str print str
def tabulateCompositions2(specs, withErrs=False, normalize=False, prop=epq.SpectrumProperties.MicroanalyticalComposition): """Syntax: tabulateCompositions2(specs,[withErrs=False],[normalize=False],[prop=epq.SpectrumProperties.MicroanalyticalComposition]) Tabulate the compositions associated with the specified collection of spectra. Rows represent spectra and columns represent elements.""" res = {} elms = ju.TreeSet() for spec in specs: c = spec.getProperties().getObjectWithDefault(prop, None) if c != None: res[spec] = c elms.addAll(c.getElementSet()) str = "Name" for elm in elms: str = "%s\t%s" % (str, elm.toAbbrev()) if withErrs: str = "%s\td%s" % (str, elm.toAbbrev()) print str for spec in res: c = res[spec] str = "%s" % spec for elm in elms: u = c.weightFractionU(elm, normalize) str = "%s\t%g" % (str, 100 * u.doubleValue()) if withErrs: str = "%s\t%g" % (str, 100.0 * u.uncertainty()) print str
def compStats(comps, norm=0): """compStats(comps, norm=0) Compute compositional statistics for the list of Composition objects. Parameters ---------- comps A list of Composition objects. Example: [comp1, comp2, comp3] norm An integer. Default: 0. If norm=1, the Composition objects are normalized to 100%; otherwise not. Returns ------- None. Prints results to the command line """ elms = ju.TreeSet() for comp in comps: elms.addAll(comp.getElementSet()) dss = dict() for elm in elms: dss[elm] = epu.DescriptiveStatistics() for comp in comps: for elm in elms: dss[elm].add(comp.weightPercent(elm, norm)) return dss
def compStats(comps, norm=False): """Syntax: compStats([comp1,comp2,...,compN],norm=False) Compute compositional statistics for the list of Composition objects. If norm=1, then the Composition objects are normalized to 100%; otherwise not.""" elms = ju.TreeSet() for comp in comps: elms.addAll(comp.getElementSet()) dss = {} for elm in elms: dss[elm] = epu.DescriptiveStatistics() for comp in comps: for elm in elms: dss[elm].add(comp.weightPercent(elm, norm)) return dss
def to10dash1(action_code, sample_id, specs, instrument_analysis_date, analysis_lab_id="N", srm_id="IIIE", pkg_lab_id="N", instrument="E", instrument_number="2", spot_size="5", operator="NWMR", spectrometer="EDS15", comment={}): """to10dash1( action_code, sample_id, specs, instrument_analysis_date, analysis_lab_id="N", srm_id="IIIE", pkg_lab_id="N", instrument="I", instrument_number="1", spot_size="5", operator="NWMR", spectrometer="EDS15", comment={} ) * action_code = "N", "R" or "D" * sample_id unique id * specs = selected() or a list of spectra * instrument_analysis_date = "10-DEC-2020" or equivalent for date of acquisition * srm_id = "IIIX" where "X" is the letter of your block * pkg_lab and analysis_lab_id = your lab ID letter * instrument - Instrument id * spot_size a number in unspecified units as a string * operator = "Your initials" * spectrometer = the spectrometer ID * comment = { element("Fe"):"Eat more iron", element("Si"):"Sillycone" } or similar The function prints a line per element for each element in the "MicroanalyticalComposition" property of the selected spectra. The selected spectra are assumed to come from the same material. The "_error" columns reflect the standard deviation between the spectra not the single spectrum uncertainty.""" def savg(vals): s = 0.0 for val in vals: s = s + val return s / len(vals) def sstd(vals): s, s2 = savg(vals), 0.0 for val in vals: s2 += (val - s) * (val - s) return jl.Math.sqrt(s2 / len(vals)) elms = ju.TreeSet() props = specs[0].getProperties() e0 = props.getNumericProperty(epq.SpectrumProperties.BeamEnergy) beam_current = "%0.3f" % (props.getNumericProperty( epq.SpectrumProperties.FaradayBegin), ) for spec in specs: mat = spec.getProperties().getObjectProperty( epq.SpectrumProperties.MicroanalyticalComposition) elms.addAll(mat.getElementSet()) for elm in elms: comment.setifabsent(elm, "") wfa, afa, ks, cr = {}, {}, {}, [] for spec in specs: props = spec.getProperties() mat = props.getObjectProperty( epq.SpectrumProperties.MicroanalyticalComposition) krs = props.getObjectProperty(epq.SpectrumProperties.OptimalKRatios) cr.append( epq.SpectrumUtils.integrate(spec, 100.0, 1000.0 * e0) / props.getNumericProperty(epq.SpectrumProperties.LiveTime)) for elm in elms: wfa.setifabsent(elm, []), afa.setifabsent(elm, []), ks.setifabsent(elm, []), wfa[elm].append(mat.weightFraction(elm, False)) afa[elm].append(mat.atomicPercent(elm)) xrts = krs.optimalDatum(elm) ks[elm].append(krs.getKRatio(xrts) if xrts != None else 0.0) full = "" for elm in elms: weight_percent = "%0.2f" % (100.0 * savg(wfa[elm]), ) weight_percent_error = "%0.2f" % (100.0 * sstd(wfa[elm]), ) atom_percent = "%0.2f" % (100.0 * savg(afa[elm]), ) atom_percent_error = "%0.2f" % (100.0 * sstd(afa[elm]), ) amount = ("MAJOR" if weight_percent > 10.0 else ("MINOR" if weight_percent > 1.0 else "TRACE")) k_value = "%0.4f" % (savg(ks[elm]), ) normalization_factor = "" normalization_model = "" count_rate = "%0.0f" % (savg(cr)) diffracting_crystal = "NA" incident_beam_energy = "%0.1f" % (e0, ) star_elemental_comments = comment[elm] element = str(jl.String(elm.toAbbrev()).toUpperCase()) item = (action_code, sample_id, srm_id, pkg_lab_id, analysis_lab_id, element, instrument, instrument_number, instrument_analysis_date, operator, weight_percent, weight_percent_error, atom_percent, atom_percent_error, amount, k_value, normalization_factor, normalization_model, count_rate, diffracting_crystal, spectrometer, e0, beam_current, spot_size, star_elemental_comments) res = "%1s%07i %-6s %1s %1s %-3s %-2s %-3s %-11s %12s %12s %12s %12s %12s %5s %12s %12s %3s %12s %-6s %5s %4s %5s %5s %s" % item full = "%s%s\n" % (full, res) print(res) return full[0:-1]