<jupyter_start><jupyter_text>Spectral sensitivities<jupyter_code>_ , sss = get_CIES026(asdf=True)
#sss = sss[::5] # downsample to 5nm bins
sss.plot()
sss = sss.fillna(0)<jupyter_output><empty_output><jupyter_text>OceanOptics spectrometer data<jupyter_code># Load data
oo_spectra      = pd.read_csv('../data/oo_spectra_11-25-20-15-32.csv', index_col=['led','intensity'])
oo_info         = pd.read_csv('../data/oo_info_11-25-20-15-32.csv', index_col=['led','intensity'])
cal_per_wl      = pd.read_csv('../data/oo_calibration.csv', header=None)
sensor_area_cm2 = pd.read_csv('../data/oo_sensorArea.csv', header=None)

# Predict dark counts and get calibrated radiance
oo_spectra.reset_index(inplace=True, drop=True)
oo_info.reset_index(inplace=True)
oo_dark_counts = predict_dark_counts(oo_info, '../data/oo_dark_cal.txt')
wperm2pernm    = calibrated_radiance(oo_spectra, oo_info, oo_dark_counts, cal_per_wl, sensor_area_cm2)

# Mung
wperm2pernm['led'] = oo_info['led']
wperm2pernm['intensity'] = oo_info['intensity']
wperm2pernm.set_index(['led', 'intensity'], inplace=True)
wperm2pernm.sort_index(inplace=True)
wperm2pernm.columns = sss.index

# Get alphaopic radiance and save
wperm2pernm = wperm2pernm.fillna(0)
oo_aor = wperm2pernm.dot(sss)
oo_aor.to_csv('../data/stlab_oo_alphaopic.csv')
wperm2pernm.to_csv('../data/corrected_oo_spectra.csv')<jupyter_output><empty_output><jupyter_text>STLAB spectrometer data<jupyter_code># Gather some data
stlab_spectra = pd.read_csv('../data/stlab_spectra_11-25-20-15-32.csv')
stlab_info    = pd.read_csv('../data/stlab_info_11-25-20-15-32.csv')

# Mung
stlab_spectra['led'] = stlab_info['led']
stlab_spectra['intensity'] = stlab_info['intensity']
stlab_spectra.set_index(['led', 'intensity'], inplace=True)
stlab_spectra.sort_index(inplace=True)
stlab_spectra.columns = sss.index[::5]

# Get alphaopic radiance and save
stlab_aor = stlab_spectra.dot(sss[::5])
stlab_aor.to_csv('../data/stlab_alphaopic.csv')
stlab_aor
oo_aor
oo_aor.reset_index(inplace=True)
stlab_aor.reset_index(inplace=True)
colors = ['blueviolet', 'royalblue', 'darkblue', 'blue', 'cyan', 
          'green', 'lime', 'orange', 'red', 'darkred']
fig, axs = plt.subplots(5, 2, figsize=(12,16), sharex=True)
axs = [ax for sublist in axs for ax in sublist]

for i, pr in enumerate(['S', 'M', 'L', 'Rods', 'Mel']):
    sns.lineplot(data=oo_aor,    x='intensity', y=pr,    hue='led', palette=colors, ax=axs[i*2])
    sns.lineplot(data=stlab_aor, x='intensity', y=pr,    hue='led', palette=colors, ax=axs[i*2+1])

for ax in axs[1:]:
    ax.get_legend().remove()
axs[0].set_title('STLAB')
axs[1].set_title('Ocean Optics STS')

stlab_aor.set_index(['led'], inplace=True)
oo_aor.set_index(['led'], inplace=True)

fig, axs = plt.subplots(10, 5, figsize=(16,18))
plt.setp(axs.flat, xlabel='STLAB', ylabel='OO')

cols = ['{}'.format(col) for col in ['S','M','L','Rods','Mel']]
rows = ['LED: {}'.format(row) for row in range(10)]

pad = 5 # in points

for ax, col in zip(axs[0], cols):
    ax.annotate(col, xy=(0.5, 1), xytext=(0, pad),
                xycoords='axes fraction', textcoords='offset points',
                size='large', ha='center', va='baseline')

for ax, row in zip(axs[:,0], rows):
    ax.annotate(row, xy=(0, 0.5), xytext=(-ax.yaxis.labelpad - pad, 0),
                xycoords=ax.yaxis.label, textcoords='offset points',
                size='large', ha='right', va='center')
axs = [ax for sublist in axs for ax in sublist]
i=0
for led in range(10):
    for pr in ['S','M','L','Rods','Mel']:
        sns.regplot(x=stlab_aor.loc[led,pr], y=oo_aor.loc[led,pr], ax=axs[i], scatter_kws={'s':1}, color=colors[led])
        axs[i].set_xlabel('')
        axs[i].set_ylabel('')
        i+=1
        
for ax in axs[-5:-1]:
    ax.set_xlabel('STLAB')
axs[-1].set_xlabel('STLAB')
for ax in axs[0:-1:5]:
    ax.set_ylabel('Ocean Optics')
    
plt.tight_layout()
fig.subplots_adjust(left=0.15, top=0.95)
from IPython.display import display

for led in range(10):
    print('{}\n{:*^60s}\n{}'.format('*' * 60, ' LED ' + str(led) + ' ', '*' * 60))
    for pr in ['S','M','L','Rods','Mel']:    
        lm = pg.linear_regression(s.loc[led, pr], o.loc[led, pr])
        display(lm.round(2))<jupyter_output>************************************************************
************************** LED 0 ***************************
************************************************************
{'fraction_non_alphanumeric': 0.22255125284738042, 'fraction_numerical': 0.02733485193621868, 'mean_word_length': 5.193229901269394, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '287644', 'license': 'MIT', 'n_tokens_mistral': 1859, 'n_tokens_neox': 1756, 'n_words': 291, 'path': 'notebooks/stlab_oo_spectrometer_regression.ipynb', 'repo_name': 'PyPlr/cvd_pupillometry', 'size': '4390'}