GUIS shot_designer_eqΒΆ

# -*-Python-*-
# Created by bgrierson at 20 Dec 2016  14:22

# Location of variables and namelist
loc = "root['INPUTS']['GUIS_shot_designer']"
nml = eval(loc)

# EQ history variables
ext = ['CUR', 'RBZ']

# Initialize
nml.setdefault('eq_times', nml['tinit'])
for e in ext:
    nml.setdefault('{}'.format(e), np.zeros(1))

# Check to guarantee times are floats or npumpy arrays, and the initial time is in the time list.
def check_time(value):
    return nml['tinit'] in np.atleast_1d(value)


# Check that values are of the right length
def check_vals(value):
    return len(value) == len(np.atleast_1d(nml['eq_times']))


# Preview functions of time
def preview():
    t = nml['eq_times']
    fn = FigureNotebook(0, 'Profiles')
    for e in ext:
        fig, ax = fn.subplots(label=e)
        y = nml['{}'.format(e)]
        ax.plot(t, y, marker='o', label=e)
        ax.set_xlabel('Time (s)')
        ax.legend()


# Time vertices
OMFITx.Entry(loc + "['eq_times']", 'Times (s)', default=nml['tinit'], check=check_time, updateGUI=True)
for e in ext:
    if check_vals(nml['{}'.format(e)]):
        OMFITx.Tab(e)
    else:
        OMFITx.Tab('*' + e + '*')
    OMFITx.Entry(loc + "['{}']".format(e), e, default=np.zeros(len(np.atleast_1d(nml['eq_times']))), check=check_vals)

# Preview
OMFITx.Tab()
OMFITx.Button('Preview', preview)