Skip to content

Commit

Permalink
Wrapping ready
Browse files Browse the repository at this point in the history
  • Loading branch information
vasole committed May 2, 2023
1 parent 4288bc2 commit 76d59de
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
24 changes: 23 additions & 1 deletion python/cython/PyXRF.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ from libcpp.map cimport map as std_map
from XRF cimport *
from Layer cimport *
from TransmissionTable cimport *
from Beam cimport *

cdef class PyXRF:
cdef XRF *thisptr
Expand Down Expand Up @@ -393,6 +394,10 @@ cdef class PyXRF:
cdef std_vector[std_string] lineFamiliesVector
cdef std_map[std_string, std_map[int, std_map[std_string, std_map[std_string, double]]]] result
cdef Beam beamInstance = Beam();
cdef std_vector[double] beamEnergies
cdef std_vector[double] beamWeights
cdef std_vector[int] dummyIntVec
cdef std_vector[double] dummyDoubleVec

if hasattr(elementNames[0], "__len__"):
# we have received a list of elements
Expand All @@ -415,6 +420,23 @@ cdef class PyXRF:
# we should have a peak family, convert to list
lineFamily = [lineFamily]

if beam:
# for the time being only a list expected
if not hasattr(beam, "__len__"):
# assume a single energy
beamEnergies.push_back(beam)
elif len(beam):
if hasattr(beam[0], "__len__"):
# at the very least have energies and weights
for item in beam:
beamEnergies.push_back(item[0])
beamWeights.push_back(item[1])
else:
# we have a list of energies
for item in beam:
beamEnergies.push_back(item)
beamInstance.setBeam(beamEnergies, beamWeights, dummyIntVec, dummyDoubleVec)

# check the sizes match
if len(lineFamily) != len(elementNames):
raise IndexError("Number of elements should match the number of requested peak families")
Expand All @@ -436,7 +458,7 @@ cdef class PyXRF:
with nogil:
result = self.thisptr.getMultilayerFluorescence(elementNamesVector, deref(elementsLibrary.thisptr), \
sampleLayerIndicesVector, lineFamiliesVector, secondary, useGeometricEfficiency, useMassFractions, \
secondaryCalculationLimit, beam)
secondaryCalculationLimit, beamInstance)

return toStringKeysAndValues(result)

Expand Down
1 change: 1 addition & 0 deletions python/fisx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from ._fisx import PySimpleSpecfile as SimpleSpecfile
from ._fisx import PyEPDL97 as EPDL97
from ._fisx import PyShell as Shell
from ._fisx import PyBeam as Beam
from ._fisx import PyElement as Element
from ._fisx import PyElements as Elements
from ._fisx import PyLayer as Layer
Expand Down

0 comments on commit 76d59de

Please sign in to comment.