public override bool SaveAs(string filename, DotSpatial.Data.ICancelProgressHandler progress) { StreamWriter sw = new StreamWriter(FileName); string newline = "# extension modules"; sw.WriteLine(newline); sw.WriteLine("## Julian Start"); sw.WriteLine(StartInJulian.ToString()); sw.WriteLine("## SolverEx"); sw.WriteLine(Bool2String(EnableSolverEx)); newline = string.Format("{0} {1} #Max_TS_ITER, HCLOSER", Max_TS_ITER, HCLOSER); sw.WriteLine(newline); sw.WriteLine("## MFOutputEx"); sw.WriteLine(Bool2String(EnableMFOutputEx)); sw.WriteLine(_MFOutputExFile); sw.WriteLine("## SFREx"); newline = string.Format("{0} {1} {2} #SFREx SFRReport SFROutEX", Bool2String(EnableSFREx), Bool2String(EnableSFRReport), Bool2String(EnableSFROutEx)); sw.WriteLine(newline); sw.WriteLine(_SFRExFile); sw.WriteLine(_SFRReportFile); sw.WriteLine(_SFROutEXFile); sw.WriteLine("## LakeEX"); sw.WriteLine(Bool2String(EnableLakeEx)); sw.WriteLine(_LakeExFile); sw.WriteLine("## AllocationCurveEX"); sw.WriteLine(Bool2String(EnableAllocCurveEx)); sw.WriteLine(_AllocCurveExFile); sw.WriteLine("## MF IO LOG FILE"); sw.WriteLine(_MF_IOLOG_File); sw.Close(); OnSaved(progress); return(true); }
public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { var vec = GetVector(Matrix); var var_name = GetName(Matrix); if (vec != null) { if (Number <= 0) { Number = 10; } if (Number >= 100) { Number = 100; } var vec_name = "Histogram of " + GetName(Matrix); cancelProgressHandler.Progress("Package_Tool", 10, "Calculating..."); var dou_vec = MatrixOperation.ToDouble(vec); var hist = new Histogram(dou_vec, Number); int nhist = hist.BucketCount; int[] xx = new int[nhist]; int[] yy = new int[nhist]; for (int i = 0; i < nhist; i++) { xx[i] = (int)((hist[i].LowerBound + hist[i].UpperBound) * 0.5); yy[i] = (int)hist[i].Count; } WorkspaceView.Plot <int>(xx, yy, vec_name, Models.UI.MySeriesChartType.Column); return(true); } else { return(false); } }
public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { var vec = GetVector(Matrix); if (vec != null) { var dou_vec = MatrixOperation.ToDouble(vec); string vec_name = "CDF of " + GetName(Matrix); int nlen = dou_vec.Length; cancelProgressHandler.Progress("Package_Tool", 10, "Calculating..."); Array.Sort <double>(dou_vec); var cdf = MathNet.Numerics.Statistics.Statistics.EmpiricalCDFFunc(dou_vec); var cdf_value = new double[nlen]; for (int i = 0; i < nlen; i++) { cdf_value[i] = cdf(dou_vec[i]); } WorkspaceView.Plot <double>(dou_vec, cdf_value, vec_name, Models.UI.MySeriesChartType.FastLine); return(true); } else { return(false); } }
public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { StreamReader sr = new StreamReader(DataFileName); var line = sr.ReadLine(); line = sr.ReadLine(); var buf = TypeConverterEx.Split <string>(line); int ncell = int.Parse(buf[1]); int nvar = int.Parse(buf[3]); var variables = new string[nvar + 2]; variables[0] = "x"; variables[1] = "y"; for (int i = 0; i < nvar; i++) { variables[i + 2] = buf[4 + i]; } var mat_out = new DataCube <float>(nvar + 2, 1, ncell); mat_out.Name = OutputDataCube; mat_out.Variables = variables; for (int i = 0; i < ncell; i++) { line = sr.ReadLine().Trim(); var vec = TypeConverterEx.Split <float>(line); for (int j = 0; j < nvar + 2; j++) { mat_out[j, 0, i] = vec[j]; } } sr.Close(); Workspace.Add(mat_out); cancelProgressHandler.Progress("Package_Tool", 100, "Finished"); return(true); }
public override bool Load(DotSpatial.Data.ICancelProgressHandler progess) { if (File.Exists(FileName)) { FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); StreamReader sr = new StreamReader(fs); string newline = sr.ReadLine(); newline = sr.ReadLine(); newline = sr.ReadLine(); StartInJulian = int.Parse(newline.Trim()); newline = sr.ReadLine(); newline = sr.ReadLine(); EnableSolverEx = String2Bool(newline.Trim()); newline = sr.ReadLine(); var buf = TypeConverterEx.Split <int>(newline, 2); Max_TS_ITER = buf[0]; HCLOSER = buf[1]; newline = sr.ReadLine(); newline = sr.ReadLine(); EnableMFOutputEx = String2Bool(newline.Trim()); MFOutputExFile = sr.ReadLine().Trim(); newline = sr.ReadLine(); newline = sr.ReadLine(); buf = TypeConverterEx.Split <int>(newline, 3); EnableSFREx = Int2Bool(buf[0]); EnableSFRReport = Int2Bool(buf[1]); EnableSFROutEx = Int2Bool(buf[2]); SFRExFile = sr.ReadLine().Trim(); SFRReportFile = sr.ReadLine().Trim(); SFROutExFile = sr.ReadLine().Trim(); newline = sr.ReadLine(); newline = sr.ReadLine(); EnableLakeEx = String2Bool(newline.Trim()); LakeExFile = sr.ReadLine().Trim(); newline = sr.ReadLine(); newline = sr.ReadLine(); EnableAllocCurveEx = String2Bool(newline.Trim()); AllocCurveExFile = sr.ReadLine().Trim(); newline = sr.ReadLine(); MF_IOLOG_File = sr.ReadLine().Trim(); fs.Close(); sr.Close(); OnLoaded(progess); return(true); } else { Message = "The extension manager file dose not exist: " + FileName; OnLoadFailed(Message, progess); return(false); } }
public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { var mat = Get3DMat(InputDataCube); var dims = GetDims(InputDataCube); if (mat != null) { int nvar = mat.Size[0]; int ntime = mat.Size[1]; DataCube <float> mean_mat = null; if (dims[0] == ":") { mean_mat = new DataCube <float>(nvar, ntime, 1); for (int i = 0; i < nvar; i++) { if (mat.ILArrays[i] != null) { for (int j = 0; j < ntime; j++) { var vec = mat.GetVector(i, j.ToString(), ":"); var av = vec.Average(); mean_mat[i, j, 0] = av * Multiplier; } } } } else { mean_mat = new DataCube <float>(1, ntime, 1); int var_index = int.Parse(dims[0]); if (mat.ILArrays[var_index] != null) { for (int j = 0; j < ntime; j++) { var vec = mat.GetVector(var_index, j.ToString(), ":"); var av = vec.Average(); mean_mat[0, j, 0] = av * Multiplier; } } } mean_mat.Name = OutputDataCube; mean_mat.TimeBrowsable = true; Workspace.Add(mean_mat); return(true); } else { return(false); } }
public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { var vecX = GetVector(MatrixX); if (vecX != null) { WorkspaceView.Plot <float>(vecX, SeriesTitle, Models.UI.MySeriesChartType.FastLine); return(true); } else { return(false); } }
public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { var vec_src = GetVector(SourceDataCube); var mat_tar = Get3DMat(TargetDataCube); if (vec_src != null) { var dims = GetDims(TargetDataCube); mat_tar.ILArrays[int.Parse(dims[0])][dims[1], dims[2]] = vec_src; cancelProgressHandler.Progress("Package_Tool", 100, "Successful"); return(true); } else { cancelProgressHandler.Progress("Package_Tool", 100, "Failed. The source or target matrix style is wrong."); return(false); } }
public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { StreamWriter sw = new StreamWriter(OutputFileName); int nmon = (End.Year - Start.Year + 1) * 12; sw.WriteLine("Animation output control file created on " + DateTime.Now); sw.WriteLine(nmon); for (int y = Start.Year; y <= End.Year; y++) { for (int m = 1; m <= 12; m++) { int days = DateTime.DaysInMonth(y, m); sw.WriteLine(days); } } sw.Close(); return(true); }
public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { int var_indexA = 0; int var_indexB = 0; var matA = Get3DMat(MatrixA, ref var_indexA); var matB = Get3DMat(MatrixB, ref var_indexB); double prg = 0; if (matA != null && matB != null) { int nstep = System.Math.Min(matA.Size[1], matB.Size[1]); int ncell = matA.Size[2]; var mat_out = new DataCube <float>(1, 1, ncell); mat_out.Name = OutputMatrix; mat_out.Variables = new string[] { "CorrelationCoefficients" }; for (int c = 0; c < ncell; c++) { var vecA = matA.GetVector(var_indexA, ":", c.ToString()); var dou_vecA = MatrixOperation.ToDouble(vecA); var vecB = matB.GetVector(var_indexB, ":", c.ToString());; var dou_vecB = MatrixOperation.ToDouble(vecB); var len = System.Math.Min(vecA.Length, vecB.Length); // var cor = MyStatisticsMath.Correlation(dou_vecA, dou_vecB); var cor = Heiflow.Core.Alglib.alglib.basestat.pearsoncorrelation(dou_vecA, dou_vecB, len); if (double.IsNaN(cor) || double.IsInfinity(cor)) { cor = 0; } mat_out[0, 0, c] = (float)cor; prg = (c + 1) * 100.0 / ncell; if (prg % 10 == 0) { cancelProgressHandler.Progress("Package_Tool", (int)prg, "Caculating Cell: " + (c + 1)); } } Workspace.Add(mat_out); return(true); } else { return(false); } }
public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { int var_indexA = 0; var matA = Get3DMat(InputDataCube, ref var_indexA); double prg = 0; int count = 1; if (matA != null) { int nstep = matA.Size[1]; int ncell = matA.Size[2]; var mat_out = new DataCube <float>(1, 1, ncell); mat_out.Name = OutputDataCube; mat_out.Variables = new string[] { "Slope" }; for (int c = 0; c < ncell; c++) { var vec = matA.GetVector(var_indexA, ":", c.ToString()); var dou_vec = MatrixOperation.ToDouble(vec); var steps = new double[nstep]; double rs, slope, yint; for (int t = 1; t < nstep; t++) { steps[t] = t + 1; } MyStatisticsMath.LinearRegression(steps, dou_vec, 0, nstep, out rs, out yint, out slope); mat_out[0, 0, c] = (float)slope; prg = (c + 1) * 100.0 / ncell; if (prg > count) { cancelProgressHandler.Progress("Package_Tool", (int)prg, "Caculating Cell: " + (c + 1)); count++; } } Workspace.Add(mat_out); return(true); } else { return(false); } }
public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { var da = GetVector(DataCubeA); var db = GetVector(DataCubeB); if (da != null && db != null && da.Length == db.Length) { var vec = new DataCube <float>(1, 1, da.Length); for (int i = 0; i < da.Length; i++) { vec[0, 0, i] = da[i] + db[i]; } vec.Name = OutputDataCube; Workspace.Add(vec); return(true); } else { return(false); } }
public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { var vec_minu = GetVector(MinuendDataCube); var vec_subt = GetVector(SubtrahendDataCube); if (vec_minu != null && vec_subt != null && vec_minu.Length == vec_subt.Length) { var vec = new DataCube <float>(1, 1, vec_minu.Length); for (int i = 0; i < vec_minu.Length; i++) { vec[0, 0, i] = vec_minu[i] - vec_subt[i]; } vec.Name = OutputDataCube; Workspace.Add(vec); return(true); } else { return(false); } }
public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { DataCubeStreamReader ds = new DataCubeStreamReader(CloudCoverFileName); ds.LoadDataCube(); var cloudcover = ds.DataCube; CSVFileStream locationcsv = new CSVFileStream(LocationFileName); var locations = locationcsv.Load <double>(); StreamReader sr_dates = new StreamReader(DateTimeFileName); int ndays = cloudcover.Size[1]; int nlocation = cloudcover.Size[2]; var dates = new DateTime[ndays]; int progress = 0; int np = 1; var swmat = new DataCube <float>(cloudcover.Size[0], cloudcover.Size[1], cloudcover.Size[2]); swmat.Name = OutputName; for (int i = 0; i < ndays; i++) { var line = sr_dates.ReadLine(); dates[i] = DateTime.Parse(line); } sr_dates.Close(); for (int i = 0; i < ndays; i++) { for (int j = 0; j < nlocation; j++) { swmat[0, i, j] = (float)_ShortWaveRadiation.DailyIncomingRadiationIntensity(locations.GetValue(j, 1), locations.GetValue(j, 0), dates[i], cloudcover[0, i, j]); } progress = i * 100 / ndays; if (progress == 5 * np) { cancelProgressHandler.Progress("Package_Tool", progress, "Processing step: " + progress + "%"); np++; } } Workspace.Add(swmat); return(true); }
public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { int var_index = 0; var mat = Get3DMat(InputDataCube, ref var_index); int prg = 0; int count = 1; if (mat != null) { int nstep = mat.Size[1]; int ncell = mat.Size[2]; var mat_out = new DataCube <float>(4, 1, ncell); mat_out.Name = OutputDataCube; mat_out.Variables = new string[] { "Mean", "Variance", "Skewness", "kurtosis" }; for (int c = 0; c < ncell; c++) { double mean = 0, variance = 0, skewness = 0, kurtosis = 0; var vec = mat.GetVector(var_index, ":", c.ToString()); var dou_vec = MatrixOperation.ToDouble(vec); Heiflow.Core.Alglib.alglib.basestat.samplemoments(dou_vec, vec.Length, ref mean, ref variance, ref skewness, ref kurtosis); mat_out[0, 0, c] = (float)mean; mat_out[1, 0, c] = (float)variance; mat_out[2, 0, c] = (float)skewness; mat_out[3, 0, c] = (float)kurtosis; prg = (c + 1) * 100 / ncell; if (prg > count) { cancelProgressHandler.Progress("Package_Tool", prg, "Caculating Cell: " + (c + 1)); count++; } } Workspace.Add(mat_out); return(true); } else { return(false); } }
public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { var vector = GetVector(Matrix); if (vector != null) { cancelProgressHandler.Progress("Package_Tool", 10, "Calculating..."); var dt = ProjectService.Project.Model.Grid.FeatureSet.DataTable; if (vector.Length == dt.Rows.Count) { for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i][RegularGrid.ParaValueField] = vector[i]; } } return(true); } else { return(false); } }
public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { var source = Get3DMat(Source); if (source != null) { var tag = new DataCube <float>(source.Size[0], source.Size[1], source.Size[2]); for (int i = 0; i < source.Size[0]; i++) { if (source[i] != null) { tag[i] = source[i] * Scale; } } tag.Name = OutputDataCube; Workspace.Add(tag); return(true); } else { return(false); } }
public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { var var_index = 0; var mat = Get3DMat(Source, ref var_index); var dims = GetDims(Source); if (mat != null) { var buf = mat.ILArrays[var_index]; var array = buf[dims[1], dims[2]]; var size = array.Size.ToIntArray(); DataCube <float> dc = new DataCube <float>(1, 1, 1, true); dc[0] = array; dc.SetSize(new int[] { 1, size[0], size[1] }); dc.Name = Output; Workspace.Add(dc); return(true); } else { return(false); } }
public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { DataCubeStreamReader ass = new DataCubeStreamReader(InputFileName); DataCubeStreamWriter dcw = new DataCubeStreamWriter(OutputFileName); ass.Open(); dcw.WriteHeader(ass.Variables, ass.FeatureCount); if (InputTemperatureUnit == TemperatureUnit.Kelvin) { for (int t = 0; t < ass.NumTimeStep; t++) { var mat = ass.LoadStep(); for (int i = 0; i < mat.Size[2]; i++) { mat[0, 0, i] = UnitConversion.Kelvin2Fahrenheit(mat[0, 0, i]); } dcw.WriteStep(1, ass.FeatureCount, mat); } } else if (InputTemperatureUnit == TemperatureUnit.Celsius) { for (int t = 0; t < ass.NumTimeStep; t++) { var mat = ass.LoadStep(); for (int i = 0; i < mat.Size[2]; i++) { mat[0, 0, i] = UnitConversion.Celsius2Fahrenheit(mat[0, 0, i]); } dcw.WriteStep(1, ass.FeatureCount, mat); } } ass.Close(); dcw.Close(); return(true); }
public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { int var_index = 0; var mat = Get3DMat(Source, ref var_index); double prg = 0; int count = 1; if (mat != null) { DataTable dt = new DataTable(); DataColumn dc_time = new DataColumn("DateTime", Type.GetType("System.DateTime")); dt.Columns.Add(dc_time); DataColumn dc = new DataColumn("Mean", Type.GetType("System.Double")); dt.Columns.Add(dc); dc = new DataColumn("Variance", Type.GetType("System.Double")); dt.Columns.Add(dc); dc = new DataColumn("Skewness", Type.GetType("System.Double")); dt.Columns.Add(dc); dc = new DataColumn("Kurtosis", Type.GetType("System.Double")); dt.Columns.Add(dc); int nstep = mat.Size[1]; double mean = 0, variance = 0, skewness = 0, kurtosis = 0; List <int> list_selected = new List <int>(); bool use_selected = false; // selected_index = null; if (BaseTimeStep >= 0 && BaseTimeStep < mat.Size[0]) { var vec = mat[var_index, BaseTimeStep.ToString(), ":"]; for (int i = 0; i < vec.Length; i++) { if (vec[i] != NoDataValue) { list_selected.Add(i); } } use_selected = true; } for (int i = 0; i < nstep; i++) { var dr = dt.NewRow(); var vec = mat[var_index, i.ToString(), ":"]; double[] vec_selected = null; if (use_selected) { vec_selected = new double[list_selected.Count]; for (int j = 0; j < list_selected.Count; j++) { vec_selected[j] = vec[list_selected[j]]; } } else { var dou_vec = Array.ConvertAll <float, double>(vec, s => s); vec_selected = dou_vec.Where(s => s != NoDataValue).ToArray(); } Heiflow.Core.Alglib.alglib.basestat.samplemoments(vec_selected, vec_selected.Length, ref mean, ref variance, ref skewness, ref kurtosis); dr[0] = DateTime.Now; dr[1] = mean; dr[2] = variance; dr[3] = skewness; dr[4] = kurtosis; dt.Rows.Add(dr); prg = (i + 1) * 100.0 / nstep; if (prg > count) { cancelProgressHandler.Progress("Package_Tool", (int)prg, "Time Step:" + dr[0].ToString()); count++; } } if (mat.DateTimes != null) { for (int i = 0; i < nstep; i++) { dt.Rows[i][0] = mat.DateTimes[i]; } } else { for (int i = 0; i < nstep; i++) { dt.Rows[i][0] = DateTime.Now.AddDays(i); } } WorkspaceView.OutputTo(dt); return(true); } else { return(false); } }
public abstract bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler);
public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { var var_index = 0; var mat = Get3DMat(Source, ref var_index); double prg = 0; int count = 1; var grid = ProjectService.Project.Model.Grid as RegularGrid; if (mat != null && grid != null) { int nstep = mat.Size[1]; int ncell = mat.Size[2]; var mat_out = new DataCube <float>(1, nstep, ncell); mat_out.Name = Output; mat_out.Variables = mat.Variables; mat_out.DateTimes = mat.DateTimes; mat.CopyTo(mat_out); List <float[]> neibor = new List <float[]>(); int num_dep_modified = 0; int num_head_modified = 0; int num_no_neighbor_found = 0; for (int c = 0; c < ncell; c++) { var vec = mat[var_index, ":", c.ToString()]; var buf = (from vv in vec select vv - grid.Elevations[0, 0, c]).ToArray(); var max = buf.Maximum(); if (max > MaxPositiveDepth) { var scale = max / MaxPositiveDepth; for (int i = 0; i < nstep; i++) { if (buf[i] > 0) { buf[i] /= scale; mat_out[var_index, i, c] = grid.Elevations[0, 0, c] + buf[i]; } } num_dep_modified++; } } for (int c = 0; c < ncell; c++) { var vec = mat_out[var_index, ":", c.ToString()]; var buf = (from vv in vec select vv - vec[0]).ToArray(); var max = buf.Maximum(); var min = buf.Minimum(); bool modify = false; if (max > MaxPositiveDeviation) { var scale = max / MaxPositiveDeviation; for (int i = 1; i < nstep; i++) { if (buf[i] > 0) { buf[i] /= scale; } } modify = true; } if (min < MinPositiveDeviation) { var scale = min / MinPositiveDeviation; for (int i = 1; i < nstep; i++) { if (buf[i] < 0) { buf[i] /= scale; } } modify = true; } if (modify) { //var cell_id = grid.Topology.ActiveCellIDs[c]; int[] loc = grid.Topology.ActiveCell[c]; neibor.Clear(); for (int ii = loc[0] - NeighborCount; ii <= loc[0] + NeighborCount; ii++) { for (int jj = loc[1] - NeighborCount; jj <= loc[1] + NeighborCount; jj++) { if (ii >= 0 && ii < grid.RowCount && jj >= 0 && jj < grid.ColumnCount && grid.IBound[0, ii, jj] > 0) { var cell_index = grid.Topology.GetSerialIndex(ii, jj); if (!RequireModify(mat_out, var_index, cell_index)) { var neibor_vec = mat_out[var_index, ":", cell_index.ToString()]; var buf_nei = (from vv in neibor_vec select vv - neibor_vec[0]).ToArray(); neibor.Add(buf_nei); } } } } if (neibor.Count > 0) { for (int i = 1; i < nstep; i++) { // float av_value = 0; var sds = (from vv in neibor select vv.StandardDeviation()).ToArray(); var min_sd = sds.Min(); var min_sd_index = 0; for (int n = 0; n < sds.Count(); n++) { if (min_sd == sds[n]) { min_sd_index = n; break; } } //foreach (var ss in neibor) //{ // av_value += ss[i]; //} //av_value /= neibor.Count; //mat_out.Value[var_index][i][c] = mat_out.Value[var_index][0][c] + av_value; mat_out[var_index, i, c] = mat_out[var_index, 0, c] + neibor[min_sd_index][i]; } } else { for (int i = 1; i < nstep; i++) { vec[i] = vec[0] + buf[i] * 0.5f; mat_out[var_index, i, c] = vec[i]; } num_no_neighbor_found++; } num_head_modified++; } prg = (c + 1) * 100.0 / ncell; if (prg > count) { cancelProgressHandler.Progress("Package_Tool", (int)prg, "Caculating Cell: " + (c + 1)); count++; } } cancelProgressHandler.Progress("Package_Tool", 100, string.Format(" \num_dep_modified: {0};\n num_head_modified: {1};\n num_no_neighbor_found:{2}", num_dep_modified, num_head_modified, num_no_neighbor_found)); Workspace.Add(mat_out); return(true); } else { return(false); } }
public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { var var_index = 0; var mat = Get3DMat(Source, ref var_index); double prg = 0; int count = 1; if (mat != null) { int nstep = mat.Size[1]; int ncell = mat.Size[2]; var vec = mat[var_index, ":", "0"]; var dou_vec = MatrixOperation.ToDouble(vec); var date_source = new DateTime[nstep]; if (mat.DateTimes != null && mat.DateTimes.Length >= nstep) { for (int i = 0; i < nstep; i++) { date_source[i] = mat.DateTimes[i]; } } else { for (int i = 0; i < nstep; i++) { date_source[i] = ModelService.Start.AddDays(i); } } var ts = new DataCube <float>(vec, date_source); var derieved_ts = TimeSeriesAnalyzer.Derieve(ts, NumericalDataType, TimeUnits); var derieved_steps = derieved_ts.DateTimes.Length; var mat_out = new DataCube <float>(1, derieved_steps, ncell); mat_out.Name = Derived; mat_out.Variables = new string[] { "Derived" }; mat_out.DateTimes = derieved_ts.DateTimes.ToArray(); mat_out.TimeBrowsable = true; for (int c = 0; c < ncell; c++) { vec = mat[var_index, ":", c.ToString()]; ts = new DataCube <float>(vec, date_source); derieved_ts = TimeSeriesAnalyzer.Derieve(ts, NumericalDataType, TimeUnits); for (int t = 0; t < derieved_steps; t++) { mat_out[0, t, c] = derieved_ts[0, t, 0]; } prg = (c + 1) * 100.0 / ncell; if (prg > count) { cancelProgressHandler.Progress("Package_Tool", (int)prg, "Caculating Cell: " + (c + 1)); count++; } } Workspace.Add(mat_out); return(true); } else { return(false); } }
public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { //Save2DB(); StreamReader sr = new StreamReader(Filename); StreamWriter sw_stat = new StreamWriter(Filename + "_stat.csv"); StreamWriter sw_records = new StreamWriter(Filename + "_record.csv"); Dictionary <string, SiteInfo> sites = new Dictionary <string, SiteInfo>(); Dictionary <string, SiteInfo> filtered_sites = new Dictionary <string, SiteInfo>(); var head = sr.ReadLine(); sw_records.WriteLine(head); DateTime start = new DateTime(2000, 1, 1); while (!sr.EndOfStream) { var str = sr.ReadLine().Trim(); var buf = TypeConverterEx.Split <string>(str, TypeConverterEx.Comma); var name = buf[1].Trim(); var date = DateTime.Parse(buf[2].Trim()); if (sites.Keys.Contains(name)) { var site = sites[name]; site.Dates.Add(new DateTime(date.Year, date.Month, 1)); if (date > start) { site.Records.Add(str); } } else { var site = new SiteInfo() { Name = name }; site.Dates.Add(new DateTime(date.Year, date.Month, 1)); sites.Add(name, site); if (date > start) { site.Records.Add(str); } } } List <DateTime> basedates = new List <DateTime>(); for (int i = 2000; i < 2017; i++) { for (int j = 1; j < 13; j++) { basedates.Add(new DateTime(i, j, 1)); } } var temp = (from dt in basedates select dt.ToString("yyyy-MM-dd")).ToArray(); int ndate = temp.Count(); var header = "Name," + string.Join(",", temp); sw_stat.WriteLine(header); for (int i = 0; i < sites.Count; i++) { var flags = new int[ndate]; var ss = sites.Values.ElementAt(i); for (int j = 0; j < ndate; j++) { if (ss.Dates.Contains(basedates[j])) { flags[j] = 1; } } ss.Flags = flags; var line = sites.Keys.ElementAt(i) + "," + string.Join(",", flags); sw_stat.WriteLine(line); } for (int i = 0; i < sites.Count; i++) { var ss = sites.Values.ElementAt(i); if (ss.Flags.Sum() > 200) { filtered_sites.Add(ss.Name, ss); } } for (int i = 0; i < filtered_sites.Count; i++) { var ss = filtered_sites.Values.ElementAt(i); for (int j = 0; j < ndate; j++) { if (ss.Flags[j] == 0) { var strs = TypeConverterEx.Split <string>(ss.Records[j - 1], TypeConverterEx.Comma); strs[2] = basedates[j].ToString("yyyy-MM-dd"); strs[3] = basedates[j].Month.ToString(); var sline = string.Join(",", strs); ss.Records.Insert(j, sline); } } for (int j = 0; j < ndate; j++) { sw_records.WriteLine(ss.Records[j]); } } sr.Close(); sw_stat.Close(); sw_records.Close(); return(true); }