public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { cancelProgressHandler.Progress("Package_Tool", 10, "Begin to calculate"); PenmanMonteithET pet = new PenmanMonteithET(); StreamReader sr = new StreamReader(InputDataFile); List <float> et0 = new List <float>(); int nrow = 0; sr = new StreamReader(InputDataFile); List <DateTime> dates = new List <DateTime>(); List <float[]> meto = new List <float[]>(); List <float> tav = new List <float>(); while (!sr.EndOfStream) { var line = sr.ReadLine(); if (!TypeConverterEx.IsNull(line)) { var strs = TypeConverterEx.Split <string>(line); var date = DateTime.Parse(strs[0]); var vv = TypeConverterEx.SkipSplit <float>(line, 1); dates.Add(date); meto.Add(vv); tav.Add(vv[0]); nrow++; } } sr.Close(); var ts = new DataCube <float>(tav.ToArray(), dates.ToArray()); var tav_mon = TimeSeriesAnalyzer.GetMonthlyMean(ts, NumericalDataType.Average); pet.MonthTemperature = Array.ConvertAll(tav_mon, x => (double)x); for (int i = 0; i < nrow; i++) { var vv = meto[i]; et0.Add((float)pet.ET0(Latitude, Longitude, vv[0], vv[1], vv[2], vv[3], vv[4], vv[5], dates[i], CloudCover)); } DataCube <float> mat_out = new DataCube <float>(1, 1, et0.Count); mat_out[0, "0", ":"] = et0.ToArray(); mat_out.Name = PET; cancelProgressHandler.Progress("Package_Tool", 100, "Calculated"); Workspace.Add(mat_out); return(true); }
public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { //string basedir = @"E:\Heihe\HRB\DataSets\Driving Forces\PXD\"; //AverageTemperatureFileName = basedir + "daily_tavk_11243.dcx"; //MaxTemperatureFileName = basedir + "daily_tmaxk_11243.dcx"; //MinTemperatureFileName = basedir + "daily_tmink_11243.dcx"; //RelativeHumidityFileName = @"E:\Heihe\HRB\DataSets\Driving Forces\TY\rh.dcx"; //AirPressureFileName = basedir + "daily_ap_11243.dcx"; //WindSpeedFileName = basedir + "daily_windspeed_11243.dcx"; IFeatureSet fs = FeatureSet.Open(PointFeatureFileName); string[] files = new string[] { AverageTemperatureFileName, MaxTemperatureFileName, MinTemperatureFileName, RelativeHumidityFileName, AirPressureFileName, WindSpeedFileName }; var npt = fs.NumRows(); Coordinate[] coors = new Coordinate[npt]; for (int i = 0; i < npt; i++) { var geo_pt = fs.GetFeature(i).Geometry; coors[i] = geo_pt.Coordinate; } int nfile = files.Length; DataCubeStreamReader[] ass = new DataCubeStreamReader[nfile]; DataCube <float>[] mats = new DataCube <float> [nfile]; for (int i = 0; i < nfile; i++) { ass[i] = new DataCubeStreamReader(files[i]); ass[i].Open(); } int progress = 0; int nstep = ass[0].NumTimeStep; int ncell = ass[0].FeatureCount; PenmanMonteithET pet = new PenmanMonteithET(); DataCubeStreamWriter sw = new DataCubeStreamWriter(OutputFileName); sw.WriteHeader(new string[] { "pet" }, ncell); DataCube <float> mat_out = new DataCube <float>(1, 1, ncell); mat_out.DateTimes = new DateTime[nstep]; int count = 1; for (int t = 0; t < nstep; t++) { for (int i = 0; i < nfile; i++) { mats[i] = ass[i].LoadStep(); } for (int n = 0; n < ncell; n++) { var tav = mats[0][0, 0, n]; var tmax = mats[1][0, 0, n]; var tmin = mats[2][0, 0, n]; if (InputTemperatureUnit == TemperatureUnit.Fahrenheit) { tmax = (float)UnitConversion.Fahrenheit2Kelvin(tmax); tmin = (float)UnitConversion.Fahrenheit2Kelvin(tmin); tav = (float)UnitConversion.Fahrenheit2Kelvin(tav); } else if (InputTemperatureUnit == TemperatureUnit.Celsius) { tmax = (float)UnitConversion.Celsius2Kelvin(tmax); tmin = (float)UnitConversion.Celsius2Kelvin(tmin); tav = (float)UnitConversion.Celsius2Kelvin(tav); } double ap = mats[4][0, 0, n] / 1000; var et0 = pet.ET0(coors[n].Y, coors[n].X, tav, tmax, tmin, mats[3][0, 0, n], ap, mats[5][0, 0, n], Start.AddDays(t), CloudCover); if (OutputLengthUnit == LengthUnit.inch) { mat_out[0, 0, n] = (float)System.Math.Round(et0 * UnitConversion.mm2Inch, 3); } else { mat_out[0, 0, n] = (float)System.Math.Round(et0, 3); } } mat_out.DateTimes[t] = Start.AddDays(1); sw.WriteStep(1, ncell, mat_out); progress = t * 100 / nstep; if (progress > count) { cancelProgressHandler.Progress("Package_Tool", progress, "Processing step:" + (t + 1)); count++; } } sw.Close(); for (int i = 0; i < nfile; i++) { ass[i].Close(); } return(true); }
public bool Execute1(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler) { //(double tavrg, double tmax, double tmin, double rh, double airP, double wind2, double Rnet, DateTime day) string[] files = new string[] { AverageTemperatureFileName, MaxTemperatureFileName, MinTemperatureFileName, RelativeHumidityFileName, AirPressureFileName, WindSpeedFileName, NetRadiationFileName }; int nfile = files.Length; DataCubeStreamReader[] ass = new DataCubeStreamReader[nfile]; DataCube <float>[] mats = new DataCube <float> [nfile]; for (int i = 0; i < nfile; i++) { ass[i] = new DataCubeStreamReader(files[i]); ass[i].LoadDataCube(); mats[i] = ass[i].DataCube; } int progress = 0; int count = 1; int nstep = mats[0].DateTimes.Length; int ncell = mats[0].Size[2]; PenmanMonteithET pet = new PenmanMonteithET(); var mat_out = new DataCube <float>(1, nstep, ncell); mat_out.Name = "mat"; mat_out.Variables = new string[] { "pet" }; for (int t = 0; t < nstep; t++) { for (int i = 0; i < ncell; i++) { var tav = mats[0][0, t, i]; var tmax = mats[1][0, t, i]; var tmin = mats[2][0, t, i]; if (InputTemperatureUnit == TemperatureUnit.Fahrenheit) { tmax = (float)UnitConversion.Fahrenheit2Kelvin(tmax); tmin = (float)UnitConversion.Fahrenheit2Kelvin(tmin); tav = (float)UnitConversion.Fahrenheit2Kelvin(tav); } var et0 = pet.ET0(0, 0, tav, tmax, tmin, mats[3][0, t, i], mats[4][0, t, i], mats[5][0, t, i], mats[6][0, t, i], mats[0].DateTimes[t]); // var et1 = (float)pet.ET0(40, 100, tav, tmax, tmin, //mats[3].Value[0][t][i], mats[4].Value[0][t][i], mats[5].Value[0][t][i], 7, mats[0].DateTimes[t], 0.1); if (et0 <= 0) { et0 = 0.1; } if (OutputLengthUnit == LengthUnit.inch) { mat_out[0, t, i] = (float)System.Math.Round(et0 * UnitConversion.mm2Inch, 3); } else { mat_out[0, t, i] = (float)System.Math.Round(et0, 3); } } progress = t * 100 / nstep; if (progress > count) { cancelProgressHandler.Progress("Package_Tool", progress, "Processing step:" + (t + 1)); count++; } } mat_out.DateTimes = mats[0].DateTimes; Workspace.Add(mat_out); return(true); }