public void FromCSVTest() { DataTable data = new DataTable(); string filename = string.Empty; // TODO: Initialize to an appropriate value data.FromCSV( @"D:\DK_information\output.csv",""); data.ToCSV(@"D:\DK_information\output2.csv"); }
/// <summary> /// Initializes all models /// </summary> public void Initialize() { LogThis("Initializing"); LogThis("Reading catchments"); LoadCatchments(); LogThis(AllCatchments.Values.Count + " catchments read"); LoadCoastalZone(); LoadLakes(); //This should be made dependent on the actual submodels StateVariables = new DataTable(); if (InitialConditionsfile != null) //Work from previous simulation { LogThis("Reading initial conditions from previous simulation. FileName: " + InitialConditionsfile.FileName); StateVariables.FromCSV(InitialConditionsfile.FileName, InitialConditionsfile.ColumnNames.First()); LogThis("Have read " + StateVariables.Rows.Count); //Removing rows that are not within the requested time period for (int i = StateVariables.Rows.Count - 1; i >= 0; i--) { DateTime time = (DateTime) StateVariables.Rows[i]["Time"]; if (time < Start || time > End) StateVariables.Rows.RemoveAt(i); } for (int i = 0; i < StateVariables.Columns.Count; i++) LogThis(StateVariables.Columns[i].ColumnName); //Read in catchment values CurrentTime = Start; foreach (var c in AllCatchments.Values) { var catchm = StateVariables.Rows.Find(new object[] { c.ID, StateVariables.Rows[0][1] }); if (catchm == null) LogThis("Could not find inital conditions for cathment with ID = " + c.ID); else { var precipvalues = new List<double>(); c.Temperature = new TimeStampSeries(); c.Leaching = new TimeStampSeries(); var m11values = new List<double>(); while (CurrentTime <= End) { var CurrentState = StateVariables.Rows.Find(new object[] { c.ID, CurrentTime }); if (!CurrentState.IsNull("Precipitation")) precipvalues.Add((double)CurrentState["Precipitation"]); if (!CurrentState.IsNull("Air Temperature")) c.Temperature.Items.Add(new TimeStampValue(CurrentTime, (double)CurrentState["Air Temperature"])); if (!CurrentState.IsNull("M11Flow")) m11values.Add((double)CurrentState["M11Flow"] / (DateTime.DaysInMonth(CurrentTime.Year, CurrentTime.Month) * 86400.0)); if (!CurrentState.IsNull("Leaching")) c.Leaching.Items.Add(new TimeStampValue(CurrentTime, (double)CurrentState["Leaching"] / (DateTime.DaysInMonth(CurrentTime.Year, CurrentTime.Month) * 86400.0))); CurrentTime = CurrentTime.AddMonths(1); } if (m11values.Count > 0) { c.M11Flow = new ZoomTimeSeries(); c.M11Flow.GetTs(TimeStepUnit.Month).AddRange(Start, m11values); } if (precipvalues.Count > 0) { c.Precipitation = new ZoomTimeSeries() { Accumulate = true }; c.Precipitation.GetTs(TimeStepUnit.Month).AddRange(Start, precipvalues); } CurrentTime = Start; } } CurrentTime = Start; } else { StateVariables.Columns.Add("ID", typeof(int)); StateVariables.Columns.Add("Time", typeof(DateTime)); StateVariables.Columns.Add("ObservedFlow", typeof(double)); StateVariables.Columns.Add("ObservedNitrate", typeof(double)); StateVariables.Columns.Add("M11Flow", typeof(double)); StateVariables.Columns.Add("NetM11Flow", typeof(double)); StateVariables.Columns.Add("Precipitation", typeof(double)); StateVariables.Columns.Add("Air Temperature", typeof(double)); StateVariables.Columns.Add("DownStreamOutput", typeof(double)); StateVariables.Columns.Add("Leaching", typeof(double)); StateVariables.PrimaryKey = new DataColumn[] { StateVariables.Columns[0], StateVariables.Columns[1] }; } if (Stations!=null && StationData!=null) LoadStationData(Stations, StationData.FileName, Start, End); foreach (var c in AllCatchments.Values) { c.SourceModels = SourceModels; c.InternalReduction = InternalReductionModels; c.MainStreamReduction = MainStreamRecutionModels; c.StateVariables = StateVariables; } foreach (var mshe in MsheSetups) LoadMikeSheData(mshe.FileName, Start, End); if (M11FlowOverride != null) { OverrideMike11(); } if (M11Base != null) BiasCorrectFlow(); foreach(var c in AllCatchments.Values) { var v = c.NetInflow; } LogThis("Initializing source models"); foreach (var m in SourceModels) { if (!StateVariables.Columns.Contains(m.Name)) StateVariables.Columns.Add(m.Name, typeof(double)); if (m.Update) m.Initialize(Start, End, AllCatchments.Values); } //Do we have an updated groundwater model? GroundWaterSource gwmodel = SourceModels.FirstOrDefault(s => s.Update & s.GetType() == typeof(GroundWaterSource)) as GroundWaterSource; if (gwmodel != null) { foreach (var c in AllCatchments.Values) { CurrentTime = Start; c.Leaching = new TimeStampSeries(); while (CurrentTime < End) { c.Leaching.Items.Add(new TimeStampValue(CurrentTime, gwmodel.leachdata.GetValue(c, CurrentTime))); CurrentTime = CurrentTime.AddMonths(1); } } CurrentTime = Start; } LogThis("Initializing internal sink models"); foreach (var m in InternalReductionModels) { if (!StateVariables.Columns.Contains(m.Name)) StateVariables.Columns.Add(m.Name, typeof(double)); if (m.Update) m.Initialize(Start, End, AllCatchments.Values); } LogThis("Initializing main stream models"); foreach (var m in MainStreamRecutionModels) { if (!StateVariables.Columns.Contains(m.Name)) StateVariables.Columns.Add(m.Name, typeof(double)); if (m.Update) m.Initialize(Start, End, AllCatchments.Values); } }
public void ToExcelTemplateTest() { DataTable data = new DataTable(); data.FromCSV(@"D:\DK_information\output_temp2.csv",""); string TemplateFilename = @"D:\DK_information\Output\DetailedStationOutputTemplate.xls"; Extensions.ToExcelTemplate(data, TemplateFilename, @"D:\DK_information\Output"); }
public void ToCSVTest() { DataTable data = new DataTable(); data.FromCSV(@"D:\DK_information\output_temp2.csv",""); int ID15 = 82101044; Extensions.ToCSV(data, ID15, @"D:\DK_information\ts.csv"); }
public void ExtractTimeSeriesTest() { DataTable data = new DataTable(); data.FromCSV(@"D:\DK_information\output_temp2.csv", ""); string parametername = "Groundwater"; var actual = Extensions.ExtractTimeSeries(data, parametername); }
public void ToCSVTest1() { DataTable data = new DataTable(); data.FromCSV(@"D:\DK_information\output_temp2.csv", ""); string parametername = "Groundwater"; string filename = @"D:\DK_information\groundwater.csv"; Extensions.ToCSV(data, parametername, filename); }