STE-Nexus's picture
Develop very good app time in second, min, hours option and stepsize option using code "import numpy as np import pandas as pd import matplotlib.pyplot as plt from scipy.constants import N_A # Avogadro's number # ============================================= # PARAMETERS (24-hour simulation) # ============================================= initial_cells = 1e4 # Initial T-cell count (10,000 cells) growth_rate = 0.15 # Growth rate (0.15 per hour) blood_volume = 5 # Blood volume (5 liters) noise_level = 0.05 # 5% multiplicative noise total_seconds = 86400 # 24 hours in seconds step_size = 1 # 1-second resolution # ============================================= # TIME GRID (1-second steps) # ============================================= time_seconds = np.arange(0, total_seconds + 1, step_size) time_hours = time_seconds / 3600 # Convert to hours # ============================================= # GROWTH MODEL CALCULATIONS # ============================================= # Convert growth rate to per-second growth_rate_per_second = growth_rate / 3600 # Exponential growth model ideal_counts = initial_cells * np.exp(growth_rate_per_second * time_seconds) # Add log-normal noise (preserves positivity) np.random.seed(42) # For reproducibility noise = np.random.lognormal(mean=0, sigma=noise_level, size=len(time_seconds)) noisy_counts = ideal_counts * noise # Convert to molar concentration molar_conversion = 1 / (N_A * blood_volume) molar_ideal = ideal_counts * molar_conversion molar_noisy = noisy_counts * molar_conversion # ============================================= # CREATE DATAFRAME (86,401 rows) # ============================================= data = { 'time_seconds': time_seconds, 'time_hours': np.round(time_hours, 6), 'ideal_cell_count': np.round(ideal_counts, 2), 'noisy_cell_count': np.round(noisy_counts, 2), 'molar_ideal': molar_ideal, 'molar_noisy': molar_noisy } df = pd.DataFrame(data) print(f"Generated {len(df)} data points (1-second resolution)") print(df.head()) print(df.tail()) # ============================================= # VISUALIZATION (Sampled for clarity) # ============================================= sample_interval = 300 # Show every 5 minutes fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(12, 8)) # Linear-scale plot (sampled) ax1.plot(time_seconds[::sample_interval], molar_ideal[::sample_interval], 'b--', label='Ideal Growth') ax1.plot(time_seconds[::sample_interval], molar_noisy[::sample_interval], 'r-', alpha=0.7, label='Noisy Measurements') ax1.set_xlabel('Time (seconds)') ax1.set_ylabel('Concentration (M)') ax1.set_title('T-cell Growth (Linear Scale)') ax1.legend() ax1.grid(True) # Log-scale plot (sampled) ax2.semilogy(time_seconds[::sample_interval], molar_ideal[::sample_interval], 'b--', label='Ideal Growth') ax2.semilogy(time_seconds[::sample_interval], molar_noisy[::sample_interval], 'r-', alpha=0.7, label='Noisy Measurements') ax2.set_xlabel('Time (seconds)') ax2.set_ylabel('Concentration (M)') ax2.set_title('T-cell Growth (Log Scale)') ax2.legend() ax2.grid(True, which="both", ls="--") plt.tight_layout() plt.show() # ============================================= # DATA EXPORT # ============================================= df.to_csv('tcell_growth_1sec_resolution_24h.csv', index=False) print("Data saved to 'tcell_growth_1sec_resolution_24h.csv'")" - Initial Deployment
029dabb verified