<jupyter_start><jupyter_text>Analyse some recent GOLEM shots from 25000 to 26023.   Getting data The dataset has been created from the [GolSQL tool](http://golem.fjfi.cvut.cz/utils/miner), with the follow URL used to generate the dataset: http://golem.fjfi.cvut.cz/utils/miner?new_diagn=electron_density%3Areliability&action=Add&xaxis=ShotNo&start_shot=21000&end_shot=29162&diagn_0=breakdown_field&filter_0=none&subplot_0=&yrange0_0=&yrange1_0=&scale_0=linear&diagn_1=breakdown_probability&filter_1=none&subplot_1=&yrange0_1=&yrange1_1=&scale_1=linear&diagn_2=breakdown_rate&filter_2=none&subplot_2=&yrange0_2=&yrange1_2=&scale_2=linear&diagn_3=breakdown_rate_err&filter_3=none&subplot_3=&yrange0_3=&yrange1_3=&scale_3=linear&diagn_4=breakdown_time&filter_4=none&subplot_4=&yrange0_4=&yrange1_4=&scale_4=linear&diagn_5=breakdown_voltage&filter_5=none&subplot_5=&yrange0_5=&yrange1_5=&scale_5=linear&diagn_6=cb&filter_6=none&subplot_6=&yrange0_6=&yrange1_6=&scale_6=linear&diagn_7=cbd&filter_7=none&subplot_7=&yrange0_7=&yrange1_7=&scale_7=linear&diagn_8=ccd&filter_8=none&subplot_8=&yrange0_8=&yrange1_8=&scale_8=linear&diagn_9=cst&filter_9=none&subplot_9=&yrange0_9=&yrange1_9=&scale_9=linear&diagn_10=chamber_inductance&filter_10=none&subplot_10=&yrange0_10=&yrange1_10=&scale_10=linear&diagn_11=chamber_resistance&filter_11=none&subplot_11=&yrange0_11=&yrange1_11=&scale_11=linear&diagn_12=chamber_temperature&filter_12=none&subplot_12=&yrange0_12=&yrange1_12=&scale_12=linear&diagn_13=discharge_aborted&filter_13=none&subplot_13=&yrange0_13=&yrange1_13=&scale_13=linear&diagn_14=electron_confinement_t98&filter_14=none&subplot_14=&yrange0_14=&yrange1_14=&scale_14=linear&diagn_15=electron_confinement_time&filter_15=none&subplot_15=&yrange0_15=&yrange1_15=&scale_15=linear&diagn_16=electron_temperature_max&filter_16=none&subplot_16=&yrange0_16=&yrange1_16=&scale_16=linear&diagn_17=lb&filter_17=none&subplot_17=&yrange0_17=&yrange1_17=&scale_17=linear&diagn_18=loop_voltage_max&filter_18=none&subplot_18=&yrange0_18=&yrange1_18=&scale_18=linear&diagn_19=loop_voltage_mean&filter_19=none&subplot_19=&yrange0_19=&yrange1_19=&scale_19=linear&diagn_20=plasma&filter_20=none&subplot_20=&yrange0_20=&yrange1_20=&scale_20=linear&diagn_21=plasma_life&filter_21=none&subplot_21=&yrange0_21=&yrange1_21=&scale_21=linear&diagn_22=toroidal_field_mean&filter_22=none&subplot_22=&yrange0_22=&yrange1_22=&scale_22=linear&diagn_23=toroidal_field_max&filter_23=none&subplot_23=&yrange0_23=&yrange1_23=&scale_23=linear&diagn_24=ub&filter_24=none&subplot_24=&yrange0_24=&yrange1_24=&scale_24=linear&diagn_25=ubd&filter_25=none&subplot_25=&yrange0_25=&yrange1_25=&scale_25=linear&diagn_26=ucd&filter_26=none&subplot_26=&yrange0_26=&yrange1_26=&scale_26=linear&diagn_27=ust&filter_27=none&subplot_27=&yrange0_27=&yrange1_27=&scale_27=linear&diagn_28=tst&filter_28=none&subplot_28=&yrange0_28=&yrange1_28=&scale_28=linear&diagn_29=tcd&filter_29=none&subplot_29=&yrange0_29=&yrange1_29=&scale_29=linear&diagn_30=tb&filter_30=none&subplot_30=&yrange0_30=&yrange1_30=&scale_30=linear&diagn_31=tbd&filter_31=none&subplot_31=&yrange0_31=&yrange1_31=&scale_31=linear&diagn_32=pressure&filter_32=none&subplot_32=&yrange0_32=&yrange1_32=&scale_32=linear&diagn_33=pressure_chamber&filter_33=none&subplot_33=&yrange0_33=&yrange1_33=&scale_33=linear&diagn_34=pressure_initial&filter_34=none&subplot_34=&yrange0_34=&yrange1_34=&scale_34=linear&diagn_35=pressure_request&filter_35=none&subplot_35=&yrange0_35=&yrange1_35=&scale_35=linear&diagn_36=plasma_current_mean&filter_36=none&subplot_36=&yrange0_36=&yrange1_36=&scale_36=linear&diagn_37=plasma_current_decay&filter_37=none&subplot_37=&yrange0_37=&yrange1_37=&scale_37=linear&diagn_38=zeff&filter_38=none&subplot_38=&yrange0_38=&yrange1_38=&scale_38=linear&diagn_39=input_power_mean&filter_39=none&subplot_39=&yrange0_39=&yrange1_39=&scale_39=linear&diagn_40=input_power_plasma_mean&filter_40=none&subplot_40=&yrange0_40=&yrange1_40=&scale_40=linear&diagn_41=electron_density_mean&filter_41=none&subplot_41=&yrange0_41=&yrange1_41=&scale_41=linear&diagn_42=electron_density_equilibrium&filter_42=none&subplot_42=&yrange0_42=&yrange1_42=&scale_42=linear<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
import pandas as pd
import seaborn
import numpy as np
dataset_orig = pd.read_csv('close_shots.txt', delimiter='\s+', index_col='shots')
dataset_orig.head()<jupyter_output><empty_output><jupyter_text>Cleaning data Filter bad shots from the dataset, as adviced in the [GOLEM DataMining Page](http://golem.fjfi.cvut.cz/wiki/Handling/DataMining/data_mining)<jupyter_code>print(len(dataset_orig)) # number of shot before cleaning 
# Drop failed plasma
dataset = dataset_orig.dropna(subset=['plasma'])

# Drop plasma longer than 25 ms
dataset = dataset.drop(dataset[dataset['plasma_life'] > 50e-3].index)

# Drop loop voltage below than 5V
dataset = dataset.drop(dataset[dataset['loop_voltage_max'] < 5].index)

# Drop pressure larger than 100mPa
dataset = dataset.drop(dataset[dataset['pressure'] > 100].index)

# Drop negative pressure request
dataset = dataset.drop(dataset[dataset['pressure_request'] < 0].index)

# Drop non physical ucd values
dataset = dataset.drop(dataset[dataset['ucd'] < 200].index)

# Drop non physical pressure
dataset = dataset.drop(dataset[dataset['pressure'] < 0].index)

# number of shot after cleaning
print(len(dataset))<jupyter_output>7217<jupyter_text>Confinement Time Evolution<jupyter_code>dataset.columns
te_med = dataset.electron_confinement_time.median()
print(f'Median Confinement Time {te_med*1e6} [µs]')
ax=dataset.plot(x='plasma_current_mean', y='electron_confinement_time', kind='scatter', logy=True)
ax.set_ylim(1e-6, 1e-3)
ax.axhline(te_med, color='k')<jupyter_output>Median Confinement Time 23.8295 [µs]<jupyter_text>It is not clear if the confinement time directly depends of the plasma current in GOLEM. The plasma being resistive, this scaling law probably doesn't apply in this case. Now we test if the confinement time depends of the density. A proxy for the density is the pressure, if we suppose that most of the injected gaz is ionized.<jupyter_code>ax=dataset.plot(x='pressure', y='electron_confinement_time', kind='scatter', logy=True, grid=True)
ax.set_ylim(1e-6, 1e-3)
ax.set_xlim(0, 80)<jupyter_output><empty_output><jupyter_text>Now let's see if as expected, increasing the plasma current increases the electron temperature<jupyter_code>dataset.plot(x='plasma_current_mean', y='electron_temperature_max', kind='scatter', alpha=0.2)<jupyter_output><empty_output><jupyter_text>Which parameters to maximize the plasma current?<jupyter_code># get the longest shots
dataset_ip = dataset[['ub', 'ucd', 'tcd', 'pressure_request','plasma_current_mean', 'input_power_mean']].dropna()
# keep only the pressure request=20 (majority) to remove a dimension
dataset_ip = dataset_ip[dataset_ip['pressure_request'] == 20]
# keep only the tcd=600 µs (majority) to remove a dimension
dataset_ip = dataset_ip[dataset_ip['tcd'] == 0.006]
dataset_ip = dataset_ip.drop(['tcd','pressure_request'], axis=1)

dataset_ip.sort_values('plasma_current_mean', ascending=False).head()

seaborn.pairplot(dataset_ip[['ub', 'ucd','plasma_current_mean']], diag_kind='kde')
# make the average of similar parameters
dataset_ip_avg = dataset_ip.groupby(['ucd','ub']).mean().reset_index()
dataset_ip_avg.head(10)
fig, ax = plt.subplots()
cax1=ax.scatter(x=dataset_ip_avg['ucd'], y=dataset_ip_avg['ub'], c=dataset_ip_avg['plasma_current_mean'])
cb1=plt.colorbar(cax1)
ax.set_xlabel('$U_{cd}$')
ax.set_ylabel('$U_B$')
ax.set_title('Plasma current (mean)')<jupyter_output><empty_output><jupyter_text>Which parameters to improve the plasma lifetime?<jupyter_code># get the longest shots
dataset_lt = dataset[['ub', 'ucd', 'tcd', 'pressure_request','plasma_life']].dropna()
dataset_lt.sort_values('plasma_life', ascending=False).head()<jupyter_output><empty_output><jupyter_text>According to the GOLEM documentation, the following parameters can be tuned for each plasma shot: - Toroidal Magnetic Field, set by $U_B$ - Current Drive, set by $U_{CD}$ - Time delay for Current Drive, $\tau_{CD}$ - Filling Pressure, $p_{WG}$ [mPa] So let's look for the set of parameters which maximize the plasma duration The question is : what is the set of parameters $\{u_B, u_{CD}, \tau_{CD}, p\}$ which maximize the plasma duration ?  The plasma life distribution is<jupyter_code>seaborn.distplot(dataset_lt['plasma_life']*1e3, axlabel='plasma duration [ms]')<jupyter_output><empty_output><jupyter_text>So, how to produce a plasma duration larger than 15 ms ?<jupyter_code>longest_shots = dataset_lt[dataset_lt['plasma_life'] > 15e-3]
fig, ax = plt.subplots(3,1)
seaborn.distplot(longest_shots['ub'], ax=ax[0])
seaborn.distplot(longest_shots['ucd'], ax=ax[1])
seaborn.distplot(longest_shots['tcd']*1e3, ax=ax[2], axlabel='$t_{CD}$ [ms]')
fig.tight_layout()<jupyter_output><empty_output><jupyter_text>The longuest shots are the ones using high $U_B$=1100 V, $U_{cd}$ close to 400 V and $t_{cd}$ around 5-6 ms.<jupyter_code># make the average of similar parameters
dataset_pl_avg = dataset.groupby(['ucd','ub','tcd']).mean().reset_index()
dataset_pl_avg.head(10)<jupyter_output><empty_output><jupyter_text>GOLEM Most frequent set of parameters<jupyter_code># get the number of occurence of unique rows, 
# ie the most frequent set of parameters used on GOLEM
dataset.groupby(['ucd', 'tcd','ub','pressure_request']).size().reset_index(name='count').sort_values('count', ascending=False).head()<jupyter_output><empty_output><jupyter_text>Most parameter set are $U_{cd}=400$, $t_{cd}=6$ ms, $U_B=800$ and a pressure request of 20 mPa. Maybe the default set of parameter in the graphical interface?   Hugill Diagram Hugill diagram is convenient way to summarize the operating regimes. It consists in representing the inverse of the safety factor at the edge $1/q_a$ (which is proportional to the plasma current) to the parameter $\bar n R / B$ (Murakami parameter)<jupyter_code>from scipy.constants import pi, mu_0
R0 = 0.4 # m
a = 0.085 # m 

dataset['q_a'] = 2*pi*a**2 * dataset.toroidal_field_mean/(mu_0 * dataset.plasma_current_mean * R0)
dataset['1/q_a'] = 1/dataset.q_a
dataset['Murakami'] = dataset.electron_density_equilibrium/1e19 * R0 / dataset.toroidal_field_mean

dataset.plot(kind='scatter', x='Murakami', y='1/q_a', xlim=(-1,10), ylim=(0,0.4), alpha=0.2)<jupyter_output><empty_output><jupyter_text>Paschen Curve<jupyter_code># breakdown_voltage: Loop voltage during breakdown
ax = dataset.plot(kind='scatter', x='pressure', y='breakdown_voltage', 
             alpha=0.2, xlim=(0,100), ylim=(0,20))
ax.set_xlabel('Measured pressure [mPa]')
ax.set_ylabel('Breakdown Voltage [V]')
# analytical model
p = np.linspace(0, 100e-3, num=101) # pressure from 0 to 100 mPa
d = 0.085 # gap distance
gamma_se = 2 # secondary emission coefficient
A = 7 # saturation ionization in the gas [Pa.m]^-1
B = 173 # related to the excitation and ionization energies [Pa.m]^-1
V_B = B*p*d / (np.log(A*p*d / np.log(1+1/gamma_se)))

fig, ax = plt.subplots()
ax.plot(p, V_B)<jupyter_output>C:\Users\JH218595\AppData\Local\Continuum\Anaconda3\lib\site-packages\ipykernel_launcher.py:7: RuntimeWarning: divide by zero encountered in log
  import sys
{'fraction_non_alphanumeric': 0.13369410929737402, 'fraction_numerical': 0.0646735273243435, 'mean_word_length': 11.347207009857613, 'pattern_counts': {'":': 0, '<': 54, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '151016', 'license': 'MIT', 'n_tokens_mistral': 4762, 'n_tokens_neox': 4192, 'n_words': 641, 'path': 'GOLEM_Estimating the best parameter set to maximize something.ipynb', 'repo_name': 'jhillairet/GOLEM', 'size': '11272'}