Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
59b1cf7
[#1158] try/except
dvezinet Dec 5, 2025
2d13d93
[#1158] More robust coverage plotting
dvezinet Dec 9, 2025
8cdaf3f
[#1158] imasdef not crashing at import
dvezinet Dec 9, 2025
325ef13
from imas.ids_defs import HDF5_BACKEND
Dec 10, 2025
c7aab3c
check ids disabled
Dec 10, 2025
b31a702
rollback to previous commit
Dec 10, 2025
e0252f5
rollforward to last commit
Dec 10, 2025
d1c6a04
[#1158] minor cleanup
dvezinet Dec 10, 2025
11c1add
[#1158] More debug
dvezinet Dec 11, 2025
abdcfda
Merge branch 'Issue1158_IMASbugs' of github.com:ToFuProject/tofu into…
dvezinet Dec 11, 2025
2ec0bf5
[#1158] imas.ids_primitive.IDSNumericArray
dvezinet Dec 11, 2025
128c1fb
[#1158] imas.ids_primitive.IDSNumericArray => array
dvezinet Dec 11, 2025
c691af9
pdb
Dec 11, 2025
2dbe5b8
Merge branch 'Issue1158_IMASbugs' of https://github.com/ToFuProject/t…
Dec 11, 2025
668e858
[#1158] Handling IMAS new classes where appropriate!
dvezinet Dec 11, 2025
108e045
remove pdb
Dec 11, 2025
d14a4d8
Merge branch 'Issue1158_IMASbugs' of https://github.com/ToFuProject/t…
Dec 11, 2025
5a9f302
[#1158] Handling IMAS new classes where appropriate2
dvezinet Dec 11, 2025
b8a2e66
Merge branch 'Issue1158_IMASbugs' of https://github.com/ToFuProject/t…
Dec 11, 2025
bc174bc
[#1158] Handling IMAS new classes where appropriate3
dvezinet Dec 11, 2025
0bbfd14
Merge branch 'Issue1158_IMASbugs' of https://github.com/ToFuProject/t…
Dec 11, 2025
a1e6e47
fixed IDSNumeric0D
Dec 11, 2025
81a9bb4
[#1158] Clean-up
dvezinet Dec 11, 2025
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
4 changes: 2 additions & 2 deletions tofu/data/_class8_plot_coverage_broadband.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def _plot_cross(
# prepare figure
# ----------------

if dax.get('ndet_cross') is None:
if dax is None or len(dax) == 0:

if fs is None:
fs = (16, 7)
Expand Down Expand Up @@ -430,7 +430,7 @@ def _plot_cross(
# check / format dax

dax = ds._generic_check._check_dax(dax)
fig = dax['ndet_cross']['handle'].figure
fig = dax[list(dax.keys())[0]]['handle'].figure

# ---------------
# plot spans
Expand Down
45 changes: 35 additions & 10 deletions tofu/imas2tofu/_comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@

_DSHORT = _defimas2tofu._dshort
_DCOMP = _defimas2tofu._dcomp
_DDUNITS = imas.dd_units.DataDictionaryUnits()
try:
_DDUNITS = imas.dd_units.DataDictionaryUnits()
except Exception:
_DDUNITS = None

_ISCLOSE = True
_POS = False
Expand Down Expand Up @@ -294,6 +297,19 @@ def fsig(obj, indt=None, indch=None, stack=None, dcond=dcond):
raise Exception(msg)
sig[jj] = sig[jj][ind[0]]

# convert from IMAS classes to numpy / float etc
for ii in range(len(sig)):
if isinstance(sig[ii], imas.ids_primitive.IDSNumericArray):
sig[ii] = np.array(sig[ii])
elif isinstance(sig[ii], imas.ids_primitive.IDSFloat0D):
sig[ii] = float(sig[ii])
elif isinstance(sig[ii], imas.ids_primitive.IDSInt0D):
sig[ii] = int(sig[ii])
elif isinstance(sig[ii], imas.ids_primitive.IDSString0D):
sig[ii] = str(sig[ii])
elif isinstance(sig[ii], imas.ids_primitive.IDSString1D):
sig[ii] = str(sig[ii])

# Conditions for stacking / sqeezing sig
lc = [
(
Expand Down Expand Up @@ -660,12 +676,16 @@ def _check_data(data, pos=None, nan=None, isclose=None, empty=None):
isempty = [None for ii in range(len(data))]
if empty is True:
for ii in range(len(data)):
isempty[ii] = (len(data[ii]) == 0
or (isinstance(data[ii], np.ndarray)
and (data[ii].size == 0
or 0 in data[ii].shape)))
isempty[ii] = (
len(data[ii]) == 0
or (
isinstance(data[ii], np.ndarray)
and (data[ii].size == 0 or 0 in data[ii].shape)
)
)
if isinstance(data[ii], np.ndarray) and data[ii].dtype.kind != 'U':
isempty[ii] &= bool(np.all(np.isnan(data[ii])))

return data, isempty


Expand Down Expand Up @@ -767,17 +787,22 @@ def _get_data_units(ids=None, sig=None, occ=None,
# Check data
isempty = None
if errdata is None and data is True:
out, isempty = _check_data(out,
pos=pos, nan=nan,
isclose=isclose, empty=empty)
out, isempty = _check_data(
out,
pos=pos, nan=nan,
isclose=isclose, empty=empty,
)
if np.all(isempty):
msg = ("empty data in {}.{}".format(ids, sig))
errdata = Exception(msg)
elif nocc == 1 and flatocc is True:
out = out[0]
isempty = isempty[0]
return {'data': out, 'units': unit,
'isempty': isempty, 'errdata': errdata, 'errunits': errunits}

return {
'data': out, 'units': unit,
'isempty': isempty, 'errdata': errdata, 'errunits': errunits,
}


def get_data_units(dsig=None, occ=None,
Expand Down
23 changes: 21 additions & 2 deletions tofu/imas2tofu/_comp_toobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ def get_plasma(
R = out_['2dmeshR']['data']
Z = out_['2dmeshZ']['data']
if R.ndim == 2:
if np.allclose(R[0, :], R[0,0]):
if np.allclose(R[0, :], R[0, 0]):
R = R[:, 0]
Z = Z[0, :]
else:
Expand All @@ -658,13 +658,32 @@ def get_plasma(
# profiles2d on mesh

lprof2d = set(out_.keys()).difference(lsigmesh)

# Check for non-arrays
derr = {
ss: type(out_[ss]['data']) for ss in lprof2d
if not isinstance(out_[ss]['data'], np.ndarray)
}

if len(derr) > 0:
lstr = [f"\t- {kk}: {vv}" for kk, vv in derr.items()]
msg = (
"The following keys in profiles2d are not np.ndarrays:\n"
+ "\n".join(lstr)
)
raise Exception(msg)

# loop
for ss in lprof2d:

# identify proper 2d mesh
lm = [
km for km, vm in dmesh.items()
if (
(km == 'tri' and vm['n1'] in out_[ss]['data'].shape)
(
km == 'tri'
and vm['n1'] in out_[ss]['data'].shape
)
or (
km == 'rect'
and vm['n1'] in out_[ss]['data'].shape
Expand Down
36 changes: 18 additions & 18 deletions tofu/imas2tofu/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@
# imas
try:
import imas
from imas import imasdef
from imas.ids_defs import HDF5_BACKEND
try:
from imas import imasdef
except Exception:
imasdef = None
except Exception as err:
raise Exception('imas not available')
raise Exception(f'imas not available: {str(err)}')


__all__ = [
Expand Down Expand Up @@ -957,15 +961,11 @@ def _checkformat_idd(
user=user, database=database, version=version,
backend=backend,
)
for kk,vv in defidd.items():
for kk, vv in defidd.items():
if params[kk] is None:
params[kk] = vv

# convert backend str => pointer
params['backend'] = getattr(
imasdef,
f"{params['backend']}_BACKEND".upper(),
)
params['backend'] = HDF5_BACKEND

# create entry
idd = imas.DBEntry(
Expand Down Expand Up @@ -1189,13 +1189,13 @@ def _checkformat_ids(
ids = [ids]

# check ids is allowed
for ids_ in ids:
if not ids_ in self._lidsnames:
msg = (
"ids {ids_} matched no known imas ids !"
f" => Available ids are:\n{repr(self._lidsnames)}"
)
raise Exception(msg)
# for ids_ in ids:
# if not ids_ in self._lidsnames:
# msg = (
# "ids {ids_} matched no known imas ids !"
# f" => Available ids are:\n{repr(self._lidsnames)}"
# )
# raise Exception(msg)

# initialise dict
for k in ids:
Expand Down Expand Up @@ -2012,14 +2012,14 @@ class with which the output shall be returned
# ----------------------
# 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 Expand Up @@ -3797,4 +3797,4 @@ def _save_to_imas_DataCam1D(
# ------------------
_put_ids(idd, ids, shotfile, occ=occ,
cls_name='%s_%s'%(obj.Id.Cls,obj.Id.Name),
err=err0, dryrun=dryrun, verb=verb)
err=err0, dryrun=dryrun, verb=verb)
Loading