Skip to content

Issue321 rectangular grid metis#325

Merged
Didou09 merged 29 commits intodevelfrom
Issue321_RectangularGridMETIS
Jan 14, 2020
Merged

Issue321 rectangular grid metis#325
Didou09 merged 29 commits intodevelfrom
Issue321_RectangularGridMETIS

Conversation

@Didou09
Copy link
Copy Markdown
Member

@Didou09 Didou09 commented Jan 10, 2020

Main changes:

  • Multi.to_Config() is now operational for vessel / limiter / mobile and also for limiter-only wall ids
  • Plasma2D now handles rectangular (R, Z) grids for interpolation, assuming the array order (shapeRZ=('R', 'Z') or ('Z', 'R') is provided by the user.
  • Multi.calc_signal() now properly handles METIS simulations with rectangular grids
  • Multi.to_Cam(), Multi.to_Data() and Multi.calc_signal() all now properly handle indch_auto=True (propagated)
  • Slightly more explicit warning in case of missing tofu sub-package

Some implementation details:

  • description_2d and indDescription were 2 different variable names for the same thing
    => description_2d is kept only
  • Multi._get_indch_geomtdata() hidden method implement to handle automated determination of indch in all cases (LOS, time and data), for readability and modularity
  • Shortcuts 2dmeshR and 2dmeshZ added for rectangular meshes

Status:

To this day (2020-01-10), on WEST intra servers, the following syntthetic diagnostics are operational directly from IMAS / METIS:

  • Polarimeter : ok
  • Interferometer : ok (provided METIS writes Nan outside of separatrix)
  • Bolometer: ok (provided Etendues are stored in ids and proper geometry)
  • Bremsstrahlung_visible: ok (provided proper units in ids and proper geometry)

The soft_x_rays ids is not operational yet because it requires atomic data, not implemented yet

Example (only on WEST intra servers):

In [1]: import tofu as tf

In [2]: multi = tf.imas2tofu.MultiIDSLoader(ids=['interferometer', 'polarimeter', 'spectrometer_visible', 'bolometer', 'bremsstrahlung_visible', 'soft_x_rays'], shot=54178, get=False)

In [3]: multi.add_ids_synthdiag(user='CB165101', shot=54178, run=13, tokamak='west')
Getting ids             [occ]  tokamak  user         version  shot   run  refshot  refrun
----------------------  -----  -------  -----------  -------  -----  ---  -------  ------
core_profiles           [0]    west     CB165101     3        54178  13   -1       -1    
core_sources            [0]    "        "            "        "      "    "        "     
equilibrium             [0]    "        "            "        "      "    "        "     
bolometer               [0]    west     imas_public  3        54178  0    -1       -1      
interferometer          [0]    "        "            "        "      "    "        "     
polarimeter             [0]    "        "            "        "      "    "        "     
pulse_schedule          [0]    "        "            "        "      "    "        "     
wall                    [0]    "        "            "        "      "    "        "     

In [4]: sig_pola = multi.calc_signal('polarimeter', indch_auto=True)
/Home/DV226270/ToFu_All/tofu_git/tofu/tofu/imas2tofu/_core.py:3165: UserWarning: indch set automatically for None
  (due to inhomogeneous data shapes)
    - main shape: (46446,)
    - nb. chan. selected: 8
    - indch: [2, 3, 4, 5, 6, 7, 8, 9]
  warnings.warn(msg)
/Home/DV226270/ToFu_All/tofu_git/tofu/tofu/imas2tofu/_core.py:2114: UserWarning: The following data could not be retrieved:
	- equilibrium:
		2dmeshFaces  : list index out of range
  warnings.warn(msg)

Issues:

Fixes, in devel, issue #321

VEZINET Didier added 14 commits December 18, 2019 15:00
…rategy : vessel in vessel, PFC in limiter or mobile units if any mobile, and more descriptions written
…ti.to_Cam() and Multi.to_Data(), hence 'names' field also added to all diag default shortcuts
@pep8speaks
Copy link
Copy Markdown

pep8speaks commented Jan 10, 2020

Hello @Didou09! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-01-14 10:05:00 UTC

@codecov-io
Copy link
Copy Markdown

codecov-io commented Jan 10, 2020

Codecov Report

Merging #325 into devel will increase coverage by 0.02%.
The diff coverage is 0.97%.

Impacted file tree graph

@@            Coverage Diff             @@
##            devel     #325      +/-   ##
==========================================
+ Coverage   40.04%   40.06%   +0.02%     
==========================================
  Files          79       79              
  Lines       24108    24094      -14     
==========================================
  Hits         9653     9653              
+ Misses      14455    14441      -14
Impacted Files Coverage Δ
tofu/data/_core.py 38.97% <ø> (ø) ⬆️
tofu/geom/_core.py 63.19% <0%> (-0.09%) ⬇️
tofu/imas2tofu/_core.py 0.67% <0%> (ø) ⬆️
tofu/data/_comp.py 19.93% <0%> (-0.4%) ⬇️
tofu/version.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 762f2fe...74ab681. Read the comment docs.

Comment thread tofu/data/_comp.py
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, :]
Copy link
Copy Markdown
Member Author

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

Comment thread tofu/data/_core.py
indpts = indR*nZ + indZ
else:
indpts = indZ*nR + indR
indout = ((r < R[0]) | (r > R[-1])
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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

Comment thread tofu/data/_core.py
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':
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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)

Comment thread tofu/data/_plot.py
msg = "All Data objects do not have the same:\n"
msg += " dlabels['t'], dlabels['X'] and dlabels['data'] !"
raise Exception(msg)
warnings.warn(msg)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is a non-critical error => downgraded from Exception to warning

Comment thread tofu/geom/_core.py
if Brightness is False:
if dataname is None:
dataname = r"LOS-integral x Etendue"
if E is None or np.all(np.isnan(E)):
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Check etendue is correct before using it

Comment thread tofu/imas2tofu/_core.py Outdated
if units[ii].phi_extensions.size > 0:
pos, extent = units[ii].phi_extensions.T
# Get vessel
nlim = len(wall.limiter.unit)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We now consider both limiter and mobile wall types

Comment thread tofu/imas2tofu/_core.py Outdated
nmob = len(wall.mobile.unit)
onelimonly = False
try:
if len(wall.vessel.unit) != 1:
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There should be only one vessel in the IMAS ids (corresponds to tofu call Ves : a StructIn sub-class)

Comment thread tofu/imas2tofu/_core.py Outdated

# Determine if mobile or not
lS = []
if onelimonly is False:
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If there are several PFC, we load them either from limiter or mobile

Comment thread tofu/imas2tofu/_core.py

return geomcls

def _get_indch_geomtdata(self, indch=None, indch_auto=None,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

hidden method created to handle automated determination of indch in a modular way

Comment thread tofu/imas2tofu/_core.py
node.phi_extensions = np.array([lS[ii].pos, lS[ii].extent]).T
node.closed = True
node.name = '%s_%s'%(lS[ii].__class__.__name__, lS[ii].Id.Name)
wall = idd.wall.description_2d[description_2d]
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We make sure that we can save to vessel / limiter / mobile froma tofu Config

Comment thread tofu/data/_comp.py

# Interpolate
indpts = trifind(r, z)
indok = indpts > -1
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

is this used after ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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

Comment thread tofu/data/_core.py
dcom = d0._extract_common_params(d0)

elif isinstance(other, np.ndarray):
data = opfunc(d0.data, other)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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

Comment thread tofu/imas2tofu/_core.py Outdated
config = mod.Config(lStruct=lS, Name=Name, **kwargs)
if Name is None:
Name = wall.type.name
if Name == '':
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

is this rightly indented ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes, it happens that people save empty names ('') in IMAS, because they forget to fill it in

Comment thread tofu/imas2tofu/_core.py
shapeu = np.unique(np.r_[R.shape, Z.shape])
shapeRZ = [None, None]
if shapeRZ is None:
shapeRZ = [None, None]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

should shapeRZ not be a tuple instead of a list (see below)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ultmately, shapeRZ will be returned as a tuple, yes,
But at this point we have to define it as a list because we may have to modify it, and tuples are immutable.
So we define it as a list, possibly modify it, and finally convert it to a tuple

VEZINET Didier added 6 commits January 13, 2020 17:11
…s nan already from source in Plasma2D.interp_pts2profile()

Set sig = -2*sig for polarimeter due to vect direction (laser direction)
Set vect = -u in newcalc=False
Double checked all METIS synthetic diagnostics:
 polarimeter and interferometer ok
 bremsstrhalung_visible and bolometer waiting for sequenceur replay for units, geometry and etendues

Synthetic diag now need to be double-checked for NICE / EQUINOX
…ctions. To be double-tested for all cases, METIS and NICE
…n-zero and different in Multi.to_Config(), and limiter chosen by default (with warning) when they are equal
@Didou09 Didou09 merged commit 80bc6fe into devel Jan 14, 2020
@Didou09 Didou09 deleted the Issue321_RectangularGridMETIS branch January 14, 2020 12:25
@Didou09 Didou09 mentioned this pull request Jan 30, 2020
@Didou09 Didou09 mentioned this pull request Mar 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants