<jupyter_start><jupyter_text>AIAA 2020 Figures related to absorption emission spectroscopy (Figure 4)<jupyter_code>import os
import numpy as np
import pandas as pd
import xarray as xr
import matplotlib as mpl
import matplotlib.pyplot as plt
from pandas import Timestamp
import pickle

from mhdpy import *
import mhdpy

import pytz
mpl.rcParams.update({'font.size': 16, 'timezone': pytz.timezone('America/Los_Angeles')})
finalanalysisfolder = mhdpy.fp.gen_path('mhdlab','Analysis', 'Lee', 'MHDGEN','Final')

ds_alpha = xr.load_dataset(os.path.join(finalanalysisfolder, 'Data', 'spectral_data', 'ds_alpha.cdf'))
ds_alpha_residualseed = xr.load_dataset(os.path.join(finalanalysisfolder, 'Data','spectral_data', 'ds_alpha_residualseed.cdf'))
ds_p = xr.load_dataset(os.path.join(finalanalysisfolder, 'Data','spectral_data', 'fit_params.cdf'))
ds_p_stderr = xr.load_dataset(os.path.join(finalanalysisfolder, 'Data','spectral_data', 'fit_params_stderr.cdf'))

# ds_alpha = ds_alpha.sel(wavelength = slice(765,771))<jupyter_output><empty_output><jupyter_text>Residual Seed<jupyter_code>nK_residualseed = ds_alpha_residualseed['alpha_fit'].attrs['fit_nK']
nK_residualseed_stderr = ds_alpha_residualseed['alpha_fit'].attrs['fit_nK_stderr']

nK_residualseed = round(nK_residualseed,3)

fitstr = '$n_{K,expt}$ = ' + '{:0.2e}'.format(nK_residualseed) + ' $\#/m^3$'

ds_alpha_residualseed['alpha'].plot(marker='o', label = 'Residual Seed 2020-07-01', figsize = (14,3))
ds_alpha_residualseed['alpha_fit'].plot(label = 'Fit:' + fitstr)
# plt.plot(wls_fit, out.eval(x=wls_fit), label = 'Fit:' + fitstr)
plt.ylim(1e-4,1)
plt.xlim(765.5,771)
# plt.xlim(766,767)
# plt.yscale('log')
plt.ylabel('$\\alpha$')
plt.legend(bbox_to_anchor=[0,0,0.7,0.8])
plt.title('')<jupyter_output><empty_output><jupyter_text>Seeded Cases<jupyter_code>fits = ds_alpha['alpha_fit']
alpha_tc_red = ds_alpha['alpha_red']
# fits, ds_p, ds_p_stderr = analysis.xr.fit_da_lmfit(A_abs, final_model, pars, 'wavelength', wls_interp)
ds_together = xr.merge([fits,alpha_tc_red]).rename(alpha_fit='Fit').rename(alpha_red='Experiment').to_array('var')
ds_together.attrs = dict(long_name = '$\\alpha$')

ds_together
g = ds_together.sel(tf=12.94, method = 'nearest').plot(hue='var', col='Kwt', row='date', ylim = (1e-2,2), yscale='log', figsize=(10,10))

plot.dropna(g)
g = ds_together.sel(tf=12.94, method = 'nearest').plot(hue='var', col='date', row='Kwt', ylim = (1e-2,2), yscale='log', figsize=(15,5))

plot.dropna(g)

g.figlegend.set_bbox_to_anchor([0,0,0.42,0.5])

# g.figlegend.remove()

ds = xr.merge([fits,alpha_tc_red]).rename(alpha_fit='Fit').rename(alpha_red='Experiment')
ds = ds.sel(date='2020-06-23').sel(tf=12.94, method='nearest')

g = xr.plot.FacetGrid(ds,row='Kwt', figsize=(7,7))

axes_list=g.axes.flatten()

for i, ax in enumerate(axes_list):
    d = g.name_dicts.flatten()[i]
    ds['Experiment'].sel(d).plot(ax=ax, marker = 'o', label='Data')
    ds['Fit'].sel(d).plot(ax=ax, label='Fit')
    
    if i!=len(axes_list)-1:
        ax.set_xlabel('')
    
# #     if i != len(axes_list)-1:
#     ax.get_legend().remove()
# #     else:
# #         ax.get_legend().set_bbox_to_anchor([0,0,2,1])
    if i == 0:
        ax.legend(bbox_to_anchor=[0,0,0.5,1])
        
    
    ax.set_title('K wt%' + ' = ' + str(d['Kwt']))
    
plot.dropna(g)

plt.suptitle('2020-06-23')<jupyter_output><empty_output><jupyter_text>nK Results<jupyter_code>ds_p.coords['tf'].attrs = dict(long_name = 'Total Mass Flow', units = 'g/s') #Shorten

nK = ds_p['nK_m3']
nK.name ='nK'
nK_err = ds_p_stderr['nK_m3']
g = nK.plot(hue='date', col='tf', marker='o', xscale='log', yscale='log')
plot.dropna(g)
# fitstr = 'sigma = ' + str(pars['p1_sigma'].value) + ' nm, gamma = ' + str(pars['p1_gamma'].value) + ' nm'
# plt.suptitle(fitstr, y=1.05)
g = nK.plot(hue='tf', col='date', marker='o', yscale='log', xscale='log', figsize = (15,3))
plot.dropna(g)

g.figlegend.set_bbox_to_anchor([0,0,0.43,1])

# fitstr = 'sigma = ' + str(pars['p1_sigma'].value) + ' nm, gamma = ' + str(pars['p1_gamma'].value) + ' nm'
# plt.suptitle(fitstr, y=1.05)
coldim = 'tf'
huedim = 'date'

m = nK
s = nK_err

g = xr.plot.FacetGrid(m,col=coldim)

axes_list=g.axes.flatten()

for i, ax in enumerate(axes_list):
    d = g.name_dicts.flatten()[i]
    plot.common.xr_errorbar_axes(m.sel(d).drop(coldim), s.sel(d).drop(coldim), ax, huedim=huedim, capsize=5)
    
    ax.set_yscale('log')
    ax.set_xscale('log')    
    
    if i!=0:
        ax.set_ylabel('')
    
    if i != len(axes_list)-1:
        ax.get_legend().remove()
    else:
        ax.get_legend().set_bbox_to_anchor([0,0,2,1])
        
    ax.set_title('TF' + ' = ' + str(d[coldim]))
    
plot.dropna(g)
coldim = 'date'
huedim = 'tf'

m = nK
s = nK_err

g = xr.plot.FacetGrid(m,col=coldim,figsize = (15,2.5))

axes_list=g.axes.flatten()

for i, ax in enumerate(axes_list):
    d = g.name_dicts.flatten()[i]
    plot.common.xr_errorbar_axes(m.sel(d).drop(coldim), s.sel(d).drop(coldim), ax, huedim=huedim, capsize=5)
    
    ax.set_yscale('log')
    ax.set_xscale('log')    
    
    if i!=0:
        ax.set_ylabel('')
    
    if i != 1:
        ax.get_legend().remove()
    else:
        ax.get_legend().set_bbox_to_anchor([0,0,1.1,1])
    
        
    ax.set_title('Date' + ' = ' + str(d[coldim]))
    
plot.dropna(g)
nK_mean = nK.mean('date', keep_attrs=True)
nK_std = nK.std('date', keep_attrs=True)


fig, axes = plot.common.xr_errorbar(nK_mean, nK_std, huedim='tf')

# fig.set_size_inches(5,6.5)
plt.yscale('log')
plt.xscale('log')

plt.gca().get_legend().remove()
nK_mean = nK.mean('date', keep_attrs=True)
nK_std = nK.std('date', keep_attrs=True)


fig, axes = plot.common.xr_errorbar(nK_mean, nK_std, huedim='tf')

fig.set_size_inches(5,6.5)
plt.yscale('log')
plt.xscale('log')

plt.gca().get_legend().remove()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19728475683107063, 'fraction_numerical': 0.027152431689293693, 'mean_word_length': 5.018614270941055, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '31452', 'license': 'MIT', 'n_tokens_mistral': 2666, 'n_tokens_neox': 2522, 'n_words': 340, 'path': 'public_data/AIAA 2020/.ipynb_checkpoints/Figures_Absem-checkpoint.ipynb', 'repo_name': 'MHDLab/MHDLab.github.io', 'size': '5819'}