From bfe447a8e90f9e193890b94839f38f09a763fb59 Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Thu, 12 Sep 2019 15:42:24 +0200 Subject: [PATCH 01/12] [Issue 188] Renamed tf.geom.Rays.calc_kInOut_IsoFlux to ..._Isoflux_... (minor case for F) --- tofu/geom/_core.py | 12 ++++++------ tofu/version.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tofu/geom/_core.py b/tofu/geom/_core.py index 88d8efa88..9914cd44f 100644 --- a/tofu/geom/_core.py +++ b/tofu/geom/_core.py @@ -4639,7 +4639,7 @@ def get_sample(self, res=None, resMode='abs', DL=None, method='sum', ind=None, k = np.split(k, lind, axis=-1) return k, reseff, lind - def _kInOut_IsoFlux_inputs(self, lPoly, lVIn=None): + def _kInOut_Isoflux_inputs(self, lPoly, lVIn=None): if self._method=='ref': D, u = np.ascontiguousarray(self.D), np.ascontiguousarray(self.u) @@ -4668,7 +4668,7 @@ def _kInOut_IsoFlux_inputs(self, lPoly, lVIn=None): pass return largs, dkwd - def _kInOut_IsoFlux_inputs_usr(self, lPoly, lVIn=None): + def _kInOut_Isoflux_inputs_usr(self, lPoly, lVIn=None): # Check lPoly if type(lPoly) is np.ndarray: @@ -4713,7 +4713,7 @@ def _kInOut_IsoFlux_inputs_usr(self, lPoly, lVIn=None): return nPoly, lPoly, lVIn - def calc_kInkOut_IsoFlux(self, lPoly, lVIn=None, Lim=None, + def calc_kInkOut_Isoflux(self, lPoly, lVIn=None, Lim=None, kInOut=True): """ Calculate the intersection points of each ray with each isoflux @@ -4733,7 +4733,7 @@ def calc_kInkOut_IsoFlux(self, lPoly, lVIn=None, Lim=None, """ # Preformat input - nPoly, lPoly, lVIn = self._kInOut_IsoFlux_inputs_usr(lPoly, lVIn=lVIn) + nPoly, lPoly, lVIn = self._kInOut_Isoflux_inputs_usr(lPoly, lVIn=lVIn) # Prepare output kIn = np.full((self.nRays,nPoly), np.nan) @@ -4743,14 +4743,14 @@ def calc_kInkOut_IsoFlux(self, lPoly, lVIn=None, Lim=None, assert(self._method in ['ref', 'optimized']) if self._method=='ref': for ii in range(0,nPoly): - largs, dkwd = self._kInOut_IsoFlux_inputs([lPoly[ii]], + largs, dkwd = self._kInOut_Isoflux_inputs([lPoly[ii]], lVIn=[lVIn[ii]]) out = _GG.SLOW_LOS_Calc_PInOut_VesStruct(*largs, **dkwd) # PIn, POut, kin, kout, VperpIn, vperp, IIn, indout = out[] kIn[:,ii], kOut[:,ii] = out[2], out[3] elif self._method=="optimized": for ii in range(0,nPoly): - largs, dkwd = self._kInOut_IsoFlux_inputs([lPoly[ii]], + largs, dkwd = self._kInOut_Isoflux_inputs([lPoly[ii]], lVIn=[lVIn[ii]]) out = _GG.LOS_Calc_PInOut_VesStruct(*largs, **dkwd) diff --git a/tofu/version.py b/tofu/version.py index 6be347a9d..4ca067270 100644 --- a/tofu/version.py +++ b/tofu/version.py @@ -1,2 +1,2 @@ # Do not edit this file, pipeline versioning is governed by git tags ! -__version__='1.4.1-4-g7cfbe9f' \ No newline at end of file +__version__='1.4.1-38-gb476c26' \ No newline at end of file From 3184b479fcf8c026cb3f73c28066f7ca1d01e1f9 Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Thu, 12 Sep 2019 16:41:46 +0200 Subject: [PATCH 02/12] [Issue 188] tf.geom.Rays._kInOut_Isoflux_inputs_usr(): lPoly can be 3d array --- tofu/geom/_core.py | 38 ++++++++++++++++++++++++++++---------- tofu/version.py | 2 +- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/tofu/geom/_core.py b/tofu/geom/_core.py index 9914cd44f..036f1d89b 100644 --- a/tofu/geom/_core.py +++ b/tofu/geom/_core.py @@ -4669,19 +4669,37 @@ def _kInOut_Isoflux_inputs(self, lPoly, lVIn=None): return largs, dkwd def _kInOut_Isoflux_inputs_usr(self, lPoly, lVIn=None): + c0 = type(lPoly) in [np.ndarray,list,tuple] # Check lPoly - if type(lPoly) is np.ndarray: - lPoly = [lPoly] - lPoly = [np.ascontiguousarray(pp) for pp in lPoly] - msg = "Arg lPoly must be a list of (2,N) or (N,2) np.ndarrays !" - assert all([pp.ndim==2 and 2 in pp.shape for pp in lPoly]), msg + if c0 and type(lPoly) is np.ndarray: + c0 = c0 and assert lPoly.ndim in [2,3] + if c0 and lPoly.ndim == 2: + c0 = c0 and lPoly.shape[0] == 2 + if c0: + lPoly = [np.ascontiguousarray(lPoly)] + elif c0: + c0 = c0 and lPoly.shape[1] == 2 + if c0: + lPoly = np.ascontiguousarray(lpoly) + elif c0: + lPoly = [np.ascontiguousarray(pp) for pp in lPoly] + c0 = all([pp.ndim == 2 and pp.shape[0] == 2 for pp in lPoly]) + if not c0: + msg = "Arg lPoly must be either:\n" + msg += " - a (2,N) np.ndarray (signle polygon of N points)\n" + msg += " - a list of M polygons, each being a (2,Ni) np.ndarray\n" + msg += " - where Ni is the number of point of each polygon\n" + msg += " - a (M,2,N) np.ndarray where:\n" + msg += " - M is the number of polygons\n" + msg += " - N is the (common) number of points per polygon\n" + raise Exception(msg) + nPoly = len(lPoly) - for ii in range(0,nPoly): - if lPoly[ii].shape[0]!=2: - lPoly[ii] = lPoly[ii].T - # Check closed and anti-clockwise - lPoly[ii] = _GG.Poly_Order(lPoly[ii], Clock=False, close=True) + # for ii in range(0,nPoly): + # if lPoly[ii].shape[0] != 2: + # # Check closed and anti-clockwise + # lPoly[ii] = _GG.Poly_Order(lPoly[ii], Clock=False, close=True) # Check lVIn if lVIn is None: diff --git a/tofu/version.py b/tofu/version.py index 4ca067270..841a0a7ac 100644 --- a/tofu/version.py +++ b/tofu/version.py @@ -1,2 +1,2 @@ # Do not edit this file, pipeline versioning is governed by git tags ! -__version__='1.4.1-38-gb476c26' \ No newline at end of file +__version__='1.4.1-39-gbfe447a' \ No newline at end of file From 487e20a824da9942887b29975d4d36b2fd35ebde Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Thu, 12 Sep 2019 18:10:18 +0200 Subject: [PATCH 03/12] [Issue 188] tf.geom.Rays._kInOut_Isoflux_inputs_usr(): lVIn can also be 3d array, tested and unit tests updated with low-case method name --- tofu/geom/_core.py | 82 +++++++++++++++++-------- tofu/tests/tests01_geom/tests03_core.py | 4 +- tofu/version.py | 2 +- 3 files changed, 58 insertions(+), 30 deletions(-) diff --git a/tofu/geom/_core.py b/tofu/geom/_core.py index 036f1d89b..15dae2491 100644 --- a/tofu/geom/_core.py +++ b/tofu/geom/_core.py @@ -4673,7 +4673,7 @@ def _kInOut_Isoflux_inputs_usr(self, lPoly, lVIn=None): # Check lPoly if c0 and type(lPoly) is np.ndarray: - c0 = c0 and assert lPoly.ndim in [2,3] + c0 = c0 and lPoly.ndim in [2,3] if c0 and lPoly.ndim == 2: c0 = c0 and lPoly.shape[0] == 2 if c0: @@ -4694,40 +4694,68 @@ def _kInOut_Isoflux_inputs_usr(self, lPoly, lVIn=None): msg += " - M is the number of polygons\n" msg += " - N is the (common) number of points per polygon\n" raise Exception(msg) - nPoly = len(lPoly) - # for ii in range(0,nPoly): - # if lPoly[ii].shape[0] != 2: - # # Check closed and anti-clockwise - # lPoly[ii] = _GG.Poly_Order(lPoly[ii], Clock=False, close=True) + + # Check anti-clockwise and closed + if type(lPoly) is list: + for ii in range(nPoly): + # Check closed and anti-clockwise + if _GG.Poly_isClockwise(lPoly[ii]): + lPoly[ii] = lPoly[ii][:,::-1] + if not np.allclose(lPoly[ii][:,0], lPoly[ii][:,-1]): + lPoly[ii] = np.concatenate((lPoly[ii],lPoly[ii][:,0:1]), axis=-1) + else: + for ii in range(nPoly): + # Check closed and anti-clockwise + if _GG.Poly_isClockwise(lPoly[ii]): + lPoly[ii] = lPoly[ii][:,::-1] + d = np.sum((lPoly[:,:,0]-lPoly[:,:,-1])**2, axis=1) + if np.allclose(d,0.): + pass + elif np.all(d > 0.): + lPoly = np.concatenate((lPoly, lPoly[:,:,0:1]), axis=-1) + else: + msg = "All poly in lPoly should be closed or all non-closed!" + raise Exception(msg) + # Check lVIn if lVIn is None: lVIn = [] for pp in lPoly: - VIn = np.diff(pp, axis=1) - VIn = VIn/(np.sqrt(np.sum(VIn**2,axis=0))[np.newaxis,:]) - VIn = np.ascontiguousarray([-VIn[1,:],VIn[0,:]]) - lVIn.append(VIn) + vIn = np.diff(pp, axis=1) + vIn = vIn/(np.sqrt(np.sum(vIn**2,axis=0))[None,:]) + vIn = np.ascontiguousarray([-vIn[1,:], vIn[0,:]]) + lVIn.append(vIn) else: - if type(lVIn) is np.ndarray: - lVIn = [lVIn] - assert len(lVIn)==nPoly - lVIn = [np.ascontiguousarray(pp) for pp in lVIn] - msg = "Arg lVIn must be a list of (2,N) or (N,2) np.ndarrays !" - assert all([pp.ndim==2 and 2 in pp.shape for pp in lVIn]), msg + c0 = type(lVIn) in [np.ndarray,list,tuple] + if c0 and type(lVIn) is np.ndarray and lVIn.ndim == 2: + c0 = c0 and lVIn.shape == (2, lPoly[0].shape[1]-1) + if c0: + lVIn = [np.ascontiguousarray(lVIn)] + elif c0 and type(lVIn) is np.ndarray: + c0 = c0 and lVIn.shape == (nPoly, 2, lPoly.shape[-1]-1) + if c0: + lVIn = np.ascontiguousarray(lVIn) + elif c0: + c0 = c0 and len(lVIn) == nPoly + if c0: + c0 = c0 and all([vv.shape == (2, pp.shape[1]-1) + for vv,pp in zip(lVIn,lPoly)]) + if c0: + lVIn = [np.ascontiguousarray(vv) for vv in lVIn] + + # Check normalization and direction for ii in range(0,nPoly): - if lVIn[ii].shape[0]!=2: - lVIn[ii] = lVIn[ii].T - lVIn[ii] = lVIn[ii]/(np.sqrt(np.sum(lVIn[ii]**2,axis=0))[np.newaxis,:]) - assert lVIn[ii].shape==(2,lPoly[ii].shape[1]-1) - vect = np.diff(lPoly[ii],axis=1) - det = vect[0,:]*lVIn[ii][1,:] - vect[1,:]*lVIn[ii][0,:] - if not np.allclose(np.abs(det),1.): - msg = "Each lVIn must be perp. to each lPoly segment !" - raise Exception(msg) - ind = np.abs(det+1)<1.e-12 - lVIn[ii][:,ind] = -lVIn[ii][:,ind] + lVIn[ii] = lVIn[ii]/np.sqrt(np.sum(lVIn[ii]**2,axis=0))[None,:] + vect = np.diff(lPoly[ii], axis=1) + vect = vect / np.sqrt(np.sum(vect**2,axis=0))[None,:] + det = vect[0,:]*lVIn[ii][1,:] - vect[1,:]*lVIn[ii][0,:] + if not np.allclose(np.abs(det),1.): + msg = "Each lVIn must be perp. to each lPoly segment !" + raise Exception(msg) + ind = np.abs(det+1) < 1.e-12 + lVIn[ii][:,ind] = -lVIn[ii][:,ind] return nPoly, lPoly, lVIn diff --git a/tofu/tests/tests01_geom/tests03_core.py b/tofu/tests/tests01_geom/tests03_core.py index 3781e27df..46df0a3a3 100644 --- a/tofu/tests/tests01_geom/tests03_core.py +++ b/tofu/tests/tests01_geom/tests03_core.py @@ -792,7 +792,7 @@ def test08_get_sample(self): & (k[ii][ind]<=obj.kOut[ii]+res[ii])) - def test09_calc_kInkOut_IsoFlux(self): + def test09_calc_kInkOut_Isoflux(self): nP = 10 r = np.linspace(0.1,0.4,nP) theta = np.linspace(0.,2*np.pi,100) @@ -801,7 +801,7 @@ def test09_calc_kInkOut_IsoFlux(self): for typ in self.dobj.keys(): for c in self.dobj[typ].keys(): obj = self.dobj[typ][c] - kIn, kOut = obj.calc_kInkOut_IsoFlux(lp2D) + kIn, kOut = obj.calc_kInkOut_Isoflux(lp2D) assert kIn.shape==(obj.nRays, nP) assert kOut.shape==(obj.nRays, nP) for ii in range(0,nP): diff --git a/tofu/version.py b/tofu/version.py index 841a0a7ac..be92ddbee 100644 --- a/tofu/version.py +++ b/tofu/version.py @@ -1,2 +1,2 @@ # Do not edit this file, pipeline versioning is governed by git tags ! -__version__='1.4.1-39-gbfe447a' \ No newline at end of file +__version__='1.4.1-40-g3184b47' \ No newline at end of file From ccb8d6b23fd22d82d10e3f9981662db9bc64423c Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Thu, 12 Sep 2019 18:16:18 +0200 Subject: [PATCH 04/12] [Issue 188] tf.geom.Rays._kInOut_Isoflux_inputs_usr(): Debugged --- tofu/geom/_core.py | 2 +- tofu/version.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tofu/geom/_core.py b/tofu/geom/_core.py index 15dae2491..2d33496f9 100644 --- a/tofu/geom/_core.py +++ b/tofu/geom/_core.py @@ -4681,7 +4681,7 @@ def _kInOut_Isoflux_inputs_usr(self, lPoly, lVIn=None): elif c0: c0 = c0 and lPoly.shape[1] == 2 if c0: - lPoly = np.ascontiguousarray(lpoly) + lPoly = np.ascontiguousarray(lPoly) elif c0: lPoly = [np.ascontiguousarray(pp) for pp in lPoly] c0 = all([pp.ndim == 2 and pp.shape[0] == 2 for pp in lPoly]) diff --git a/tofu/version.py b/tofu/version.py index be92ddbee..e9ffcb0bb 100644 --- a/tofu/version.py +++ b/tofu/version.py @@ -1,2 +1,2 @@ # Do not edit this file, pipeline versioning is governed by git tags ! -__version__='1.4.1-40-g3184b47' \ No newline at end of file +__version__='1.4.1-41-g487e20a' \ No newline at end of file From 546799884b41f88dd7b19e33c8f72104066a3aee Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Fri, 13 Sep 2019 08:57:18 +0200 Subject: [PATCH 05/12] [Issue 188] tf.geom.Rays.calc_kInOut_Isoflux() now return kin, kout as (nPoly,nRays) instead of (nRays,nPoly) --- tofu/geom/_core.py | 17 ++++++++--------- tofu/version.py | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/tofu/geom/_core.py b/tofu/geom/_core.py index 2d33496f9..14c6d904e 100644 --- a/tofu/geom/_core.py +++ b/tofu/geom/_core.py @@ -4782,8 +4782,8 @@ def calc_kInkOut_Isoflux(self, lPoly, lVIn=None, Lim=None, nPoly, lPoly, lVIn = self._kInOut_Isoflux_inputs_usr(lPoly, lVIn=lVIn) # Prepare output - kIn = np.full((self.nRays,nPoly), np.nan) - kOut = np.full((self.nRays,nPoly), np.nan) + kIn = np.full((nPoly, self.nRays), np.nan) + kOut = np.full((nPoly, self.nRays), np.nan) # Compute intersections assert(self._method in ['ref', 'optimized']) @@ -4793,20 +4793,19 @@ def calc_kInkOut_Isoflux(self, lPoly, lVIn=None, Lim=None, lVIn=[lVIn[ii]]) out = _GG.SLOW_LOS_Calc_PInOut_VesStruct(*largs, **dkwd) # PIn, POut, kin, kout, VperpIn, vperp, IIn, indout = out[] - kIn[:,ii], kOut[:,ii] = out[2], out[3] + kIn[ii,:], kOut[ii,:] = out[2], out[3] elif self._method=="optimized": for ii in range(0,nPoly): largs, dkwd = self._kInOut_Isoflux_inputs([lPoly[ii]], lVIn=[lVIn[ii]]) - out = _GG.LOS_Calc_PInOut_VesStruct(*largs, **dkwd) - kin, kout, _, _ = out - kIn[:,ii], kOut[:,ii] = kin, kout + out = _GG.LOS_Calc_PInOut_VesStruct(*largs, **dkwd)[:2] + kIn[ii,:], kOut[ii,:] = out if kInOut: indok = ~np.isnan(kIn) - ind = np.zeros((self.nRays,nPoly), dtype=bool) - kInref = np.tile(self.kIn[:,np.newaxis],nPoly) - kOutref = np.tile(self.kOut[:,np.newaxis],nPoly) + ind = np.zeros((nPoly, self.nRays), dtype=bool) + kInref = np.tile(self.kIn, (nPoly,1)) + kOutref = np.tile(self.kOut, (nPoly,1)) ind[indok] = (kIn[indok]kOutref[indok]) kIn[ind] = np.nan diff --git a/tofu/version.py b/tofu/version.py index e9ffcb0bb..24077f7ed 100644 --- a/tofu/version.py +++ b/tofu/version.py @@ -1,2 +1,2 @@ # Do not edit this file, pipeline versioning is governed by git tags ! -__version__='1.4.1-41-g487e20a' \ No newline at end of file +__version__='1.4.1-42-gccb8d6b' \ No newline at end of file From cd25d5b9c2b7be65db7ab66a597dfe78e8fd0265 Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Fri, 13 Sep 2019 09:08:24 +0200 Subject: [PATCH 06/12] [Issue 188] PEP8 compliance --- tofu/geom/_core.py | 38 ++++++++++++++++++++------------------ tofu/version.py | 2 +- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/tofu/geom/_core.py b/tofu/geom/_core.py index 14c6d904e..fab2313ee 100644 --- a/tofu/geom/_core.py +++ b/tofu/geom/_core.py @@ -4669,11 +4669,11 @@ def _kInOut_Isoflux_inputs(self, lPoly, lVIn=None): return largs, dkwd def _kInOut_Isoflux_inputs_usr(self, lPoly, lVIn=None): - c0 = type(lPoly) in [np.ndarray,list,tuple] + c0 = type(lPoly) in [np.ndarray, list, tuple] # Check lPoly if c0 and type(lPoly) is np.ndarray: - c0 = c0 and lPoly.ndim in [2,3] + c0 = c0 and lPoly.ndim in [2, 3] if c0 and lPoly.ndim == 2: c0 = c0 and lPoly.shape[0] == 2 if c0: @@ -4688,8 +4688,8 @@ def _kInOut_Isoflux_inputs_usr(self, lPoly, lVIn=None): if not c0: msg = "Arg lPoly must be either:\n" msg += " - a (2,N) np.ndarray (signle polygon of N points)\n" - msg += " - a list of M polygons, each being a (2,Ni) np.ndarray\n" - msg += " - where Ni is the number of point of each polygon\n" + msg += " - a list of M polygons, each a (2,Ni) np.ndarray\n" + msg += " - where Ni is the number of pts of each polygon\n" msg += " - a (M,2,N) np.ndarray where:\n" msg += " - M is the number of polygons\n" msg += " - N is the (common) number of points per polygon\n" @@ -4701,19 +4701,21 @@ def _kInOut_Isoflux_inputs_usr(self, lPoly, lVIn=None): for ii in range(nPoly): # Check closed and anti-clockwise if _GG.Poly_isClockwise(lPoly[ii]): - lPoly[ii] = lPoly[ii][:,::-1] - if not np.allclose(lPoly[ii][:,0], lPoly[ii][:,-1]): - lPoly[ii] = np.concatenate((lPoly[ii],lPoly[ii][:,0:1]), axis=-1) + lPoly[ii] = lPoly[ii][:, ::-1] + if not np.allclose(lPoly[ii][:, 0], lPoly[ii][:, -1]): + lPoly[ii] = np.concatenate( + (lPoly[ii], lPoly[ii][:, 0:1]), axis=-1 + ) else: for ii in range(nPoly): # Check closed and anti-clockwise if _GG.Poly_isClockwise(lPoly[ii]): - lPoly[ii] = lPoly[ii][:,::-1] - d = np.sum((lPoly[:,:,0]-lPoly[:,:,-1])**2, axis=1) - if np.allclose(d,0.): + lPoly[ii] = lPoly[ii][:, ::-1] + d = np.sum((lPoly[:, :, 0]-lPoly[:, :, -1])**2, axis=1) + if np.allclose(d, 0.): pass elif np.all(d > 0.): - lPoly = np.concatenate((lPoly, lPoly[:,:,0:1]), axis=-1) + lPoly = np.concatenate((lPoly, lPoly[:, :, 0:1]), axis=-1) else: msg = "All poly in lPoly should be closed or all non-closed!" raise Exception(msg) @@ -4724,11 +4726,11 @@ def _kInOut_Isoflux_inputs_usr(self, lPoly, lVIn=None): lVIn = [] for pp in lPoly: vIn = np.diff(pp, axis=1) - vIn = vIn/(np.sqrt(np.sum(vIn**2,axis=0))[None,:]) + vIn = vIn/(np.sqrt(np.sum(vIn**2, axis=0))[None,:]) vIn = np.ascontiguousarray([-vIn[1,:], vIn[0,:]]) lVIn.append(vIn) else: - c0 = type(lVIn) in [np.ndarray,list,tuple] + c0 = type(lVIn) in [np.ndarray, list, tuple] if c0 and type(lVIn) is np.ndarray and lVIn.ndim == 2: c0 = c0 and lVIn.shape == (2, lPoly[0].shape[1]-1) if c0: @@ -4741,21 +4743,21 @@ def _kInOut_Isoflux_inputs_usr(self, lPoly, lVIn=None): c0 = c0 and len(lVIn) == nPoly if c0: c0 = c0 and all([vv.shape == (2, pp.shape[1]-1) - for vv,pp in zip(lVIn,lPoly)]) + for vv,pp in zip(lVIn, lPoly)]) if c0: lVIn = [np.ascontiguousarray(vv) for vv in lVIn] # Check normalization and direction for ii in range(0,nPoly): - lVIn[ii] = lVIn[ii]/np.sqrt(np.sum(lVIn[ii]**2,axis=0))[None,:] + lVIn[ii] = lVIn[ii]/np.sqrt(np.sum(lVIn[ii]**2, axis=0))[None,:] vect = np.diff(lPoly[ii], axis=1) - vect = vect / np.sqrt(np.sum(vect**2,axis=0))[None,:] + vect = vect / np.sqrt(np.sum(vect**2, axis=0))[None,:] det = vect[0,:]*lVIn[ii][1,:] - vect[1,:]*lVIn[ii][0,:] - if not np.allclose(np.abs(det),1.): + if not np.allclose(np.abs(det), 1.): msg = "Each lVIn must be perp. to each lPoly segment !" raise Exception(msg) ind = np.abs(det+1) < 1.e-12 - lVIn[ii][:,ind] = -lVIn[ii][:,ind] + lVIn[ii][:, ind] = -lVIn[ii][:, ind] return nPoly, lPoly, lVIn diff --git a/tofu/version.py b/tofu/version.py index 24077f7ed..a5720ccbf 100644 --- a/tofu/version.py +++ b/tofu/version.py @@ -1,2 +1,2 @@ # Do not edit this file, pipeline versioning is governed by git tags ! -__version__='1.4.1-42-gccb8d6b' \ No newline at end of file +__version__='1.4.1-43-g5467998' \ No newline at end of file From c925c330dbea220650fcbd6ea1131227df914e05 Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Fri, 13 Sep 2019 09:12:07 +0200 Subject: [PATCH 07/12] [Issue 188] PEP8 compliance 2 --- tofu/geom/_core.py | 16 ++++++++-------- tofu/version.py | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tofu/geom/_core.py b/tofu/geom/_core.py index fab2313ee..96f1e57c6 100644 --- a/tofu/geom/_core.py +++ b/tofu/geom/_core.py @@ -4708,9 +4708,9 @@ def _kInOut_Isoflux_inputs_usr(self, lPoly, lVIn=None): ) else: for ii in range(nPoly): - # Check closed and anti-clockwise - if _GG.Poly_isClockwise(lPoly[ii]): - lPoly[ii] = lPoly[ii][:, ::-1] + # Check closed and anti-clockwise + if _GG.Poly_isClockwise(lPoly[ii]): + lPoly[ii] = lPoly[ii][:, ::-1] d = np.sum((lPoly[:, :, 0]-lPoly[:, :, -1])**2, axis=1) if np.allclose(d, 0.): pass @@ -4726,8 +4726,8 @@ def _kInOut_Isoflux_inputs_usr(self, lPoly, lVIn=None): lVIn = [] for pp in lPoly: vIn = np.diff(pp, axis=1) - vIn = vIn/(np.sqrt(np.sum(vIn**2, axis=0))[None,:]) - vIn = np.ascontiguousarray([-vIn[1,:], vIn[0,:]]) + vIn = vIn/(np.sqrt(np.sum(vIn**2, axis=0))[None, :]) + vIn = np.ascontiguousarray([-vIn[1, :], vIn[0, :]]) lVIn.append(vIn) else: c0 = type(lVIn) in [np.ndarray, list, tuple] @@ -4749,10 +4749,10 @@ def _kInOut_Isoflux_inputs_usr(self, lPoly, lVIn=None): # Check normalization and direction for ii in range(0,nPoly): - lVIn[ii] = lVIn[ii]/np.sqrt(np.sum(lVIn[ii]**2, axis=0))[None,:] + lVIn[ii] = lVIn[ii]/np.sqrt(np.sum(lVIn[ii]**2, axis=0))[None, :] vect = np.diff(lPoly[ii], axis=1) - vect = vect / np.sqrt(np.sum(vect**2, axis=0))[None,:] - det = vect[0,:]*lVIn[ii][1,:] - vect[1,:]*lVIn[ii][0,:] + vect = vect / np.sqrt(np.sum(vect**2, axis=0))[None, :] + det = vect[0, :]*lVIn[ii][1, :] - vect[1, :]*lVIn[ii][0, :] if not np.allclose(np.abs(det), 1.): msg = "Each lVIn must be perp. to each lPoly segment !" raise Exception(msg) diff --git a/tofu/version.py b/tofu/version.py index a5720ccbf..045550897 100644 --- a/tofu/version.py +++ b/tofu/version.py @@ -1,2 +1,2 @@ # Do not edit this file, pipeline versioning is governed by git tags ! -__version__='1.4.1-43-g5467998' \ No newline at end of file +__version__='1.4.1-44-gcd25d5b' \ No newline at end of file From 18918f293f8fd8d6a290dd264cd9e013b5fbeb84 Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Fri, 13 Sep 2019 09:13:59 +0200 Subject: [PATCH 08/12] [Issue 188] PEP8 compliance 3 --- tofu/geom/_core.py | 13 +++++++------ tofu/version.py | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tofu/geom/_core.py b/tofu/geom/_core.py index 96f1e57c6..7bb2d9014 100644 --- a/tofu/geom/_core.py +++ b/tofu/geom/_core.py @@ -4743,13 +4743,14 @@ def _kInOut_Isoflux_inputs_usr(self, lPoly, lVIn=None): c0 = c0 and len(lVIn) == nPoly if c0: c0 = c0 and all([vv.shape == (2, pp.shape[1]-1) - for vv,pp in zip(lVIn, lPoly)]) + for vv, pp in zip(lVIn, lPoly)]) if c0: lVIn = [np.ascontiguousarray(vv) for vv in lVIn] # Check normalization and direction for ii in range(0,nPoly): - lVIn[ii] = lVIn[ii]/np.sqrt(np.sum(lVIn[ii]**2, axis=0))[None, :] + lVIn[ii] = (lVIn[ii] + / np.sqrt(np.sum(lVIn[ii]**2, axis=0))[None, :]) vect = np.diff(lPoly[ii], axis=1) vect = vect / np.sqrt(np.sum(vect**2, axis=0))[None, :] det = vect[0, :]*lVIn[ii][1, :] - vect[1, :]*lVIn[ii][0, :] @@ -4795,19 +4796,19 @@ def calc_kInkOut_Isoflux(self, lPoly, lVIn=None, Lim=None, lVIn=[lVIn[ii]]) out = _GG.SLOW_LOS_Calc_PInOut_VesStruct(*largs, **dkwd) # PIn, POut, kin, kout, VperpIn, vperp, IIn, indout = out[] - kIn[ii,:], kOut[ii,:] = out[2], out[3] + kIn[ii, :], kOut[ii, :] = out[2], out[3] elif self._method=="optimized": for ii in range(0,nPoly): largs, dkwd = self._kInOut_Isoflux_inputs([lPoly[ii]], lVIn=[lVIn[ii]]) out = _GG.LOS_Calc_PInOut_VesStruct(*largs, **dkwd)[:2] - kIn[ii,:], kOut[ii,:] = out + kIn[ii, :], kOut[ii, :] = out if kInOut: indok = ~np.isnan(kIn) ind = np.zeros((nPoly, self.nRays), dtype=bool) - kInref = np.tile(self.kIn, (nPoly,1)) - kOutref = np.tile(self.kOut, (nPoly,1)) + kInref = np.tile(self.kIn, (nPoly, 1)) + kOutref = np.tile(self.kOut, (nPoly, 1)) ind[indok] = (kIn[indok]kOutref[indok]) kIn[ind] = np.nan diff --git a/tofu/version.py b/tofu/version.py index 045550897..5d4d522c8 100644 --- a/tofu/version.py +++ b/tofu/version.py @@ -1,2 +1,2 @@ # Do not edit this file, pipeline versioning is governed by git tags ! -__version__='1.4.1-44-gcd25d5b' \ No newline at end of file +__version__='1.4.1-45-gc925c33' \ No newline at end of file From 52808cefdc7b3621a8eefd8b62510876861cfa32 Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Fri, 13 Sep 2019 09:18:45 +0200 Subject: [PATCH 09/12] [Issue 188] PEP8 compliance 4 --- _updateversion.py | 5 +++-- tofu/tests/tests01_geom/tests03_core.py | 1 - tofu/version.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/_updateversion.py b/_updateversion.py index cdcb1f415..af80b6a89 100644 --- a/_updateversion.py +++ b/_updateversion.py @@ -23,9 +23,10 @@ def updateversion(path=_HERE): version_git = fh.read().strip().split("=")[-1].replace("'",'') version_git = version_git.lower().replace('v','') - version_msg = "# Do not edit this file, pipeline versioning is governed by git tags !" + version_msg = "# Do not edit, pipeline versioning governed by git tags!" with open(version_py,"w") as fh: - fh.write((version_msg + os.linesep + '__version__=').replace('',"") + "'%s'" % version_git) + msg = "{0}__version__ = {1}{0}".format(os.linesep, version_git) + fh.write((version_msg + msg) return version_git diff --git a/tofu/tests/tests01_geom/tests03_core.py b/tofu/tests/tests01_geom/tests03_core.py index 46df0a3a3..c1d013000 100644 --- a/tofu/tests/tests01_geom/tests03_core.py +++ b/tofu/tests/tests01_geom/tests03_core.py @@ -791,7 +791,6 @@ def test08_get_sample(self): assert np.all((k[ii][ind]>=obj.kIn[ii]-res[ii]) & (k[ii][ind]<=obj.kOut[ii]+res[ii])) - def test09_calc_kInkOut_Isoflux(self): nP = 10 r = np.linspace(0.1,0.4,nP) diff --git a/tofu/version.py b/tofu/version.py index 5d4d522c8..e5f9ff315 100644 --- a/tofu/version.py +++ b/tofu/version.py @@ -1,2 +1,2 @@ # Do not edit this file, pipeline versioning is governed by git tags ! -__version__='1.4.1-45-gc925c33' \ No newline at end of file +__version__ = '1.4.1-45-gc925c33' From 3d653a7dd7b33ffaf7dc1ae65bfd624e6bcdd7ee Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Fri, 13 Sep 2019 09:19:00 +0200 Subject: [PATCH 10/12] [Issue 188] PEP8 compliance 4 --- _updateversion.py | 2 +- tofu/version.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/_updateversion.py b/_updateversion.py index af80b6a89..73d35ad85 100644 --- a/_updateversion.py +++ b/_updateversion.py @@ -26,7 +26,7 @@ def updateversion(path=_HERE): version_msg = "# Do not edit, pipeline versioning governed by git tags!" with open(version_py,"w") as fh: msg = "{0}__version__ = {1}{0}".format(os.linesep, version_git) - fh.write((version_msg + msg) + fh.write(version_msg + msg) return version_git diff --git a/tofu/version.py b/tofu/version.py index e5f9ff315..c63e6ac21 100644 --- a/tofu/version.py +++ b/tofu/version.py @@ -1,2 +1,2 @@ -# Do not edit this file, pipeline versioning is governed by git tags ! -__version__ = '1.4.1-45-gc925c33' +# Do not edit, pipeline versioning governed by git tags! +__version__ = 1.4.1-47-g52808ce From 373fc3c4d0cf5b08192d1225c9b88aee739610e0 Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Fri, 13 Sep 2019 09:51:16 +0200 Subject: [PATCH 11/12] [Issue 188] PEP8 compliance 5 and nosetests fix and version number fix (pep8) via _updateversion.py --- _updateversion.py | 2 +- tofu/tests/tests01_geom/tests03_core.py | 37 ++++++++++++------------- tofu/version.py | 2 +- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/_updateversion.py b/_updateversion.py index 73d35ad85..b14f878f2 100644 --- a/_updateversion.py +++ b/_updateversion.py @@ -25,7 +25,7 @@ def updateversion(path=_HERE): version_msg = "# Do not edit, pipeline versioning governed by git tags!" with open(version_py,"w") as fh: - msg = "{0}__version__ = {1}{0}".format(os.linesep, version_git) + msg = "{0}__version__ = '{1}'{0}".format(os.linesep, version_git) fh.write(version_msg + msg) return version_git diff --git a/tofu/tests/tests01_geom/tests03_core.py b/tofu/tests/tests01_geom/tests03_core.py index c1d013000..ee1cc1aa5 100644 --- a/tofu/tests/tests01_geom/tests03_core.py +++ b/tofu/tests/tests01_geom/tests03_core.py @@ -801,32 +801,29 @@ def test09_calc_kInkOut_Isoflux(self): for c in self.dobj[typ].keys(): obj = self.dobj[typ][c] kIn, kOut = obj.calc_kInkOut_Isoflux(lp2D) - assert kIn.shape==(obj.nRays, nP) - assert kOut.shape==(obj.nRays, nP) - for ii in range(0,nP): - ind = ~np.isnan(kIn[:,ii]) - if not np.all((kIn[ind,ii]>=obj.kIn[ind]) - & (kIn[ind,ii]<=obj.kOut[ind])): + assert kIn.shape == (nP, obj.nRays) + assert kOut.shape == (nP, obj.nRays) + for ii in range(0, nP): + ind = ~np.isnan(kIn[ii, :]) + if not np.all((kIn[ii,ind] >= obj.kIn[ind]) + & (kIn[ii, ind] <= obj.kOut[ind])): msg = typ+' '+c+' '+str(ii) - msg += "\n {0} {1}".format(obj.kIn[ind],obj.kOut[ind]) - msg += "\n {0}".format(str(kIn[ind,ii])) - print(msg) + msg += "\n {0} {1}".format(obj.kIn[ind], obj.kOut[ind]) + msg += "\n {0}".format(str(kIn[ii, ind])) raise Exception(msg) - ind = ~np.isnan(kOut[:,ii]) - if not np.all((kOut[ind,ii]>=obj.kIn[ind]) - & (kOut[ind,ii]<=obj.kOut[ind])): + ind = ~np.isnan(kOut[ii, :]) + if not np.all((kOut[ii, ind] >= obj.kIn[ind]) + & (kOut[ii, ind] <= obj.kOut[ind])): msg = typ+' '+c+' '+str(ii) - msg += "\n {0} {1}".format(obj.kIn[ind],obj.kOut[ind]) - msg += "\n {0}".format(str(kOut[ind,ii])) - print(msg) + msg += "\n {0} {1}".format(obj.kIn[ind], obj.kOut[ind]) + msg += "\n {0}".format(str(kOut[ii, ind])) raise Exception(msg) - ind = (~np.isnan(kIn[:,ii])) & (~np.isnan(kOut[:,ii])) - if not np.all(kIn[ind,ii]<=kOut[ind,ii]): + ind = (~np.isnan(kIn[ii, :])) & (~np.isnan(kOut[ii, :])) + if not np.all(kIn[ii, ind] <= kOut[ii, ind]): msg = typ+' '+c+' '+str(ii) - msg += "\n {0}".format(str(kIn[ind,ii])) - msg += "\n {0}".format(str(kOut[ind,ii])) - print(msg) + msg += "\n {0}".format(str(kIn[ii, ind])) + msg += "\n {0}".format(str(kOut[ii, ind])) raise Exception(msg) diff --git a/tofu/version.py b/tofu/version.py index c63e6ac21..5dc949ac3 100644 --- a/tofu/version.py +++ b/tofu/version.py @@ -1,2 +1,2 @@ # Do not edit, pipeline versioning governed by git tags! -__version__ = 1.4.1-47-g52808ce +__version__ = '1.4.1-48-g3d653a7' From 100762b66e62b7e526c7477645ee7e5604dbe730 Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Fri, 13 Sep 2019 09:52:36 +0200 Subject: [PATCH 12/12] [Issue 188] PEP8 compliance 6 --- tofu/tests/tests01_geom/tests03_core.py | 2 +- tofu/version.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tofu/tests/tests01_geom/tests03_core.py b/tofu/tests/tests01_geom/tests03_core.py index ee1cc1aa5..0e0c2ebdb 100644 --- a/tofu/tests/tests01_geom/tests03_core.py +++ b/tofu/tests/tests01_geom/tests03_core.py @@ -805,7 +805,7 @@ def test09_calc_kInkOut_Isoflux(self): assert kOut.shape == (nP, obj.nRays) for ii in range(0, nP): ind = ~np.isnan(kIn[ii, :]) - if not np.all((kIn[ii,ind] >= obj.kIn[ind]) + if not np.all((kIn[ii, ind] >= obj.kIn[ind]) & (kIn[ii, ind] <= obj.kOut[ind])): msg = typ+' '+c+' '+str(ii) msg += "\n {0} {1}".format(obj.kIn[ind], obj.kOut[ind]) diff --git a/tofu/version.py b/tofu/version.py index 5dc949ac3..131f008cd 100644 --- a/tofu/version.py +++ b/tofu/version.py @@ -1,2 +1,2 @@ # Do not edit, pipeline versioning governed by git tags! -__version__ = '1.4.1-48-g3d653a7' +__version__ = '1.4.1-49-g373fc3c'