public void GetDataTest() { Matrix3d M = _dfs.GetData(0, 1); Assert.AreEqual(6.733541, M[151, 86, 17], 1e-5); Assert.AreEqual(13.94974, _dfs.GetData(1, 1)[150, 86, 17], 1e-5); Assert.AreEqual(13.7237, _dfs.GetData(0, 1)[150, 86, 17], 1e-5); }
public void TimeMaxTest() { new XElement("GridOperations"); XElement Op = new XElement("GridOperation", new XAttribute("Type", "TimeMax"), new XElement("DFSFileName", @"..\..\..\TestData\TestModel.she - Result Files\TestModel_3DSZflow.dfs3"), new XElement("Items", ""), new XElement("TimeInterval", "Year"), new XElement("DFSOutputFileName", @"..\..\..\TestData\TestModel.she - Result Files\YearlyMax.dfs3") ); GridFunctions.TimeMax(Op); DFS3 dfs = new DFS3(@"..\..\..\TestData\TestModel.she - Result Files\YearlyMax.dfs3"); Assert.AreEqual(1, dfs.NumberOfTimeSteps); Assert.AreEqual(2.000215e-005, dfs.GetData(0, 1)[19, 14, 0], 1e-7); Assert.AreEqual(2.527396e-007, dfs.GetData(0, 4)[21, 17, 0], 1e-9); dfs.Dispose(); }
public void TimeMinTest() { new XElement("GridOperations"); XElement Op = new XElement("GridOperation", new XAttribute("Type", "TimeMin"), new XElement("DFSFileName", @"..\..\..\TestData\TestModel.she - Result Files\TestModel_3DSZflow.dfs3"), new XElement("Items", ""), new XElement("TimeInterval", "Year"), new XElement("DFSOutputFileName", @"..\..\..\TestData\TestModel.she - Result Files\YearlyMin.dfs3") ); GridFunctions.TimeMin(Op); DFS3 dfs = new DFS3(@"..\..\..\TestData\TestModel.she - Result Files\YearlyMin.dfs3"); Assert.AreEqual(1, dfs.NumberOfTimeSteps); Assert.AreEqual(5, dfs.NumberOfItems); Assert.AreEqual(-1.601641e-007, dfs.GetData(0, 1)[24, 7, 0], 1e-10); Assert.AreEqual(-100.7973, dfs.GetData(0, 3)[18, 11, 0], 1e-2); dfs.Dispose(); }
public void TimeSummationTest() { new XElement("GridOperations"); XElement Op = new XElement("GridOperation", new XAttribute("Type", "TimeSummation"), new XElement("DFSFileName", @"..\..\..\TestData\TestModel.she - Result Files\TestModel_3DSZflow.dfs3"), new XElement("Items", ""), new XElement("TimeInterval", "Year"), new XElement("DFSOutputFileName", @"..\..\..\TestData\TestModel.she - Result Files\YearlySum.dfs3") ); GridFunctions.TimeSummation(Op); DFS3 dfs = new DFS3(@"..\..\..\TestData\TestModel.she - Result Files\YearlySum.dfs3"); Assert.AreEqual(1, dfs.NumberOfTimeSteps); Assert.AreEqual(5, dfs.NumberOfItems); Assert.AreEqual(-6.925168e-007, dfs.GetData(0, 1)[25, 6, 0], 1e-10); Assert.AreEqual(-3.86626e-005, dfs.GetData(0, 4)[21, 16, 0], 1e-8); dfs.Dispose(); }
/// <summary> /// Sums layers from a DFS3 into a DFS2 /// </summary> /// <param name="OperationData"></param> public static void LayerSummation(XElement OperationData) { string Dfs3File = OperationData.Element("DFS3FileName").Value; string DFS2OutPut = OperationData.Element("DFS2OutputFileName").Value; DFS3.MaxEntriesInBuffer = 1; DFS2.MaxEntriesInBuffer = 1; DFS3 input = new DFS3(Dfs3File); var Items = ParseString(OperationData.Element("Items").Value, 1, input.Items.Count()); var Layers = ParseString(OperationData.Element("Layers").Value, 0, input.NumberOfLayers - 1); DenseMatrix Sumdata = new DenseMatrix(input.NumberOfRows, input.NumberOfColumns); //Create the output file and copy info from input file DFS2 output = new DFS2(DFS2OutPut, Items.Count()); output.CopyFromTemplate(input); int l = 0; //Create the items foreach (int j in Items) { int i = j - 1; output.Items[l].EumItem = input.Items[i].EumItem; output.Items[l].EumUnit = input.Items[i].EumUnit; output.Items[l].Name = input.Items[i].Name; l++; } for (int i = 0; i < input.NumberOfTimeSteps; i++) { foreach (int j in Items) { IMatrix3d data = input.GetData(i, j); Sumdata = data[Layers[0]]; for (int k = 1; k < Layers.Count(); k++) { Sumdata = Sumdata + data[Layers[k]]; } RecreateDeleteValues(data[Layers[0]], Sumdata, input.DeleteValue); output.SetData(i, j, Sumdata); } } input.Dispose(); output.Dispose(); }
public static string GetASCIIGrid(this DFS3 dfsfile, int TimeStep, int Item, int Layer) { ASCIIGrid ascii = new ASCIIGrid(); ascii.NumberOfColumns = dfsfile.NumberOfColumns; ascii.NumberOfRows = dfsfile.NumberOfRows; ascii.XOrigin = dfsfile.XOrigin; ascii.YOrigin = dfsfile.YOrigin; ascii.GridSize = dfsfile.GridSize; ascii.DeleteValue = dfsfile.DeleteValue; ascii.Data = dfsfile.GetData(TimeStep, Item)[Layer]; return(ascii.ToString()); }
public void TestMethod1() { DFS3 df = new DFS3(@"C:\Users\Jacob\Documents\MIKE Zero Projects\SHEPar1.she - Result Files\SHEPar1_3DSZflow.dfs3"); for (int i = 0; i < 30; i++) { var mat = df.GetData(i, 1); mat[0][1, 1] = -0.5; mat[1][1, 1] = -0.5; df.SetData(i, 1, mat); } df.Dispose(); }
public void SetDataTest() { Matrix3d M = _dfs.GetData(0, 1); M[90, 130, 1] = 100000; _dfsWrite.SetData(0, 1, M); //Check that buffer is updated Assert.AreEqual(_dfsWrite.GetData(0, 1)[90, 130, 1], 100000); //Note that here is a potential pitfall. Because of the reference and the buffering it will appear as if the data also //changes in _dfs Assert.AreEqual(_dfs.GetData(0, 1)[90, 130, 1], 100000); }
void v_SimulationFinished(object sender, EventArgs e) { Model mshe = sender as Model; var dfs = DfsFileFactory.OpenFile(mshe.Files.SZ3DFileName); double[] percentiles = new double[] { 0.1 }; string filename = Path.Combine(mshe.Files.ResultsDirectory, "SZ3D_percentiles.dfs3"); var dfsout = DfsFileFactory.CreateFile(filename, percentiles.Count()); dfsout.CopyFromTemplate(dfs); dfs.Percentile(1, dfsout, percentiles, 80000000); dfsout.Dispose(); DFS3 dfsout2 = new DFS3(filename); Console.WriteLine(dfsout2.GetData(0, 1)[10, 10, 0]); dfsout2.Dispose(); RunNext(mshe); }
public void CreateFile() { DFS3 df = new DFS3("test.dfs3", 1); df.NumberOfColumns = 5; df.NumberOfRows = 7; df.NumberOfLayers = 3; df.XOrigin = 9000; df.YOrigin = 6000; df.Orientation = 1; df.GridSize = 15; df.TimeOfFirstTimestep = DateTime.Now; df.TimeStep = TimeSpan.FromHours(2); df.FirstItem.Name = "SGS Kriged dyn. corr.precip"; df.FirstItem.EumItem = eumItem.eumIPrecipitationRate; df.FirstItem.EumUnit = eumUnit.eumUmillimeterPerDay; Matrix3d m3 = new Matrix3d(df.NumberOfRows, df.NumberOfColumns, df.NumberOfLayers); m3[0] = new DenseMatrix(df.NumberOfRows, df.NumberOfColumns); m3[1] = new DenseMatrix(df.NumberOfRows, df.NumberOfColumns, 3); m3[2] = new DenseMatrix(df.NumberOfRows, df.NumberOfColumns, 2); m3[3, 4, 0] = 25; df.SetData(0, 1, m3); m3[3, 4, 0] = 24; m3[3, 4, 1] = 100; m3[3, 4, 2] = 110; df.SetData(1, 1, m3); df.Dispose(); df = new DFS3("test.dfs3"); Assert.AreEqual(eumItem.eumIPrecipitationRate, df.FirstItem.EumItem); Matrix m2 = df.GetData(0, 1)[0]; Assert.AreEqual(25, m2[3, 4]); }
public ExtractData(string FileName, string Dfs3FileName) { mShe = new Model(FileName); DFS3 dfs = new DFS3(Dfs3FileName); List <List <double> > wells = new List <List <double> >(); foreach (var W in mShe.ExtractionWells) { wells.Add(new List <double>()); } for (int i = 0; i < dfs.NumberOfTimeSteps; i++) { for (int j = 0; j < mShe.ExtractionWells.Count; j++) { var w = mShe.ExtractionWells[j]; wells[j].Add(dfs.GetData(i, 1)[w.Row, w.Column, w.Layer]); } } }
private void MakePlots() { if (!PlotsMade) //Only do this once { Model mShe = new Model(SheFileName); DFS3 dfs = new DFS3(Dfs3FileName); Item dfsI = dfs.Items[ItemNumber - 1]; string BaseFileName = System.IO.Path.ChangeExtension(Dfs3FileName, ""); int[] TimeSteps = Dfs3plotdfs0.MainWindow.ParseString(TimeStepsAsString, 0, dfs.NumberOfTimeSteps - 1); int[] Layers = Dfs3plotdfs0.MainWindow.ParseString(LayersAsString, 0, dfs.NumberOfLayers - 1); //Set graph headers Header.Content = dfsI.Name; Unit.Content = dfsI.EumQuantity.UnitAbbreviation; //Give plot the same scale as the dfs grid plotter.Width = plotter.Height * ((double)dfs.NumberOfColumns) / (double)dfs.NumberOfRows; //Plot the extraction wells EnumerableDataSource <MikeSheWell> ds = new EnumerableDataSource <MikeSheWell>(mShe.ExtractionWells); ds.SetXMapping(var => var.X); ds.SetYMapping(var => var.Y); var point = new Microsoft.Research.DynamicDataDisplay.PointMarkers.CirclePointMarker(); point.Size = 10; point.Pen = new Pen(Brushes.Black, 3); plotter.AddLineGraph(ds, null, point, null); //Now loop, first on time steps then on layers foreach (int T in TimeSteps) { foreach (int L in Layers) { Header2.Content = "Time: " + dfs.TimeSteps[T].ToShortDateString() + ", Layer: " + L; var M = dfs.GetData(T, ItemNumber)[L]; NaiveColorMap nc = new NaiveColorMap(); M.Transpose(); //Need to transpose nc.Data = M.ToArray(); M.Transpose(); //Transpose back as this is a reference to data held in the buffer nc.Palette = Microsoft.Research.DynamicDataDisplay.Common.Palettes.UniformLinearPalettes.RedGreenBluePalette; var bmp = nc.BuildImage(); image.Source = bmp; //Set the color scale paletteControl.Palette = nc.Palette; paletteControl.Range = nc.Data.GetMinMax(); //Set the size var visible = new Microsoft.Research.DynamicDataDisplay.DataRect(dfs.XOrigin, dfs.YOrigin, dfs.GridSize * dfs.NumberOfColumns, dfs.GridSize * dfs.NumberOfRows); ViewportPanel.SetViewportBounds(image, visible); plotter.Visible = visible; //Write the bitmap this.UpdateLayout(); string fname = BaseFileName + "TimeStep_" + T + "_Layer_" + L; Dfs3plotdfs0.MainWindow.SaveScreen(this, fname + ".jpg", (int)ActualWidth, (int)ActualHeight); //Now write the ascii grid using (StreamWriter sw = new StreamWriter(fname + ".asc")) { sw.Write(dfs.GetASCIIGrid(T, ItemNumber, L)); } } } } }
public static void InsertPointValues(XElement OperationData) { string filename = OperationData.Element("DFSFileName").Value; int Item = OperationData.Element("Item") == null ? 1 : int.Parse(OperationData.Element("Item").Value); bool ClearValues = OperationData.Element("ClearValues") == null ? true: bool.Parse(OperationData.Element("ClearValues").Value); List <Tuple <double, double, int, int, double> > points = new List <Tuple <double, double, int, int, double> >(); foreach (var p in OperationData.Element("Points").Elements()) { Tuple <double, double, int, int, double> point = new Tuple <double, double, int, int, double>( p.Element("X") == null ? -1 : double.Parse(p.Element("X").Value), p.Element("Y") == null ? -1 : double.Parse(p.Element("Y").Value), p.Element("Z") == null ? 0 : int.Parse(p.Element("Z").Value), p.Element("TimeStep") == null ? 0 : int.Parse(p.Element("TimeStep").Value), double.Parse(p.Element("Value").Value)); points.Add(point); } if (Path.GetExtension(filename).EndsWith("0")) { using (DFS0 dfs = new DFS0(filename)) { if (ClearValues) { for (int i = 0; i < dfs.NumberOfTimeSteps; i++) { dfs.SetData(i, Item, 0); } } foreach (var p in points) { dfs.SetData(p.Item4, Item, p.Item5); } } } else if (Path.GetExtension(filename).EndsWith("2")) { using (DFS2 dfs = new DFS2(filename)) { if (ClearValues) { for (int i = 0; i < dfs.NumberOfTimeSteps; i++) { dfs.SetData(i, Item, new DenseMatrix(dfs.NumberOfRows, dfs.NumberOfColumns)); } } foreach (var p in points) { var data = dfs.GetData(p.Item4, Item); int column = dfs.GetColumnIndex(p.Item1); int row = dfs.GetRowIndex(p.Item2); if (column >= 0 & row >= 0) { data[row, column] = p.Item5; } dfs.SetData(p.Item4, Item, data); } } } else if (Path.GetExtension(filename).EndsWith("3")) { using (DFS3 dfs = new DFS3(filename)) { if (ClearValues) { for (int i = 0; i < dfs.NumberOfTimeSteps; i++) { dfs.SetData(i, Item, new Matrix3d(dfs.NumberOfRows, dfs.NumberOfColumns, dfs.NumberOfLayers)); } } foreach (var p in points) { var data = dfs.GetData(p.Item4, Item); int column = dfs.GetColumnIndex(p.Item1); int row = dfs.GetRowIndex(p.Item2); if (column >= 0 & row >= 0) { data[row, column, p.Item3] = p.Item5; } dfs.SetData(p.Item4, Item, data); } } } }
static void Main(string[] args) { string DFS3FileName = args.FirstOrDefault(var => Path.GetExtension(var).Equals(".dfs3")); var SheFiles = args.Where(var => Path.GetExtension(var).Equals(".she")); if (DFS3FileName == null) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Known file types (*.dfs3)|*.dfs3"; //Only open .dfs2-files ofd.Title = "Select a .dfs2-file with grid codes marking the areas where timeseries should be aggregated"; if (ofd.ShowDialog() == DialogResult.OK) DFS3FileName = ofd.FileName; else return; } if (SheFiles.Count() == 0) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Known file types (*.she)|*.she"; //Only open .asc-files ofd.Title = "Select the she-files with the scenarios"; ofd.Multiselect = true; if (ofd.ShowDialog() == DialogResult.OK) SheFiles = ofd.FileNames; else return; } DFS3 GridFile = new DFS3(DFS3FileName); foreach (var file in SheFiles) { Model M = new Model(file); ITSObject timeseries = new TSObjectClass(); timeseries.Time.AddTimeSteps(M.Results.PhreaticHead.TimeSteps.Count()); for (int t = 0; t < M.Results.PhreaticHead.TimeSteps.Count(); t++) { for (int k=0;k<GridFile.NumberOfLayers;k++) { Dictionary<int,List<double>> AggregatedValues = new Dictionary<int,List<double>>(); for (int i =0;i< GridFile.NumberOfRows;i++) { for (int j=0;j<GridFile.NumberOfColumns;j++) { int gridcode = (int)GridFile.GetData(0,1)[i,j,k]; List<double> Values; if(!AggregatedValues.TryGetValue(gridcode, out Values)) { Values = new List<double>(); AggregatedValues.Add(gridcode,Values); } Values.Add(M.Results.PhreaticHead.TimeData(t)[i,j,k]); } } foreach(var kvp in AggregatedValues) { } } timeseries.Time.SetTimeForTimeStepNr(t,M.Results.PhreaticHead.TimeSteps[t]); timeseries.Item(0).SetDataForTimeStepNr(t, } } }
private void MakePlots() { if (!PlotsMade) //Only do this once { Model mShe = new Model(SheFileName); DFS3 dfs = new DFS3(Dfs3FileName); Item dfsI = dfs.Items[ItemNumber - 1]; List <TimestampSeries> well_Concentration = new List <TimestampSeries>(); int[] TimeSteps = ParseString(TimeStepsAsString, 0, dfs.NumberOfTimeSteps - 1); int[] WellNumbers = ParseString(WellsAsString, 0, mShe.ExtractionWells.Count - 1); List <MikeSheWell> wells = new List <MikeSheWell>(); foreach (int j in WellNumbers) { wells.Add(mShe.ExtractionWells[j]); } foreach (int i in TimeSteps) { int k = 0; foreach (var w in wells) { if (i == TimeSteps[0]) { well_Concentration.Add(new TimestampSeries(w.ID, new Unit(dfsI.EumQuantity.UnitAbbreviation, 1, 0))); } well_Concentration[k].Items.Add(new TimestampValue(dfs.TimeSteps[i], (dfs.GetData(i, ItemNumber)[w.Row, w.Column, w.Layer]))); k++; } } //Sets the upper title Header.Content = dfsI.Name; //Sets the title of the y-axis var ytitle = new VerticalAxisTitle(); ytitle.Content = dfsI.EumQuantity.ItemDescription + " [" + dfsI.EumQuantity.UnitAbbreviation + "]"; TheChart.Children.Add(ytitle); int l = 0; //Loop the wells for plotting foreach (var w in wells) { if (g != null) { TheChart.Children.Remove(g); TheChart.FitToView(); } var axis = new Microsoft.Research.DynamicDataDisplay.Charts.HorizontalDateTimeAxis(); TheChart.MainHorizontalAxis = axis; TheChart.MainVerticalAxis = new Microsoft.Research.DynamicDataDisplay.Charts.VerticalAxis(); //set the data source EnumerableDataSource <TimestampValue> ds = new EnumerableDataSource <TimestampValue>(well_Concentration[l].Items); ds.SetXMapping(var => axis.ConvertToDouble(var.Time)); ds.SetYMapping(var => var.Value); //create the graph g = TheChart.AddLineGraph(ds, new Pen(Brushes.Black, 3), new PenDescription(w.ID)); //create a filename outfile = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Dfs3FileName), "Well_No" + "_" + WellNumbers[l].ToString() + "_" + dfsI.EumQuantity.ItemDescription); //now save to file this.UpdateLayout(); MainWindow.SaveScreen(this, outfile + ".jpg", (int)ActualWidth, (int)ActualHeight); //Now create the dfs0-file using (DFS0 dfs0 = new DFS0(outfile + ".dfs0", 1)) { dfs0.FirstItem.Name = dfsI.Name; dfs0.FirstItem.EumItem = dfsI.EumItem; dfs0.FirstItem.EumUnit = dfsI.EumUnit; dfs0.FirstItem.ValueType = dfsI.ValueType; int t = 0; foreach (var v in well_Concentration[l].Items) { dfs0.InsertTimeStep(v.Time); dfs0.SetData(t, 1, v.Value); t++; } } //Now create the text-file using (StreamWriter sw = new StreamWriter(outfile + ".txt", false)) { foreach (var v in well_Concentration[l].Items) { sw.WriteLine(v.Time + "; " + v.Value); } } l++; } mShe.Dispose(); dfs.Dispose(); PlotsMade = true; } }