Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions tofu/data/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,35 @@
#############################################

def _format_ind(ind=None, n=None):
"""Helper routine to convert selected channels (as numbers) in `ind` to
a boolean array format.

Parameters
----------
ind : integer, or list of integers
A channel or a list of channels that the user wants to select.
n : integer, or None
The total number of available channels.

Returns
-------
ind : ndarray of booleans, size (n,)
The array with the selected channels set to True, remaining ones set
to False


Examples
--------

>>> _format_ind(ind=[0, 3], n=4)
[True, False, False, True]

"""
if ind is None:
ind = np.ones((n,),dtype=bool)
else:
lInt = [int,np.int64]
# list of accepted integer types
lInt = [int, np.int64, np.int32, np.int_, np.longlong]
if type(ind) in lInt:
ii = np.zeros((n,),dtype=bool)
ii[int(ii)] = True
Expand All @@ -65,7 +90,10 @@ def _format_ind(ind=None, n=None):
ii[ind] = True
ind = ii
else:
msg = "Index must be a int, or an iterable of bool or int !"
msg = ("Index must be int, or an iterable of bool or int "
"(first element of index has"
" type: {})!".format(type(ind[0]))
)
raise Exception(msg)
return ind

Expand Down
10 changes: 5 additions & 5 deletions tofu/geom/_GG02.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ def _Ves_Smesh_Tor_SubFromD_cython(double dL, double dRPhi,
PtsCross, dLr, indL, Rref = PtsCross[:,indin], dLr[indin], \
indL[indin], Rref[indin]
Ln = indin.sum()
Indin = indin.nonzero()[0]
Indin = indin.nonzero()[0].astype(np.long)

dRPhir, dPhir = np.empty((Ln,)), np.empty((Ln,))
Phin = np.zeros((Ln,),dtype=int)
Expand Down Expand Up @@ -1471,7 +1471,7 @@ def _Ves_Smesh_Tor_SubFromD_cython(double dL, double dRPhi,
ind[NP] = NRPhi0[ii] + indiijj
dS[NP] = dLr[ii]*dRPhir[ii]
NP += 1
indok = (~np.isnan(ind)).nonzero()[0]
indok = (~np.isnan(ind)).nonzero()[0].astype(np.long)
ind = ind[indok]
dS = dS[indok]
if len(indok)==1:
Expand Down Expand Up @@ -2001,7 +2001,7 @@ def _Ves_Smesh_Lin_SubFromInd_cython(double[::1] XMinMax, double dL, double dX,

LPts, LdS = [], []
# First face
ii = (ind<NY0*NZ0).nonzero()[0]
ii = (ind<NY0*NZ0).nonzero()[0].astype(np.long)
nii = len(ii)
if nii>0:
indZ0 = ind[ii] // NY0
Expand All @@ -2013,7 +2013,7 @@ def _Ves_Smesh_Lin_SubFromInd_cython(double[::1] XMinMax, double dL, double dX,
LdS.append( dY0r*dZ0r*np.ones((nii,)) )

# Cylinder
ii = ((ind>=NY0*NZ0) & (ind<NY0*NZ0+NX*Ln)).nonzero()[0]
ii = ((ind>=NY0*NZ0) & (ind<NY0*NZ0+NX*Ln)).nonzero()[0].astype(np.long)
nii = len(ii)
if nii>0:
indX = (ind[ii]-NY0*NZ0) // Ln
Expand All @@ -2026,7 +2026,7 @@ def _Ves_Smesh_Lin_SubFromInd_cython(double[::1] XMinMax, double dL, double dX,
LdS.append( dXr*dLr[indL] )

# End face
ii = (ind >= NY0*NZ0+NX*Ln).nonzero()[0]
ii = (ind >= NY0*NZ0+NX*Ln).nonzero()[0].astype(np.long)
nii = len(ii)
if nii>0:
indZ0 = (ind[ii]-NY0*NZ0-NX*Ln) // NY0
Expand Down
10 changes: 5 additions & 5 deletions tofu/geom/_GG03.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ def _Ves_Smesh_Tor_SubFromD_cython(double dL, double dRPhi,
PtsCross, dLr, indL, Rref = PtsCross[:,indin], dLr[indin], \
indL[indin], Rref[indin]
Ln = indin.sum()
Indin = indin.nonzero()[0]
Indin = indin.nonzero()[0].astype(np.long)

dRPhir, dPhir = np.empty((Ln,)), np.empty((Ln,))
Phin = np.zeros((Ln,),dtype=int)
Expand Down Expand Up @@ -1471,7 +1471,7 @@ def _Ves_Smesh_Tor_SubFromD_cython(double dL, double dRPhi,
ind[NP] = NRPhi0[ii] + indiijj
dS[NP] = dLr[ii]*dRPhir[ii]
NP += 1
indok = (~np.isnan(ind)).nonzero()[0]
indok = (~np.isnan(ind)).nonzero()[0].astype(np.long)
ind = ind[indok]
dS = dS[indok]
if len(indok)==1:
Expand Down Expand Up @@ -2001,7 +2001,7 @@ def _Ves_Smesh_Lin_SubFromInd_cython(double[::1] XMinMax, double dL, double dX,

LPts, LdS = [], []
# First face
ii = (ind<NY0*NZ0).nonzero()[0]
ii = (ind<NY0*NZ0).nonzero()[0].astype(np.long)
nii = len(ii)
if nii>0:
indZ0 = ind[ii] // NY0
Expand All @@ -2013,7 +2013,7 @@ def _Ves_Smesh_Lin_SubFromInd_cython(double[::1] XMinMax, double dL, double dX,
LdS.append( dY0r*dZ0r*np.ones((nii,)) )

# Cylinder
ii = ((ind>=NY0*NZ0) & (ind<NY0*NZ0+NX*Ln)).nonzero()[0]
ii = ((ind>=NY0*NZ0) & (ind<NY0*NZ0+NX*Ln)).nonzero()[0].astype(np.long)
nii = len(ii)
if nii>0:
indX = (ind[ii]-NY0*NZ0) // Ln
Expand All @@ -2026,7 +2026,7 @@ def _Ves_Smesh_Lin_SubFromInd_cython(double[::1] XMinMax, double dL, double dX,
LdS.append( dXr*dLr[indL] )

# End face
ii = (ind >= NY0*NZ0+NX*Ln).nonzero()[0]
ii = (ind >= NY0*NZ0+NX*Ln).nonzero()[0].astype(np.long)
nii = len(ii)
if nii>0:
indZ0 = (ind[ii]-NY0*NZ0-NX*Ln) // NY0
Expand Down
4 changes: 2 additions & 2 deletions tofu/geom/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4290,7 +4290,7 @@ def _check_indch(self, ind, out=int):
if ind is not None:
ind = np.asarray(ind)
assert ind.ndim==1
assert ind.dtype in [np.int64,np.bool_]
assert ind.dtype in [np.int64, np.bool_, np.long]
if ind.dtype == np.bool_:
assert ind.size==self.nRays
if out is int:
Expand Down Expand Up @@ -5365,7 +5365,7 @@ def plot_touch(self, key=None, quant='lengths', invert=None, ind=None,
useful for assessing reflection probabilities)
- 'indices': the index of each LOS
(useful for checking numbering)
- 'Etendues': the étendue associated to each LOS (user-provided)
- 'Etendues': the etendue associated to each LOS (user-provided)
- 'Surfaces': the surfaces associated to each LOS (user-provided)
"""
out = _plot.Rays_plot_touch(self, key=key, Bck=Bck,
Expand Down
4 changes: 2 additions & 2 deletions tofu/tests/tests01_geom/tests01_GG.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ def test13_LOS_PInOut():
SL2 = np.asarray([np.array([2./3.,1.])*2.*np.pi])
lspolyx = np.asarray(SP0x + SP1x + SP2x)
lspolyy = np.asarray(SP0y + SP1y + SP2y)
lnvert = np.cumsum(np.ones(nstruct_tot, dtype=np.int64)*5)
lnvert = np.cumsum(np.ones(nstruct_tot, dtype=np.long)*5)
lsvinx = np.asarray([VIn[0], VIn[0], VIn[0]]).flatten()
lsviny = np.asarray([VIn[1], VIn[1], VIn[1]]).flatten()
# Linear without Struct
Expand Down Expand Up @@ -1804,7 +1804,7 @@ def test24_is_visible():
SL2 = np.asarray([np.array([2./3.,1.])*2.*np.pi])
lspolyx = np.asarray(SP0x + SP1x + SP2x)
lspolyy = np.asarray(SP0y + SP1y + SP2y)
lnvert = np.cumsum(np.ones(nstruct_tot, dtype=np.int64)*5)
lnvert = np.cumsum(np.ones(nstruct_tot, dtype=np.long)*5)
lsvinx = np.asarray([VIn[0], VIn[0], VIn[0]]).flatten()
lsviny = np.asarray([VIn[1], VIn[1], VIn[1]]).flatten()
# ...
Expand Down
2 changes: 1 addition & 1 deletion tofu/tests/tests02_data/tests03_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def test09_dtreat_set_interp_indt(self):

def test10_dtreat_set_interp_indch(self):
for oo in self.lobj:
ind = np.arange(0,oo.nch,10)
ind = np.arange(0, oo.nch, 10, dtype=np.long)
oo.set_dtreat_interp_indch( ind )
assert oo._dtreat['interp-indch'].sum() == ind.size

Expand Down