<jupyter_start><jupyter_text>Generate our own michele-levy chart, to demonstrate the power of colour<jupyter_code>def mlEQ(lam, ret):
    '''
    lam: wavelength in nm
    ret: retardence in microns
    '''
    return np.sin(np.pi*ret/lam*10**3)**2. #ml equation

lamL = np.arange(360,830,1) #visiable light range 
retL = np.arange(0.4, 0.8, .001) #generate range of rets
I = np.array([[mlEQ(l,r) for l in lamL] for r in retL])
I_indx = np.array([[(l,r) for l in lamL] for r in retL])
I_indx 
# [[I(lam1, r1), I(lam2, r1), ... I(lamN, r1)],
#  [I(lam1, r2), ..., I(lamN, r2)]...]
#This generates list, so for each retardence (row), we find the intensity at each wavelength (cols)

#Convert to linear colour space (CIE XYZ), assuming a 'standard' spectral weighting
XYZ = [colour.sd_to_XYZ(colour.SpectralDistribution({
    lam:i for (lam,i) in zip(lamL,iL)}),illuminant=colour.ILLUMINANTS_RELATIVE_SPDS["D65"]) for iL in I]       
#Now, we can convert to rgb for displaying
sRGB = [list(colour.XYZ_to_sRGB(xyz/100)) for xyz in XYZ] 
mlChart = np.array([[i for i in sRGB] for j in np.arange(0,200)])
fig,ax = plt.subplots(figsize= (20,10))
#ax.axis('off')
ax.imshow(mlChart, extent= (.4,.8,0,.01), aspect='auto')
#It's not perfect, but this is the basic ML chart. We could improve this by choosing a more 
#appropriate spectral illumination source (changing the D65 value)<jupyter_output><empty_output><jupyter_text>Finding the retardence of an image region<jupyter_code>im = plt.imread('./mx12160_1point1PercentBa6Fe_islandFormationCooling_44C_afterV2_img2.jpg')
plt.imshow(im)
#pixel map
#yellow/orange island: px[col][row] = 294, 742
#purple island: 819, 667
#blue island: 824, 530
#red island: 493, 279
#orange island: 969, 729

#now, get these pixel maps

island_coords = [(742,292),(667,819), (530,824), (279,493), (729,969)]
island_px = [im[i_cord] for i_cord in island_coords]
island_px #these are in rgb values, need to convert to linear colour space
island_xyz = [colour.sRGB_to_XYZ(col/255) for col in island_px]
island_xyz

#Now, find the most likely retardence by minimizing the mse error for island colour and the retardence chart
#we calculated earlier
delE = np.array([[colour.delta_E(colour.XYZ_to_Lab(c1),colour.XYZ_to_Lab(c2/100), metric = 2000) for c2 in XYZ] for c1 in island_xyz])
ret = np.array([retL[i.argmin()] for i in delE])
ret_col = np.array([sRGB[i.argmin()] for i in delE])
ret
fig,ax = plt.subplots(figsize= (8,4))
#ax.axis('off')
ax.imshow(mlChart, extent= (.4,.8,0,.01), aspect='auto')
#pixel map
#yellow/orange island: px[col][row] = 294, 742
#purple island: 819, 667
#blue island: 824, 530
#red island: 493, 279
#orange island: 969, 729

fig1, [ax1,ax2] = plt.subplots(nrows=1,ncols=2, figsize=(14,10))
ax2.imshow(im)
ax2.axis('off')
for i,island in enumerate(delE):
    ax1.plot(retL,island, label = 'island: {}'.format(i))
    ax1.set_xlabel('retardence')
    ax1.set_ylabel('delta_E')
    ax2.text(*island_coords[i][::-1], '{}'.format(i), color='white')
ax1.legend(loc='best')

    
swatch = np.zeros([400,400,3]).astype('int')
fig2, aList = plt.subplots(nrows=2,ncols=3,figsize=(8,6))
a_i = 0
aList = aList.flatten()
for i, px in enumerate(island_px):
    swatch[:,:200,:] = px
    swatch[:,200:,:] = 255*ret_col[i]
    aList[a_i].axis('off')
    aList[a_i].imshow(swatch)
    #aList[a_i].text(0,400,'measured')
    #aList[a_i].text(200,200,'ML colour')
    a_i +=1<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16365754222481071, 'fraction_numerical': 0.06377402446126966, 'mean_word_length': 5.155913978494624, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '297014', 'license': 'MIT', 'n_tokens_mistral': 1566, 'n_tokens_neox': 1388, 'n_words': 355, 'path': 'Calculating Thickness from Colour Information.ipynb', 'repo_name': 'aasgreen/biref', 'size': '3434'}