Skip to content

Commit

Permalink
[#1016] Fixed order of lids + better error msg
Browse files Browse the repository at this point in the history
  • Loading branch information
tbarbui committed Feb 4, 2025
1 parent 76c30ff commit a6fc015
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
30 changes: 29 additions & 1 deletion tofu/imas2tofu/_comp_toobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,15 @@ def get_plasma(
# -------------
# loop on ids
# -------------

# IMPROVEMENT:
# This for loop should be divided in 2
# First: read all meshes on all ids + time traces
# second: read all fields that depend on meshes
# Use case: when a 2d mesh is needed for ids0 but only exists in ids1 (or vice-versa)

for ids in lids:

idsshort = _def._dshortids.get(ids, ids)

# -----
Expand Down Expand Up @@ -582,6 +589,7 @@ def get_plasma(

cmesh = any([ss in out_.keys() for ss in lsigmesh])

lprof2d = None
if len(out_) > 0 and cmesh is True:

npts, datashape = None, None
Expand Down Expand Up @@ -628,7 +636,8 @@ def get_plasma(
# profiles2d on mesh

meshtype = coll.dobj[wm][keym]['type']
for ss in set(out_.keys()).difference(lsigmesh):
lprof2d = set(out_.keys()).difference(lsigmesh)
for ss in lprof2d:
add_profile2d(
multi=multi,
ids=ids,
Expand Down Expand Up @@ -703,6 +712,7 @@ def get_plasma(

elif len(drad) == 1:
k0ref = list(drad.keys())[0]

else:
if not np.unique([v0.size for v0 in drad.values()]).size == 1:
lstr = [f"\t- {k0}: {v0.size}" for k0, v0 in drad.items()]
Expand Down Expand Up @@ -731,20 +741,38 @@ def get_plasma(
dim = multi._dcomp[ids][k0ref].get('dim', 'unknown')
quant = multi._dcomp[ids][k0ref].get('quant', 'unknown')

# ------------------------------
# list available 2d radius maps

radius2d = [
k0 for k0, v0 in coll.ddata.items()
if '2d' in k0
and v0['dim'] == dim
and v0['quant'] == quant
and v0['bsplines'] is not None
]

# one map found
if len(radius2d) == 1:
radius2d = radius2d[0]

# None found
elif len(radius2d) == 0:
msg = (
"No 2d radius for polar mesh!\n"
f"\t- ids = {ids}\n"
f"\t- cmesh = {cmesh}\n"
f"\t- lsigmesh = {lsigmesh}\n"
f"\t- dim = {dim}\n"
f"\t- quant = {quant}\n"
f"\t- k0ref = {k0ref}\n"
f"\t- kref = {kref}\n"
f"\t- nr = {nr}\n"
f"\t- lprof2d = {lprof2d}\n"
)
raise Exception(msg)

# multiple maps found => ambiguous
else:
msg = (
"Several possible 2d radius identified!\n"
Expand Down
9 changes: 8 additions & 1 deletion tofu/imas2tofu/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2009,10 +2009,17 @@ class with which the output shall be returned
# plot, plot_X, plot_sig,
# dsig=dsig)

# lids
# ----------------------
# lids determines order in which ids are read
# may be important in case 2d mesh only exists in one ids!

lids = sorted(dsig.keys())
if 'equilibrium' in lids:
lids = ['equilibrium'] + [ids for ids in lids if ids != 'equilibrium']

# -------------------------
# data source consistency

_, _, shot, Exp = _comp_toobjects.get_lidsidd_shotExp(
lids, upper=True, errshot=False, errExp=False,
dids=self._dids, didd=self._didd,
Expand Down

0 comments on commit a6fc015

Please sign in to comment.