Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9813371
[debugging] added prints for Issue247
lasofivec Nov 13, 2019
28c5c1f
[debugging] k coeffs from get sample ok, not pts reconstruction
lasofivec Nov 13, 2019
8fcd989
[debugging] found bug in los get_sample
lasofivec Nov 13, 2019
d290787
[debugging] found bug in los integration
lasofivec Nov 13, 2019
4654415
[debugging] cleaning code
lasofivec Nov 13, 2019
9b7c9ef
[debugging] took out c code for maintainability
lasofivec Nov 13, 2019
fcb5b33
[Issue247] cleaning, reverting some changes
lasofivec Nov 13, 2019
0f27f15
[Issue247] found bug in hybird and memory minimization methods
lasofivec Nov 14, 2019
03b8cfb
[Issue247] Added np.allclose() test in tests01_geom.tests03_core.Test…
Nov 15, 2019
83bb165
[Issue247] Removed CamLOS2D and 'rel' cases from tests01_geom.tests03…
Nov 15, 2019
8a0924e
[Issue247] Added tests09_tutorials for running tutorials
Nov 15, 2019
7cd3e3c
[Issue247] PEP8 compliance 1
Nov 15, 2019
57e9d6a
[Issue247] PEP8 compliance 2
Nov 15, 2019
56df4eb
[Issue247] PEP8 compliance 3
Nov 15, 2019
23539c9
[Issue247] PEP8 compliance 4
Nov 15, 2019
f855d29
[Issue247] Fixed tests, but test files generated not yet deleted
Nov 17, 2019
48cd492
[Issue247] Fixed unit tests and removed saved files automatically
Nov 17, 2019
fdc6fa0
[Issue247] Trting to remove Config print in unit tests tests01_geom/t…
Nov 17, 2019
bb8ce2d
[Issue247] Renamed tutorials and copied in tests folder to easily run…
Nov 17, 2019
2254e7f
[Issue247] Fixed tests again
Nov 17, 2019
4760fd3
[Issue247] One last print of Config left in unit tests, can't find it
Nov 17, 2019
ed51236
[Issue247] PEP8 compliance
Nov 17, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
import matplotlib.pyplot as plt
import tofu.geom as tfg

import os
import tofu as tf
print(os.getcwd())
print(tf.__version__)
print(tf.__path__)

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.

Not sure why these lines were added. I didn't reviewed the last version of this PR, but if you agree @Didou09 I will revert these lines.
Furthermore, the renaming of the files means that the doc construction will fail, see sphinx-gallery's doc. I'm working on making the necessary changes on another branch

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These lines were added for debugging, I forgot to remove them, yes you can delete them


###############################################################################
# Creating an empty Vessel
Expand Down Expand Up @@ -86,7 +92,7 @@

# Plot the polygon by default in two projections (cross-section and horizontal)
# and return the list of axes
Lax = ves.plot(element="P")
lax = ves.plot(element="P")


###############################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ def project_to_2D(xyz):
sig, units = cam2d.calc_signal(emissivity,
res=0.01,
reflections=False,
minimize="hybrid",
method="sum",
newcalc=True,
plot=False,
t=time_vector)

sig.plot(ntMax=1)
plt.show()
plt.show(block=False)
148 changes: 71 additions & 77 deletions tofu/geom/_GG.pyx

Large diffs are not rendered by default.

16 changes: 0 additions & 16 deletions tofu/geom/_basic_geom_tools.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@ from cpython.array cimport array, clone
cdef double _VSMALL
cdef double _SMALL

cdef extern from "_fast_sum.c":
void sum_rows_blocks(double *orig, double *out, int n_rows, int n_cols) nogil

cdef extern from "_fast_sum.c":
void sum_par_mat(double *orig, double *out, int n_rows, int n_cols) nogil

cdef extern from "_fast_sum.c":
double sum_par_one_row(double *orig, int n_rows) nogil

# ==============================================================================
# == Redifinition of functions
# ==============================================================================
Expand Down Expand Up @@ -107,11 +98,4 @@ cdef void compute_diff_div(const double[:, ::1] vec1,
# ==============================================================================
# == Matrix sum (np.sum)
# ==============================================================================
cdef void sum_by_rows(double *orig, double *out,
int n_rows, int n_cols) nogil

cdef void sum_naive_rows(double* orig, double* out,
int n_rows, int n_cols) nogil
cdef double sum_naive(double* orig, int n_cols) nogil

cdef long sum_naive_int(long* orig, int n_cols) nogil
17 changes: 0 additions & 17 deletions tofu/geom/_basic_geom_tools.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -370,23 +370,6 @@ cdef inline void sum_by_rows(double *orig, double *out,


# ...........
cdef inline void sum_naive_rows(double* orig, double* out,
int n_rows, int n_cols) nogil:
cdef int ii, jj
for ii in prange(n_rows):
out[ii] = 0
for jj in range(n_cols):
out[ii] += orig[ii*n_cols + jj]

return


cdef inline double sum_naive(double* orig, int n_cols) nogil:
cdef int ii
cdef double out = 0.
for ii in prange(n_cols):
out += orig[ii]
return out

cdef inline long sum_naive_int(long* orig, int n_cols) nogil:
cdef int ii
Expand Down
9 changes: 4 additions & 5 deletions tofu/geom/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5886,7 +5886,7 @@ def calc_signal(
self,
func,
t=None,
ani=None,
ani=False,
fkwdargs={},
Brightness=True,
res=None,
Expand Down Expand Up @@ -5981,6 +5981,7 @@ def calc_signal(
num_threads=num_threads,
Test=True,
)

c0 = (
reflections
and self._dgeom["dreflect"] is not None
Expand Down Expand Up @@ -6013,11 +6014,11 @@ def calc_signal(
)

# Integrate
# Creating the arrays with null everywhere..........
if s.ndim == 2:
sig = np.full((s.shape[0], self.nRays), np.nan)
else:
sig = np.full((1, self.nRays), np.nan)

if t is None or len(t) == 1:
sig[0, indok] = s
else:
Expand All @@ -6033,6 +6034,7 @@ def calc_signal(
compact=True,
pts=True,
)

if ani:
nbrep = np.r_[
indpts[0], np.diff(indpts), pts.shape[1] - indpts[-1]
Expand All @@ -6045,13 +6047,11 @@ def calc_signal(
# This is the slowest step (~3.8 s with res=0.02
# and interferometer)
val = func(pts, t=t, vect=vect)

# Integrate
if val.ndim == 2:
sig = np.full((val.shape[0], self.nRays), np.nan)
else:
sig = np.full((1, self.nRays), np.nan)

indpts = np.r_[0, indpts, pts.shape[1]]
for ii in range(0, self.nRays):
sig[:, ii] = (
Expand All @@ -6061,7 +6061,6 @@ def calc_signal(
)
* reseff[ii]
)

# Format output
return self._calc_signal_postformat(
sig,
Expand Down
56 changes: 0 additions & 56 deletions tofu/geom/_fast_sum.c

This file was deleted.

43 changes: 14 additions & 29 deletions tofu/geom/_sampling_tools.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,20 @@ cdef call_get_sample_single_ani(double los_kmin, double los_kmax,
int n_dmode, int n_imode,
double[1] eff_res,
long[1] nb_rows,
double[:,::1] ray_orig,
double[:,::1] ray_vdir)

cdef cnp.ndarray[double,ndim=2,mode='c'] call_get_sample_single(double los_kmin, double los_kmax,
double resol,
int n_dmode, int n_imode,
double[1] eff_res,
long[1] nb_rows,
double[:,::1] ray_orig,
double[:,::1] ray_vdir)
double[:, ::1] ray_orig,
double[:, ::1] ray_vdir)

cdef cnp.ndarray[double,
ndim=2,
mode='c'] call_get_sample_single(double los_kmin,
double los_kmax,
double resol,
int n_dmode,
int n_imode,
double[1] eff_res,
long[1] nb_rows,
double[:, ::1] ray_orig,
double[:, ::1] ray_vdir)

cdef int los_get_sample_core_const_res(int nlos,
double* los_lim_min,
Expand Down Expand Up @@ -124,22 +128,3 @@ cdef void los_get_sample_pts(int nlos,
double* coeff_ptr,
long* los_ind,
int num_threads) nogil

# -- Integrations utility function ---------------------------------------------
cdef void integrate_sum_nlos(int nlos, int nt,
double[:,::1] val_2d,
double[::1,:] sig_mv,
long* ind_arr,
double* reseff_arr,
int num_threads) nogil

cdef void integrate_c_sum_mat(double[:,::1] val_mv,
double* sig,
int nrows, int ncols,
double loc_eff_res,
int num_threads) nogil

cdef double integrate_c_sum_vec(double* val_mv,
int nza,
double loc_eff_res,
int num_threads) nogil
82 changes: 10 additions & 72 deletions tofu/geom/_sampling_tools.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ cdef inline void middle_rule_abs_s2(int nlos,
loc_x = los_kmin[0]
middle_rule_single(num_raf, loc_x, loc_resol,
&los_coeffs[first_index])

# filling tab...... CANNOT BE PARALLEL !!
for ii in range(1, nlos):
num_raf = ind_cum[ii]
Expand Down Expand Up @@ -505,8 +506,6 @@ cdef inline void middle_rule_abs_var_s1(int nlos,
return




cdef inline void middle_rule_abs_var_s2(int nlos,
double* los_kmin,
double* los_kmax,
Expand Down Expand Up @@ -561,7 +560,6 @@ cdef inline void middle_rule_abs_var(int nlos,
middle_rule_abs_var_s2(nlos, los_kmin, los_kmax,
eff_resolution, los_coeffs,
los_ind, los_nraf, num_threads)

# ...
free(los_nraf)
return
Expand Down Expand Up @@ -1301,7 +1299,8 @@ cdef inline call_get_sample_single_ani(double los_kmin, double los_kmax,
# computing points
usbis = np.repeat(ray_vdir, sz_coeff, axis=1)
ksbis = np.asarray(<double[:sz_coeff]>los_coeffs[0])
pts = ray_orig + ksbis[None,:] * usbis
pts = ray_orig + ksbis[None, :] * usbis
# freeing memory used
if los_coeffs != NULL:
if los_coeffs[0] != NULL:
free(los_coeffs[0])
Expand Down Expand Up @@ -1458,7 +1457,7 @@ cdef inline void los_get_sample_core_var_res(int nlos,
return


# # -- utility for calc signal ---------------------------------------------------
# -- utility for calc signal ---------------------------------------------------
cdef inline void los_get_sample_pts(int nlos,
double* ptx,
double* pty,
Expand All @@ -1482,9 +1481,9 @@ cdef inline void los_get_sample_pts(int nlos,
loc_vy = ray_vdir[1,0]
loc_vz = ray_vdir[2,0]
for ii in range(los_ind[0]):
ptx[ii] = loc_ox + coeff_ptr[ii] + loc_vx
pty[ii] = loc_oy + coeff_ptr[ii] + loc_vy
ptz[ii] = loc_oz + coeff_ptr[ii] + loc_vz
ptx[ii] = loc_ox + coeff_ptr[ii] * loc_vx
pty[ii] = loc_oy + coeff_ptr[ii] * loc_vy
ptz[ii] = loc_oz + coeff_ptr[ii] * loc_vz
usx[ii] = loc_vx
usy[ii] = loc_vy
usz[ii] = loc_vz
Expand All @@ -1497,71 +1496,10 @@ cdef inline void los_get_sample_pts(int nlos,
loc_vy = ray_vdir[1,jj]
loc_vz = ray_vdir[2,jj]
for ii in range(los_ind[jj-1], los_ind[jj]):
ptx[ii] = loc_ox + coeff_ptr[ii] + loc_vx
pty[ii] = loc_oy + coeff_ptr[ii] + loc_vy
ptz[ii] = loc_oz + coeff_ptr[ii] + loc_vz
ptx[ii] = loc_ox + coeff_ptr[ii] * loc_vx
pty[ii] = loc_oy + coeff_ptr[ii] * loc_vy
ptz[ii] = loc_oz + coeff_ptr[ii] * loc_vz
usx[ii] = loc_vx
usy[ii] = loc_vy
usz[ii] = loc_vz
return


# -- calling sampling and intergrating with sum --------------------------------
cdef inline void integrate_sum_nlos(int nlos, int nt,
double[:,::1] val_2d,
double[::1,:] sig_mv,
long* ind_arr,
double* reseff_arr,
int num_threads) nogil:
cdef int ii, jj
cdef int jjp1
jj = 0
jjp1 = ind_arr[0]
integrate_c_sum_mat(val_2d[:,jj:jjp1],
&sig_mv[0,0],
nt, jjp1 - jj,
reseff_arr[0], num_threads)
with nogil, parallel(num_threads=num_threads):
for ii in prange(1,nlos):
# sig[:,ii] = np.sum(val_2d[:,indbis[ii]:indbis[ii+1]],
# axis=-1)*reseff_mv[ii]
jj = ind_arr[ii-1]
jjp1 = ind_arr[ii]
integrate_c_sum_mat(val_2d[:,jj:jjp1],
&sig_mv[0,ii],
nt, jjp1 - jj,
reseff_arr[ii], num_threads)
return

cdef inline void integrate_c_sum_mat(double[:,::1] val_mv,
double* sig,
int nrows, int ncols,
double loc_eff_res,
int num_threads) nogil:
cdef double* vsum
cdef int jj
# ...
vsum = <double*>malloc(nrows*sizeof(double))
_bgt.sum_rows_blocks(&val_mv[0,0], &vsum[0],
nrows, ncols)
# _bgt.sum_by_rows(val_mv, &vsum[0],
# nrows, ncols)
# _bgt.sum_naive_rows(val_mv, &vsum[0],
# nrows, ncols)
# _bgt.sum_par_mat(val_mv, &vsum[0],
# nrows, ncols)
for jj in range(nrows):
sig[jj] = vsum[jj] * loc_eff_res
free(vsum)
return


cdef inline double integrate_c_sum_vec(double* val_mv,
int nsz,
double loc_eff_res,
int num_threads) nogil:
cdef double vsum
cdef int jj
# ...
vsum = _bgt.sum_par_one_row(val_mv, nsz)
return vsum * loc_eff_res
Loading