Bug ID S-32: Time Step Bug
Problem
The time steps for the CSV output files are uneven for some intervals. For example, when a time interval of 1.0 is chosen, the times in the CSV file are 0,1.1,2,3,4,5.1 etc but they should be 0,1,2,3,4,5 etc instead.
Solution
Make the time steps even by using a small epsilon number to compensate for rounding errors.
Modified file list
- org.simBio.sim.analyzer.csv.CsvMaker
- org.simBio.sim.gui.CsvDialog
Code explanation
org.simBio.sim.analyzer.csv.CsvMaker
A small epsilon number was added to CsvMaker.java to compensate for rounding errors in the calculations.
private double epsilon = 0.000001;
The original version of CsvMaker had the following code:
if ( t < nextTime) return;
This resulted in uneven time steps in the CSV output file, such as the following, produced from matsuoka_et_al_2003/model.xml, where dtMin = 0.1, dtMax = 0.1,and the interval = 1.0:
time (ms), simulation/model/cell/Vm, simulation/model/cell/Na, simulation/model/cell/K 0.0, -85.9575, 4.925761, 143.1837 1.1, -85.9559, 4.925753, 143.1838 2, -85.9552, 4.925746, 143.1838 3, -85.9547, 4.925739, 143.1838 4, -85.9544, 4.925731, 143.1838 5.1, -85.9543, 4.925723, 143.1839
In the modified version, the epsilon value is subtracted from nextTime in the comparison:
if ( t < nextTime - epsilon ) return;
After this code change the CSV output file has even time steps:
time (ms), simulation/model/cell/Vm, simulation/model/cell/Na, simulation/model/cell/K 0, -85.9575, 4.925761, 143.1837 1, -85.956, 4.925754, 143.1838 2, -85.9552, 4.925746, 143.1838 3, -85.9547, 4.925739, 143.1838 4, -85.9544, 4.925731, 143.1838 5, -85.9543, 4.925724, 143.1839
org.simBio.sim.gui.CsvDialog
The same kind of time step bug occurred in the CSV files created using the menu option File -> Export to CSV. This was fixed by adding an epsilon value to CsvDialog and changing code in the csvMaker method from this
if ( nextTime > time) { continue; }
to this
if ( nextTime - epsilon > time) { continue; }