<jupyter_start><jupyter_text>Notebook 6: Tauc Analysis and PlottingThis notebook shows how to take optical measurements and x-ray fluorescence measurements to generate direct and indirect Tauc plots. Band gaps are then shown for each of three different methods, including:- The Santosh-Newhouse-Gregoire Method- The Segmentation Method- The Multivariate Adaptive Regression Splines (MARS) Method<jupyter_code>import sys
import pandas as pd
import numpy as np
from scipy import signal
sys.path.append('../lib')
#Note: When working in Windows environments, use:
#sys.path.append('..\lib')
from library import Library
from sample import Sample
from bandgaps import *
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import seaborn as sns
color = sns.color_palette()

%matplotlib inline
#Absorption coefficient
def band_gap_run(sample,bg_type='direct',show_graph=True,method='MARS'):
    try:
        optical_spectra = Sample(sample).spectra('optical') #Error with this in the absence of optical data.
        uvit = sorted(zip(list(optical_spectra.uvit_wave),list(optical_spectra.uvit_response)))
        uvir = sorted(zip(list(optical_spectra.uvir_wave),list(optical_spectra.uvir_response)))
        nirt = sorted(zip(list(optical_spectra.nirt_wave.dropna()),list(optical_spectra.nirt_response.dropna())))
        nirr = sorted(zip(list(optical_spectra.nirr_wave.dropna()),list(optical_spectra.nirr_response.dropna())))
    except TypeError:
        print "Sorry, the requested optical data is unavailable. :("
        return
    thickness = float(Sample(209139).properties().thickness)
    transmittance = sorted(uvit+nirt)
    reflectance = sorted(uvir+nirr)
    absorption_coefficient = []
    for i in range(0,len(transmittance)): #Equation for absorption coefficient
        absorption_coefficient.append(-1*np.log(abs(transmittance[i][1]/(1-reflectance[i][1])))/float(thickness*10**-4))
    energy = [1240.0/i[0] for i in transmittance]
    calculate_band_gap(energy,absorption_coefficient,bg_type=bg_type,show_graph=show_graph,method=method)


def calculate_band_gap(energy,absorption_coefficient,bg_type='direct',show_graph=True,method='MARS'):
    absorption_coeff_savgol_filt = np.ndarray.tolist(scipy.signal.savgol_filter(absorption_coefficient,25,4))
    absorption_y = []
    if bg_type == 'direct':
        for k in range(0,len(absorption_coeff_savgol_filt)):
            absorption_y.append((abs(absorption_coeff_savgol_filt[k])**2.0)*energy[k]**2.0)
    elif bg_type == 'indirect':
        for k in range(0,len(absorption_coeff_savgol_filt)):
            absorption_y.append((abs(absorption_coeff_savgol_filt[k])**.5)*energy[k]**.5)
    elif bg_type == 'log10':
        for k in range(0,len(absorption_coeff_savgol_filt)):
            absorption_y.append(np.log10(abs(absorption_coeff_savgol_filt[k]))-3)
    elif bg_type == 'raw_alpha':
        for k in range(0,len(absorption_coeff_savgol_filt)):
            absorption_y.append(abs(absorption_coeff_savgol_filt[k]))
    else:
        return 'Not a valid band gap type.'
    
    if method == 'S-N-G':
        return bandgaps.santosh_newhouse_gregoire_method(energy,absorption_y,bg_type,show_graph)
    elif method == 'Segmentation':
        return bandgaps.segmentation_method(energy,absorption_y,bg_type,show_graph)
    elif method == 'MARS':
        return bandgaps.mars_method(energy,absorption_y,bg_type,show_graph)
    else:
        return 'Not a valid band gap methodology.'
band_gap_run(221101)<jupyter_output>Sorry, the requested optical data is unavailable. :(
{'fraction_non_alphanumeric': 0.10933108487914558, 'fraction_numerical': 0.012647554806070826, 'mean_word_length': 4.941569282136895, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '405692', 'license': 'FSFAP', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1139, 'n_words': 235, 'path': 'notebooks/6_Tauc_Analysis.ipynb', 'repo_name': 'NREL/htem-api-examples', 'size': '3558'}