The initial system state will consist of:
0 - A constant baseline of value 30
1 - A sine wave of frequency 1 (1 cycle across the system's length), of amplitude 10
2 - A sine wave of frequency 10 , of amplitude 4
3 - A sine wave of frequency 40 , of amplitude 2
LAST_REVISED = "May 2, 2025"
LIFE123_VERSION = "1.0.0rc3" # Library version this experiment is based on
#import set_path # Using MyBinder? Uncomment this before running the next cell!
#import sys
#sys.path.append("C:/some_path/my_env_or_install") # CHANGE to the folder containing your venv or libraries installation!
# NOTE: If any of the imports below can't find a module, uncomment the lines above, or try: import set_path
from life123 import BioSim1D, ChemData, check_version
check_version(LIFE123_VERSION)
OK
# Initialize the system. We use a RELATIVELY LARGE NUMBER OF BINS,
# to captures the many changes in the high-frequency component
chem_data = ChemData(names="A", diffusion_rates=0.5)
bio = BioSim1D(n_bins=500, chem_data=chem_data)
bio.inject_sine_conc(chem_label="A", amplitude=10, bias=30, number_cycles=1)
bio.show_system_snapshot()
SYSTEM SNAPSHOT at time 0:
| A | |
|---|---|
| 0 | 30.000000 |
| 1 | 30.125660 |
| 2 | 30.251301 |
| 3 | 30.376902 |
| 4 | 30.502443 |
| ... | ... |
| 495 | 29.372095 |
| 496 | 29.497557 |
| 497 | 29.623098 |
| 498 | 29.748699 |
| 499 | 29.874340 |
500 rows × 1 columns
# Visualize the system's initial state
bio.visualize_system(title_prefix="Low-frequency component of the Initial System State")
# Show as heatmap
bio.system_heatmaps(title_prefix="Low-frequency component of the Initial System State")
bio.inject_sine_conc(chem_label="A", amplitude=4, bias=0, number_cycles=10)
bio.visualize_system(title_prefix="Low- and mid-frequency components of the Initial System State",
show=True)
bio.system_heatmaps(title_prefix="Low- and mid-frequency components of the Initial System State")
bio.inject_sine_conc(chem_label="A", amplitude=2, bias=0, number_cycles=40)
bio.visualize_system(title_prefix="Initial System State with 3 superposed frequencies",
show=True)
bio.system_heatmaps(title_prefix="Initial System State with 3 superposed frequencies")
# Take a look at the frequency domain of the concentration values
bio.frequency_analysis(chem_label="A")
| Frequency | Relative Amplitude | |
|---|---|---|
| 0 | 0.0 | 3.0 |
| 1 | 1.0 | 1.0 |
| 2 | 10.0 | 0.4 |
| 3 | 40.0 | 0.2 |
bio.diffuse(total_duration=10, time_step=0.1)
bio.visualize_system(title_prefix="Diffusion") # Show as a line plot
# Take a look at the frequency domain of the concentration values
bio.frequency_analysis(chem_label="A")
| Frequency | Relative Amplitude | |
|---|---|---|
| 0 | 0.0 | 3.002048 |
| 1 | 1.0 | 1.000000 |
| 2 | 2.0 | 0.000214 |
| 3 | 3.0 | 0.000321 |
| 4 | 4.0 | 0.000426 |
| ... | ... | ... |
| 246 | 246.0 | 0.001063 |
| 247 | 247.0 | 0.001063 |
| 248 | 248.0 | 0.001063 |
| 249 | 249.0 | 0.001062 |
| 250 | 250.0 | 0.001062 |
251 rows × 2 columns
# A lot of tiny frequency components are now present; take just the largest 4
bio.frequency_analysis(chem_label="A", n_largest=4)
| Frequency | Relative Amplitude | |
|---|---|---|
| 0 | 0.0 | 3.002048 |
| 1 | 1.0 | 1.000000 |
| 10 | 10.0 | 0.370945 |
| 40 | 40.0 | 0.060187 |
# Advance the diffusion
bio.diffuse(total_duration=20, time_step=0.1)
# Show as a line plot
bio.visualize_system(title_prefix="Diffusion")
bio.frequency_analysis(chem_label="A", n_largest=10)
| Frequency | Relative Amplitude | |
|---|---|---|
| 0 | 0.0 | 3.005903 |
| 1 | 1.0 | 1.000000 |
| 10 | 10.0 | 0.319950 |
| 40 | 40.0 | 0.009387 |
| 25 | 25.0 | 0.005578 |
| 24 | 24.0 | 0.005577 |
| 26 | 26.0 | 0.005565 |
| 23 | 23.0 | 0.005563 |
| 27 | 27.0 | 0.005541 |
| 22 | 22.0 | 0.005533 |
# Advance the diffusion
bio.diffuse(total_duration=90, time_step=0.1)
# Show as a line plot
bio.visualize_system(title_prefix="Diffusion")
bio.frequency_analysis(chem_label="A", n_largest=3)
| Frequency | Relative Amplitude | |
|---|---|---|
| 0 | 0.0 | 3.022429 |
| 1 | 1.0 | 1.000000 |
| 10 | 10.0 | 0.169929 |
# Advance the diffusion
bio.diffuse(total_duration=100, time_step=0.1)
# Show as a line plot
bio.visualize_system(title_prefix="Diffusion")
bio.frequency_analysis(chem_label="A", n_largest=3)
| Frequency | Relative Amplitude | |
|---|---|---|
| 0 | 0.0 | 3.040431 |
| 1 | 1.0 | 1.000000 |
| 10 | 10.0 | 0.091228 |
# Advance the diffusion
bio.diffuse(total_duration=180, time_step=0.1)
# Show as a line plot
bio.visualize_system(title_prefix="Diffusion")
bio.frequency_analysis(chem_label="A", n_largest=3)
| Frequency | Relative Amplitude | |
|---|---|---|
| 0 | 0.0 | 3.073257 |
| 1 | 1.0 | 1.000000 |
| 10 | 10.0 | 0.040847 |
# Advance the diffusion
bio.diffuse(total_duration=600, time_step=0.3)
# Show as a line plot
bio.visualize_system(title_prefix="Diffusion")
bio.frequency_analysis(chem_label="A", n_largest=10)
| Frequency | Relative Amplitude | |
|---|---|---|
| 0 | 0.0 | 3.184159 |
| 1 | 1.0 | 1.000000 |
| 4 | 4.0 | 0.045772 |
| 5 | 5.0 | 0.044181 |
| 3 | 3.0 | 0.043093 |
| 6 | 6.0 | 0.040484 |
| 7 | 7.0 | 0.036275 |
| 2 | 2.0 | 0.034303 |
| 8 | 8.0 | 0.032375 |
| 9 | 9.0 | 0.029048 |
# Advance the diffusion
bio.diffuse(total_duration=8000, time_step=.5)
# Show as a line plot
bio.visualize_system(title_prefix="Diffusion")
bio.frequency_analysis(chem_label="A", n_largest=2)
| Frequency | Relative Amplitude | |
|---|---|---|
| 0 | 0.0 | 4.456851 |
| 1 | 1.0 | 1.000000 |
Note how the zero-frequency is now gaining over the baseline 1-cycle signal
# Advance the diffusion
bio.diffuse(total_duration=91000, time_step=.5)
# Show as a line plot
bio.visualize_system(title_prefix="Diffusion")
bio.frequency_analysis(chem_label="A", n_largest=2)
| Frequency | Relative Amplitude | |
|---|---|---|
| 0 | 0.0 | 28.997098 |
| 1 | 1.0 | 1.000000 |
# Advance the diffusion
bio.diffuse(total_duration=100000, time_step=.6)
{'steps': 166667}
# Show as a line plot
bio.visualize_system(title_prefix="Diffusion", show=True)
bio.system_heatmaps(title_prefix="Diffusion")
bio.frequency_analysis(chem_label="A", n_largest=2)
| Frequency | Relative Amplitude | |
|---|---|---|
| 0 | 0.0 | 208.747593 |
| 1 | 1.0 | 1.000000 |