From 68e3ec0aef62d4e344972b0669a6e9450444ae2e Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Thu, 20 Feb 2020 09:58:25 +0100 Subject: [PATCH 01/16] [Issue346] from_mat operational, but to be tested --- tofu/{data => }/_physics.py | 0 tofu/data/_core.py | 4 +- tofu/data/_core_new.py | 4 +- tofu/imas2tofu/__init__.py | 2 + tofu/imas2tofu/_core.py | 23 +++--- tofu/utils.py | 138 ++++++++++++++++++++++++++++-------- tofu/version.py | 2 +- 7 files changed, 129 insertions(+), 44 deletions(-) rename tofu/{data => }/_physics.py (100%) diff --git a/tofu/data/_physics.py b/tofu/_physics.py similarity index 100% rename from tofu/data/_physics.py rename to tofu/_physics.py diff --git a/tofu/data/_core.py b/tofu/data/_core.py index a4f45c47e..0529c28ec 100644 --- a/tofu/data/_core.py +++ b/tofu/data/_core.py @@ -24,13 +24,13 @@ import tofu.data._comp as _comp import tofu.data._plot as _plot import tofu.data._def as _def - import tofu.data._physics as _physics + import tofu._physics as _physics import tofu.data._spectrafit2d as _spectrafit2d except Exception: from . import _comp as _comp from . import _plot as _plot from . import _def as _def - from . import _physics as _physics + from .. import _physics as _physics from . import _spectrafit2d as _spectrafit2d __all__ = ['DataCam1D','DataCam2D', diff --git a/tofu/data/_core_new.py b/tofu/data/_core_new.py index 6c9b97937..0b2b49d33 100644 --- a/tofu/data/_core_new.py +++ b/tofu/data/_core_new.py @@ -24,12 +24,12 @@ import tofu.data._comp as _comp import tofu.data._plot as _plot import tofu.data._def as _def - import tofu.data._physics as _physics + import tofu._physics as _physics except Exception: from . import _comp as _comp from . import _plot as _plot from . import _def as _def - from . import _physics as _physics + from .. import _physics as _physics __all__ = ['DataHolder'] # , 'Plasma0D'] diff --git a/tofu/imas2tofu/__init__.py b/tofu/imas2tofu/__init__.py index 842ecaef4..5df50ae23 100644 --- a/tofu/imas2tofu/__init__.py +++ b/tofu/imas2tofu/__init__.py @@ -11,8 +11,10 @@ try: try: from tofu.imas2tofu._core import * + from tofu.imas2tofu._mat2ids2calc import * except Exception: from ._core import * + from ._mat2ids2calc import * except Exception as err: if str(err) == 'imas not available': msg = "" diff --git a/tofu/imas2tofu/_core.py b/tofu/imas2tofu/_core.py index 6ec5f4939..6c3ba6e03 100644 --- a/tofu/imas2tofu/_core.py +++ b/tofu/imas2tofu/_core.py @@ -581,6 +581,8 @@ def _rhosign(rho, theta): rho[ind] = -rho[ind] return rho + def _lamb(lamb_up, lamb_lo): + return 0.5*(lamb_up + lamb_lo) _dcomp = { 'pulse_schedule': @@ -640,7 +642,7 @@ def _rhosign(rho, theta): 'units':'adim.'}}, 'bremsstrahlung_visible': - {'lamb':{'lstr':['lamb_up','lamb_lo'], 'func':np.mean, + {'lamb':{'lstr':['lamb_up','lamb_lo'], 'func':_lamb, 'dim':'distance', 'quantity':'wavelength', 'units':'m'}} } @@ -2547,21 +2549,22 @@ def to_Config(self, Name=None, occ=None, mobile = True elif nmob == 0 and nlim > 0: mobile = False - elif nmob == nlim: + elif nmob > nlim: msgw = 'wall.description_2[{}]'.format(description_2d) - msg = ("\nids wall has same number of limiter / mobile units\n" + msg = ("\nids wall has less limiter than mobile units\n" + "\t- len({}.limiter.unit) = {}\n".format(msgw, nlim) + "\t- len({}.mobile.unit) = {}\n".format(msgw, nmob) - + " => Choosing limiter by default") + + " => Choosing mobile by default") warnings.warn(msg) - mobile = False - else: + mobile = True + elif nmob <= nlim: msgw = 'wall.description_2[{}]'.format(description_2d) - msg = ("Can't decide automatically whether to choose" - + " limiter or mobile!\n" + msg = ("\nids wall has more limiter than mobile units\n" + "\t- len({}.limiter.unit) = {}\n".format(msgw, nlim) - + "\t- len({}.mobile.unit) = {}".format(msgw, nmob)) - raise Exception(msg) + + "\t- len({}.mobile.unit) = {}\n".format(msgw, nmob) + + " => Choosing limiter by default") + warnings.warn(msg) + mobile = False assert isinstance(mobile, bool) # Get PFC diff --git a/tofu/utils.py b/tofu/utils.py index 6db96227e..56cbac45e 100644 --- a/tofu/utils.py +++ b/tofu/utils.py @@ -1039,8 +1039,9 @@ def calc_from_imas(shot=None, run=None, user=None, tokamak=None, version=None, ids=None, Name=None, out=None, tlim=None, config=None, occ=None, indch=None, description_2d=None, equilibrium=None, dsig=None, data=None, X=None, t0=None, dextra=None, - Brightness=None, res=None, interp_t=None, extra=True, - plot=True, plot_compare=True, sharex=False, + Brightness=None, res=None, interp_t=None, extra=None, + plot=None, plot_compare=True, sharex=False, + input_file=None, output_file=None, bck=True, indch_auto=True, t=None, init=None): # ------------------- # import imas2tofu @@ -1049,19 +1050,30 @@ def calc_from_imas(shot=None, run=None, user=None, tokamak=None, version=None, import tofu.imas2tofu as imas2tofu except Exception as err: msg = str(err) - msg += "\n\n module imas2tofu does not seem available\n" - msg += " => imas may not be installed ?" + msg += ("\n\n module imas2tofu does not seem available\n" + + " => imas may not be installed?") raise Exception(msg) lok = ['Data'] c0 = out is None or out in lok if not c0: - msg = "Arg out must be in %s"%str(lok) + msg = "Arg out must be in {}".format(lok) raise Exception(msg) + if plot is None: + if output_file is not None: + plot = False + else: + plot = True + if extra is None: + if input_file is not None: + extra = False + else: + extra = True + # ------------------- # Prepare ids - assert ids is None or type(ids) in [list,str] + assert ids is None or type(ids) in [list, str] if type(ids) is str: ids = [ids] if type(ids) is list: @@ -1083,12 +1095,24 @@ def calc_from_imas(shot=None, run=None, user=None, tokamak=None, version=None, if nids > 1: assert not any([ids_ in ids for ids_ in lidscustom]) + # Check if input_file + if input_file is not None: + lids_input_file = ['bremsstrahlung_visible'] + if nids != 1 or ids[0] not in lids_input_file: + msg = ("input_file is only available for a single ids in:\n" + + "\t- " + "\n\t- ".join(lids_input_file)) + raise Exception(msg) # ------------------- # Prepare shot shot = np.r_[shot].astype(int) nshot = shot.size + # Check if input_file + if input_file is not None: + if nshot != 1: + msg = "input_file not available for multiple shots!" + raise Exception(msg) # ------------------- # Prepare out @@ -1107,8 +1131,8 @@ def calc_from_imas(shot=None, run=None, user=None, tokamak=None, version=None, if nids > 1: if not all([ids_ in imas2tofu.MultiIDSLoader._lidsdiag for ids_ in ids]): - msg = "tf.load_from_imas() only handles multipe ids\n" - msg += "if all are diagnostics ids !" + msg = ("tf.load_from_imas() only handles multipe ids " + + "if all are diagnostics ids!") raise Exception(msg) # ------------------- @@ -1215,29 +1239,85 @@ def calc_from_imas(shot=None, run=None, user=None, tokamak=None, version=None, # ------------------- # load - for ss in shot: - multi = imas2tofu.MultiIDSLoader(shot=ss, run=run, user=user, - tokamak=tokamak, version=version, - ids=lids, synthdiag=True) - - # export to instances - for ii in range(0,nids): - if out[ii] == "Data": - multi.calc_signal(ids=lids[ii], - tlim=tlim, dsig=dsig, - config=config, t=t, - res=res, indch=indch, - Brightness=Brightness, - interp_t=interp_t, - indch_auto=indch_auto, - t0=t0, dextra=dextra, - plot=True, - plot_compare=plot_compare) - - - + if input_file is None: + for ss in shot: + multi = imas2tofu.MultiIDSLoader(shot=ss, run=run, user=user, + tokamak=tokamak, version=version, + ids=lids, synthdiag=True) + + # export to instances + for ii in range(0,nids): + if out[ii] == "Data": + multi.calc_signal(ids=lids[ii], + tlim=tlim, dsig=dsig, + config=config, t=t, + res=res, indch=indch, + Brightness=Brightness, + interp_t=interp_t, + indch_auto=indch_auto, + t0=t0, dextra=dextra, + plot=True, + plot_compare=plot_compare) + else: + multi = imas2tofu.MultiIDSLoader(shot=shot[0], run=run, user=user, + tokamak=tokamak, version=version, + ids=lids, synthdiag=False, get=False) + if 'bremsstrahlung_visible' in lids: + multi.add_ids('equilibrium', get=True) + plasma = multi.to_Plasma2D() + lf = ['t', 'rhotn', 'brem'] + lamb = multi.get_data('bremsstrahlung_visible', sig='lamb')['lamb'] + dout = imas2tofu.get_data_from_matids(input_file, + return_fields=lf, + lamb=lamb[0]) + plasma.add_ref(key='core_profiles.t', data=dout['t'], group='time', + origin='input_file') + nrad = dout['rhotn'].shape[1] + plasma.add_ref(key='core_profiles.radius', data=np.arange(0, nrad), + group='radius', origin='input_file') + plasma.add_quantity(key='core_profiles.1drhotn', + data=dout['rhotn'], + depend=('core_profiles.t', + 'core_profiles.radius'), + origin='input_file', + quant='rhotn', dim='rho', units='adim.') + plasma.add_quantity(key='core_profiles.1dbrem', data=dout['brem'], + depend=('core_profiles.t', + 'core_profiles.radius'), + origin='input_file') + cam = multi.to_Cam(plot=False) + sig = cam.calc_signal_from_Plasma2D(plasma, + quant='core_profiles.1dbrem', + ref1d='core_profiles.1drhotn', + ref2d='equilibrium.2drhotn', + Brightness=True, plot=plot)[0] + if output_file is not None: + try: + # Format output dictionnary to be saved + dout = {'shot': shot[0], + 't': sig.t, + 'data': sig.data, + 'units_t': 's', + 'units_data': 'ph / (s.m2.sr.m)', + 'channels': sig.dchans('names'), + 'tofu_version': __version__} + + # Save to specified path + filename + extension + if output_file[-4:] != '.mat': + assert len(output_file.split('.')) == 1 + output_file += '.mat' + scpio.savemat(output_file, dout) + msg = ("Successfully saved in:\n" + + "\t{}".format(output_file)) + print(msg) + except Exception as err: + msg = str(err) + msg += "\nCould not save computed synthetic signal to:\n" + msg += "scpio.savemat({0}, dout)".format(output_file) + warnings.warn(msg) + import pdb; pdb.set_trace() # DB ############################################# diff --git a/tofu/version.py b/tofu/version.py index f3fbe0706..058e43496 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.2b4-39-g2b1aa022' +__version__ = '1.4.2b4-41-gdd17eb2c' From 8a409da349ffbb11f66a1b36ea9aff5487896827 Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Thu, 20 Feb 2020 15:06:02 +0100 Subject: [PATCH 02/16] [Issue346] Debugged and tested when possible tofucalc with --input_file and --output_file --- tofu/imas2tofu/_core.py | 410 ++------------------------------------- tofu/scripts/tofucalc.py | 8 + tofu/utils.py | 13 +- tofu/version.py | 2 +- 4 files changed, 27 insertions(+), 406 deletions(-) diff --git a/tofu/imas2tofu/_core.py b/tofu/imas2tofu/_core.py index 6c3ba6e03..fb6953aa5 100644 --- a/tofu/imas2tofu/_core.py +++ b/tofu/imas2tofu/_core.py @@ -23,6 +23,12 @@ import matplotlib as mpl import datetime as dtm +# tofu +try: + import tofu.imas2tofu._def as _defimas2tofu +except: + from . import _def as _defimas2tofu + # imas try: import imas @@ -90,402 +96,8 @@ class MultiIDSLoader(object): 'shot', 'run', 'refshot', 'refrun'] # Known short version of signal str - - _dshort = { - 'wall': - {'wallR':{'str':'description_2d[0].limiter.unit[0].outline.r'}, - 'wallZ':{'str':'description_2d[0].limiter.unit[0].outline.z'}}, - - 'pulse_schedule': - {'events_times':{'str':'event[].time_stamp'}, - 'events_names':{'str':'event[].identifier'}}, - - 'equilibrium': - {'t':{'str':'time'}, - 'ip':{'str':'time_slice[time].global_quantities.ip', - 'dim':'current', 'quant':'Ip', 'units':'A'}, - 'q0':{'str':'time_slice[time].global_quantities.q_axis'}, - 'qmin':{'str':'time_slice[time].global_quantities.q_min.value'}, - 'q95':{'str':'time_slice[time].global_quantities.q_95'}, - 'volume':{'str':'time_slice[time].global_quantities.volume', - 'dim':'volume', 'quant':'pvol', 'units':'m3'}, - 'psiaxis':{'str':'time_slice[time].global_quantities.psi_axis', - 'dim':'B flux', 'quant':'psi', 'units':'Wb'}, - 'psisep':{'str':'time_slice[time].global_quantities.psi_boundary', - 'dim':'B flux', 'quant':'psi', 'units':'Wb'}, - 'BT0':{'str':'time_slice[time].global_quantities.magnetic_axis.b_field_tor', - 'dim':'B', 'quant':'BT', 'units':'T'}, - 'axR':{'str':'time_slice[time].global_quantities.magnetic_axis.r', - 'dim':'distance', 'quant':'R', 'units':'m'}, - 'axZ':{'str':'time_slice[time].global_quantities.magnetic_axis.z', - 'dim':'distance', 'quant':'Z', 'units':'m'}, - 'x0R':{'str':'time_slice[time].boundary.x_point[0].r'}, - 'x0Z':{'str':'time_slice[time].boundary.x_point[0].z'}, - 'x1R':{'str':'time_slice[time].boundary.x_point[1].r'}, - 'x1Z':{'str':'time_slice[time].boundary.x_point[1].z'}, - 'strike0R':{'str':'time_slice[time].boundary.strike_point[0].r'}, - 'strike0Z':{'str':'time_slice[time].boundary.strike_point[0].z'}, - 'strike1R':{'str':'time_slice[time].boundary.strike_point[1].r'}, - 'strike1Z':{'str':'time_slice[time].boundary.strike_point[1].z'}, - 'sepR':{'str':'time_slice[time].boundary_separatrix.outline.r'}, - 'sepZ':{'str':'time_slice[time].boundary_separatrix.outline.z'}, - - '1drhotn':{'str':'time_slice[time].profiles_1d.rho_tor_norm', - 'dim':'rho', 'quant':'rhotn', 'units':'adim.'}, - '1dphi':{'str':'time_slice[time].profiles_1d.phi', - 'dim':'B flux', 'quant':'phi', 'units':'Wb'}, - '1dpsi':{'str':'time_slice[time].profiles_1d.psi', - 'dim':'B flux', 'quant':'psi', 'units':'Wb'}, - '1dq':{'str':'time_slice[time].profiles_1d.q', - 'dim':'safety factor', 'quant':'q', 'units':'adim.'}, - '1dpe':{'str':'time_slice[time].profiles_1d.pressure', - 'dim':'pressure', 'quant':'pe', 'units':'Pa'}, - '1djT':{'str':'time_slice[time].profiles_1d.j_tor', - 'dim':'vol. current dens.', 'quant':'jT', 'units':'A/m^2'}, - - '2dphi':{'str':'time_slice[time].ggd[0].phi[0].values', - 'dim':'B flux', 'quant':'phi', 'units':'Wb'}, - '2dpsi':{'str':'time_slice[time].ggd[0].psi[0].values', - 'dim':'B flux', 'quant':'psi', 'units':'Wb'}, - '2djT':{'str':'time_slice[time].ggd[0].j_tor[0].values', - 'dim':'vol. current dens.', 'quant':'jT', 'units':'A/m^2'}, - '2dBR':{'str':'time_slice[time].ggd[0].b_field_r[0].values', - 'dim':'B', 'quant':'BR', 'units':'T'}, - '2dBT':{'str':'time_slice[time].ggd[0].b_field_tor[0].values', - 'dim':'B', 'quant':'BT', 'units':'T'}, - '2dBZ':{'str':'time_slice[time].ggd[0].b_field_z[0].values', - 'dim':'B', 'quant':'BZ', 'units':'T'}, - '2dmeshNodes': {'str': ('grids_ggd[0].grid[0].space[0]' - + '.objects_per_dimension[0]' - + '.object[].geometry')}, - '2dmeshFaces': {'str': ('grids_ggd[0].grid[0].space[0]' - + '.objects_per_dimension[2]' - + '.object[].nodes')}, - '2dmeshR': {'str': 'time_slice[0].profiles_2d[0].r'}, - '2dmeshZ': {'str': 'time_slice[0].profiles_2d[0].z'}}, - - 'core_profiles': - {'t':{'str':'time'}, - 'ip':{'str':'global_quantities.ip', - 'dim':'current', 'quant':'Ip', 'units':'A'}, - 'vloop':{'str':'global_quantities.v_loop', - 'dim':'voltage', 'quant':'Vloop', 'units':'V/m'}, - - '1dTe':{'str':'profiles_1d[time].electrons.temperature', - 'dim':'temperature', 'quant':'Te', 'units':'eV'}, - '1dne':{'str':'profiles_1d[time].electrons.density', - 'dim':'density', 'quant':'ne', 'units':'/m^3'}, - '1dzeff':{'str':'profiles_1d[time].zeff', - 'dim':'charge', 'quant':'zeff', 'units':'adim.'}, - '1dphi':{'str':'profiles_1d[time].grid.phi', - 'dim':'B flux', 'quant':'phi', 'units':'Wb'}, - '1dpsi':{'str':'profiles_1d[time].grid.psi', - 'dim':'B flux', 'quant':'psi', 'units':'Wb'}, - '1drhotn':{'str':'profiles_1d[time].grid.rho_tor_norm', - 'dim':'rho', 'quant':'rhotn', 'units':'adim.'}, - '1drhopn':{'str':'profiles_1d[time].grid.rho_pol_norm', - 'dim':'rho', 'quant':'rhopn', 'units':'adim.'}, - '1dnW':{'str':'profiles_1d[time].ions[identifier.label=W].density', - 'dim':'density', 'quant':'nI', 'units':'/m^3'}}, - - 'edge_profiles': - {'t':{'str':'time'}}, - - 'core_sources': - {'t':{'str':'time'}, - '1dpsi':{'str':'source[identifier.name=lineradiation].profiles_1d[time].grid.psi', - 'dim':'B flux', 'quant':'psi', 'units':'Wb'}, - '1drhotn':{'str':'source[identifier.name=lineradiation].profiles_1d[time].grid.rho_tor_norm', - 'dim':'rho', 'quant':'rhotn', 'units':'Wb'}, - '1dbrem':{'str':"source[identifier.name=bremsstrahlung].profiles_1d[time].electrons.energy", - 'dim':'vol.emis.', 'quant':'brem.', 'units':'W/m^3'}, - '1dline':{'str':"source[identifier.name=lineradiation].profiles_1d[time].electrons.energy", - 'dim':'vol. emis.', 'quant':'lines', 'units':'W/m^3'}}, - - 'edge_sources': - {'t':{'str':'time'}, - '2dmeshNodes':{'str':'grid_ggd[0].space[0].objects_per_dimension[0].object[].geometry'}, - '2dmeshFaces':{'str':'grid_ggd[0].space[0].objects_per_dimension[2].object[].nodes'}, - '2dradiation':{'str':'source[13].ggd[0].electrons.energy[0].values', - 'dim':'vol. emis.', 'quant':'vol.emis.', - 'name':'tot. vol. emis.','units':'W/m^3'}}, - - 'lh_antennas': - {'t':{'str':'antenna[chan].power_launched.time'}, - 'power0':{'str':'antenna[0].power_launched.data', - 'dim':'power', 'quant':'lh power', 'units':'W', - 'pos':True}, - 'power1':{'str':'antenna[1].power_launched.data', - 'dim':'power', 'quant':'lh power', 'units':'W', - 'pos':True}, - 'power':{'str':'antenna[chan].power_launched.data', - 'dim':'power', 'quant':'lh power', 'units':'W', - 'pos':True}, - 'R':{'str':'antenna[chan].position.r.data', - 'dim':'distance', 'quant':'R', 'units':'m'}}, - - 'ic_antennas': - {'t':{'str':'antenna[chan].module[0].power_forward.time'}, - 'power0mod_fwd':{'str':'antenna[0].module[].power_forward.data', - 'dim':'power', 'quant':'ic power', 'units':'W'}, - 'power0mod_reflect':{'str':'antenna[0].module[].power_reflected.data', - 'dim':'power', 'quant':'ic power', 'units':'W'}, - 'power1mod_fwd':{'str':'antenna[1].module[].power_forward.data', - 'dim':'power', 'quant':'ic power', 'units':'W'}, - 'power1mod_reflect':{'str':'antenna[1].module[].power_reflected.data', - 'dim':'power', 'quant':'ic power', 'units':'W'}, - 'power2mod_fwd':{'str':'antenna[2].module[].power_forward.data', - 'dim':'power', 'quant':'ic power', 'units':'W'}, - 'power2mod_reflect':{'str':'antenna[2].module[].power_reflected.data', - 'dim':'power', 'quant':'ic power', 'units':'W'}, - }, - - 'magnetics': - {'t':{'str':'time'}, - 'ip':{'str':'method[0].ip.data'}, - 'diamagflux':{'str':'method[0].diamagnetic_flux.data'}, - 'bpol_B':{'str':'bpol_probe[chan].field.data', - 'dim':'B', 'quant':'Bpol', 'units':'T'}, - 'bpol_name':{'str':'bpol_probe[chan].name'}, - 'bpol_R':{'str':'bpol_probe[chan].position.r', - 'dim':'distance', 'quant':'R', 'units':'m'}, - 'bpol_Z':{'str':'bpol_probe[chan].position.z', - 'dim':'distance', 'quant':'Z', 'units':'m'}, - 'bpol_angpol':{'str':'bpol_probe[chan].poloidal_angle', - 'dim':'angle', 'quant':'angle_pol', 'units':'rad'}, - 'bpol_angtor':{'str':'bpol_probe[chan].toroidal_angle', - 'dim':'angle', 'quant':'angle_tor', 'units':'rad'}, - 'floop_flux':{'str':'flux_loop[chan].flux.data', - 'dim':'B flux', 'quant':'B flux', 'units':'Wb'}, - 'floop_name':{'str':'flux_loop[chan].name'}, - 'floop_R': {'str': 'flux_loop[chan].position.r', - 'dim': 'distance', 'quant': 'R', 'units': 'm'}, - 'floop_Z': {'str': 'flux_loop[chan].position.z', - 'dim': 'distance', 'quant': 'Z', 'units': 'm'}}, - - 'barometry': - {'t': {'str': 'gauge[chan].pressure.time'}, - 'names': {'str': 'gauge[chan].name'}, - 'p': {'str': 'gauge[chan].pressure.data', - 'dim': 'pressure', 'quant': 'p', 'units': 'Pa?'}}, - - 'calorimetry': - {'t': {'str': 'group[chan].component[0].power.time'}, - 'names': {'str': 'group[chan].name'}, - 'power': {'str': 'group[chan].component[0].power.data', - 'dim': 'power', 'quant': 'extracted power', - 'units': 'W'}}, - - 'neutron_diagnostic': - {'t':{'str':'time', 'units':'s'}, - 'flux_total':{'str':'synthetic_signals.total_neutron_flux', - 'dim':'particle flux', 'quant':'particle flux', 'units':'Hz'}}, - - 'ece': - {'t':{'str':'time', - 'quant':'t', 'units':'s'}, - 'freq':{'str':'channel[chan].frequency.data', - 'dim':'freq', 'quant':'freq', 'units':'Hz'}, - 'Te': {'str':'channel[chan].t_e.data', - 'dim':'temperature', 'quant':'Te', 'units':'eV'}, - 'R': {'str':'channel[chan].position.r.data', - 'dim':'distance', 'quant':'R', 'units':'m'}, - 'rhotn':{'str':'channel[chan].position.rho_tor_norm.data', - 'dim':'rho', 'quant':'rhotn', 'units':'adim.'}, - 'theta':{'str':'channel[chan].position.theta.data', - 'dim':'angle', 'quant':'theta', 'units':'rad.'}, - 'tau1keV':{'str':'channel[chan].optical_depth.data', - 'dim':'optical_depth', 'quant':'tau', 'units':'adim.'}, - 'validity_timed': {'str':'channel[chan].t_e.validity_timed'}, - 'names': {'str': 'channel[chan].name'}, - 'Te0': {'str':'t_e_central.data', - 'dim':'temperature', 'quant':'Te', 'units':'eV'}}, - - 'reflectometer_profile': - {'t': {'str': 'time'}, - 'ne': {'str': 'channel[chan].n_e.data', - 'dim': 'density', 'quant': 'ne', 'units': '/m^3'}, - 'R': {'str': 'channel[chan].position.r', - 'dim': 'distance', 'quant': 'R', 'units': 'm'}, - 'Z': {'str': 'channel[chan].position.z', - 'dim': 'distance', 'quant': 'Z', 'units': 'm'}, - 'phi': {'str': 'channel[chan].position.phi', - 'dim': 'angle', 'quant': 'phi', 'units': 'rad'}, - 'names': {'str': 'channel[chan].name'}, - 'mode': {'str': 'mode'}, - 'sweep': {'str': 'sweep_time'}}, - - 'interferometer': - {'t': {'str': 'time', - 'quant': 't', 'units': 's'}, - 'names': {'str': 'channel[chan].name'}, - 'ne_integ': {'str': 'channel[chan].n_e_line.data', - 'dim': 'ne_integ', 'quant': 'ne_integ', - 'units': '/m2', 'Brightness': True}}, - - 'polarimeter': - {'t': {'str': 'time', - 'quant': 't', 'units': 's'}, - 'lamb': {'str': 'channel[chan].wavelength', - 'dim': 'distance', 'quant': 'wavelength', - 'units': 'm'}, - 'fangle': {'str': 'channel[chan].faraday_angle.data', - 'dim': 'angle', 'quant': 'faraday angle', - 'units': 'rad', 'Brightness': True}, - 'names': {'str': 'channel[chan].name'}}, - - 'bolometer': - {'t': {'str': 'channel[chan].power.time', - 'quant': 't', 'units': 's'}, - 'power': {'str': 'channel[chan].power.data', - 'dim': 'power', 'quant': 'power radiative', - 'units': 'W', 'Brightness': False}, - 'etendue': {'str': 'channel[chan].etendue', - 'dim': 'etendue', 'quant': 'etendue', - 'units': 'm2.sr'}, - 'names': {'str': 'channel[chan].name'}, - 'tpower': {'str': 'time', 'quant': 't', 'units': 's'}, - 'prad': {'str': 'power_radiated_total', - 'dim': 'power', 'quant': 'power radiative', - 'units': 'W'}, - 'pradbulk': {'str': 'power_radiated_inside_lcfs', - 'dim': 'power', 'quant': 'power radiative', - 'units': 'W'}}, - - 'soft_x_rays': - {'t': {'str': 'time', - 'quant': 't', 'units': 's'}, - 'power': {'str': 'channel[chan].power.data', - 'dim': 'power', 'quant': 'power radiative', - 'units': 'W', 'Brightness': False}, - 'brightness': {'str': 'channel[chan].brightness.data', - 'dim': 'brightness', 'quant': 'brightness', - 'units': 'W/(m2.sr)', 'Brightness': True}, - 'names': {'str': 'channel[chan].name'}, - 'etendue': {'str': 'channel[chan].etendue', - 'dim': 'etendue', 'quant': 'etendue', - 'units': 'm2.sr'}}, - - 'spectrometer_visible': - {'t':{'str':'channel[chan].grating_spectrometer.radiance_spectral.time', - 'quant':'t', 'units':'s'}, - 'spectra': {'str': ('channel[chan].grating_spectrometer' - + '.radiance_spectral.data'), - 'dim': 'radiance_spectral', - 'quant': 'radiance_spectral', - 'units': 'ph/s/(m2.sr)/m', 'Brightness': True}, - 'names': {'str': 'channel[chan].name'}, - 'lamb':{'str':'channel[chan].grating_spectrometer.wavelengths', - 'dim':'wavelength', 'quant':'wavelength', 'units':'m'}}, - - 'bremsstrahlung_visible': - {'t': {'str': 'time', - 'quant': 't', 'units': 's'}, - 'radiance': {'str': 'channel[chan].radiance_spectral.data', - 'dim': 'radiance_spectral', - 'quant': 'radiance_spectral', - 'units': 'ph/s/(m2.sr)/m', - 'Brightness': True}, - 'names': {'str': 'channel[chan].name'}, - 'lamb_up': {'str':'channel[chan].filter.wavelength_upper'}, - 'lamb_lo': {'str':'channel[chan].filter.wavelength_lower'}}, - } - - _didsdiag = {'lh_antennas': {'datacls': 'DataCam1D', - 'geomcls': False, - 'sig': {'data': 'power', - 't': 't'}}, - 'ic_antennas': {'datacls': 'DataCam1D', - 'geomcls': False, - 'sig': {'data': 'power', - 't': 't'}}, - 'magnetics': {'datacls': 'DataCam1D', - 'geomcls': False, - 'sig': {'data': 'bpol_B', - 't': 't'}}, - 'barometry': {'datacls': 'DataCam1D', - 'geomcls': False, - 'sig': {'data': 'p', - 't': 't'}}, - 'calorimetry': {'datacls': 'DataCam1D', - 'geomcls': False, - 'sig': {'data': 'power', - 't': 't'}}, - 'ece': {'datacls': 'DataCam1D', - 'geomcls': False, - 'sig': {'t': 't', - 'X': 'rhotn_sign', - 'data': 'Te'}}, - 'neutron_diagnostic': {'datacls': 'DataCam1D', - 'geomcls': False, - 'sig': {'t': 't', - 'data': 'flux_total'}}, - 'reflectometer_profile': {'datacls': 'DataCam1D', - 'geomcls': False, - 'sig': {'t': 't', - 'X': 'R', - 'data': 'ne'}}, - 'interferometer': {'datacls': 'DataCam1D', - 'geomcls': 'CamLOS1D', - 'sig': {'t': 't', - 'data': 'ne_integ'}, - 'synth': {'dsynth': { - 'quant': 'core_profiles.1dne', - 'ref1d': 'core_profiles.1drhotn', - 'ref2d': 'equilibrium.2drhotn'}, - 'dsig': {'core_profiles': ['t'], - 'equilibrium': ['t']}, - 'Brightness': True}}, - 'polarimeter': {'datacls': 'DataCam1D', - 'geomcls': 'CamLOS1D', - 'sig': {'t': 't', - 'data': 'fangle'}, - 'synth': {'dsynth': { - 'fargs': ['core_profiles.1dne', - 'equilibrium.2dBR', - 'equilibrium.2dBT', - 'equilibrium.2dBZ', - 'core_profiles.1drhotn', - 'equilibrium.2drhotn']}, - 'dsig': {'core_profiles': ['t'], - 'equilibrium': ['t']}, - 'Brightness': True}}, - 'bolometer': {'datacls': 'DataCam1D', - 'geomcls': 'CamLOS1D', - 'sig': {'t': 't', - 'data': 'power'}, - 'synth': {'dsynth': { - 'quant': 'core_sources.1dprad', - 'ref1d': 'core_sources.1drhotn', - 'ref2d': 'equilibrium.2drhotn'}, - 'dsig': {'core_sources': ['t'], - 'equilibrium': ['t']}, - 'Brightness': True}}, - 'soft_x_rays': {'datacls': 'DataCam1D', - 'geomcls': 'CamLOS1D', - 'sig': {'t': 't', - 'data': 'power'}}, - 'spectrometer_visible': {'datacls': 'DataCam1DSpectral', - 'geomcls': 'CamLOS1D', - 'sig': {'data': 'spectra', - 't': 't', - 'lamb': 'lamb'}}, - 'bremsstrahlung_visible': { - 'datacls': 'DataCam1D', - 'geomcls': 'CamLOS1D', - 'sig': {'t': 't', - 'data': 'radiance'}, - 'synth': { - 'dsynth': { - 'quant': ['core_profiles.1dTe', - 'core_profiles.1dne', - 'core_profiles.1dzeff'], - 'ref1d': 'core_profiles.1drhotn', - 'ref2d': 'equilibrium.2drhotn'}, - 'dsig': {'core_profiles': ['t'], - 'equilibrium': ['t']}, - 'Brightness': True}}} - + _dshort = _defimas2tofu._dshort + _didsdiag = _defimas2tofu._didsdiag _lidsplasma = ['equilibrium', 'core_profiles', 'core_sources', 'edge_profiles', 'edge_sources'] @@ -3379,7 +2991,9 @@ def _checkformat_Cam_geom(self, ids=None, geomcls=None, indch=None): ids = next(iter(idsok)) if ids not in self._dids.keys(): - msg = "Provided ids should be available as a self.dids.keys() !" + msg = ("Provided ids should be available as a self.dids.keys()!\n" + + "\t- provided: {}\n".format(str(ids)) + + "\t- available: {}".format(sorted(self._dids.keys()))) raise Exception(msg) if ids not in self._lidsdiag: @@ -3660,7 +3274,7 @@ def to_Cam(self, ids=None, indch=None, indch_auto=False, """ # Check ids - idsok = set(self._lidsdiag).intersection(self._dids.keys()) + idsok = set(self._lidslos).intersection(self._dids.keys()) if ids is None and len(idsok) == 1: ids = next(iter(idsok)) diff --git a/tofu/scripts/tofucalc.py b/tofu/scripts/tofucalc.py index e2394bb7d..cf5e53461 100755 --- a/tofu/scripts/tofucalc.py +++ b/tofu/scripts/tofucalc.py @@ -79,6 +79,7 @@ def call_tfcalcimas(shot=None, run=_RUN, user=_USER, plot_compare=True, Brightness=None, res=None, interp_t=None, sharex=_SHAREX, indch=None, indch_auto=_INDCH_AUTO, + input_file=None, output_file=None, background=_BCK): if t0.lower() == 'none': @@ -89,6 +90,7 @@ def call_tfcalcimas(shot=None, run=_RUN, user=_USER, ids=ids, indch=indch, indch_auto=indch_auto, plot_compare=plot_compare, extra=extra, Brightness=Brightness, res=res, interp_t=interp_t, + input_file=input_file, output_file=output_file, t0=t0, plot=True, sharex=sharex, bck=background) plt.show(block=True) @@ -159,6 +161,12 @@ def main(): parser.add_argument('-sx', '--sharex', type=_str2bool, required=False, help='Should X axis be shared between diagnostics ids ?', default=_SHAREX, const=True, nargs='?') + parser.add_argument('-if', '--input_file', type=str, required=False, + help='mat file from which to load core_profiles', + default=None) + parser.add_argument('-of', '--output_file', type=str, required=False, + help='mat file into which to save synthetic signal', + default=None) parser.add_argument('-bck', '--background', type=_str2bool, required=False, help='Plot data enveloppe as grey background ?', default=_BCK, const=True, nargs='?') diff --git a/tofu/utils.py b/tofu/utils.py index 56cbac45e..0d6c501fd 100644 --- a/tofu/utils.py +++ b/tofu/utils.py @@ -1287,12 +1287,12 @@ def calc_from_imas(shot=None, run=None, user=None, tokamak=None, version=None, depend=('core_profiles.t', 'core_profiles.radius'), origin='input_file') - cam = multi.to_Cam(plot=False) - sig = cam.calc_signal_from_Plasma2D(plasma, - quant='core_profiles.1dbrem', - ref1d='core_profiles.1drhotn', - ref2d='equilibrium.2drhotn', - Brightness=True, plot=plot)[0] + cam = multi.to_Cam(plot=False) + sig = cam.calc_signal_from_Plasma2D(plasma, + quant='core_profiles.1dbrem', + ref1d='core_profiles.1drhotn', + ref2d='equilibrium.2drhotn', + Brightness=True, plot=plot)[0] if output_file is not None: try: # Format output dictionnary to be saved @@ -1317,7 +1317,6 @@ def calc_from_imas(shot=None, run=None, user=None, tokamak=None, version=None, msg += "\nCould not save computed synthetic signal to:\n" msg += "scpio.savemat({0}, dout)".format(output_file) warnings.warn(msg) - import pdb; pdb.set_trace() # DB ############################################# diff --git a/tofu/version.py b/tofu/version.py index 058e43496..f5eaf62e6 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.2b4-41-gdd17eb2c' +__version__ = '1.4.2b4-42-g68e3ec0a' From 919e2cba31818f4073611397d9d5e35a449df3c1 Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Thu, 20 Feb 2020 15:06:35 +0100 Subject: [PATCH 03/16] [Issue346] moved _dshort and _didsdiag of Multi to tofu/imas2tofu/_def.py --- tofu/imas2tofu/_def.py | 394 +++++++++++++++++++++++++++++++++++++++++ tofu/version.py | 2 +- 2 files changed, 395 insertions(+), 1 deletion(-) create mode 100644 tofu/imas2tofu/_def.py diff --git a/tofu/imas2tofu/_def.py b/tofu/imas2tofu/_def.py new file mode 100644 index 000000000..31c66bf6d --- /dev/null +++ b/tofu/imas2tofu/_def.py @@ -0,0 +1,394 @@ +_dshort = { + 'wall': + {'wallR':{'str':'description_2d[0].limiter.unit[0].outline.r'}, + 'wallZ':{'str':'description_2d[0].limiter.unit[0].outline.z'}}, + + 'pulse_schedule': + {'events_times':{'str':'event[].time_stamp'}, + 'events_names':{'str':'event[].identifier'}}, + + 'equilibrium': + {'t':{'str':'time'}, + 'ip':{'str':'time_slice[time].global_quantities.ip', + 'dim':'current', 'quant':'Ip', 'units':'A'}, + 'q0':{'str':'time_slice[time].global_quantities.q_axis'}, + 'qmin':{'str':'time_slice[time].global_quantities.q_min.value'}, + 'q95':{'str':'time_slice[time].global_quantities.q_95'}, + 'volume':{'str':'time_slice[time].global_quantities.volume', + 'dim':'volume', 'quant':'pvol', 'units':'m3'}, + 'psiaxis':{'str':'time_slice[time].global_quantities.psi_axis', + 'dim':'B flux', 'quant':'psi', 'units':'Wb'}, + 'psisep':{'str':'time_slice[time].global_quantities.psi_boundary', + 'dim':'B flux', 'quant':'psi', 'units':'Wb'}, + 'BT0':{'str':'time_slice[time].global_quantities.magnetic_axis.b_field_tor', + 'dim':'B', 'quant':'BT', 'units':'T'}, + 'axR':{'str':'time_slice[time].global_quantities.magnetic_axis.r', + 'dim':'distance', 'quant':'R', 'units':'m'}, + 'axZ':{'str':'time_slice[time].global_quantities.magnetic_axis.z', + 'dim':'distance', 'quant':'Z', 'units':'m'}, + 'x0R':{'str':'time_slice[time].boundary.x_point[0].r'}, + 'x0Z':{'str':'time_slice[time].boundary.x_point[0].z'}, + 'x1R':{'str':'time_slice[time].boundary.x_point[1].r'}, + 'x1Z':{'str':'time_slice[time].boundary.x_point[1].z'}, + 'strike0R':{'str':'time_slice[time].boundary.strike_point[0].r'}, + 'strike0Z':{'str':'time_slice[time].boundary.strike_point[0].z'}, + 'strike1R':{'str':'time_slice[time].boundary.strike_point[1].r'}, + 'strike1Z':{'str':'time_slice[time].boundary.strike_point[1].z'}, + 'sepR':{'str':'time_slice[time].boundary_separatrix.outline.r'}, + 'sepZ':{'str':'time_slice[time].boundary_separatrix.outline.z'}, + + '1drhotn':{'str':'time_slice[time].profiles_1d.rho_tor_norm', + 'dim':'rho', 'quant':'rhotn', 'units':'adim.'}, + '1dphi':{'str':'time_slice[time].profiles_1d.phi', + 'dim':'B flux', 'quant':'phi', 'units':'Wb'}, + '1dpsi':{'str':'time_slice[time].profiles_1d.psi', + 'dim':'B flux', 'quant':'psi', 'units':'Wb'}, + '1dq':{'str':'time_slice[time].profiles_1d.q', + 'dim':'safety factor', 'quant':'q', 'units':'adim.'}, + '1dpe':{'str':'time_slice[time].profiles_1d.pressure', + 'dim':'pressure', 'quant':'pe', 'units':'Pa'}, + '1djT':{'str':'time_slice[time].profiles_1d.j_tor', + 'dim':'vol. current dens.', 'quant':'jT', 'units':'A/m^2'}, + + '2dphi':{'str':'time_slice[time].ggd[0].phi[0].values', + 'dim':'B flux', 'quant':'phi', 'units':'Wb'}, + '2dpsi':{'str':'time_slice[time].ggd[0].psi[0].values', + 'dim':'B flux', 'quant':'psi', 'units':'Wb'}, + '2djT':{'str':'time_slice[time].ggd[0].j_tor[0].values', + 'dim':'vol. current dens.', 'quant':'jT', 'units':'A/m^2'}, + '2dBR':{'str':'time_slice[time].ggd[0].b_field_r[0].values', + 'dim':'B', 'quant':'BR', 'units':'T'}, + '2dBT':{'str':'time_slice[time].ggd[0].b_field_tor[0].values', + 'dim':'B', 'quant':'BT', 'units':'T'}, + '2dBZ':{'str':'time_slice[time].ggd[0].b_field_z[0].values', + 'dim':'B', 'quant':'BZ', 'units':'T'}, + '2dmeshNodes': {'str': ('grids_ggd[0].grid[0].space[0]' + + '.objects_per_dimension[0]' + + '.object[].geometry')}, + '2dmeshFaces': {'str': ('grids_ggd[0].grid[0].space[0]' + + '.objects_per_dimension[2]' + + '.object[].nodes')}, + '2dmeshR': {'str': 'time_slice[0].profiles_2d[0].r'}, + '2dmeshZ': {'str': 'time_slice[0].profiles_2d[0].z'}}, + + 'core_profiles': + {'t':{'str':'time'}, + 'ip':{'str':'global_quantities.ip', + 'dim':'current', 'quant':'Ip', 'units':'A'}, + 'vloop':{'str':'global_quantities.v_loop', + 'dim':'voltage', 'quant':'Vloop', 'units':'V/m'}, + + '1dTe':{'str':'profiles_1d[time].electrons.temperature', + 'dim':'temperature', 'quant':'Te', 'units':'eV'}, + '1dne':{'str':'profiles_1d[time].electrons.density', + 'dim':'density', 'quant':'ne', 'units':'/m^3'}, + '1dzeff':{'str':'profiles_1d[time].zeff', + 'dim':'charge', 'quant':'zeff', 'units':'adim.'}, + '1dphi':{'str':'profiles_1d[time].grid.phi', + 'dim':'B flux', 'quant':'phi', 'units':'Wb'}, + '1dpsi':{'str':'profiles_1d[time].grid.psi', + 'dim':'B flux', 'quant':'psi', 'units':'Wb'}, + '1drhotn':{'str':'profiles_1d[time].grid.rho_tor_norm', + 'dim':'rho', 'quant':'rhotn', 'units':'adim.'}, + '1drhopn':{'str':'profiles_1d[time].grid.rho_pol_norm', + 'dim':'rho', 'quant':'rhopn', 'units':'adim.'}, + '1dnW':{'str':'profiles_1d[time].ions[identifier.label=W].density', + 'dim':'density', 'quant':'nI', 'units':'/m^3'}}, + + 'edge_profiles': + {'t':{'str':'time'}}, + + 'core_sources': + {'t':{'str':'time'}, + '1dpsi':{'str':'source[identifier.name=lineradiation].profiles_1d[time].grid.psi', + 'dim':'B flux', 'quant':'psi', 'units':'Wb'}, + '1drhotn':{'str':'source[identifier.name=lineradiation].profiles_1d[time].grid.rho_tor_norm', + 'dim':'rho', 'quant':'rhotn', 'units':'Wb'}, + '1dbrem':{'str':"source[identifier.name=bremsstrahlung].profiles_1d[time].electrons.energy", + 'dim':'vol.emis.', 'quant':'brem.', 'units':'W/m^3'}, + '1dline':{'str':"source[identifier.name=lineradiation].profiles_1d[time].electrons.energy", + 'dim':'vol. emis.', 'quant':'lines', 'units':'W/m^3'}}, + + 'edge_sources': + {'t':{'str':'time'}, + '2dmeshNodes':{'str':'grid_ggd[0].space[0].objects_per_dimension[0].object[].geometry'}, + '2dmeshFaces':{'str':'grid_ggd[0].space[0].objects_per_dimension[2].object[].nodes'}, + '2dradiation':{'str':'source[13].ggd[0].electrons.energy[0].values', + 'dim':'vol. emis.', 'quant':'vol.emis.', + 'name':'tot. vol. emis.','units':'W/m^3'}}, + + 'lh_antennas': + {'t':{'str':'antenna[chan].power_launched.time'}, + 'power0':{'str':'antenna[0].power_launched.data', + 'dim':'power', 'quant':'lh power', 'units':'W', + 'pos':True}, + 'power1':{'str':'antenna[1].power_launched.data', + 'dim':'power', 'quant':'lh power', 'units':'W', + 'pos':True}, + 'power':{'str':'antenna[chan].power_launched.data', + 'dim':'power', 'quant':'lh power', 'units':'W', + 'pos':True}, + 'R':{'str':'antenna[chan].position.r.data', + 'dim':'distance', 'quant':'R', 'units':'m'}}, + + 'ic_antennas': + {'t':{'str':'antenna[chan].module[0].power_forward.time'}, + 'power0mod_fwd':{'str':'antenna[0].module[].power_forward.data', + 'dim':'power', 'quant':'ic power', 'units':'W'}, + 'power0mod_reflect':{'str':'antenna[0].module[].power_reflected.data', + 'dim':'power', 'quant':'ic power', 'units':'W'}, + 'power1mod_fwd':{'str':'antenna[1].module[].power_forward.data', + 'dim':'power', 'quant':'ic power', 'units':'W'}, + 'power1mod_reflect':{'str':'antenna[1].module[].power_reflected.data', + 'dim':'power', 'quant':'ic power', 'units':'W'}, + 'power2mod_fwd':{'str':'antenna[2].module[].power_forward.data', + 'dim':'power', 'quant':'ic power', 'units':'W'}, + 'power2mod_reflect':{'str':'antenna[2].module[].power_reflected.data', + 'dim':'power', 'quant':'ic power', 'units':'W'}, + }, + + 'magnetics': + {'t':{'str':'time'}, + 'ip':{'str':'method[0].ip.data'}, + 'diamagflux':{'str':'method[0].diamagnetic_flux.data'}, + 'bpol_B':{'str':'bpol_probe[chan].field.data', + 'dim':'B', 'quant':'Bpol', 'units':'T'}, + 'bpol_name':{'str':'bpol_probe[chan].name'}, + 'bpol_R':{'str':'bpol_probe[chan].position.r', + 'dim':'distance', 'quant':'R', 'units':'m'}, + 'bpol_Z':{'str':'bpol_probe[chan].position.z', + 'dim':'distance', 'quant':'Z', 'units':'m'}, + 'bpol_angpol':{'str':'bpol_probe[chan].poloidal_angle', + 'dim':'angle', 'quant':'angle_pol', 'units':'rad'}, + 'bpol_angtor':{'str':'bpol_probe[chan].toroidal_angle', + 'dim':'angle', 'quant':'angle_tor', 'units':'rad'}, + 'floop_flux':{'str':'flux_loop[chan].flux.data', + 'dim':'B flux', 'quant':'B flux', 'units':'Wb'}, + 'floop_name':{'str':'flux_loop[chan].name'}, + 'floop_R': {'str': 'flux_loop[chan].position.r', + 'dim': 'distance', 'quant': 'R', 'units': 'm'}, + 'floop_Z': {'str': 'flux_loop[chan].position.z', + 'dim': 'distance', 'quant': 'Z', 'units': 'm'}}, + + 'barometry': + {'t': {'str': 'gauge[chan].pressure.time'}, + 'names': {'str': 'gauge[chan].name'}, + 'p': {'str': 'gauge[chan].pressure.data', + 'dim': 'pressure', 'quant': 'p', 'units': 'Pa?'}}, + + 'calorimetry': + {'t': {'str': 'group[chan].component[0].power.time'}, + 'names': {'str': 'group[chan].name'}, + 'power': {'str': 'group[chan].component[0].power.data', + 'dim': 'power', 'quant': 'extracted power', + 'units': 'W'}}, + + 'neutron_diagnostic': + {'t':{'str':'time', 'units':'s'}, + 'flux_total':{'str':'synthetic_signals.total_neutron_flux', + 'dim':'particle flux', 'quant':'particle flux', 'units':'Hz'}}, + + 'ece': + {'t':{'str':'time', + 'quant':'t', 'units':'s'}, + 'freq':{'str':'channel[chan].frequency.data', + 'dim':'freq', 'quant':'freq', 'units':'Hz'}, + 'Te': {'str':'channel[chan].t_e.data', + 'dim':'temperature', 'quant':'Te', 'units':'eV'}, + 'R': {'str':'channel[chan].position.r', + 'dim':'distance', 'quant':'R', 'units':'m'}, + 'rhotn':{'str':'channel[chan].position.rho_tor_norm', + 'dim':'rho', 'quant':'rhotn', 'units':'adim.'}, + 'theta':{'str':'channel[chan].position.theta', + 'dim':'angle', 'quant':'theta', 'units':'rad.'}, + 'tau1keV':{'str':'channel[chan].optical_depth.data', + 'dim':'optical_depth', 'quant':'tau', 'units':'adim.'}, + 'validity_timed': {'str':'channel[chan].t_e.validity_timed'}, + 'names': {'str': 'channel[chan].name'}, + 'Te0': {'str':'t_e_central.data', + 'dim':'temperature', 'quant':'Te', 'units':'eV'}}, + + 'reflectometer_profile': + {'t': {'str': 'time'}, + 'ne': {'str': 'channel[chan].n_e.data', + 'dim': 'density', 'quant': 'ne', 'units': '/m^3'}, + 'R': {'str': 'channel[chan].position.r', + 'dim': 'distance', 'quant': 'R', 'units': 'm'}, + 'Z': {'str': 'channel[chan].position.z', + 'dim': 'distance', 'quant': 'Z', 'units': 'm'}, + 'phi': {'str': 'channel[chan].position.phi', + 'dim': 'angle', 'quant': 'phi', 'units': 'rad'}, + 'names': {'str': 'channel[chan].name'}, + 'mode': {'str': 'mode'}, + 'sweep': {'str': 'sweep_time'}}, + + 'interferometer': + {'t': {'str': 'time', + 'quant': 't', 'units': 's'}, + 'names': {'str': 'channel[chan].name'}, + 'ne_integ': {'str': 'channel[chan].n_e_line.data', + 'dim': 'ne_integ', 'quant': 'ne_integ', + 'units': '/m2', 'Brightness': True}}, + + 'polarimeter': + {'t': {'str': 'time', + 'quant': 't', 'units': 's'}, + 'lamb': {'str': 'channel[chan].wavelength', + 'dim': 'distance', 'quant': 'wavelength', + 'units': 'm'}, + 'fangle': {'str': 'channel[chan].faraday_angle.data', + 'dim': 'angle', 'quant': 'faraday angle', + 'units': 'rad', 'Brightness': True}, + 'names': {'str': 'channel[chan].name'}}, + + 'bolometer': + {'t': {'str': 'channel[chan].power.time', + 'quant': 't', 'units': 's'}, + 'power': {'str': 'channel[chan].power.data', + 'dim': 'power', 'quant': 'power radiative', + 'units': 'W', 'Brightness': False}, + 'etendue': {'str': 'channel[chan].etendue', + 'dim': 'etendue', 'quant': 'etendue', + 'units': 'm2.sr'}, + 'names': {'str': 'channel[chan].name'}, + 'tpower': {'str': 'time', 'quant': 't', 'units': 's'}, + 'prad': {'str': 'power_radiated_total', + 'dim': 'power', 'quant': 'power radiative', + 'units': 'W'}, + 'pradbulk': {'str': 'power_radiated_inside_lcfs', + 'dim': 'power', 'quant': 'power radiative', + 'units': 'W'}}, + + 'soft_x_rays': + {'t': {'str': 'time', + 'quant': 't', 'units': 's'}, + 'power': {'str': 'channel[chan].power.data', + 'dim': 'power', 'quant': 'power radiative', + 'units': 'W', 'Brightness': False}, + 'brightness': {'str': 'channel[chan].brightness.data', + 'dim': 'brightness', 'quant': 'brightness', + 'units': 'W/(m2.sr)', 'Brightness': True}, + 'names': {'str': 'channel[chan].name'}, + 'etendue': {'str': 'channel[chan].etendue', + 'dim': 'etendue', 'quant': 'etendue', + 'units': 'm2.sr'}}, + + 'spectrometer_visible': + {'t':{'str':'channel[chan].grating_spectrometer.radiance_spectral.time', + 'quant':'t', 'units':'s'}, + 'spectra': {'str': ('channel[chan].grating_spectrometer' + + '.radiance_spectral.data'), + 'dim': 'radiance_spectral', + 'quant': 'radiance_spectral', + 'units': 'ph/s/(m2.sr)/m', 'Brightness': True}, + 'names': {'str': 'channel[chan].name'}, + 'lamb':{'str':'channel[chan].grating_spectrometer.wavelengths', + 'dim':'wavelength', 'quant':'wavelength', 'units':'m'}}, + + 'bremsstrahlung_visible': + {'t': {'str': 'time', + 'quant': 't', 'units': 's'}, + 'radiance': {'str': 'channel[chan].radiance_spectral.data', + 'dim': 'radiance_spectral', + 'quant': 'radiance_spectral', + 'units': 'ph/s/(m2.sr)/m', + 'Brightness': True}, + 'names': {'str': 'channel[chan].name'}, + 'lamb_up': {'str':'channel[chan].filter.wavelength_upper'}, + 'lamb_lo': {'str':'channel[chan].filter.wavelength_lower'}}, + } + +_didsdiag = {'lh_antennas': {'datacls': 'DataCam1D', + 'geomcls': False, + 'sig': {'data': 'power', + 't': 't'}}, + 'ic_antennas': {'datacls': 'DataCam1D', + 'geomcls': False, + 'sig': {'data': 'power', + 't': 't'}}, + 'magnetics': {'datacls': 'DataCam1D', + 'geomcls': False, + 'sig': {'data': 'bpol_B', + 't': 't'}}, + 'barometry': {'datacls': 'DataCam1D', + 'geomcls': False, + 'sig': {'data': 'p', + 't': 't'}}, + 'calorimetry': {'datacls': 'DataCam1D', + 'geomcls': False, + 'sig': {'data': 'power', + 't': 't'}}, + 'ece': {'datacls': 'DataCam1D', + 'geomcls': False, + 'sig': {'t': 't', + 'X': 'rhotn_sign', + 'data': 'Te'}}, + 'neutron_diagnostic': {'datacls': 'DataCam1D', + 'geomcls': False, + 'sig': {'t': 't', + 'data': 'flux_total'}}, + 'reflectometer_profile': {'datacls': 'DataCam1D', + 'geomcls': False, + 'sig': {'t': 't', + 'X': 'R', + 'data': 'ne'}}, + 'interferometer': {'datacls': 'DataCam1D', + 'geomcls': 'CamLOS1D', + 'sig': {'t': 't', + 'data': 'ne_integ'}, + 'synth': {'dsynth': { + 'quant': 'core_profiles.1dne', + 'ref1d': 'core_profiles.1drhotn', + 'ref2d': 'equilibrium.2drhotn'}, + 'dsig': {'core_profiles': ['t'], + 'equilibrium': ['t']}, + 'Brightness': True}}, + 'polarimeter': {'datacls': 'DataCam1D', + 'geomcls': 'CamLOS1D', + 'sig': {'t': 't', + 'data': 'fangle'}, + 'synth': {'dsynth': { + 'fargs': ['core_profiles.1dne', + 'equilibrium.2dBR', + 'equilibrium.2dBT', + 'equilibrium.2dBZ', + 'core_profiles.1drhotn', + 'equilibrium.2drhotn']}, + 'dsig': {'core_profiles': ['t'], + 'equilibrium': ['t']}, + 'Brightness': True}}, + 'bolometer': {'datacls': 'DataCam1D', + 'geomcls': 'CamLOS1D', + 'sig': {'t': 't', + 'data': 'power'}, + 'synth': {'dsynth': { + 'quant': 'core_sources.1dprad', + 'ref1d': 'core_sources.1drhotn', + 'ref2d': 'equilibrium.2drhotn'}, + 'dsig': {'core_sources': ['t'], + 'equilibrium': ['t']}, + 'Brightness': True}}, + 'soft_x_rays': {'datacls': 'DataCam1D', + 'geomcls': 'CamLOS1D', + 'sig': {'t': 't', + 'data': 'power'}}, + 'spectrometer_visible': {'datacls': 'DataCam1DSpectral', + 'geomcls': 'CamLOS1D', + 'sig': {'data': 'spectra', + 't': 't', + 'lamb': 'lamb'}}, + 'bremsstrahlung_visible': { + 'datacls': 'DataCam1D', + 'geomcls': 'CamLOS1D', + 'sig': {'t': 't', + 'data': 'radiance'}, + 'synth': { + 'dsynth': { + 'quant': ['core_profiles.1dTe', + 'core_profiles.1dne', + 'core_profiles.1dzeff'], + 'ref1d': 'core_profiles.1drhotn', + 'ref2d': 'equilibrium.2drhotn'}, + 'dsig': {'core_profiles': ['t'], + 'equilibrium': ['t']}, + 'Brightness': True}}} diff --git a/tofu/version.py b/tofu/version.py index f5eaf62e6..cc3e16686 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.2b4-42-g68e3ec0a' +__version__ = '1.4.2b4-43-g8a409da3' From 8ab25190900d12f319b51158c7e8aa303c5989bd Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Thu, 20 Feb 2020 15:10:28 +0100 Subject: [PATCH 04/16] [Issue346] Added tofu/imas2tofu/_mat2ids2calc.py --- tofu/imas2tofu/_mat2ids2calc.py | 205 ++++++++++++++++++++++++++++++++ tofu/version.py | 2 +- 2 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 tofu/imas2tofu/_mat2ids2calc.py diff --git a/tofu/imas2tofu/_mat2ids2calc.py b/tofu/imas2tofu/_mat2ids2calc.py new file mode 100644 index 000000000..fa3fa14d5 --- /dev/null +++ b/tofu/imas2tofu/_mat2ids2calc.py @@ -0,0 +1,205 @@ + +# Built-in +import os + +# Common +import scipy.io as scpio +import numpy as np + +# tofu-specific +from .. import _physics + + +__all__ = ['get_data_from_matids'] +_LIDSOK = ['core_profiles'] +_DRETURN = {'core_profiles': ['rhotn', 'ne', 'Te', 'zeff', 't', 'brem']} +_MSG0 = ("The input file structure is not as expected !\n" + + " => Maybe file structure changed ?\n" + + " => Maybe corrupted data ?\n") + + +# #################################################### +# Utility +# #################################################### + +def _get_indtlim(t, tlim=None, shot=None, out=bool): + """ """ + c0 = tlim is None + c1 = type(tlim) in [list, tuple, np.ndarray] + assert c0 or c1 + assert type(t) is np.ndarray + + if c0: + tlim = [-np.inf, np.inf] + else: + assert len(tlim) == 2 + ls = [int, float, np.int64, np.float64] # , str + assert all([tt is None or type(tt) in ls for tt in tlim]) + tlim = list(tlim) + for (ii, sgn) in [(0, -1.), (1, 1.)]: + if tlim[ii] is None: + tlim[ii] = sgn*np.inf + # elif type(tlim[ii]) is str and 'ign' in tlim[ii].lower(): + # tlim[ii] = get_t0(shot) + + assert tlim[0] < tlim[1] + indt = (t >= tlim[0]) & (t <= tlim[1]) + if out is int: + indt = indt.nonzero()[0] + return indt + + +# #################################################### +# Main function +# #################################################### + +def get_data_from_matids(input_pfe=None, tlim=None, + return_fields=None, lamb=None): + """ Extract tofu-compatible from an ids saved as a mat file + + Assumes that the mat file contains the ids data + Only the following ids are handled: + {} + + """.format(_LIDSOK) + + # --------------- + # Check + if not os.path.isfile(input_pfe): + msg = ("Provided file does not seem to exist:\n" + + "\t- {}".format(input_pfe)) + raise Exception(msg) + lc = [return_fields is None, + isinstance(return_fields, str), + isinstance(return_fields, list) + and all([isinstance(ss, str) for ss in return_fields])] + if not any(lc): + msg = "return_fields must be a str or a list of str " + raise Exception(msg) + if lc[1]: + return_fields = [return_fields] + + # --------------- + # Load and check / extract ids + mat = scpio.loadmat(input_pfe) + ids = [k0 for k0 in mat.keys() if '__' not in k0] + if len(ids) != 1 or ids[0] not in _LIDSOK: + msg = ("The file does not seem to contain a known ids:\n" + + "\t- file: {}\n".format(input_pfe) + + "\t- keys: {}\n".format(sorted(mat.keys())) + + "\t- known ids: {}".format(_LIDSOK)) + raise Exception(msg) + ids = ids[0] + data = mat[ids] + + if return_fields is None: + return_fields = _DRETURN[ids] + notok = [ss for ss in return_fields if ss not in _DRETURN[ids]] + if len(notok) > 0: + msg = ("Some requested fields are not available:\n" + + "\t- requested: {}\n".format(notok) + + "\t- available: {}".format(_DRETURN[ids])) + raise Exception(msg) + + # --------------- + # Get inside ids and extract data + if ids == 'core_profiles': + # --------------- + # Check expected structure + if not (data.shape == (1, 1) and data[0, 0].size == 1): + msg = ("\t{}.shape = {}\n".format(ids, data.shape) + + "\t{}.size = {}".format(ids, data[0, 0].size)) + raise Exception(_MSG0 + msg) + data = data[0, 0].tolist() + if not (isinstance(data, tuple) and len(data) == 6): + msg = ("\ttype({}[0, 0].tolist()) = {}\n".format(ids, type(data)) + + "\tlen({}[0, 0].tolist()) = {}".format(ids, len(data))) + raise Exception(_MSG0 + msg) + + ls = [pp.shape for pp in data] + c0 = [len(ss) == 2 for ss in ls] + c1 = np.sum([ss == (1, 1) for ss in ls])==4 + c2 = np.sum([(ss[1] == 1 and ss[0] > ss[1]) for ss in ls]) == 1 + c3 = np.sum([(ss[0] == 1 and ss[1] > ss[0]) for ss in ls]) == 1 + if c0 and c1 and c2 and c3: + indt = [ii for ii in range(len(ls)) if ls[ii][0] > ls[ii][1]] + indp = [ii for ii in range(len(ls)) if ls[ii][0] < ls[ii][1]] + else: + if np.sum([ss == (1, 1) for ss in ls]) == 6: + warnings.warn("There seems to be only one time step...") + indt = [ii for ii in range(len(ls)) if data[ii].dtype == ' Date: Thu, 20 Feb 2020 16:32:57 +0100 Subject: [PATCH 05/16] [Issue346] Debugged default values of parameters in tofucalc.py --- tofu/scripts/tofucalc.py | 4 ++-- tofu/version.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tofu/scripts/tofucalc.py b/tofu/scripts/tofucalc.py index cf5e53461..cacd2e829 100755 --- a/tofu/scripts/tofucalc.py +++ b/tofu/scripts/tofucalc.py @@ -53,7 +53,7 @@ _T0 = 'IGNITRON' _SHAREX = False _BCK = True -_EXTRA = True +_EXTRA = None _INDCH_AUTO = True ################################################### @@ -91,7 +91,7 @@ def call_tfcalcimas(shot=None, run=_RUN, user=_USER, plot_compare=plot_compare, extra=extra, Brightness=Brightness, res=res, interp_t=interp_t, input_file=input_file, output_file=output_file, - t0=t0, plot=True, sharex=sharex, bck=background) + t0=t0, plot=None, sharex=sharex, bck=background) plt.show(block=True) diff --git a/tofu/version.py b/tofu/version.py index 4c2ba557a..1b3085fa2 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.2b4-44-g919e2cba' +__version__ = '1.4.2b4-45-g8ab25190' From 644741c1cc2bb14866687e14cc3e5aeedcedf487 Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Thu, 20 Feb 2020 16:58:31 +0100 Subject: [PATCH 06/16] [Issue346] PEP8 compliance 1 --- tofu/imas2tofu/_core.py | 8 +- tofu/imas2tofu/_def.py | 743 ++++++++++++++++---------------- tofu/imas2tofu/_mat2ids2calc.py | 10 +- tofu/utils.py | 2 +- tofu/version.py | 2 +- 5 files changed, 390 insertions(+), 375 deletions(-) diff --git a/tofu/imas2tofu/_core.py b/tofu/imas2tofu/_core.py index fb6953aa5..6f298dcc8 100644 --- a/tofu/imas2tofu/_core.py +++ b/tofu/imas2tofu/_core.py @@ -26,7 +26,7 @@ # tofu try: import tofu.imas2tofu._def as _defimas2tofu -except: +except Exception as err: from . import _def as _defimas2tofu # imas @@ -254,8 +254,10 @@ def _lamb(lamb_up, lamb_lo): 'units':'adim.'}}, 'bremsstrahlung_visible': - {'lamb':{'lstr':['lamb_up','lamb_lo'], 'func':_lamb, - 'dim':'distance', 'quantity':'wavelength', 'units':'m'}} + {'lamb': {'lstr': ['lamb_up', 'lamb_lo'], 'func': _lamb, + 'dim': 'distance', + 'quantity': 'wavelength', + 'units': 'm'}} } _lstr = ['los_pt1R', 'los_pt1Z', 'los_pt1Phi', diff --git a/tofu/imas2tofu/_def.py b/tofu/imas2tofu/_def.py index 31c66bf6d..cd4f29c4f 100644 --- a/tofu/imas2tofu/_def.py +++ b/tofu/imas2tofu/_def.py @@ -1,394 +1,407 @@ _dshort = { - 'wall': - {'wallR':{'str':'description_2d[0].limiter.unit[0].outline.r'}, - 'wallZ':{'str':'description_2d[0].limiter.unit[0].outline.z'}}, + 'wall': { + 'wallR': {'str': 'description_2d[0].limiter.unit[0].outline.r'}, + 'wallZ': {'str': 'description_2d[0].limiter.unit[0].outline.z'}}, - 'pulse_schedule': - {'events_times':{'str':'event[].time_stamp'}, - 'events_names':{'str':'event[].identifier'}}, + 'pulse_schedule': { + 'events_times': {'str': 'event[].time_stamp'}, + 'events_names': {'str': 'event[].identifier'}}, - 'equilibrium': - {'t':{'str':'time'}, - 'ip':{'str':'time_slice[time].global_quantities.ip', - 'dim':'current', 'quant':'Ip', 'units':'A'}, - 'q0':{'str':'time_slice[time].global_quantities.q_axis'}, - 'qmin':{'str':'time_slice[time].global_quantities.q_min.value'}, - 'q95':{'str':'time_slice[time].global_quantities.q_95'}, - 'volume':{'str':'time_slice[time].global_quantities.volume', - 'dim':'volume', 'quant':'pvol', 'units':'m3'}, - 'psiaxis':{'str':'time_slice[time].global_quantities.psi_axis', - 'dim':'B flux', 'quant':'psi', 'units':'Wb'}, - 'psisep':{'str':'time_slice[time].global_quantities.psi_boundary', - 'dim':'B flux', 'quant':'psi', 'units':'Wb'}, - 'BT0':{'str':'time_slice[time].global_quantities.magnetic_axis.b_field_tor', - 'dim':'B', 'quant':'BT', 'units':'T'}, - 'axR':{'str':'time_slice[time].global_quantities.magnetic_axis.r', - 'dim':'distance', 'quant':'R', 'units':'m'}, - 'axZ':{'str':'time_slice[time].global_quantities.magnetic_axis.z', - 'dim':'distance', 'quant':'Z', 'units':'m'}, - 'x0R':{'str':'time_slice[time].boundary.x_point[0].r'}, - 'x0Z':{'str':'time_slice[time].boundary.x_point[0].z'}, - 'x1R':{'str':'time_slice[time].boundary.x_point[1].r'}, - 'x1Z':{'str':'time_slice[time].boundary.x_point[1].z'}, - 'strike0R':{'str':'time_slice[time].boundary.strike_point[0].r'}, - 'strike0Z':{'str':'time_slice[time].boundary.strike_point[0].z'}, - 'strike1R':{'str':'time_slice[time].boundary.strike_point[1].r'}, - 'strike1Z':{'str':'time_slice[time].boundary.strike_point[1].z'}, - 'sepR':{'str':'time_slice[time].boundary_separatrix.outline.r'}, - 'sepZ':{'str':'time_slice[time].boundary_separatrix.outline.z'}, + 'equilibrium': { + 't': {'str': 'time'}, + 'ip': {'str': 'time_slice[time].global_quantities.ip', + 'dim': 'current', 'quant': 'Ip', 'units': 'A'}, + 'q0': {'str': 'time_slice[time].global_quantities.q_axis'}, + 'qmin': {'str': 'time_slice[time].global_quantities.q_min.value'}, + 'q95': {'str': 'time_slice[time].global_quantities.q_95'}, + 'volume': {'str': 'time_slice[time].global_quantities.volume', + 'dim': 'volume', 'quant': 'pvol', 'units': 'm3'}, + 'psiaxis': {'str': 'time_slice[time].global_quantities.psi_axis', + 'dim': 'B flux', 'quant': 'psi', 'units': 'Wb'}, + 'psisep': {'str': 'time_slice[time].global_quantities.psi_boundary', + 'dim': 'B flux', 'quant': 'psi', 'units': 'Wb'}, + 'BT0': {'str': ('time_slice[time].global_quantities' + + '.magnetic_axis.b_field_tor'), + 'dim': 'B', 'quant': 'BT', 'units': 'T'}, + 'axR':{'str': 'time_slice[time].global_quantities.magnetic_axis.r', + 'dim': 'distance', 'quant': 'R', 'units': 'm'}, + 'axZ': {'str': 'time_slice[time].global_quantities.magnetic_axis.z', + 'dim': 'distance', 'quant': 'Z', 'units': 'm'}, + 'x0R': {'str': 'time_slice[time].boundary.x_point[0].r'}, + 'x0Z': {'str': 'time_slice[time].boundary.x_point[0].z'}, + 'x1R': {'str': 'time_slice[time].boundary.x_point[1].r'}, + 'x1Z': {'str': 'time_slice[time].boundary.x_point[1].z'}, + 'strike0R': {'str': 'time_slice[time].boundary.strike_point[0].r'}, + 'strike0Z': {'str': 'time_slice[time].boundary.strike_point[0].z'}, + 'strike1R': {'str': 'time_slice[time].boundary.strike_point[1].r'}, + 'strike1Z': {'str': 'time_slice[time].boundary.strike_point[1].z'}, + 'sepR': {'str': 'time_slice[time].boundary_separatrix.outline.r'}, + 'sepZ': {'str': 'time_slice[time].boundary_separatrix.outline.z'}, - '1drhotn':{'str':'time_slice[time].profiles_1d.rho_tor_norm', - 'dim':'rho', 'quant':'rhotn', 'units':'adim.'}, - '1dphi':{'str':'time_slice[time].profiles_1d.phi', - 'dim':'B flux', 'quant':'phi', 'units':'Wb'}, - '1dpsi':{'str':'time_slice[time].profiles_1d.psi', - 'dim':'B flux', 'quant':'psi', 'units':'Wb'}, - '1dq':{'str':'time_slice[time].profiles_1d.q', - 'dim':'safety factor', 'quant':'q', 'units':'adim.'}, - '1dpe':{'str':'time_slice[time].profiles_1d.pressure', - 'dim':'pressure', 'quant':'pe', 'units':'Pa'}, - '1djT':{'str':'time_slice[time].profiles_1d.j_tor', - 'dim':'vol. current dens.', 'quant':'jT', 'units':'A/m^2'}, + '1drhotn': {'str': 'time_slice[time].profiles_1d.rho_tor_norm', + 'dim': 'rho', 'quant': 'rhotn', 'units': 'adim.'}, + '1dphi': {'str': 'time_slice[time].profiles_1d.phi', + 'dim': 'B flux', 'quant': 'phi', 'units': 'Wb'}, + '1dpsi': {'str': 'time_slice[time].profiles_1d.psi', + 'dim': 'B flux', 'quant': 'psi', 'units': 'Wb'}, + '1dq': {'str': 'time_slice[time].profiles_1d.q', + 'dim': 'safety factor', 'quant': 'q', 'units': 'adim.'}, + '1dpe': {'str': 'time_slice[time].profiles_1d.pressure', + 'dim': 'pressure', 'quant': 'pe', 'units': 'Pa'}, + '1djT': {'str': 'time_slice[time].profiles_1d.j_tor', + 'dim': 'vol. current dens.', 'quant': 'jT', 'units': 'A/m^2'}, - '2dphi':{'str':'time_slice[time].ggd[0].phi[0].values', - 'dim':'B flux', 'quant':'phi', 'units':'Wb'}, - '2dpsi':{'str':'time_slice[time].ggd[0].psi[0].values', - 'dim':'B flux', 'quant':'psi', 'units':'Wb'}, - '2djT':{'str':'time_slice[time].ggd[0].j_tor[0].values', - 'dim':'vol. current dens.', 'quant':'jT', 'units':'A/m^2'}, - '2dBR':{'str':'time_slice[time].ggd[0].b_field_r[0].values', - 'dim':'B', 'quant':'BR', 'units':'T'}, - '2dBT':{'str':'time_slice[time].ggd[0].b_field_tor[0].values', - 'dim':'B', 'quant':'BT', 'units':'T'}, - '2dBZ':{'str':'time_slice[time].ggd[0].b_field_z[0].values', - 'dim':'B', 'quant':'BZ', 'units':'T'}, - '2dmeshNodes': {'str': ('grids_ggd[0].grid[0].space[0]' - + '.objects_per_dimension[0]' - + '.object[].geometry')}, - '2dmeshFaces': {'str': ('grids_ggd[0].grid[0].space[0]' - + '.objects_per_dimension[2]' - + '.object[].nodes')}, - '2dmeshR': {'str': 'time_slice[0].profiles_2d[0].r'}, - '2dmeshZ': {'str': 'time_slice[0].profiles_2d[0].z'}}, + '2dphi': {'str': 'time_slice[time].ggd[0].phi[0].values', + 'dim': 'B flux', 'quant': 'phi', 'units': 'Wb'}, + '2dpsi': {'str': 'time_slice[time].ggd[0].psi[0].values', + 'dim': 'B flux', 'quant': 'psi', 'units': 'Wb'}, + '2djT': {'str': 'time_slice[time].ggd[0].j_tor[0].values', + 'dim': 'vol. current dens.', 'quant': 'jT', 'units': 'A/m^2'}, + '2dBR': {'str': 'time_slice[time].ggd[0].b_field_r[0].values', + 'dim': 'B', 'quant': 'BR', 'units': 'T'}, + '2dBT': {'str': 'time_slice[time].ggd[0].b_field_tor[0].values', + 'dim': 'B', 'quant': 'BT', 'units': 'T'}, + '2dBZ': {'str': 'time_slice[time].ggd[0].b_field_z[0].values', + 'dim': 'B', 'quant': 'BZ', 'units': 'T'}, + '2dmeshNodes': {'str': ('grids_ggd[0].grid[0].space[0]' + + '.objects_per_dimension[0]' + + '.object[].geometry')}, + '2dmeshFaces': {'str': ('grids_ggd[0].grid[0].space[0]' + + '.objects_per_dimension[2]' + + '.object[].nodes')}, + '2dmeshR': {'str': 'time_slice[0].profiles_2d[0].r'}, + '2dmeshZ': {'str': 'time_slice[0].profiles_2d[0].z'}}, - 'core_profiles': - {'t':{'str':'time'}, - 'ip':{'str':'global_quantities.ip', - 'dim':'current', 'quant':'Ip', 'units':'A'}, - 'vloop':{'str':'global_quantities.v_loop', - 'dim':'voltage', 'quant':'Vloop', 'units':'V/m'}, + 'core_profiles': { + 't': {'str': 'time'}, + 'ip': {'str': 'global_quantities.ip', + 'dim': 'current', 'quant': 'Ip', 'units': 'A'}, + 'vloop':{'str': 'global_quantities.v_loop', + 'dim': 'voltage', 'quant': 'Vloop', 'units': 'V/m'}, - '1dTe':{'str':'profiles_1d[time].electrons.temperature', - 'dim':'temperature', 'quant':'Te', 'units':'eV'}, - '1dne':{'str':'profiles_1d[time].electrons.density', - 'dim':'density', 'quant':'ne', 'units':'/m^3'}, - '1dzeff':{'str':'profiles_1d[time].zeff', - 'dim':'charge', 'quant':'zeff', 'units':'adim.'}, - '1dphi':{'str':'profiles_1d[time].grid.phi', - 'dim':'B flux', 'quant':'phi', 'units':'Wb'}, - '1dpsi':{'str':'profiles_1d[time].grid.psi', - 'dim':'B flux', 'quant':'psi', 'units':'Wb'}, - '1drhotn':{'str':'profiles_1d[time].grid.rho_tor_norm', - 'dim':'rho', 'quant':'rhotn', 'units':'adim.'}, - '1drhopn':{'str':'profiles_1d[time].grid.rho_pol_norm', - 'dim':'rho', 'quant':'rhopn', 'units':'adim.'}, - '1dnW':{'str':'profiles_1d[time].ions[identifier.label=W].density', - 'dim':'density', 'quant':'nI', 'units':'/m^3'}}, + '1dTe': {'str': 'profiles_1d[time].electrons.temperature', + 'dim': 'temperature', 'quant': 'Te', 'units': 'eV'}, + '1dne': {'str': 'profiles_1d[time].electrons.density', + 'dim': 'density', 'quant': 'ne', 'units': '/m^3'}, + '1dzeff': {'str': 'profiles_1d[time].zeff', + 'dim': 'charge', 'quant': 'zeff', 'units': 'adim.'}, + '1dphi': {'str': 'profiles_1d[time].grid.phi', + 'dim': 'B flux', 'quant': 'phi', 'units': 'Wb'}, + '1dpsi': {'str': 'profiles_1d[time].grid.psi', + 'dim': 'B flux', 'quant': 'psi', 'units': 'Wb'}, + '1drhotn': {'str': 'profiles_1d[time].grid.rho_tor_norm', + 'dim': 'rho', 'quant': 'rhotn', 'units': 'adim.'}, + '1drhopn': {'str': 'profiles_1d[time].grid.rho_pol_norm', + 'dim': 'rho', 'quant': 'rhopn', 'units': 'adim.'}, + '1dnW': {'str': 'profiles_1d[time].ions[identifier.label=W].density', + 'dim': 'density', 'quant': 'nI', 'units': '/m^3'}}, - 'edge_profiles': - {'t':{'str':'time'}}, + 'edge_profiles': { + 't':{'str': 'time'}}, - 'core_sources': - {'t':{'str':'time'}, - '1dpsi':{'str':'source[identifier.name=lineradiation].profiles_1d[time].grid.psi', - 'dim':'B flux', 'quant':'psi', 'units':'Wb'}, - '1drhotn':{'str':'source[identifier.name=lineradiation].profiles_1d[time].grid.rho_tor_norm', - 'dim':'rho', 'quant':'rhotn', 'units':'Wb'}, - '1dbrem':{'str':"source[identifier.name=bremsstrahlung].profiles_1d[time].electrons.energy", - 'dim':'vol.emis.', 'quant':'brem.', 'units':'W/m^3'}, - '1dline':{'str':"source[identifier.name=lineradiation].profiles_1d[time].electrons.energy", - 'dim':'vol. emis.', 'quant':'lines', 'units':'W/m^3'}}, + 'core_sources': { + 't': {'str': 'time'}, + '1dpsi': {'str': ('source[identifier.name=lineradiation]'+ + '.profiles_1d[time].grid.psi'), + 'dim': 'B flux', 'quant': 'psi', 'units': 'Wb'}, + '1drhotn': {'str': ('source[identifier.name=lineradiation]' + + '.profiles_1d[time].grid.rho_tor_norm'), + 'dim': 'rho', 'quant': 'rhotn', 'units': 'Wb'}, + '1dbrem': {'str': ('source[identifier.name=bremsstrahlung]' + + '.profiles_1d[time].electrons.energy'), + 'dim': 'vol.emis.', 'quant': 'brem.', 'units': 'W/m^3'}, + '1dline': {'str': ('source[identifier.name=lineradiation]' + + '.profiles_1d[time].electrons.energy'), + 'dim': 'vol. emis.', 'quant': 'lines', 'units': 'W/m^3'}}, - 'edge_sources': - {'t':{'str':'time'}, - '2dmeshNodes':{'str':'grid_ggd[0].space[0].objects_per_dimension[0].object[].geometry'}, - '2dmeshFaces':{'str':'grid_ggd[0].space[0].objects_per_dimension[2].object[].nodes'}, - '2dradiation':{'str':'source[13].ggd[0].electrons.energy[0].values', - 'dim':'vol. emis.', 'quant':'vol.emis.', - 'name':'tot. vol. emis.','units':'W/m^3'}}, + 'edge_sources': { + 't': {'str': 'time'}, + '2dmeshNodes': {'str': ('grid_ggd[0].space[0].objects_per_dimension[0]' + + '.object[].geometry')}, + '2dmeshFaces': {'str': ('grid_ggd[0].space[0].objects_per_dimension[2]' + + '.object[].nodes')}, + '2dradiation': {'str': 'source[13].ggd[0].electrons.energy[0].values', + 'dim': 'vol. emis.', 'quant': 'vol.emis.', + 'name': 'tot. vol. emis.','units': 'W/m^3'}}, - 'lh_antennas': - {'t':{'str':'antenna[chan].power_launched.time'}, - 'power0':{'str':'antenna[0].power_launched.data', - 'dim':'power', 'quant':'lh power', 'units':'W', - 'pos':True}, - 'power1':{'str':'antenna[1].power_launched.data', - 'dim':'power', 'quant':'lh power', 'units':'W', - 'pos':True}, - 'power':{'str':'antenna[chan].power_launched.data', - 'dim':'power', 'quant':'lh power', 'units':'W', - 'pos':True}, - 'R':{'str':'antenna[chan].position.r.data', - 'dim':'distance', 'quant':'R', 'units':'m'}}, + 'lh_antennas': { + 't': {'str': 'antenna[chan].power_launched.time'}, + 'power0': {'str': 'antenna[0].power_launched.data', + 'dim': 'power', 'quant': 'lh power', 'units': 'W', + 'pos':True}, + 'power1': {'str': 'antenna[1].power_launched.data', + 'dim': 'power', 'quant': 'lh power', 'units': 'W', + 'pos': True}, + 'power': {'str': 'antenna[chan].power_launched.data', + 'dim': 'power', 'quant': 'lh power', 'units': 'W', + 'pos': True}, + 'R': {'str': 'antenna[chan].position.r.data', + 'dim': 'distance', 'quant': 'R', 'units': 'm'}}, - 'ic_antennas': - {'t':{'str':'antenna[chan].module[0].power_forward.time'}, - 'power0mod_fwd':{'str':'antenna[0].module[].power_forward.data', - 'dim':'power', 'quant':'ic power', 'units':'W'}, - 'power0mod_reflect':{'str':'antenna[0].module[].power_reflected.data', - 'dim':'power', 'quant':'ic power', 'units':'W'}, - 'power1mod_fwd':{'str':'antenna[1].module[].power_forward.data', - 'dim':'power', 'quant':'ic power', 'units':'W'}, - 'power1mod_reflect':{'str':'antenna[1].module[].power_reflected.data', - 'dim':'power', 'quant':'ic power', 'units':'W'}, - 'power2mod_fwd':{'str':'antenna[2].module[].power_forward.data', - 'dim':'power', 'quant':'ic power', 'units':'W'}, - 'power2mod_reflect':{'str':'antenna[2].module[].power_reflected.data', - 'dim':'power', 'quant':'ic power', 'units':'W'}, - }, + 'ic_antennas': { + 't': {'str': 'antenna[chan].module[0].power_forward.time'}, + 'power0mod_fwd': {'str': 'antenna[0].module[].power_forward.data', + 'dim': 'power', 'quant': 'ic power', 'units': 'W'}, + 'power0mod_reflect': {'str': ('antenna[0].module[]' + + '.power_reflected.data'), + 'dim': 'power', 'quant': 'ic power', + 'units': 'W'}, + 'power1mod_fwd': {'str': 'antenna[1].module[].power_forward.data', + 'dim': 'power', 'quant': 'ic power', 'units': 'W'}, + 'power1mod_reflect': {'str': 'antenna[1].module[].power_reflected.data', + 'dim': 'power', 'quant': 'ic power', + 'units': 'W'}, + 'power2mod_fwd': {'str': 'antenna[2].module[].power_forward.data', + 'dim': 'power', 'quant': 'ic power', 'units': 'W'}, + 'power2mod_reflect': {'str': 'antenna[2].module[].power_reflected.data', + 'dim': 'power', 'quant': 'ic power', + 'units': 'W'}}, - 'magnetics': - {'t':{'str':'time'}, - 'ip':{'str':'method[0].ip.data'}, - 'diamagflux':{'str':'method[0].diamagnetic_flux.data'}, - 'bpol_B':{'str':'bpol_probe[chan].field.data', - 'dim':'B', 'quant':'Bpol', 'units':'T'}, - 'bpol_name':{'str':'bpol_probe[chan].name'}, - 'bpol_R':{'str':'bpol_probe[chan].position.r', - 'dim':'distance', 'quant':'R', 'units':'m'}, - 'bpol_Z':{'str':'bpol_probe[chan].position.z', - 'dim':'distance', 'quant':'Z', 'units':'m'}, - 'bpol_angpol':{'str':'bpol_probe[chan].poloidal_angle', - 'dim':'angle', 'quant':'angle_pol', 'units':'rad'}, - 'bpol_angtor':{'str':'bpol_probe[chan].toroidal_angle', - 'dim':'angle', 'quant':'angle_tor', 'units':'rad'}, - 'floop_flux':{'str':'flux_loop[chan].flux.data', - 'dim':'B flux', 'quant':'B flux', 'units':'Wb'}, - 'floop_name':{'str':'flux_loop[chan].name'}, - 'floop_R': {'str': 'flux_loop[chan].position.r', - 'dim': 'distance', 'quant': 'R', 'units': 'm'}, - 'floop_Z': {'str': 'flux_loop[chan].position.z', - 'dim': 'distance', 'quant': 'Z', 'units': 'm'}}, + 'magnetics': { + 't': {'str': 'time'}, + 'ip': {'str': 'method[0].ip.data'}, + 'diamagflux': {'str': 'method[0].diamagnetic_flux.data'}, + 'bpol_B': {'str': 'bpol_probe[chan].field.data', + 'dim': 'B', 'quant': 'Bpol', 'units': 'T'}, + 'bpol_name':{'str': 'bpol_probe[chan].name'}, + 'bpol_R':{'str': 'bpol_probe[chan].position.r', + 'dim': 'distance', 'quant': 'R', 'units': 'm'}, + 'bpol_Z':{'str': 'bpol_probe[chan].position.z', + 'dim': 'distance', 'quant': 'Z', 'units': 'm'}, + 'bpol_angpol':{'str': 'bpol_probe[chan].poloidal_angle', + 'dim': 'angle', 'quant': 'angle_pol', 'units': 'rad'}, + 'bpol_angtor':{'str': 'bpol_probe[chan].toroidal_angle', + 'dim': 'angle', 'quant': 'angle_tor', 'units': 'rad'}, + 'floop_flux':{'str': 'flux_loop[chan].flux.data', + 'dim': 'B flux', 'quant': 'B flux', 'units': 'Wb'}, + 'floop_name':{'str': 'flux_loop[chan].name'}, + 'floop_R': {'str': 'flux_loop[chan].position.r', + 'dim': 'distance', 'quant': 'R', 'units': 'm'}, + 'floop_Z': {'str': 'flux_loop[chan].position.z', + 'dim': 'distance', 'quant': 'Z', 'units': 'm'}}, - 'barometry': - {'t': {'str': 'gauge[chan].pressure.time'}, - 'names': {'str': 'gauge[chan].name'}, - 'p': {'str': 'gauge[chan].pressure.data', - 'dim': 'pressure', 'quant': 'p', 'units': 'Pa?'}}, + 'barometry': { + 't': {'str': 'gauge[chan].pressure.time'}, + 'names': {'str': 'gauge[chan].name'}, + 'p': {'str': 'gauge[chan].pressure.data', + 'dim': 'pressure', 'quant': 'p', 'units': 'Pa?'}}, - 'calorimetry': - {'t': {'str': 'group[chan].component[0].power.time'}, - 'names': {'str': 'group[chan].name'}, - 'power': {'str': 'group[chan].component[0].power.data', - 'dim': 'power', 'quant': 'extracted power', - 'units': 'W'}}, + 'calorimetry': { + 't': {'str': 'group[chan].component[0].power.time'}, + 'names': {'str': 'group[chan].name'}, + 'power': {'str': 'group[chan].component[0].power.data', + 'dim': 'power', 'quant': 'extracted power', + 'units': 'W'}}, - 'neutron_diagnostic': - {'t':{'str':'time', 'units':'s'}, - 'flux_total':{'str':'synthetic_signals.total_neutron_flux', - 'dim':'particle flux', 'quant':'particle flux', 'units':'Hz'}}, + 'neutron_diagnostic': { + 't':{'str': 'time', 'units': 's'}, + 'flux_total':{'str': 'synthetic_signals.total_neutron_flux', + 'dim': 'particle flux', 'quant': 'particle flux', + 'units': 'Hz'}}, - 'ece': - {'t':{'str':'time', - 'quant':'t', 'units':'s'}, - 'freq':{'str':'channel[chan].frequency.data', - 'dim':'freq', 'quant':'freq', 'units':'Hz'}, - 'Te': {'str':'channel[chan].t_e.data', - 'dim':'temperature', 'quant':'Te', 'units':'eV'}, - 'R': {'str':'channel[chan].position.r', - 'dim':'distance', 'quant':'R', 'units':'m'}, - 'rhotn':{'str':'channel[chan].position.rho_tor_norm', - 'dim':'rho', 'quant':'rhotn', 'units':'adim.'}, - 'theta':{'str':'channel[chan].position.theta', - 'dim':'angle', 'quant':'theta', 'units':'rad.'}, - 'tau1keV':{'str':'channel[chan].optical_depth.data', - 'dim':'optical_depth', 'quant':'tau', 'units':'adim.'}, - 'validity_timed': {'str':'channel[chan].t_e.validity_timed'}, - 'names': {'str': 'channel[chan].name'}, - 'Te0': {'str':'t_e_central.data', - 'dim':'temperature', 'quant':'Te', 'units':'eV'}}, + 'ece': { + 't':{'str': 'time', + 'quant': 't', 'units': 's'}, + 'freq':{'str': 'channel[chan].frequency.data', + 'dim': 'freq', 'quant': 'freq', 'units': 'Hz'}, + 'Te': {'str': 'channel[chan].t_e.data', + 'dim': 'temperature', 'quant': 'Te', 'units': 'eV'}, + 'R': {'str': 'channel[chan].position.r', + 'dim': 'distance', 'quant': 'R', 'units': 'm'}, + 'rhotn':{'str': 'channel[chan].position.rho_tor_norm', + 'dim': 'rho', 'quant': 'rhotn', 'units': 'adim.'}, + 'theta':{'str': 'channel[chan].position.theta', + 'dim': 'angle', 'quant': 'theta', 'units': 'rad.'}, + 'tau1keV':{'str': 'channel[chan].optical_depth.data', + 'dim': 'optical_depth', 'quant': 'tau', 'units': 'adim.'}, + 'validity_timed': {'str': 'channel[chan].t_e.validity_timed'}, + 'names': {'str': 'channel[chan].name'}, + 'Te0': {'str': 't_e_central.data', + 'dim': 'temperature', 'quant': 'Te', 'units': 'eV'}}, - 'reflectometer_profile': - {'t': {'str': 'time'}, - 'ne': {'str': 'channel[chan].n_e.data', - 'dim': 'density', 'quant': 'ne', 'units': '/m^3'}, - 'R': {'str': 'channel[chan].position.r', - 'dim': 'distance', 'quant': 'R', 'units': 'm'}, - 'Z': {'str': 'channel[chan].position.z', - 'dim': 'distance', 'quant': 'Z', 'units': 'm'}, - 'phi': {'str': 'channel[chan].position.phi', - 'dim': 'angle', 'quant': 'phi', 'units': 'rad'}, - 'names': {'str': 'channel[chan].name'}, - 'mode': {'str': 'mode'}, - 'sweep': {'str': 'sweep_time'}}, + 'reflectometer_profile': { + 't': {'str': 'time'}, + 'ne': {'str': 'channel[chan].n_e.data', + 'dim': 'density', 'quant': 'ne', 'units': '/m^3'}, + 'R': {'str': 'channel[chan].position.r', + 'dim': 'distance', 'quant': 'R', 'units': 'm'}, + 'Z': {'str': 'channel[chan].position.z', + 'dim': 'distance', 'quant': 'Z', 'units': 'm'}, + 'phi': {'str': 'channel[chan].position.phi', + 'dim': 'angle', 'quant': 'phi', 'units': 'rad'}, + 'names': {'str': 'channel[chan].name'}, + 'mode': {'str': 'mode'}, + 'sweep': {'str': 'sweep_time'}}, - 'interferometer': - {'t': {'str': 'time', - 'quant': 't', 'units': 's'}, - 'names': {'str': 'channel[chan].name'}, - 'ne_integ': {'str': 'channel[chan].n_e_line.data', - 'dim': 'ne_integ', 'quant': 'ne_integ', - 'units': '/m2', 'Brightness': True}}, + 'interferometer': { + 't': {'str': 'time', + 'quant': 't', 'units': 's'}, + 'names': {'str': 'channel[chan].name'}, + 'ne_integ': {'str': 'channel[chan].n_e_line.data', + 'dim': 'ne_integ', 'quant': 'ne_integ', + 'units': '/m2', 'Brightness': True}}, - 'polarimeter': - {'t': {'str': 'time', - 'quant': 't', 'units': 's'}, - 'lamb': {'str': 'channel[chan].wavelength', - 'dim': 'distance', 'quant': 'wavelength', - 'units': 'm'}, - 'fangle': {'str': 'channel[chan].faraday_angle.data', - 'dim': 'angle', 'quant': 'faraday angle', - 'units': 'rad', 'Brightness': True}, - 'names': {'str': 'channel[chan].name'}}, + 'polarimeter': { + 't': {'str': 'time', + 'quant': 't', 'units': 's'}, + 'lamb': {'str': 'channel[chan].wavelength', + 'dim': 'distance', 'quant': 'wavelength', + 'units': 'm'}, + 'fangle': {'str': 'channel[chan].faraday_angle.data', + 'dim': 'angle', 'quant': 'faraday angle', + 'units': 'rad', 'Brightness': True}, + 'names': {'str': 'channel[chan].name'}}, - 'bolometer': - {'t': {'str': 'channel[chan].power.time', - 'quant': 't', 'units': 's'}, - 'power': {'str': 'channel[chan].power.data', - 'dim': 'power', 'quant': 'power radiative', - 'units': 'W', 'Brightness': False}, - 'etendue': {'str': 'channel[chan].etendue', - 'dim': 'etendue', 'quant': 'etendue', - 'units': 'm2.sr'}, - 'names': {'str': 'channel[chan].name'}, - 'tpower': {'str': 'time', 'quant': 't', 'units': 's'}, - 'prad': {'str': 'power_radiated_total', + 'bolometer': { + 't': {'str': 'channel[chan].power.time', + 'quant': 't', 'units': 's'}, + 'power': {'str': 'channel[chan].power.data', + 'dim': 'power', 'quant': 'power radiative', + 'units': 'W', 'Brightness': False}, + 'etendue': {'str': 'channel[chan].etendue', + 'dim': 'etendue', 'quant': 'etendue', + 'units': 'm2.sr'}, + 'names': {'str': 'channel[chan].name'}, + 'tpower': {'str': 'time', 'quant': 't', 'units': 's'}, + 'prad': {'str': 'power_radiated_total', + 'dim': 'power', 'quant': 'power radiative', + 'units': 'W'}, + 'pradbulk': {'str': 'power_radiated_inside_lcfs', 'dim': 'power', 'quant': 'power radiative', - 'units': 'W'}, - 'pradbulk': {'str': 'power_radiated_inside_lcfs', - 'dim': 'power', 'quant': 'power radiative', - 'units': 'W'}}, + 'units': 'W'}}, - 'soft_x_rays': - {'t': {'str': 'time', - 'quant': 't', 'units': 's'}, - 'power': {'str': 'channel[chan].power.data', - 'dim': 'power', 'quant': 'power radiative', - 'units': 'W', 'Brightness': False}, - 'brightness': {'str': 'channel[chan].brightness.data', - 'dim': 'brightness', 'quant': 'brightness', - 'units': 'W/(m2.sr)', 'Brightness': True}, - 'names': {'str': 'channel[chan].name'}, - 'etendue': {'str': 'channel[chan].etendue', - 'dim': 'etendue', 'quant': 'etendue', - 'units': 'm2.sr'}}, + 'soft_x_rays': { + 't': {'str': 'time', + 'quant': 't', 'units': 's'}, + 'power': {'str': 'channel[chan].power.data', + 'dim': 'power', 'quant': 'power radiative', + 'units': 'W', 'Brightness': False}, + 'brightness': {'str': 'channel[chan].brightness.data', + 'dim': 'brightness', 'quant': 'brightness', + 'units': 'W/(m2.sr)', 'Brightness': True}, + 'names': {'str': 'channel[chan].name'}, + 'etendue': {'str': 'channel[chan].etendue', + 'dim': 'etendue', 'quant': 'etendue', + 'units': 'm2.sr'}}, - 'spectrometer_visible': - {'t':{'str':'channel[chan].grating_spectrometer.radiance_spectral.time', - 'quant':'t', 'units':'s'}, - 'spectra': {'str': ('channel[chan].grating_spectrometer' - + '.radiance_spectral.data'), - 'dim': 'radiance_spectral', - 'quant': 'radiance_spectral', - 'units': 'ph/s/(m2.sr)/m', 'Brightness': True}, - 'names': {'str': 'channel[chan].name'}, - 'lamb':{'str':'channel[chan].grating_spectrometer.wavelengths', - 'dim':'wavelength', 'quant':'wavelength', 'units':'m'}}, + 'spectrometer_visible': { + 't':{'str': ('channel[chan].grating_spectrometer' + + '.radiance_spectral.time'), + 'quant': 't', 'units': 's'}, + 'spectra': {'str': ('channel[chan].grating_spectrometer' + + '.radiance_spectral.data'), + 'dim': 'radiance_spectral', + 'quant': 'radiance_spectral', + 'units': 'ph/s/(m2.sr)/m', 'Brightness': True}, + 'names': {'str': 'channel[chan].name'}, + 'lamb':{'str': 'channel[chan].grating_spectrometer.wavelengths', + 'dim': 'wavelength', 'quant': 'wavelength', 'units': 'm'}}, - 'bremsstrahlung_visible': - {'t': {'str': 'time', - 'quant': 't', 'units': 's'}, - 'radiance': {'str': 'channel[chan].radiance_spectral.data', - 'dim': 'radiance_spectral', - 'quant': 'radiance_spectral', - 'units': 'ph/s/(m2.sr)/m', - 'Brightness': True}, - 'names': {'str': 'channel[chan].name'}, - 'lamb_up': {'str':'channel[chan].filter.wavelength_upper'}, - 'lamb_lo': {'str':'channel[chan].filter.wavelength_lower'}}, - } + 'bremsstrahlung_visible': { + 't': {'str': 'time', + 'quant': 't', 'units': 's'}, + 'radiance': {'str': 'channel[chan].radiance_spectral.data', + 'dim': 'radiance_spectral', + 'quant': 'radiance_spectral', + 'units': 'ph/s/(m2.sr)/m', + 'Brightness': True}, + 'names': {'str': 'channel[chan].name'}, + 'lamb_up': {'str': 'channel[chan].filter.wavelength_upper'}, + 'lamb_lo': {'str': 'channel[chan].filter.wavelength_lower'}} + } -_didsdiag = {'lh_antennas': {'datacls': 'DataCam1D', - 'geomcls': False, - 'sig': {'data': 'power', - 't': 't'}}, - 'ic_antennas': {'datacls': 'DataCam1D', - 'geomcls': False, - 'sig': {'data': 'power', - 't': 't'}}, - 'magnetics': {'datacls': 'DataCam1D', +_didsdiag = { + 'lh_antennas': {'datacls': 'DataCam1D', + 'geomcls': False, + 'sig': {'data': 'power', + 't': 't'}}, + 'ic_antennas': {'datacls': 'DataCam1D', + 'geomcls': False, + 'sig': {'data': 'power', + 't': 't'}}, + 'magnetics': {'datacls': 'DataCam1D', + 'geomcls': False, + 'sig': {'data': 'bpol_B', + 't': 't'}}, + 'barometry': {'datacls': 'DataCam1D', + 'geomcls': False, + 'sig': {'data': 'p', + 't': 't'}}, + 'calorimetry': {'datacls': 'DataCam1D', + 'geomcls': False, + 'sig': {'data': 'power', + 't': 't'}}, + 'ece': {'datacls': 'DataCam1D', + 'geomcls': False, + 'sig': {'t': 't', + 'X': 'rhotn_sign', + 'data': 'Te'}}, + 'neutron_diagnostic': {'datacls': 'DataCam1D', 'geomcls': False, - 'sig': {'data': 'bpol_B', - 't': 't'}}, - 'barometry': {'datacls': 'DataCam1D', - 'geomcls': False, - 'sig': {'data': 'p', - 't': 't'}}, - 'calorimetry': {'datacls': 'DataCam1D', - 'geomcls': False, - 'sig': {'data': 'power', - 't': 't'}}, - 'ece': {'datacls': 'DataCam1D', - 'geomcls': False, - 'sig': {'t': 't', - 'X': 'rhotn_sign', - 'data': 'Te'}}, - 'neutron_diagnostic': {'datacls': 'DataCam1D', - 'geomcls': False, - 'sig': {'t': 't', - 'data': 'flux_total'}}, - 'reflectometer_profile': {'datacls': 'DataCam1D', - 'geomcls': False, - 'sig': {'t': 't', - 'X': 'R', - 'data': 'ne'}}, - 'interferometer': {'datacls': 'DataCam1D', - 'geomcls': 'CamLOS1D', - 'sig': {'t': 't', - 'data': 'ne_integ'}, - 'synth': {'dsynth': { - 'quant': 'core_profiles.1dne', - 'ref1d': 'core_profiles.1drhotn', - 'ref2d': 'equilibrium.2drhotn'}, - 'dsig': {'core_profiles': ['t'], - 'equilibrium': ['t']}, - 'Brightness': True}}, - 'polarimeter': {'datacls': 'DataCam1D', - 'geomcls': 'CamLOS1D', - 'sig': {'t': 't', - 'data': 'fangle'}, - 'synth': {'dsynth': { - 'fargs': ['core_profiles.1dne', - 'equilibrium.2dBR', - 'equilibrium.2dBT', - 'equilibrium.2dBZ', - 'core_profiles.1drhotn', - 'equilibrium.2drhotn']}, - 'dsig': {'core_profiles': ['t'], - 'equilibrium': ['t']}, - 'Brightness': True}}, - 'bolometer': {'datacls': 'DataCam1D', - 'geomcls': 'CamLOS1D', 'sig': {'t': 't', - 'data': 'power'}, - 'synth': {'dsynth': { - 'quant': 'core_sources.1dprad', - 'ref1d': 'core_sources.1drhotn', - 'ref2d': 'equilibrium.2drhotn'}, - 'dsig': {'core_sources': ['t'], - 'equilibrium': ['t']}, - 'Brightness': True}}, - 'soft_x_rays': {'datacls': 'DataCam1D', + 'data': 'flux_total'}}, + 'reflectometer_profile': {'datacls': 'DataCam1D', + 'geomcls': False, + 'sig': {'t': 't', + 'X': 'R', + 'data': 'ne'}}, + 'interferometer': {'datacls': 'DataCam1D', + 'geomcls': 'CamLOS1D', + 'sig': {'t': 't', + 'data': 'ne_integ'}, + 'synth': {'dsynth': { + 'quant': 'core_profiles.1dne', + 'ref1d': 'core_profiles.1drhotn', + 'ref2d': 'equilibrium.2drhotn'}, + 'dsig': {'core_profiles': ['t'], + 'equilibrium': ['t']}, + 'Brightness': True}}, + 'polarimeter': {'datacls': 'DataCam1D', + 'geomcls': 'CamLOS1D', + 'sig': {'t': 't', + 'data': 'fangle'}, + 'synth': {'dsynth': { + 'fargs': ['core_profiles.1dne', + 'equilibrium.2dBR', + 'equilibrium.2dBT', + 'equilibrium.2dBZ', + 'core_profiles.1drhotn', + 'equilibrium.2drhotn']}, + 'dsig': {'core_profiles': ['t'], + 'equilibrium': ['t']}, + 'Brightness': True}}, + 'bolometer': {'datacls': 'DataCam1D', + 'geomcls': 'CamLOS1D', + 'sig': {'t': 't', + 'data': 'power'}, + 'synth': {'dsynth': { + 'quant': 'core_sources.1dprad', + 'ref1d': 'core_sources.1drhotn', + 'ref2d': 'equilibrium.2drhotn'}, + 'dsig': {'core_sources': ['t'], + 'equilibrium': ['t']}, + 'Brightness': True}}, + 'soft_x_rays': {'datacls': 'DataCam1D', + 'geomcls': 'CamLOS1D', + 'sig': {'t': 't', + 'data': 'power'}}, + 'spectrometer_visible': {'datacls': 'DataCam1DSpectral', 'geomcls': 'CamLOS1D', - 'sig': {'t': 't', - 'data': 'power'}}, - 'spectrometer_visible': {'datacls': 'DataCam1DSpectral', - 'geomcls': 'CamLOS1D', - 'sig': {'data': 'spectra', - 't': 't', - 'lamb': 'lamb'}}, - 'bremsstrahlung_visible': { - 'datacls': 'DataCam1D', - 'geomcls': 'CamLOS1D', - 'sig': {'t': 't', - 'data': 'radiance'}, - 'synth': { - 'dsynth': { - 'quant': ['core_profiles.1dTe', - 'core_profiles.1dne', - 'core_profiles.1dzeff'], - 'ref1d': 'core_profiles.1drhotn', - 'ref2d': 'equilibrium.2drhotn'}, - 'dsig': {'core_profiles': ['t'], - 'equilibrium': ['t']}, - 'Brightness': True}}} + 'sig': {'data': 'spectra', + 't': 't', + 'lamb': 'lamb'}}, + 'bremsstrahlung_visible': { + 'datacls': 'DataCam1D', + 'geomcls': 'CamLOS1D', + 'sig': {'t': 't', + 'data': 'radiance'}, + 'synth': { + 'dsynth': { + 'quant': ['core_profiles.1dTe', + 'core_profiles.1dne', + 'core_profiles.1dzeff'], + 'ref1d': 'core_profiles.1drhotn', + 'ref2d': 'equilibrium.2drhotn'}, + 'dsig': {'core_profiles': ['t'], + 'equilibrium': ['t']}, + 'Brightness': True}}} diff --git a/tofu/imas2tofu/_mat2ids2calc.py b/tofu/imas2tofu/_mat2ids2calc.py index fa3fa14d5..1f490b813 100644 --- a/tofu/imas2tofu/_mat2ids2calc.py +++ b/tofu/imas2tofu/_mat2ids2calc.py @@ -33,7 +33,7 @@ def _get_indtlim(t, tlim=None, shot=None, out=bool): tlim = [-np.inf, np.inf] else: assert len(tlim) == 2 - ls = [int, float, np.int64, np.float64] # , str + ls = [int, float, np.int64, np.float64] # , str assert all([tt is None or type(tt) in ls for tt in tlim]) tlim = list(tlim) for (ii, sgn) in [(0, -1.), (1, 1.)]: @@ -118,7 +118,7 @@ def get_data_from_matids(input_pfe=None, tlim=None, ls = [pp.shape for pp in data] c0 = [len(ss) == 2 for ss in ls] - c1 = np.sum([ss == (1, 1) for ss in ls])==4 + c1 = np.sum([ss == (1, 1) for ss in ls]) == 4 c2 = np.sum([(ss[1] == 1 and ss[0] > ss[1]) for ss in ls]) == 1 c3 = np.sum([(ss[0] == 1 and ss[1] > ss[0]) for ss in ls]) == 1 if c0 and c1 and c2 and c3: @@ -168,7 +168,7 @@ def get_data_from_matids(input_pfe=None, tlim=None, indrhotn = [ii for ii in range(len(desg)) if desg[ii] == 'rho_tor_norm'][0] dout['rhotn'] = np.array([ - data[ii][0,0][indg][0,0][indrhotn].ravel() + data[ii][0, 0][indg][0, 0][indrhotn].ravel() for ii in range(nt)]) if 'brem' in return_fields or 'zeff' in return_fields: @@ -186,7 +186,7 @@ def get_data_from_matids(input_pfe=None, tlim=None, if 'brem' in return_fields or 'Te' in return_fields: indTe = [ii for ii in range(len(dese)) if dese[ii] == 'temperature'][0] - Te = np.array([data[ii][0,0][inde][0,0][indTe].ravel() + Te = np.array([data[ii][0, 0][inde][0, 0][indTe].ravel() for ii in range(nt)]) if 'Te' in return_fields: dout['Te'] = Te @@ -194,7 +194,7 @@ def get_data_from_matids(input_pfe=None, tlim=None, if 'brem' in return_fields or 'ne' in return_fields: indne = [ii for ii in range(len(dese)) if dese[ii] == 'density'][0] - ne = np.array([data[ii][0,0][inde][0,0][indne].ravel() + ne = np.array([data[ii][0, 0][inde][0, 0][indne].ravel() for ii in range(nt)]) if 'ne' in return_fields: dout['ne'] = ne diff --git a/tofu/utils.py b/tofu/utils.py index 0d6c501fd..2e2d50ce8 100644 --- a/tofu/utils.py +++ b/tofu/utils.py @@ -1247,7 +1247,7 @@ def calc_from_imas(shot=None, run=None, user=None, tokamak=None, version=None, ids=lids, synthdiag=True) # export to instances - for ii in range(0,nids): + for ii in range(0, nids): if out[ii] == "Data": multi.calc_signal(ids=lids[ii], tlim=tlim, dsig=dsig, diff --git a/tofu/version.py b/tofu/version.py index 1b3085fa2..d7d76a3d4 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.2b4-45-g8ab25190' +__version__ = '1.4.2b4-46-g6becc220' From 4a7f26d928f23b9f78dcc2bcc97e3caf2bbaf6ee Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Thu, 20 Feb 2020 17:04:44 +0100 Subject: [PATCH 07/16] [Issue346] PEP8 compliance 2 --- tofu/imas2tofu/_def.py | 78 ++++++++++++++++++++++-------------------- tofu/version.py | 2 +- 2 files changed, 41 insertions(+), 39 deletions(-) diff --git a/tofu/imas2tofu/_def.py b/tofu/imas2tofu/_def.py index cd4f29c4f..48985107d 100644 --- a/tofu/imas2tofu/_def.py +++ b/tofu/imas2tofu/_def.py @@ -23,8 +23,8 @@ 'BT0': {'str': ('time_slice[time].global_quantities' + '.magnetic_axis.b_field_tor'), 'dim': 'B', 'quant': 'BT', 'units': 'T'}, - 'axR':{'str': 'time_slice[time].global_quantities.magnetic_axis.r', - 'dim': 'distance', 'quant': 'R', 'units': 'm'}, + 'axR': {'str': 'time_slice[time].global_quantities.magnetic_axis.r', + 'dim': 'distance', 'quant': 'R', 'units': 'm'}, 'axZ': {'str': 'time_slice[time].global_quantities.magnetic_axis.z', 'dim': 'distance', 'quant': 'Z', 'units': 'm'}, 'x0R': {'str': 'time_slice[time].boundary.x_point[0].r'}, @@ -76,15 +76,15 @@ 't': {'str': 'time'}, 'ip': {'str': 'global_quantities.ip', 'dim': 'current', 'quant': 'Ip', 'units': 'A'}, - 'vloop':{'str': 'global_quantities.v_loop', - 'dim': 'voltage', 'quant': 'Vloop', 'units': 'V/m'}, + 'vloop': {'str': 'global_quantities.v_loop', + 'dim': 'voltage', 'quant': 'Vloop', 'units': 'V/m'}, '1dTe': {'str': 'profiles_1d[time].electrons.temperature', 'dim': 'temperature', 'quant': 'Te', 'units': 'eV'}, '1dne': {'str': 'profiles_1d[time].electrons.density', 'dim': 'density', 'quant': 'ne', 'units': '/m^3'}, '1dzeff': {'str': 'profiles_1d[time].zeff', - 'dim': 'charge', 'quant': 'zeff', 'units': 'adim.'}, + 'dim': 'charge', 'quant': 'zeff', 'units': 'adim.'}, '1dphi': {'str': 'profiles_1d[time].grid.phi', 'dim': 'B flux', 'quant': 'phi', 'units': 'Wb'}, '1dpsi': {'str': 'profiles_1d[time].grid.psi', @@ -97,12 +97,12 @@ 'dim': 'density', 'quant': 'nI', 'units': '/m^3'}}, 'edge_profiles': { - 't':{'str': 'time'}}, + 't': {'str': 'time'}}, 'core_sources': { 't': {'str': 'time'}, - '1dpsi': {'str': ('source[identifier.name=lineradiation]'+ - '.profiles_1d[time].grid.psi'), + '1dpsi': {'str': ('source[identifier.name=lineradiation]' + + '.profiles_1d[time].grid.psi'), 'dim': 'B flux', 'quant': 'psi', 'units': 'Wb'}, '1drhotn': {'str': ('source[identifier.name=lineradiation]' + '.profiles_1d[time].grid.rho_tor_norm'), @@ -122,13 +122,13 @@ + '.object[].nodes')}, '2dradiation': {'str': 'source[13].ggd[0].electrons.energy[0].values', 'dim': 'vol. emis.', 'quant': 'vol.emis.', - 'name': 'tot. vol. emis.','units': 'W/m^3'}}, + 'name': 'tot. vol. emis.', 'units': 'W/m^3'}}, 'lh_antennas': { 't': {'str': 'antenna[chan].power_launched.time'}, 'power0': {'str': 'antenna[0].power_launched.data', 'dim': 'power', 'quant': 'lh power', 'units': 'W', - 'pos':True}, + 'pos': True}, 'power1': {'str': 'antenna[1].power_launched.data', 'dim': 'power', 'quant': 'lh power', 'units': 'W', 'pos': True}, @@ -148,12 +148,14 @@ 'units': 'W'}, 'power1mod_fwd': {'str': 'antenna[1].module[].power_forward.data', 'dim': 'power', 'quant': 'ic power', 'units': 'W'}, - 'power1mod_reflect': {'str': 'antenna[1].module[].power_reflected.data', + 'power1mod_reflect': {'str': ('antenna[1].module[]' + + '.power_reflected.data'), 'dim': 'power', 'quant': 'ic power', 'units': 'W'}, 'power2mod_fwd': {'str': 'antenna[2].module[].power_forward.data', 'dim': 'power', 'quant': 'ic power', 'units': 'W'}, - 'power2mod_reflect': {'str': 'antenna[2].module[].power_reflected.data', + 'power2mod_reflect': {'str': ('antenna[2].module[]' + + '.power_reflected.data'), 'dim': 'power', 'quant': 'ic power', 'units': 'W'}}, @@ -163,18 +165,18 @@ 'diamagflux': {'str': 'method[0].diamagnetic_flux.data'}, 'bpol_B': {'str': 'bpol_probe[chan].field.data', 'dim': 'B', 'quant': 'Bpol', 'units': 'T'}, - 'bpol_name':{'str': 'bpol_probe[chan].name'}, - 'bpol_R':{'str': 'bpol_probe[chan].position.r', - 'dim': 'distance', 'quant': 'R', 'units': 'm'}, - 'bpol_Z':{'str': 'bpol_probe[chan].position.z', - 'dim': 'distance', 'quant': 'Z', 'units': 'm'}, - 'bpol_angpol':{'str': 'bpol_probe[chan].poloidal_angle', - 'dim': 'angle', 'quant': 'angle_pol', 'units': 'rad'}, - 'bpol_angtor':{'str': 'bpol_probe[chan].toroidal_angle', + 'bpol_name': {'str': 'bpol_probe[chan].name'}, + 'bpol_R': {'str': 'bpol_probe[chan].position.r', + 'dim': 'distance', 'quant': 'R', 'units': 'm'}, + 'bpol_Z': {'str': 'bpol_probe[chan].position.z', + 'dim': 'distance', 'quant': 'Z', 'units': 'm'}, + 'bpol_angpol': {'str': 'bpol_probe[chan].poloidal_angle', + 'dim': 'angle', 'quant': 'angle_pol', 'units': 'rad'}, + 'bpol_angtor': {'str': 'bpol_probe[chan].toroidal_angle', 'dim': 'angle', 'quant': 'angle_tor', 'units': 'rad'}, - 'floop_flux':{'str': 'flux_loop[chan].flux.data', - 'dim': 'B flux', 'quant': 'B flux', 'units': 'Wb'}, - 'floop_name':{'str': 'flux_loop[chan].name'}, + 'floop_flux': {'str': 'flux_loop[chan].flux.data', + 'dim': 'B flux', 'quant': 'B flux', 'units': 'Wb'}, + 'floop_name': {'str': 'flux_loop[chan].name'}, 'floop_R': {'str': 'flux_loop[chan].position.r', 'dim': 'distance', 'quant': 'R', 'units': 'm'}, 'floop_Z': {'str': 'flux_loop[chan].position.z', @@ -194,26 +196,26 @@ 'units': 'W'}}, 'neutron_diagnostic': { - 't':{'str': 'time', 'units': 's'}, - 'flux_total':{'str': 'synthetic_signals.total_neutron_flux', + 't': {'str': 'time', 'units': 's'}, + 'flux_total': {'str': 'synthetic_signals.total_neutron_flux', 'dim': 'particle flux', 'quant': 'particle flux', 'units': 'Hz'}}, 'ece': { - 't':{'str': 'time', - 'quant': 't', 'units': 's'}, - 'freq':{'str': 'channel[chan].frequency.data', - 'dim': 'freq', 'quant': 'freq', 'units': 'Hz'}, + 't': {'str': 'time', + 'quant': 't', 'units': 's'}, + 'freq': {'str': 'channel[chan].frequency.data', + 'dim': 'freq', 'quant': 'freq', 'units': 'Hz'}, 'Te': {'str': 'channel[chan].t_e.data', - 'dim': 'temperature', 'quant': 'Te', 'units': 'eV'}, + 'dim': 'temperature', 'quant': 'Te', 'units': 'eV'}, 'R': {'str': 'channel[chan].position.r', 'dim': 'distance', 'quant': 'R', 'units': 'm'}, - 'rhotn':{'str': 'channel[chan].position.rho_tor_norm', - 'dim': 'rho', 'quant': 'rhotn', 'units': 'adim.'}, - 'theta':{'str': 'channel[chan].position.theta', - 'dim': 'angle', 'quant': 'theta', 'units': 'rad.'}, - 'tau1keV':{'str': 'channel[chan].optical_depth.data', - 'dim': 'optical_depth', 'quant': 'tau', 'units': 'adim.'}, + 'rhotn': {'str': 'channel[chan].position.rho_tor_norm', + 'dim': 'rho', 'quant': 'rhotn', 'units': 'adim.'}, + 'theta': {'str': 'channel[chan].position.theta', + 'dim': 'angle', 'quant': 'theta', 'units': 'rad.'}, + 'tau1keV': {'str': 'channel[chan].optical_depth.data', + 'dim': 'optical_depth', 'quant': 'tau', 'units': 'adim.'}, 'validity_timed': {'str': 'channel[chan].t_e.validity_timed'}, 'names': {'str': 'channel[chan].name'}, 'Te0': {'str': 't_e_central.data', @@ -285,7 +287,7 @@ 'units': 'm2.sr'}}, 'spectrometer_visible': { - 't':{'str': ('channel[chan].grating_spectrometer' + 't': {'str': ('channel[chan].grating_spectrometer' + '.radiance_spectral.time'), 'quant': 't', 'units': 's'}, 'spectra': {'str': ('channel[chan].grating_spectrometer' @@ -294,7 +296,7 @@ 'quant': 'radiance_spectral', 'units': 'ph/s/(m2.sr)/m', 'Brightness': True}, 'names': {'str': 'channel[chan].name'}, - 'lamb':{'str': 'channel[chan].grating_spectrometer.wavelengths', + 'lamb': {'str': 'channel[chan].grating_spectrometer.wavelengths', 'dim': 'wavelength', 'quant': 'wavelength', 'units': 'm'}}, 'bremsstrahlung_visible': { diff --git a/tofu/version.py b/tofu/version.py index d7d76a3d4..fabe0f9f7 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.2b4-46-g6becc220' +__version__ = '1.4.2b4-47-g644741c1' From ee6a0f4774a53744d72ce7ccfa0f7235305b3044 Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Thu, 20 Feb 2020 17:07:00 +0100 Subject: [PATCH 08/16] [Issue346] PEP8 compliance 3 --- tofu/imas2tofu/_def.py | 18 +++++++++--------- tofu/version.py | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tofu/imas2tofu/_def.py b/tofu/imas2tofu/_def.py index 48985107d..f00700b17 100644 --- a/tofu/imas2tofu/_def.py +++ b/tofu/imas2tofu/_def.py @@ -173,7 +173,7 @@ 'bpol_angpol': {'str': 'bpol_probe[chan].poloidal_angle', 'dim': 'angle', 'quant': 'angle_pol', 'units': 'rad'}, 'bpol_angtor': {'str': 'bpol_probe[chan].toroidal_angle', - 'dim': 'angle', 'quant': 'angle_tor', 'units': 'rad'}, + 'dim': 'angle', 'quant': 'angle_tor', 'units': 'rad'}, 'floop_flux': {'str': 'flux_loop[chan].flux.data', 'dim': 'B flux', 'quant': 'B flux', 'units': 'Wb'}, 'floop_name': {'str': 'flux_loop[chan].name'}, @@ -198,8 +198,8 @@ 'neutron_diagnostic': { 't': {'str': 'time', 'units': 's'}, 'flux_total': {'str': 'synthetic_signals.total_neutron_flux', - 'dim': 'particle flux', 'quant': 'particle flux', - 'units': 'Hz'}}, + 'dim': 'particle flux', 'quant': 'particle flux', + 'units': 'Hz'}}, 'ece': { 't': {'str': 'time', @@ -207,7 +207,7 @@ 'freq': {'str': 'channel[chan].frequency.data', 'dim': 'freq', 'quant': 'freq', 'units': 'Hz'}, 'Te': {'str': 'channel[chan].t_e.data', - 'dim': 'temperature', 'quant': 'Te', 'units': 'eV'}, + 'dim': 'temperature', 'quant': 'Te', 'units': 'eV'}, 'R': {'str': 'channel[chan].position.r', 'dim': 'distance', 'quant': 'R', 'units': 'm'}, 'rhotn': {'str': 'channel[chan].position.rho_tor_norm', @@ -223,7 +223,7 @@ 'reflectometer_profile': { 't': {'str': 'time'}, - 'ne': {'str': 'channel[chan].n_e.data', + 'ne': {'str': 'channel[chan].n_e.data', 'dim': 'density', 'quant': 'ne', 'units': '/m^3'}, 'R': {'str': 'channel[chan].position.r', 'dim': 'distance', 'quant': 'R', 'units': 'm'}, @@ -288,8 +288,8 @@ 'spectrometer_visible': { 't': {'str': ('channel[chan].grating_spectrometer' - + '.radiance_spectral.time'), - 'quant': 't', 'units': 's'}, + + '.radiance_spectral.time'), + 'quant': 't', 'units': 's'}, 'spectra': {'str': ('channel[chan].grating_spectrometer' + '.radiance_spectral.data'), 'dim': 'radiance_spectral', @@ -297,7 +297,7 @@ 'units': 'ph/s/(m2.sr)/m', 'Brightness': True}, 'names': {'str': 'channel[chan].name'}, 'lamb': {'str': 'channel[chan].grating_spectrometer.wavelengths', - 'dim': 'wavelength', 'quant': 'wavelength', 'units': 'm'}}, + 'dim': 'wavelength', 'quant': 'wavelength', 'units': 'm'}}, 'bremsstrahlung_visible': { 't': {'str': 'time', @@ -406,4 +406,4 @@ 'ref2d': 'equilibrium.2drhotn'}, 'dsig': {'core_profiles': ['t'], 'equilibrium': ['t']}, - 'Brightness': True}}} + 'Brightness': True}}} diff --git a/tofu/version.py b/tofu/version.py index fabe0f9f7..75abf0acd 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.2b4-47-g644741c1' +__version__ = '1.4.2b4-48-g4a7f26d9' From cd441adea528451bf1b6f28637c4eb886e8eda13 Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Thu, 20 Feb 2020 17:08:40 +0100 Subject: [PATCH 09/16] [Issue346] PEP8 compliance 4 --- tofu/imas2tofu/_def.py | 20 ++++++++++---------- tofu/version.py | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tofu/imas2tofu/_def.py b/tofu/imas2tofu/_def.py index f00700b17..306fa7b77 100644 --- a/tofu/imas2tofu/_def.py +++ b/tofu/imas2tofu/_def.py @@ -224,16 +224,16 @@ 'reflectometer_profile': { 't': {'str': 'time'}, 'ne': {'str': 'channel[chan].n_e.data', - 'dim': 'density', 'quant': 'ne', 'units': '/m^3'}, - 'R': {'str': 'channel[chan].position.r', - 'dim': 'distance', 'quant': 'R', 'units': 'm'}, - 'Z': {'str': 'channel[chan].position.z', - 'dim': 'distance', 'quant': 'Z', 'units': 'm'}, - 'phi': {'str': 'channel[chan].position.phi', - 'dim': 'angle', 'quant': 'phi', 'units': 'rad'}, - 'names': {'str': 'channel[chan].name'}, - 'mode': {'str': 'mode'}, - 'sweep': {'str': 'sweep_time'}}, + 'dim': 'density', 'quant': 'ne', 'units': '/m^3'}, + 'R': {'str': 'channel[chan].position.r', + 'dim': 'distance', 'quant': 'R', 'units': 'm'}, + 'Z': {'str': 'channel[chan].position.z', + 'dim': 'distance', 'quant': 'Z', 'units': 'm'}, + 'phi': {'str': 'channel[chan].position.phi', + 'dim': 'angle', 'quant': 'phi', 'units': 'rad'}, + 'names': {'str': 'channel[chan].name'}, + 'mode': {'str': 'mode'}, + 'sweep': {'str': 'sweep_time'}}, 'interferometer': { 't': {'str': 'time', diff --git a/tofu/version.py b/tofu/version.py index 75abf0acd..f15d3876b 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.2b4-48-g4a7f26d9' +__version__ = '1.4.2b4-49-gee6a0f47' From 6b48154985bebcd8ba421bf70052c99318863e92 Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Thu, 20 Feb 2020 17:39:21 +0100 Subject: [PATCH 10/16] [Issue351] Comments in tofu/imas2tofu/_def.py --- tofu/imas2tofu/_def.py | 42 ++++++++++++++++++++++++++++++++++++++++++ tofu/version.py | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/tofu/imas2tofu/_def.py b/tofu/imas2tofu/_def.py index 306fa7b77..58ac31c8c 100644 --- a/tofu/imas2tofu/_def.py +++ b/tofu/imas2tofu/_def.py @@ -1,3 +1,37 @@ +""" +That's where the default shortcuts for imas2tofu are defined +Shortcuts allow you (via the class MulTiIDSLoader) to define short str + for some important data contained in IMAS ids +The are stored as a large dict, with: + {ids: { + shortcut1: long_version1, + ... + shortcutN: long_version1} + } + +There is a default copy of this file in the tfu install, but each user can +(re)define his/her own shortcuts using a local copy that will take precedence +at import time. + +To customize your tofu install with user-specific parameters, run in terminal: + + tofu-custom + +This will create a .tofu/ in your home (~) with a local copy that you can edit +To see the shortcuts available from your running ipython console do: + + > import tof as tf + > tf.imas2tofu.MultiIDSLoader.get_shortcuts() + +Available since tofu 1.4.3 +""" + +# ############################################################################ +# +# shortcuts for imas2tofu interface (MultiIDSLoader class) +# +# ############################################################################ + _dshort = { 'wall': { 'wallR': {'str': 'description_2d[0].limiter.unit[0].outline.r'}, @@ -312,6 +346,14 @@ 'lamb_lo': {'str': 'channel[chan].filter.wavelength_lower'}} } + +# ############################################################################ +# +# default data for each ids (not used yet) +# +# ############################################################################ + + _didsdiag = { 'lh_antennas': {'datacls': 'DataCam1D', 'geomcls': False, diff --git a/tofu/version.py b/tofu/version.py index f15d3876b..05fa7286d 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.2b4-49-gee6a0f47' +__version__ = '1.4.2b4-50-gcd441ade' From f62da38f36736cd7d0b26814763263eafa04ac0d Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Thu, 20 Feb 2020 18:16:55 +0100 Subject: [PATCH 11/16] [Issue351] Experimenting with get_shortcuts() class vs instance --- tofu/imas2tofu/_core.py | 27 +++++++++++++++++++-------- tofu/version.py | 2 +- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/tofu/imas2tofu/_core.py b/tofu/imas2tofu/_core.py index 6f298dcc8..e7efe94f1 100644 --- a/tofu/imas2tofu/_core.py +++ b/tofu/imas2tofu/_core.py @@ -24,10 +24,17 @@ import datetime as dtm # tofu -try: - import tofu.imas2tofu._def as _defimas2tofu -except Exception as err: - from . import _def as _defimas2tofu +pfe = os.path.join(os.path.expanduser('~'), '.tofu', '_imas2tofu_def.py') +if os.path.isfile(pfe): + cwd = os.getcwd() + os.chdir(os.path.join(os.path.expanduser('~'), '.tofu')) + import _imas2tofu_def as _defimas2tofu + os.chdir(cwd) +else: + try: + import tofu.imas2tofu._def as _defimas2tofu + except Exception as err: + from . import _def as _defimas2tofu # imas try: @@ -609,7 +616,10 @@ def _shortcuts(cls, obj=None, ids=None, return_=False, if obj is None: obj = cls if ids is None: - lids = list(obj._dids.keys()) + if hasattr(obj, '_dids'): + lids = list(obj._dids.keys()) + else: + lids = list(obj._dshort.keys()) elif ids == 'all': lids = list(obj._dshort.keys()) else: @@ -645,7 +655,8 @@ def _shortcuts(cls, obj=None, ids=None, return_=False, if return_: return short - def get_shortcuts(self, ids=None, return_=False, + @classmethod + def get_shortcuts(cls, ids=None, return_=False, verb=True, sep=' ', line='-', just='l'): """ Display and/or return the builtin shortcuts for imas signal names @@ -657,8 +668,8 @@ def get_shortcuts(self, ids=None, return_=False, They are useful for use with self.get_data() """ - return self._shortcuts(obj=self, ids=ids, return_=return_, verb=verb, - sep=sep, line=line, just=just) + return cls._shortcuts(obj=cls, ids=ids, return_=return_, verb=verb, + sep=sep, line=line, just=just) def set_shortcuts(self, dshort=None): """ Set the dictionary of shortcuts diff --git a/tofu/version.py b/tofu/version.py index 05fa7286d..fc3fbc2af 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.2b4-50-gcd441ade' +__version__ = '1.4.2b4-51-g6b481549' From 710f0d0301fe173c81ad9c68ef26346994bd5698 Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Fri, 21 Feb 2020 09:24:16 +0100 Subject: [PATCH 12/16] [Issue351] Introduced staticmethod, classmethod and instance method for get_shortcuts(c) --- tofu/imas2tofu/_core.py | 28 ++++++++++++++++++++-------- tofu/version.py | 2 +- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/tofu/imas2tofu/_core.py b/tofu/imas2tofu/_core.py index e7efe94f1..0dca96ebb 100644 --- a/tofu/imas2tofu/_core.py +++ b/tofu/imas2tofu/_core.py @@ -610,11 +610,9 @@ def _getcharray(ar, col=None, sep=' ', line='-', just='l', msg=True): out = '\n'.join(out) return out - @classmethod - def _shortcuts(cls, obj=None, ids=None, return_=False, + @staticmethod + def _shortcuts(obj, ids=None, return_=False, verb=True, sep=' ', line='-', just='l'): - if obj is None: - obj = cls if ids is None: if hasattr(obj, '_dids'): lids = list(obj._dids.keys()) @@ -630,7 +628,6 @@ def _shortcuts(cls, obj=None, ids=None, return_=False, lids = [ids] else: lids = ids - lids = sorted(set(lids).intersection(obj._dshort.keys())) short = [] @@ -656,8 +653,8 @@ def _shortcuts(cls, obj=None, ids=None, return_=False, return short @classmethod - def get_shortcuts(cls, ids=None, return_=False, - verb=True, sep=' ', line='-', just='l'): + def get_shortcutsc(cls, ids=None, return_=False, + verb=True, sep=' ', line='-', just='l'): """ Display and/or return the builtin shortcuts for imas signal names By default (ids=None), only display shortcuts for stored ids @@ -668,9 +665,24 @@ def get_shortcuts(cls, ids=None, return_=False, They are useful for use with self.get_data() """ - return cls._shortcuts(obj=cls, ids=ids, return_=return_, verb=verb, + return cls._shortcuts(cls, ids=ids, return_=return_, verb=verb, sep=sep, line=line, just=just) + def get_shortcuts(self, ids=None, return_=False, + verb=True, sep=' ', line='-', just='l'): + """ Display and/or return the builtin shortcuts for imas signal names + + By default (ids=None), only display shortcuts for stored ids + To display all possible shortcuts, use ids='all' + To display shortcuts for a specific ids, use ids= + + These shortcuts can be customized (with self.set_shortcuts()) + They are useful for use with self.get_data() + + """ + return self._shortcuts(self, ids=ids, return_=return_, verb=verb, + sep=sep, line=line, just=just) + def set_shortcuts(self, dshort=None): """ Set the dictionary of shortcuts diff --git a/tofu/version.py b/tofu/version.py index fc3fbc2af..dd9f4e7fe 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.2b4-51-g6b481549' +__version__ = '1.4.2b4-52-gf62da38f' From 0b5962bcee5c9ca6ec77981c0fa18fd6266f96a8 Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Fri, 21 Feb 2020 10:22:30 +0100 Subject: [PATCH 13/16] [Issue351] Added Laura in list of authors in setup.py --- setup.py | 2 +- tofu/version.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 704215958..13405182c 100644 --- a/setup.py +++ b/setup.py @@ -280,7 +280,7 @@ def get_version_tofu(path=_HERE): # The project's main homepage. url="https://github.com/ToFuProject/tofu", # Author details - author="Didier VEZINET", + author="Didier VEZINET and Laura MENDOZA", author_email="didier.vezinet@gmail.com", # Choose your license diff --git a/tofu/version.py b/tofu/version.py index dd9f4e7fe..082bc65c0 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.2b4-52-gf62da38f' +__version__ = '1.4.2b4-53-g710f0d03' From baa2ddb0f79c9775665b33d926b6cccf6d66a183 Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Fri, 21 Feb 2020 10:23:22 +0100 Subject: [PATCH 14/16] [Issue351] Added script tofucustom.py for creating local dir and files --- tofu/scripts/tofucustom.py | 112 +++++++++++++++++++++++++++++++++++++ tofu/version.py | 2 +- 2 files changed, 113 insertions(+), 1 deletion(-) create mode 100755 tofu/scripts/tofucustom.py diff --git a/tofu/scripts/tofucustom.py b/tofu/scripts/tofucustom.py new file mode 100755 index 000000000..970c9afca --- /dev/null +++ b/tofu/scripts/tofucustom.py @@ -0,0 +1,112 @@ +#!/usr/bin/env python + +# Built-in +import os +import getpass +from shutil import copyfile +import argparse + + +################################################### +################################################### +# default values +################################################### + +_SOURCE = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) +_USER = getpass.getuser() +_USER_HOME = os.path.expanduser('~') +_TARGET = os.path.join(_USER_HOME, '.tofu') +_LF = ['_imas2tofu_def.py'] + + +################################################### +################################################### +# function +################################################### + +def custom(target=_TARGET, source=_SOURCE, files=_LF): + + # Caveat (up to now only relevant for _TARGET) + if target != _TARGET: + msg = "" + raise Exception(msg) + + # Check files + if isinstance(files, str): + files = [files] + if not isinstance(files, list) or any([ff not in _LF for ff in files]): + msg = "All files should be in {}".format(_LF) + raise Exception(msg) + + # Try creating directory and copying modules + try: + if not os.path.isdir(target): + os.mkdir(target) + + for ff in files: + mod, f0 = ff.split('_')[1:] + copyfile(os.path.join(source, mod, '_'+f0), + os.path.join(target, ff)) + + msg = ("A local copy of default tofu parameters is now in:\n" + + "\t{}/\n".format(target) + + "You can edit it to spice up your tofu") + print(msg) + + except Exception as err: + msg = (str(err) + '\n\n' + + "A problem occured\n" + + "tofu-custom tried to create a local directory .tofu/ in " + + "your home {}\n".format(target) + + "But it could not, check the error message above to debug\n" + + "Most frequent cause is a permission issue") + raise Exception(msg) + + +################################################### +################################################### +# bash call (main) +################################################### + +def main(): + # Parse input arguments + msg = """ Create a local copy of tofu default parameters + + This creates a local copy, in your home, of tofu default parameters + A directory .tofu is created in your home directory + In this directory, modules containing default parameters are copied + You can then customize them without impacting other users + + """ + + # Instanciate parser + parser = argparse.ArgumentParser(description = msg) + + # Define input arguments + parser.add_argument('-s', '--source', + type=str, + help='tofu source directory', + required=False, + default=_SOURCE) + parser.add_argument('-t','--target', + type=str, + help=('directory where .tofu/ should be created' + + ' (default: {})'.format(_TARGET)), + required=False, + default=_TARGET) + parser.add_argument('-f','--files', + type=str, + help='list of files to be copied', + required=False, + nargs='+', + default=_LF, + choices=_LF) + + # Parse arguments + args = parser.parse_args() + + # Call function + custom(**dict(args._get_kwargs())) + +if __name__ == '__main__': + main() diff --git a/tofu/version.py b/tofu/version.py index 082bc65c0..72d48647c 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.2b4-53-g710f0d03' +__version__ = '1.4.2b4-54-g0b5962bc' From 4622b3109b7014f4ad940886a20d71f830f97016 Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Fri, 21 Feb 2020 10:25:02 +0100 Subject: [PATCH 15/16] [Issue351] Added tofu-custom bash command in setup.py, refering to tofucustom.main() --- setup.py | 1 + tofu/version.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 13405182c..5784c3292 100644 --- a/setup.py +++ b/setup.py @@ -382,6 +382,7 @@ def get_version_tofu(path=_HERE): 'console_scripts': [ 'tofuplot=tofu.scripts.tofuplot:main', 'tofucalc=tofu.scripts.tofucalc:main', + 'tofu-custom=tofu.scripts.tofucustom:main', ], }, diff --git a/tofu/version.py b/tofu/version.py index 72d48647c..964b55937 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.2b4-54-g0b5962bc' +__version__ = '1.4.2b4-55-gbaa2ddb0' From f5b47816a37ada70902a937107aec43d10db50e7 Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Fri, 21 Feb 2020 10:42:44 +0100 Subject: [PATCH 16/16] [Issue351] PEP8 compliance 1 --- tofu/scripts/tofucustom.py | 7 ++++--- tofu/version.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tofu/scripts/tofucustom.py b/tofu/scripts/tofucustom.py index 970c9afca..c0281f9cd 100755 --- a/tofu/scripts/tofucustom.py +++ b/tofu/scripts/tofucustom.py @@ -80,7 +80,7 @@ def main(): """ # Instanciate parser - parser = argparse.ArgumentParser(description = msg) + parser = argparse.ArgumentParser(description=msg) # Define input arguments parser.add_argument('-s', '--source', @@ -88,13 +88,13 @@ def main(): help='tofu source directory', required=False, default=_SOURCE) - parser.add_argument('-t','--target', + parser.add_argument('-t', '--target', type=str, help=('directory where .tofu/ should be created' + ' (default: {})'.format(_TARGET)), required=False, default=_TARGET) - parser.add_argument('-f','--files', + parser.add_argument('-f', '--files', type=str, help='list of files to be copied', required=False, @@ -108,5 +108,6 @@ def main(): # Call function custom(**dict(args._get_kwargs())) + if __name__ == '__main__': main() diff --git a/tofu/version.py b/tofu/version.py index 964b55937..2ee9c73d6 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.2b4-55-gbaa2ddb0' +__version__ = '1.4.2b4-56-g4622b310'