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
5 changes: 4 additions & 1 deletion examples/tutorials/tuto_plot_custom_emissivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -88,6 +90,7 @@ def project_to_2D(xyz):
method="sum",
newcalc=True,
plot=False,
ani=False,
t=time_vector)

sig.plot(ntMax=1)
Expand Down
36 changes: 19 additions & 17 deletions tofu/geom/_GG.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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]
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Didou09 :

Could you find the reason why an error was thrown with vect=None ? It should not

It doesn't anymore. Here is the only real change in this PR, that fixes the bug.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PS: if you see line 3319, it only happened if ani=True, minimize=hybrid, method=sum, and if you see line 2863 I took out the variable which was no longer need and verified all loops to see that this error was nowhere else.

elif n_imode == 1: # simpson integration mode
for ii in range(nlos):
pts, usbis = _st.call_get_sample_single_ani(lims[0, ii],
Expand Down Expand Up @@ -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


Expand Down
18 changes: 12 additions & 6 deletions tofu/geom/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..........................
Expand Down Expand Up @@ -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
Expand All @@ -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
-------
Expand Down
6 changes: 4 additions & 2 deletions tofu/tests/tests09_tutorials/tests01_runall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Comment thread
Didou09 marked this conversation as resolved.
error = err

Expand Down