diff --git a/tofu/data/_core.py b/tofu/data/_core.py index e587bf19d..4829cf64e 100644 --- a/tofu/data/_core.py +++ b/tofu/data/_core.py @@ -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 @@ -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 diff --git a/tofu/geom/_GG02.pyx b/tofu/geom/_GG02.pyx index fa0cf956a..0462264b8 100644 --- a/tofu/geom/_GG02.pyx +++ b/tofu/geom/_GG02.pyx @@ -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) @@ -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: @@ -2001,7 +2001,7 @@ def _Ves_Smesh_Lin_SubFromInd_cython(double[::1] XMinMax, double dL, double dX, LPts, LdS = [], [] # First face - ii = (ind0: indZ0 = ind[ii] // NY0 @@ -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) & (ind0: indX = (ind[ii]-NY0*NZ0) // Ln @@ -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 diff --git a/tofu/geom/_GG03.pyx b/tofu/geom/_GG03.pyx index fa0cf956a..0462264b8 100644 --- a/tofu/geom/_GG03.pyx +++ b/tofu/geom/_GG03.pyx @@ -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) @@ -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: @@ -2001,7 +2001,7 @@ def _Ves_Smesh_Lin_SubFromInd_cython(double[::1] XMinMax, double dL, double dX, LPts, LdS = [], [] # First face - ii = (ind0: indZ0 = ind[ii] // NY0 @@ -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) & (ind0: indX = (ind[ii]-NY0*NZ0) // Ln @@ -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 diff --git a/tofu/geom/_core.py b/tofu/geom/_core.py index d184d9c37..b4758261a 100644 --- a/tofu/geom/_core.py +++ b/tofu/geom/_core.py @@ -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: @@ -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, diff --git a/tofu/tests/tests01_geom/tests01_GG.py b/tofu/tests/tests01_geom/tests01_GG.py index 974b0de92..9609132da 100644 --- a/tofu/tests/tests01_geom/tests01_GG.py +++ b/tofu/tests/tests01_geom/tests01_GG.py @@ -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 @@ -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() # ... diff --git a/tofu/tests/tests02_data/tests03_core.py b/tofu/tests/tests02_data/tests03_core.py index 2dbe55793..1d526102f 100644 --- a/tofu/tests/tests02_data/tests03_core.py +++ b/tofu/tests/tests02_data/tests03_core.py @@ -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