diff --git a/examples/tutorials/tuto_plot_custom_emissivity.py b/examples/tutorials/tuto_plot_custom_emissivity.py index dc8676037..9d05cdb2c 100644 --- a/examples/tutorials/tuto_plot_custom_emissivity.py +++ b/examples/tutorials/tuto_plot_custom_emissivity.py @@ -31,13 +31,15 @@ # Now, we define an emissivity function that depends on r and z coordinates. # We can plot its profile in the (0, X, Z) plane. + def emissivity(pts, t=None, vect=None): """Custom emissivity as a function of geometry. :param pts: ndarray of shape (3, n_points) (each column is a xyz coordinate) :param t: optional, time parameter to add a time dependency to the emissivity function - :param vect: + :param vect: optional, ndarray of shape (3, n_points), if anisotropic + emissivity, unit direction vectors (X,Y,Z) :return: - emissivity -- 2D array holding the emissivity for each point in the input grid @@ -88,6 +90,7 @@ def project_to_2D(xyz): method="sum", newcalc=True, plot=False, + ani=False, t=time_vector) sig.plot(ntMax=1) diff --git a/tofu/geom/_GG.pyx b/tofu/geom/_GG.pyx index b2c54e936..4ffa3a155 100644 --- a/tofu/geom/_GG.pyx +++ b/tofu/geom/_GG.pyx @@ -2860,7 +2860,6 @@ def LOS_calc_signal(func, double[:,::1] ray_orig, double[:,::1] ray_vdir, res, cdef double[1] loc_eff_res cdef double[::1] reseff_mv cdef double[::1] res_mv - cdef double[::1,:] sig_mv cdef double[:,::1] val_mv cdef double[:,::1] pts_mv cdef double[:,::1] usbis_mv @@ -2928,7 +2927,6 @@ def LOS_calc_signal(func, double[:,::1] ray_orig, double[:,::1] ray_vdir, res, n_imode = _st.get_nb_imode(imode) # Initialization result sig = np.empty((nt, nlos), dtype=float, order='F') - sig_mv = sig # If the resolution is the same for every LOS, we create a tab if res_is_list : res_arr = np.asarray(res) @@ -3025,11 +3023,12 @@ def LOS_calc_signal(func, double[:,::1] ray_orig, double[:,::1] ray_vdir, res, pts, usbis = _st.call_get_sample_single_ani(lims[0, ii], lims[1, ii], res_mv[ii], - n_dmode, n_imode, + n_dmode, + n_imode, &loc_eff_res[0], &nb_rows[0], - ray_orig[:,ii:ii+1], - ray_vdir[:,ii:ii+1]) + ray_orig[:, ii:ii+1], + ray_vdir[:, ii:ii+1]) # loop over time for calling and integrating for jj in range(nt): val = func(pts, t=ltime[jj], vect=-usbis, **fkwdargs) @@ -3129,7 +3128,7 @@ def LOS_calc_signal(func, double[:,::1] ray_orig, double[:,::1] ray_vdir, res, ray_orig[:, ii:ii+1], ray_vdir[:, ii:ii+1]) val_2d = func(pts, t=t, vect=-usbis, **fkwdargs) - sig_mv[:, ii] = np.sum(val_2d, axis=-1)*loc_eff_res[0] + sig[:, ii] = np.sum(val_2d, axis=-1)*loc_eff_res[0] elif n_imode == 1: # simpson integration mode for ii in range(nlos): pts, usbis = _st.call_get_sample_single_ani(lims[0, ii], @@ -3162,39 +3161,42 @@ def LOS_calc_signal(func, double[:,::1] ray_orig, double[:,::1] ray_vdir, res, # -- not anisotropic ----------------------------------------------- if n_imode == 0: # "sum" integration mode for ii in range(nlos): - pts = _st.call_get_sample_single(lims[0,ii], lims[1,ii], + pts = _st.call_get_sample_single(lims[0, ii], + lims[1, ii], res_mv[ii], n_dmode, n_imode, &loc_eff_res[0], &nb_rows[0], - ray_orig[:,ii:ii+1], - ray_vdir[:,ii:ii+1]) + ray_orig[:, ii:ii+1], + ray_vdir[:, ii:ii+1]) val_2d = func(pts, t=t, **fkwdargs) - sig[:, ii] = np.sum(val_2d,axis=-1)*loc_eff_res[0] + sig[:, ii] = np.sum(val_2d, axis=-1)*loc_eff_res[0] elif n_imode == 1: # "simpson" integration mode for ii in range(nlos): - pts = _st.call_get_sample_single(lims[0,ii], lims[1,ii], + pts = _st.call_get_sample_single(lims[0, ii], + lims[1, ii], res_mv[ii], n_dmode, n_imode, &loc_eff_res[0], &nb_rows[0], - ray_orig[:,ii:ii+1], - ray_vdir[:,ii:ii+1]) + ray_orig[:, ii:ii+1], + ray_vdir[:, ii:ii+1]) val = func(pts, t=t, **fkwdargs) sig[:, ii] = scpintg.simps(val, x=None, axis=-1, dx=loc_eff_res[0]) elif n_imode == 2: # "romberg" integration mode for ii in range(nlos): - pts = _st.call_get_sample_single(lims[0,ii], lims[1,ii], + pts = _st.call_get_sample_single(lims[0, ii], + lims[1, ii], res_mv[ii], n_dmode, n_imode, &loc_eff_res[0], &nb_rows[0], - ray_orig[:,ii:ii+1], - ray_vdir[:,ii:ii+1]) + ray_orig[:, ii:ii+1], + ray_vdir[:, ii:ii+1]) val = func(pts, t=t, **fkwdargs) sig[:, ii] = scpintg.romb(val, show=False, axis=1, - dx=loc_eff_res[0]) + dx=loc_eff_res[0]) return sig diff --git a/tofu/geom/_core.py b/tofu/geom/_core.py index 03f76e79c..1cd9886a2 100644 --- a/tofu/geom/_core.py +++ b/tofu/geom/_core.py @@ -5789,7 +5789,9 @@ def check_ff(self, ff, t=None, ani=None): + "\t\t\t - vect is a (3, npts) np.ndarray\n" + "\t\t\t - vect contains the (x, y, z) coordinates " + "of the units vectors of the photon emission directions" - + "for each pts. Used for anisotropic emissivity.\n" + + "for each pts. Present only for anisotropic emissivity, " + + "unless specifically indicated otherwise " + + "(with ani=False in LOS_calc_signal).\n" + "\t\t\tDoes not affect the outpout shape (still (nt, npts))") # .. Checking basic definition of function .......................... @@ -6005,11 +6007,6 @@ def calc_signal( => the method returns W/m2 (resp. W/m2/sr) The line is sampled using :meth:`~tofu.geom.LOS.get_sample`, - The integral can be computed using three different methods: - - 'sum': A numpy.sum() on the local values (x segments lengths) - - 'simps': using :meth:`scipy.integrate.simps` - - 'romb': using :meth:`scipy.integrate.romb` - Except func, arguments common to :meth:`~tofu.geom.LOS.get_sample` Parameters @@ -6024,6 +6021,15 @@ def calc_signal( - vect: None / (3,N) np.ndarray, unit direction vectors (X,Y,Z) Should return at least: - val : (N,) np.ndarray, local emissivity values + method : string, the integral can be computed using 3 different methods + - 'sum': A numpy.sum() on the local values (x segments) DEFAULT + - 'simps': using :meth:`scipy.integrate.simps` + - 'romb': using :meth:`scipy.integrate.romb` + minimize : string, method to minimize for computation optimization + - "calls": minimal number of calls to `func` (default) + - "memory": slowest method, to use only if "out of memory" error + - "hybrid": mix of before-mentioned methods. + Returns ------- diff --git a/tofu/tests/tests09_tutorials/tests01_runall.py b/tofu/tests/tests09_tutorials/tests01_runall.py index c47de7fdd..e20341724 100644 --- a/tofu/tests/tests09_tutorials/tests01_runall.py +++ b/tofu/tests/tests09_tutorials/tests01_runall.py @@ -154,8 +154,10 @@ def _test_tuto(cls, tuto=None, pathtuto=_HERE, root=_TFROOT): out = subprocess.run(cmd, shell=True, check=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - if 'error' in out.stderr.decode().lower(): - error = out.stderr.decode() + ls = out.stderr.decode().split('\n') + if any(['Error' in ss and not 'ModuleNotFoundError' in ss + for ss in ls]): + error = '\n'.join(ls) except Exception as err: error = err