private void btnAddTimeSeries_Click(object sender, EventArgs e) { if (simParameters != null) { Model.TimeSeries ts = new TimeSeries("Time Series " + (listOfTimeSeries.Items.Count + 1), "", simParameters.StepTime); simParameters.TimeSeries.Add(ts); listOfTimeSeries.Items.Add(ts); listOfTimeSeries.SelectedItem = ts; } }
private void setTimeIntervalHelperLabel(TimeSeries ts) { if (ts != null) { txtTimeIntervalHelper.Text = string.Format("With a simulation step time of {0}s this time series will record every {1}s.", simParameters.StepTime, ts.Parameters.TimeInterval); } else { txtTimeIntervalHelper.Text = "No time series currently selected."; } }
public void TestSerializationEquality() { String filename = "../../UnitTests/expt1.serialized.xml"; MuCell.Model.Experiment experiment = new MuCell.Model.Experiment("experiment1"); Simulation simulation1 = new Simulation("simulation1"); Results results = new Results(); MuCell.Model.SBML.Model model = new MuCell.Model.SBML.Model(); CellDefinition cellDef1 = new CellDefinition("cellDef1"); cellDef1.addSBMLModel(model); for (int i = 0; i < 5; i++) { StateSnapshot snapshot = new StateSnapshot(); for (int j = 0; j < 10; j++) { CellInstance cell = new CellInstance(cellDef1); cell.GroupID = j; cell.CellInstanceSpatialContext.Position = new Vector3(1*j, 1+i, 2+j); cell.CellInstanceSpatialContext.Velocity = new Vector3(4*i, 5+j, 3+i); cell.CellInstanceSpatialContext.Volume = new Vector3(10+j, 14*i, 15*i); cell.CellInstanceSpatialContext.Orientation = new Vector3(2+i, 3*j, 4*j); snapshot.Cells.Add(cell); } MuCell.Model.Environment environment = new MuCell.Model.Environment(new Vector3(10 * i, 14 * i, 15 * i)); SerializableDictionary<int, MuCell.Model.SBML.Group> dict = new SerializableDictionary<int, MuCell.Model.SBML.Group>(); // create new groups x3 MuCell.Model.SBML.Group group1 = new MuCell.Model.SBML.Group(1); group1.Col = System.Drawing.Color.Beige; MuCell.Model.SBML.Group group2 = new MuCell.Model.SBML.Group(2); group2.Col = System.Drawing.Color.Brown; MuCell.Model.SBML.Group group3 = new MuCell.Model.SBML.Group(3); group3.Col = System.Drawing.Color.Green; dict.Add(1, group1); dict.Add(2, group2); dict.Add(3, group3); environment.Groups = dict; //SerializableDictionary<int, MuCell.Model.NutrientField> nutDict = new SerializableDictionary<int, MuCell.Model.NutrientField>(); //// create new nutrients x2 //MuCell.Model.NutrientField nut1 = new MuCell.Model.NutrientField(1); //MuCell.Model.NutrientField nut2 = new MuCell.Model.NutrientField(2); //nut2.Col = System.Drawing.Color.Fuchsia; //nutDict.Add(1,nut1); nutDict.Add(2,nut2); //environment.Nutrients = nutDict; snapshot.SimulationEnvironment = environment; results.StateSnapshots.Add(snapshot); } results.CurrentState = results.StateSnapshots[4]; for (int i = 0; i < 3; i++) { TimeSeries timeSeries = new TimeSeries("Function" + i, 1.2 * i); for (int j = 0; j < 20; j++) { timeSeries.Series.Add(0.43+i*j+0.031*j); } results.TimeSeries.Add(timeSeries); } results.FilePath = "some-file-path"; simulation1.SimulationResults = results; SimulationParameters simulationParams1 = new SimulationParameters(); simulationParams1.TimeSeries = results.TimeSeries; simulationParams1.InitialState = results.StateSnapshots[0]; // add to simulation simulation1.Parameters = simulationParams1; // expt.addSimulation experiment.addSimulation(simulation1); XmlSerializer s = new XmlSerializer(typeof(MuCell.Model.Experiment)); TextWriter w = new StreamWriter(filename); s.Serialize(w, experiment); w.Close(); TextReader tr = new StreamReader(filename); Experiment deserializedExpt = (Experiment)s.Deserialize(tr); tr.Close(); Assert.IsTrue(experiment.exptEquals(deserializedExpt)); }
public bool exptEquals(TimeSeries other) { //if (this.MaxValue != other.MaxValue) //{ // Console.Write("TimeSeries objects not equal: "); // Console.WriteLine("this.MaxValue=" + this.MaxValue + "; other.MaxValue=" + other.MaxValue); // return false; //} //if (this.MinValue != other.MinValue) //{ // Console.Write("TimeSeries objects not equal: "); // Console.WriteLine("this.MinValue=" + this.MinValue + "; other.MinValue=" + other.MinValue); // return false; //} if (this.Parameters.exptEquals(other.Parameters) == false) { Console.Write("TimeSeries objects not equal: "); Console.WriteLine("this.Parameters != other.Parameters"); return false; } try { for (int i = 0; i < this.Series.Count; i++) { if (this.Series[i] != other.Series[i]) { Console.Write("TimeSeries objects not equal: "); Console.Write("this.Series[" + i + "]=" + this.Series[i]); Console.WriteLine("; other.Series[" + i + "]" + other.Series[i]); return false; } } } catch (Exception e) { // Array out of bounds; lists are unequal Console.Write("TimeSeries objects not equal: "); Console.WriteLine("List lengths differed"); return false; } return true; }
/* public TimeSeries createTimeSeries(string name) { string wtf = this.currentSimulationName; Simulation currentSimulation = getCurrentSimulation(); TimeSeries ts = new TimeSeries(name, "", currentSimulation.Parameters.StepTime); currentSimulation.Parameters.TimeSeries.Add(ts); return ts; } */ public bool validateTimeSeries(TimeSeries ts) { Experiment currentExperiment = null; Simulation currentSimulation = null; List<Model.SBML.Model> models = new List<MuCell.Model.SBML.Model>(); foreach (Experiment e in openExperiments) { if (e.Id == currentExperimentID) { currentExperiment = e; System.Console.WriteLine(currentExperiment.Id); break; } } if (currentExperiment != null) { foreach (Simulation s in currentExperiment.getSimulations()) { //<<<<<<< .mine // currentSimulation = s; // System.Console.WriteLine(currentSimulation.Name); // break; //======= if (s.Name.Equals(currentSimulationName)) { currentSimulation = s; break; } ////>>>>>>> .r398 } foreach (CellDefinition cd in currentExperiment.getCellDefinitions()) { models.Add(cd.getModel()); } } if (currentSimulation != null) { try { ts.Initialize(models, currentExperiment, currentSimulation); return true; } catch (Exception e) { System.Console.Write(e.ToString()); return false; } } return false; }
public void removeTimeSeries(TimeSeries ts) { Simulation currentSimulation = getCurrentSimulation(); currentSimulation.Parameters.TimeSeries.Remove(ts); }
/* public TimeSeries createTimeSeries(string name) { string wtf = this.currentSimulationName; Simulation currentSimulation = getCurrentSimulation(); TimeSeries ts = new TimeSeries(name, "", currentSimulation.Parameters.StepTime); currentSimulation.Parameters.TimeSeries.Add(ts); return ts; } */ public bool validateTimeSeries(TimeSeries ts) { Experiment currentExperiment = null; Simulation currentSimulation = null; List<Model.SBML.Model> models = new List<MuCell.Model.SBML.Model>(); foreach (Experiment e in openExperiments) { if (e.Id == currentExperimentID) { currentExperiment = e; break; } } if (currentExperiment != null) { foreach (Simulation s in currentExperiment.getSimulations()) { if (s.Name.Equals(currentSimulationName)) { currentSimulation = s; break; } } foreach (CellDefinition cd in currentExperiment.getCellDefinitions()) { models.Add(cd.getModel()); } } if (currentSimulation != null) { try { ts.Initialize(models, currentExperiment, currentSimulation); return true; } catch { return false; } } return false; }