-
Notifications
You must be signed in to change notification settings - Fork 13
Issue321 rectangular grid metis #325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1ce295f
bc47291
8b7b95e
ccc8ff3
57ccad4
af693de
3940393
7b1cc0f
ac2a365
f7d47d5
583cb9b
3ce09a5
320dc7d
75d20ea
1b17fca
456254d
af676c7
fac943f
bb2a7e1
5212640
e74f678
762f2fe
9fc4efe
c26ae59
666ceff
f22285a
b571227
5e9b601
74ab681
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -432,6 +432,8 @@ def func(pts, vect=None, t=None, ntall=ntall, | |
| vquant[indtq[indtu[ii]], :], | ||
| trifinder=trifind | ||
| )(r, z).filled(fill_value) | ||
| if np.any(np.isnan(val)) and not np.isnan(fill_value): | ||
| val[np.isnan(val)] = fill_value | ||
| return val, t | ||
|
|
||
| # -------------------- | ||
|
|
@@ -463,6 +465,8 @@ def func(pts, vect=None, t=None, ntall=ntall, | |
| ind = indt == indtu[ii] | ||
| val[ind, indok] = vquant[indtq[indtu[ii]], | ||
| indpts[indok]] | ||
| if np.any(np.isnan(val)) and not np.isnan(fill_value): | ||
| val[np.isnan(val)] = fill_value | ||
| return val, t | ||
|
|
||
|
|
||
|
|
@@ -518,14 +522,13 @@ def func(pts, vect=None, t=None, ntall=ntall, | |
| # interpolate 1d | ||
| ind = indt == indtu[ii] | ||
| val[ind, ...] = scpinterp.interp1d( | ||
| vr1[indtr1[indtu[ii]], :], | ||
| vr1[indtr1[ii], :], | ||
| vquant[indtq[indtu[ii]], :], | ||
| kind='linear', | ||
| bounds_error=False, | ||
| fill_value=fill_value | ||
| )(np.asarray(vii)) | ||
| val[np.isnan(val)] = fill_value | ||
|
|
||
| return val, t | ||
|
|
||
| else: | ||
|
|
@@ -563,12 +566,16 @@ def func(pts, vect=None, t=None, ntall=ntall, | |
| # interpolate 1d | ||
| ind = indt == indtu[ii] | ||
| val[ind, indok] = scpinterp.interp1d( | ||
| vr1[indtr1[indtu[ii]], :], | ||
| vr1[indtr1[ii], :], | ||
| vquant[indtq[indtu[ii]], :], | ||
| kind='linear', | ||
| bounds_error=False, | ||
| fill_value=fill_value | ||
| )(vr2[indtr2[ii], indpts[indok]]) | ||
|
|
||
| # Double check nan in case vr2 is itself nan on parts of mesh | ||
| if np.any(np.isnan(val)) and not np.isnan(fill_value): | ||
| val[np.isnan(val)] = fill_value | ||
| return val, t | ||
| return func | ||
|
|
||
|
|
@@ -672,13 +679,13 @@ def func(pts, vect=None, t=None, ntall=ntall, | |
| tall=tall, tbinall=tbinall): | ||
|
|
||
| # Get pts in (r,z,phi) | ||
| r, z = np.hypot(pts[0,:],pts[1,:]), pts[2,:] | ||
| phi = np.arctan2(pts[1,:],pts[0,:]) | ||
| r, z = np.hypot(pts[0, :], pts[1, :]), pts[2, :] | ||
| phi = np.arctan2(pts[1, :], pts[0, :]) | ||
|
|
||
| # Deduce vect in (r,z,phi) | ||
| vR = np.cos(phi)*vect[0,:] + np.sin(phi)*vect[1,:] | ||
| vphi = -np.sin(phi)*vect[0,:] + np.cos(phi)*vect[1,:] | ||
| vZ = vect[2,:] | ||
| vR = np.cos(phi)*vect[0, :] + np.sin(phi)*vect[1, :] | ||
| vPhi = -np.sin(phi)*vect[0, :] + np.cos(phi)*vect[1, :] | ||
| vZ = vect[2, :] | ||
|
|
||
| # Prepare output | ||
| shapeval = list(pts.shape) | ||
|
|
@@ -689,6 +696,7 @@ def func(pts, vect=None, t=None, ntall=ntall, | |
|
|
||
| # Interpolate | ||
| indpts = trifind(r, z) | ||
| indok = indpts > -1 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this used after ?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not yet, but it will be in a future version, just preparing for it |
||
| if t is None: | ||
| for ii in range(0,ntall): | ||
| valR[ii, ...] = vq2dR[indtq[ii], indpts] | ||
|
|
@@ -697,9 +705,8 @@ def func(pts, vect=None, t=None, ntall=ntall, | |
| t = tall | ||
| else: | ||
| ntall, indt, indtu = plasma._get_indtu(t=t, tall=tall, | ||
| tbinall=tbinall, | ||
| idref1d=idref1d, | ||
| idref2d=idref2d)[1:] | ||
| tbinall=tbinall)[1:-2] | ||
|
|
||
| for ii in range(0, ntall): | ||
| ind = indt == indtu[ii] | ||
| valR[ind, ...] = vq2dR[indtq[indtu[ii]], indpts] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2026,7 +2026,11 @@ def _extract_common_params(obj0, obj1=None): | |
|
|
||
| @staticmethod | ||
| def _recreatefromoperator(d0, other, opfunc): | ||
| if type(other) in [int,float,np.int64,np.float64]: | ||
| if type(other) in [int, float, np.int64, np.float64]: | ||
| data = opfunc(d0.data, other) | ||
| dcom = d0._extract_common_params(d0) | ||
|
|
||
| elif isinstance(other, np.ndarray): | ||
| data = opfunc(d0.data, other) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would put an "or" in the if, instead of showing two different cases with the same result
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You(re right, but I wanted to separate these becasue I may to treat these cases differently later, let's say it for readability and anticipation of future needs |
||
| dcom = d0._extract_common_params(d0) | ||
|
|
||
|
|
@@ -2515,6 +2519,9 @@ def trifind(r, z, | |
| indpts = indR*nZ + indZ | ||
| else: | ||
| indpts = indZ*nR + indR | ||
| indout = ((r < R[0]) | (r > R[-1]) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We make sure points outside of the rectangular grid return -1 as index |
||
| | (z < Z[0]) | (z > Z[-1])) | ||
| indpts[indout] = -1 | ||
| return indpts | ||
|
|
||
| dd[dk][k0]['R'] = R | ||
|
|
@@ -3735,7 +3742,7 @@ def _get_finterp(self, | |
| idquant=None, idref1d=None, idref2d=None, | ||
| idq2dR=None, idq2dPhi=None, idq2dZ=None, | ||
| interp_t=None, interp_space=None, | ||
| fill_value=np.nan, ani=False, Type=None): | ||
| fill_value=None, ani=False, Type=None): | ||
|
|
||
| if interp_t is None: | ||
| interp_t = 'nearest' | ||
|
|
@@ -3853,7 +3860,7 @@ def _checkformat_qr12RPZ(self, quant=None, ref1d=None, ref2d=None, | |
| def get_finterp2d(self, quant=None, ref1d=None, ref2d=None, | ||
| q2dR=None, q2dPhi=None, q2dZ=None, | ||
| interp_t=None, interp_space=None, | ||
| fill_value=np.nan, Type=None): | ||
| fill_value=None, Type=None): | ||
| """ Return the function interpolating (X,Y,Z) pts on a 1d/2d profile | ||
|
|
||
| Can be used as input for tf.geom.CamLOS1D/2D.calc_signal() | ||
|
|
@@ -3880,7 +3887,7 @@ def interp_pts2profile(self, pts=None, vect=None, t=None, | |
| quant=None, ref1d=None, ref2d=None, | ||
| q2dR=None, q2dPhi=None, q2dZ=None, | ||
| interp_t=None, interp_space=None, | ||
| fill_value=np.nan, Type=None): | ||
| fill_value=None, Type=None): | ||
| """ Return the value of the desired profiles_1d quantity | ||
|
|
||
| For the desired inputs points (pts): | ||
|
|
@@ -3911,8 +3918,23 @@ def interp_pts2profile(self, pts=None, vect=None, t=None, | |
| else: | ||
| idmesh = [id_ for id_ in self._ddata[idref2d]['depend'] | ||
| if self._dindref[id_]['group'] == 'mesh'][0] | ||
| pts = self.dmesh[idmesh]['data']['nodes'] | ||
| pts = np.array([pts[:,0], np.zeros((pts.shape[0],)), pts[:,1]]) | ||
| if self.dmesh[idmesh]['data']['type'] == 'rect': | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sure the default pts are chosen according to the mesh type (rect vs triangular) |
||
| if self.dmesh[idmesh]['data']['shapeRZ'] == ('R', 'Z'): | ||
| R = np.repeat(self.dmesh[idmesh]['data']['R'], | ||
| self.dmesh[idmesh]['data']['nZ']) | ||
| Z = np.tile(self.dmesh[idmesh]['data']['Z'], | ||
| self.dmesh[idmesh]['data']['nR']) | ||
| else: | ||
| R = np.tile(self.dmesh[idmesh]['data']['R'], | ||
| self.dmesh[idmesh]['data']['nZ']) | ||
| Z = np.repeat(self.dmesh[idmesh]['data']['Z'], | ||
| self.dmesh[idmesh]['data']['nR']) | ||
| pts = np.array( | ||
| [R, np.zeros((self.dmesh[idmesh]['data']['size'],)), Z]) | ||
| else: | ||
| pts = self.dmesh[idmesh]['data']['nodes'] | ||
| pts = np.array( | ||
| [pts[:, 0], np.zeros((pts.shape[0],)), pts[:, 1]]) | ||
|
|
||
| pts = np.atleast_2d(pts) | ||
| if pts.shape[0] != 3: | ||
|
|
@@ -3945,7 +3967,7 @@ def calc_signal_from_Cam(self, cam, t=None, | |
| quant=None, ref1d=None, ref2d=None, | ||
| q2dR=None, q2dPhi=None, q2dZ=None, | ||
| Brightness=True, interp_t=None, | ||
| interp_space=None, fill_value=np.nan, | ||
| interp_space=None, fill_value=None, | ||
| res=0.005, DL=None, resMode='abs', method='sum', | ||
| ind=None, out=object, plot=True, dataname=None, | ||
| fs=None, dmargin=None, wintit=None, invert=True, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -364,9 +364,9 @@ def _DataCam12D_plot(lData, key=None, nchMax=_nchMax, ntMax=_ntMax, | |
| c0 = [all([dd.dlabels[kk] == lData[0].dlabels[kk] for dd in lData[1:]]) | ||
| for kk in ['t','X','data']] | ||
| if not all(c0): | ||
| msg = "All Data objects must have the same:\n" | ||
| msg = "All Data objects do not have the same:\n" | ||
| msg += " dlabels['t'], dlabels['X'] and dlabels['data'] !" | ||
| raise Exception(msg) | ||
| warnings.warn(msg) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a non-critical error => downgraded from Exception to warning |
||
|
|
||
|
|
||
| # --------- | ||
|
|
@@ -387,8 +387,9 @@ def _DataCam12D_plot(lData, key=None, nchMax=_nchMax, ntMax=_ntMax, | |
| # Check nch and X | ||
| c0 = [dd.nch == lData[0].nch for dd in lData[1:]] | ||
| if not all(c0): | ||
| msg = "All Data objects must have the same number of channels (self.nch)" | ||
| msg += "\nYou can set the indices of the channels with self.set_indch()" | ||
| msg = ("All Data objects must have the same nb. of channels\n" | ||
| + "\t- self.nch: {}\n".format([dd.nch for dd in lData]) | ||
| + "\n => use self.set_indch()") | ||
| raise Exception(msg) | ||
| nch = lData[0].nch | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5968,6 +5968,9 @@ def _calc_signal_postformat( | |
| if Brightness is False: | ||
| if dataname is None: | ||
| dataname = r"LOS-integral x Etendue" | ||
| if E is None or np.all(np.isnan(E)): | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check etendue is correct before using it |
||
| msg = "Cannot use etendue, it was not set properly !" | ||
| raise Exception(msg) | ||
| if t is None or len(t) == 1 or E.size == 1: | ||
| sig = sig * E | ||
| else: | ||
|
|
@@ -6207,7 +6210,7 @@ def calc_signal_from_Plasma2D( | |
| self, | ||
| plasma2d, | ||
| t=None, | ||
| newcalc=False, | ||
| newcalc=True, | ||
| quant=None, | ||
| ref1d=None, | ||
| ref2d=None, | ||
|
|
@@ -6252,7 +6255,9 @@ def calc_signal_from_Plasma2D( | |
|
|
||
| if newcalc: | ||
| # Get time vector | ||
| if t is None: | ||
| lc = [t is None, type(t) is str, type(t) is np.ndarray] | ||
| assert any(lc) | ||
| if lc[0]: | ||
| out = plasma2d._checkformat_qr12RPZ( | ||
| quant=quant, | ||
| ref1d=ref1d, | ||
|
|
@@ -6262,6 +6267,8 @@ def calc_signal_from_Plasma2D( | |
| q2dZ=q2dZ, | ||
| ) | ||
| t = plasma2d._get_tcom(*out[:4])[0] | ||
| elif lc[1]: | ||
| t = plasma2d._ddata[t]['data'] | ||
| else: | ||
| t = np.atleast_1d(t).ravel() | ||
|
|
||
|
|
@@ -6359,7 +6366,7 @@ def funcbis(*args, **kwdargs): | |
| nbrep = np.r_[ | ||
| indpts[0], np.diff(indpts), pts.shape[1] - indpts[-1] | ||
| ] | ||
| vect = np.repeat(self.u, nbrep, axis=1) | ||
| vect = -np.repeat(self.u, nbrep, axis=1) | ||
| if fill_value is None: | ||
| fill_value = 0. | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vphi was incorrect, it is vPhi