New to pynams? Check out the intro and basic examples and peak fitting with pynams
In [1]:
%matplotlib inline
%config InlineBackend.figure_formats=["svg"]
from __future__ import print_function, division
import pynams
from pynams import Spectrum, Profile, Diffusivities, dlib, styles
from pynams.diffusion import models
import matplotlib.pyplot as plt
import os # package to figure out where pynams is on your computer
FTIR_file_location = os.path.join(pynams.__path__[0], 'example_FTIR_spectra\\')
spectrum = Spectrum(fname='augite1', folder=FTIR_file_location, thickness_microns=268.)
profile = Profile(fnames=['olivine1', 'olivine2', 'olivine3', 'olivine4'],
folder=FTIR_file_location,
thicknesses_microns=300.,
positions_microns=[10., 20., 30., 40.])
profile.get_baselines(folder=FTIR_file_location)
Simple analytic solutions assuming diffusivity is independent of the diffusing species.
Error functions (the default) are usually preferred for the early stages of diffusion, and the infinite sum (erf_or_sum='infsum') more accurately represents diffusion at later stages (Crank 1975, Section 2.1)
In [2]:
fig, ax, x_data, y_data = models.diffusion1D(length_microns=500., log10D_m2s=-12., time_seconds=3600.)
In [3]:
fig, ax, x_data, y_data = models.diffusion1D(length_microns=500, log10D_m2s=-12, time_seconds=2*3600,
init=0.2, fin=1., symmetric=False, centered=False)
In [4]:
fig, ax, ax_water = profile.plot_diffusion(time_seconds=60*5, log10D_m2s=-13, centered=False)
In [5]:
fig, ax, ax_water = profile.plot_diffusion(time_seconds=60*5, log10D_m2s=-13, centered=True,
fin=0.6, symmetric=False)
Default solves for time while holding constant
Change these setting using keywords log10Dm2s, vary_initial, vary_final, varyD, vary_time, initial_unit_value, final_unit_value
In [6]:
initial, final, log10D, minutes = profile.fitD(symmetric=False)
In [7]:
import numpy as np
time_minutes_long = 60
time_minutes_short = 5
time_minutes_average = np.mean((time_minutes_long, time_minutes_short))
log10D = -12.
centered = False
fig, ax, ax_water = profile.plot_diffusion(time_seconds=time_minutes_average,
log10D_m2s=log10D,
centered=centered, ytop=40)
label = ' '.join((str(time_minutes_average), 'minutes'))
ax.text(15, 35, label, color='b')
x, y1 = profile.diffusion1D(time_seconds=time_minutes_long, log10D_m2s=log10D,
centered=centered)
x, y2 = profile.diffusion1D(time_seconds=time_minutes_short, log10D_m2s=log10D,
centered=centered)
ax.fill_between(x, y1, y2, color='g', alpha=0.3);
label2 = ' '.join((str(time_minutes_short), 'to', str(time_minutes_long), 'minutes'))
ax.text(15, 25, label2, color='g');
In [8]:
print('Olivine proton-polaron diffusion at 1000C')
dlib.pp.whatIsD(celsius=1000)
print('\nOlivine proton-vacancy diffusion at 1000C')
dlib.pv.whatIsD(celsius=1000);
In [9]:
from pynams.diffusion import models
time_hours, c_over_c0 = models.diffusionThinSlab(log10D_m2s=-14., thickness_microns=300.,
max_time_hours=2000, timesteps=300)
plt.plot(time_hours, c_over_c0)
plt.xlabel('Time in hours')
plt.ylabel('Concentration / Initial concentration\nmeasured in the center of the slab')
plt.title('1-dimensional diffusion in a thin slab');