2. Data Objects#

To begin with, as we have seen in the prvious chapter, we have to express what to analyze, the data. We will introduce some basic data objects here.

If you need to know more about the data, see also Data Illustration.

2.1. Learning Points#

In this chapter, you will learn about:

  • Importing necessary modules

  • SEC-SAXS data objects

  • How to plot data

  • Elution curves

  • Spectral curves

2.2. SEC-SAXS Data#

The following code loads a data set from a SEC-SAXS experiment and displays a 3D plot of the dataset. This helps visualize the relationship between elution time, scattering angle, and intensity.

from molass import get_version
assert get_version() >= '0.2.0', "This tutorial requires molass version 0.2.0 or higher."
import matplotlib.pyplot as plt
from molass_data import SAMPLE1
from molass.DataObjects import SecSaxsData as SSD
ssd = SSD(SAMPLE1)
ssd.plot_3d(title="3D Plot of Sample1");
../../_images/42985012ff4b648fec8d0d747fc88fe5791153cca30c22e9005e56cf45b9f6bf.png

In the 3D plot, you understand the whole structure of the data set and how it changes over time. Note that SAMPLE1 variable has the folder path where the tutorial data set is located.

It is often more handy if you see it in a compact 2D plot as follows.

ssd.plot_compact(title="Compact Plot of Sample1");
zeros at the angular ends of error data have been replaced with the adjacent values.
../../_images/961b76572c20b80830e178da14e7fcbad98c92db7ffba87ffb24d7658cc1fece.png

Note that the yellow vertical lines indicate the positions where other 2D plots have picked the data to draw.

Note also that this compact plot is possible only after the temporal mapping[1] between UV and XR (X-ray) data has been established, which can be easily understood when you remind the fact that frame indecies for UV ranged between 0 and 600.

Observing the following plot, confirm the ralation between the 3D and 2D plots.

ssd.plot_3d(title="Section Lines where the 2D Plots Intersect", with_2d_section_lines=True);
../../_images/fe9fbfca2e8dbb3012796b61001e315d5413b93804a3b356cfad9a4f9f3b74c1.png

To summarize, SSD (SEC-SAXS Data Set) objects provide basic utilities to grasp the data set as a whole and serve as the starting point of your analysis, from where you can derive subsequent objects required for further analysis. We will explore some of such derivations and basic matplotlib usages for them in the following sections.

2.3. Elution Curves#

An elution curve shows how the signal (such as absorbance or scattering intensity) changes as a function of elution time or eluted volume during a chromatography experiment. In SEC-SAXS, both UV absorbance and X-ray scattering elution curves are observed.

Let’s extract and plot the elution curves for both X-ray scattering and UV absorbance.

For X-ray data, elution curves are picked, by default, at Q=0.02 [Å⁻¹].

xr_icurve = ssd.xr.get_icurve()
plt.plot(xr_icurve.x, xr_icurve.y)
plt.title('X-ray Intensity Elution Curve')
plt.xlabel('Elution Time (or Volume)')
plt.ylabel('Intensity')
plt.show()
../../_images/98d073d316d9481420f42d896d77239a880f9489622925ffd2cfeb1dc6a70e6f.png

For UV data, elution curves are picked, by default, at wavelength=280 [nm].

uv_icurve = ssd.uv.get_icurve()
plt.plot(uv_icurve.x, uv_icurve.y)
plt.title('UV Absorbance Elution Curve')
plt.xlabel('Elution Time (or Volume)')
plt.ylabel('Absorbance')
plt.show()
../../_images/c3bb64693f885a3267fef086a14837c19a85f0da9661a2e559818ba159d7b7cd.png

Another plot example with two subplots: one for the X-ray scattering elution curve and one for the UV absorbance elution curve.

fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(12,5))
ax1.plot(uv_icurve.x, uv_icurve.y)
ax1.set_title('UV Absorbance')
ax2.plot(xr_icurve.x, xr_icurve.y)
ax2.set_title('X-ray Intensity')
plt.show()
../../_images/a3990612c663bfb6f7b117329436846e30658ae67a20bc6908fab0d11f251993.png

2.4. Peak Positions#

To analyze the data further, let’s find the peak positions in both elution curves. Integer array indexing is used here for NumPy arrays to highlight the peaks.

uv_peaks = uv_icurve.get_peaks()
xr_peaks = xr_icurve.get_peaks()
uv_peaks, xr_peaks
([131, 231], [88, 157])

Now, let’s plot the elution curves again and mark the peak positions.

fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(12,5))
ax1.plot(uv_icurve.x, uv_icurve.y)
ax1.plot(uv_icurve.x[uv_peaks], uv_icurve.y[uv_peaks], 'o', label='Peaks')
ax1.set_title('UV Absorbance')
ax2.plot(xr_icurve.x, xr_icurve.y)
ax2.plot(xr_icurve.x[xr_peaks], xr_icurve.y[xr_peaks], 'o', label='Peaks')
ax2.set_title('X-ray Intensity')
plt.show()
../../_images/cf7b01855ff386a37f7d8032d6ff23e6bfd8defcfee5a3ee6dea9b3af37683bf.png

The circles on the plots indicate the detected peak positions.

2.5. Spectral Curves#

Note

Here, we use “spectral” to mean either of the following two types of curves, for simplicity.

2.5.1. Absorbance Spectra#

For each detected peak in the UV absorbance elution curve, let’s plot the corresponding absorbance spectrum.

for j in uv_peaks:
    uv_jcurve = ssd.uv.get_jcurve(j=j)
    plt.plot(uv_jcurve.x, uv_jcurve.y)
plt.title('Absorbance Spectra at Peak Positions')
plt.xlabel('Wavelength (or other x-axis label)')
plt.ylabel('Absorbance')
plt.show()
../../_images/fe35e0600083e5f159299cb662ff87c7bd861a6918f90430d45104c1f12e6ad3.png

2.5.2. Scattering Curves#

Similarly, for each detected peak in the X-ray scattering elution curve, let’s plot the corresponding scattering curve.

for j in xr_peaks:
    xr_jcurve = ssd.xr.get_jcurve(j=j)
    plt.plot(xr_jcurve.x, xr_jcurve.y)
plt.title('Scattering Curves at Peak Positions')
plt.xlabel('q (or other x-axis label)')
plt.ylabel('Intensity')
plt.show()
../../_images/27943c3efe2b16e941ce6898de4bd33a6b3755c960b3e442fee541f294eea859.png

Note

You may have noticed that the curves include negative values which are invalid. The treatment of those values will be discussed in the following chapter.

We use plt.subplots here because there is no plt.set_yscale() function. Let’s plot the scattering curves on a logarithmic y-scale for better visualization.

fig, ax = plt.subplots()
ax.set_yscale('log')
for j in xr_peaks:
    xr_jcurve = ssd.xr.get_jcurve(j=j)
    ax.plot(xr_jcurve.x, xr_jcurve.y)
ax.set_title('Scattering Curves (log scale)')
ax.set_xlabel('q (or other x-axis label)')
ax.set_ylabel('Scattering Intensity')
plt.show()
../../_images/a92cf32a99c5742a1003ae994b6417a9ea744d6fa1073df707c2ab17b0216501.png

2.6. Python Basics#

We assume you are already familiar with Python basics. If not, see the following pages for example.