<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Chapter 11 :: Coding For Chemists</title>
    <link>https://codingforchemistsbook.com/book_material/chapter-11/index.html</link>
    <description>Data Download Data for Chapter 11&#xA;Alternatively, individual files can be found in the Data section.&#xA;Code from chapter &#39;&#39;&#39; A quick test of the accuracty of linear and cubic spline interpolation Written by: myself (email@domain.com) Changelog: 240606 - v1.0.0 - initial version &#39;&#39;&#39; import numpy as np import scipy.interpolate as spi # Define a function that returns the y-values for a Gaussian function def Gaussian(x, A, x0, sigma): return A * np.exp(-1 * (x - x0)**2 / (2 * sigma**2)) # Define the parameters of the Gaussian A = 1 x0 = 0 sigma = 2 # Create the x- and y-values for the fake data x_data = np.linspace(-5, 5, 8) y_data = Gaussian(x_data, A, x0, sigma) # Create the x- and (exact) y-values for the points at which we would like interpolation x_interp = np.linspace(-5, 5, 1000) y_interp_exact = Gaussian(x_interp, A, x0, sigma) # Do the interpolation. First we will do a linear interpolation y_interp_linear = np.interp(x_interp, x_data, y_data) # Do the cubic spline interpolation - first create the cubic spline object cs = spi.CubicSpline(x_data, y_data) # Now generate the array of interpolated points using the cubic spline object y_interp_cubic = cs(x_interp) # Compute and print the RMSE print(f&#34;Linear Interpolation RMSE: {np.sqrt(np.sum((y_interp_linear - y_interp_exact)**2)):4.2f}&#34;) print(f&#34; Cubic Interpolation RMSE: {np.sqrt(np.sum((y_interp_cubic - y_interp_exact)**2)):4.2f}&#34;) &#39;&#39;&#39; Produce an interpolated 785 nm raman spectrum with data points that match an old 532 nm spectrum Requires: one 532 nm and one 785 nm Raman spectrum Written by: Chris Johnson and Ben Lear (authors@codechembook.com) v1.0.0 - 250304 - initial version &#39;&#39;&#39; import numpy as np from plotly.subplots import make_subplots from codechembook.quickTools import quickSelectFolder, quickPopupMessage from codechembook.symbols.chem import wavenumber as wn # Scaling factor for 532 data scale_532 = 2.95 # Get the folder containing the files to process quickPopupMessage(message = &#39;Select the folder with the Raman spectra.&#39;) folder_name = quickSelectFolder() # Read the data: 785 is the new data that has a contaminant, 532 is the old data x532, y532 = np.genfromtxt(folder_name/&#39;oldNPs.csv&#39;, delimiter = &#39;,&#39;, skip_header = 2, unpack = True) x785, y785 = np.genfromtxt(folder_name/&#39;newNPs.csv&#39;, delimiter = &#39;,&#39;, skip_header = 2, unpack = True) # Interpolate to the 532 spectrum because 785 has the larger span of x points y785_interp = np.interp(x532, x785, y785) # Normalize the 532 data and subtract it from the 785 data y_delta = y785_interp - scale_532 * y532 # Plot the 785 spectrum, the 532 spectrum, and the difference spectrum fig = make_subplots(2, 1) fig.add_scatter(x = x532, y = y785_interp, name = &#39;785 nm&#39;, row = 1, col = 1) fig.add_scatter(x = x532, y = scale_532 * y532, name = &#39;532 nm&#39;, row=1, col=1) fig.add_scatter(x = x532, y = y_delta, name = &#39;Subtracted&#39;, showlegend = False, row = 2, col = 1) fig.update_xaxes(title = f&#39;wavenumber /{wn}&#39;) fig.update_yaxes(title = &#39;intensity&#39;) fig.update_layout(template = &#39;simple_white&#39;, font_size = 18, width = 3 * 300, height = 3 * 300, margin = dict(b = 10, t = 30, l = 10, r = 10)) fig.show(&#39;png&#39;) fig.write_image(&#39;raman.png&#39;) Solutions to Exercises Targeted exercises Implementing linear interpolation using numpy.interp Exercise 1 Consider a Gaussian distribution with $x_0 = 0$, $\sigma = 2$, and amplitude of 1.</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <managingEditor>authors@codingforchemistsbook.com (Benjamin Lear and Christopher Johnson)</managingEditor>
    <webMaster>authors@codingforchemistsbook.com (Benjamin Lear and Christopher Johnson)</webMaster>
    <atom:link href="https://codingforchemistsbook.com/book_material/chapter-11/index.xml" rel="self" type="application/rss+xml" />
  </channel>
</rss>