示例#1
0
        /// <summary>
        /// Gets evapotranspiration data using the given TimeSeriesInput parameters.
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <ITimeSeriesOutput> GetEvapotranspiration(EvapotranspirationInput input)
        {
            string errorMsg = "";

            // Constructs default error output object containing error message.
            Utilities.ErrorOutput err = new Utilities.ErrorOutput();

            // Validate evapotranspiration sources.
            errorMsg = (!Enum.TryParse(input.Source, true, out EvapoSources pSource)) ? "ERROR: 'Source' was not found or is invalid." : "";
            if (errorMsg.Contains("ERROR"))
            {
                return(err.ReturnError(errorMsg));
            }

            // Evapotranspiration object
            Evapotranspiration.Evapotranspiration evapo = new Evapotranspiration.Evapotranspiration()
            {
                Algorithm            = input.Algorithm,
                Albedo               = input.Albedo,
                CentralLongitude     = input.CentralLongitude,
                SunAngle             = input.SunAngle,
                Emissivity           = input.Emissivity,
                Model                = input.Model,
                Zenith               = input.Zenith,
                LakeSurfaceArea      = input.LakeSurfaceArea,
                LakeDepth            = input.LakeDepth,
                SubsurfaceResistance = input.SubsurfaceResistance,
                StomatalResistance   = input.StomatalResistance,
                LeafWidth            = input.LeafWidth,
                RoughnessLength      = input.RoughnessLength,
                VegetationHeight     = input.VegetationHeight,
                LeafAreaIndices      = input.LeafAreaIndices,
                AirTemperature       = input.AirTemperature,
                UserData             = input.UserData
            };

            // ITimeSeriesInputFactory object used to validate and initialize all variables of the input object.
            ITimeSeriesInputFactory iFactory = new TimeSeriesInputFactory();

            evapo.Input = iFactory.SetTimeSeriesInput(input, new List <string>()
            {
                "evapotranspiration"
            }, out errorMsg);

            // If error occurs in input validation and setup, errorMsg is added to metadata of an empty object.
            if (errorMsg.Contains("ERROR"))
            {
                return(err.ReturnError(errorMsg));
            }

            // Gets the Evapotranspiration data.
            ITimeSeriesOutput result = evapo.GetData(out errorMsg);

            if (errorMsg.Contains("ERROR"))
            {
                return(err.ReturnError(errorMsg));
            }

            return(result);
        }
示例#2
0
文件: NLDASTests.cs 项目: quanted/hms
        private void BuildITimeSeries()
        {
            string errorMsg = "";
            ITimeSeriesInputFactory iFactory = new TimeSeriesInputFactory();

            timeSeries.Input = iFactory.SetTimeSeriesInput(validInput, new List <string>()
            {
                "precipitation"
            }, out errorMsg);
        }
示例#3
0
        public void SetTimeSeriesInputTestInvalidDataset()
        {
            string errorMsg = "";
            ITimeSeriesInputFactory iFactory    = new TimeSeriesInputFactory();
            ITimeSeriesInput        sampleInput = iFactory.SetTimeSeriesInput(validInput, new List <string>()
            {
                "BadDataset"
            }, out errorMsg);

            Assert.AreEqual("ERROR: Unable to construct base url from the specified dataset and provided data source.", errorMsg);
        }
示例#4
0
        public void SetTimeSeriesInput()
        {
            string errorMsg = "";
            ITimeSeriesInputFactory iFactory    = new TimeSeriesInputFactory();
            ITimeSeriesInput        sampleInput = iFactory.SetTimeSeriesInput(validInput, new List <string>()
            {
                "precipitation"
            }, out errorMsg);

            Assert.Equal("", errorMsg);
        }
示例#5
0
        public void SetTimeSeriesInput_DatasetTest(string dataset, string expected)
        {
            string errorMsg = "";
            ITimeSeriesInputFactory iFactory    = new TimeSeriesInputFactory();
            ITimeSeriesInput        sampleInput = iFactory.SetTimeSeriesInput(validInput, new List <string>()
            {
                dataset
            }, out errorMsg);

            Assert.Equal(expected, errorMsg);
        }
示例#6
0
        public void SetValidTimeSeriesInputTest()
        {
            string errorMsg = "";
            ITimeSeriesInputFactory iFactory    = new TimeSeriesInputFactory();
            ITimeSeriesInput        sampleInput = iFactory.SetTimeSeriesInput(validInput, new List <string>()
            {
                "PRECIP"
            }, out errorMsg);

            Assert.AreEqual("", errorMsg);
        }
示例#7
0
        /// <summary>
        /// Checks the data endpoints for the Soil Moisture component.
        /// </summary>
        /// <returns></returns>
        public static async Task <Dictionary <string, Dictionary <string, string> > > CheckSoilMEndpoints()
        {
            Dictionary <string, Dictionary <string, string> > endpoints = new Dictionary <string, Dictionary <string, string> >();
            List <SoilMoisture.SoilMoisture> soils = new List <SoilMoisture.SoilMoisture>();
            List <string> sources = new List <string>()
            {
                "nldas", "gldas"
            };
            ITimeSeriesInput testInput = new TimeSeriesInput()
            {
                Source       = "nldas",
                DateTimeSpan = new DateTimeSpan()
                {
                    StartDate = new DateTime(2005, 01, 01),
                    EndDate   = new DateTime(2005, 01, 05)
                },
                Geometry = new TimeSeriesGeometry()
                {
                    Point = new PointCoordinate()
                    {
                        Latitude  = 33.925673,
                        Longitude = -83.355723
                    },
                    GeometryMetadata = new Dictionary <string, string>()
                }
            };
            ITimeSeriesInputFactory iFactory = new TimeSeriesInputFactory();

            foreach (string source in sources)
            {
                string[] validLayers = (source.Contains("nldas")) ? new string[] { "0-10", "10-40", "40-100", "100-200", "0-100", "0-200" } : new string[] { "0-10", "10-40", "40-100", "0-100" };
                foreach (string layer in validLayers)
                {
                    SoilMoisture.SoilMoisture soil = new SoilMoisture.SoilMoisture();
                    testInput.Source = source;
                    string l = layer.Replace('-', '_') + "_soilmoisture";
                    soil.Input = iFactory.SetTimeSeriesInput(testInput, new List <string>()
                    {
                        l
                    }, out string errorMsg);
                    soil.Input.Source = source + "_" + l;
                    soils.Add(soil);
                }
            }

            Parallel.ForEach(soils, (SoilMoisture.SoilMoisture soil) =>
            {
                endpoints.Add(soil.Input.Source, soil.CheckEndpointStatus());
            });
            return(endpoints);
        }
示例#8
0
        /// <summary>
        /// Gets the historic precipitation data.
        /// </summary>
        /// <param name="errorMsg"></param>
        /// <param name="years">Years of historic data.</param>
        /// <param name="input"></param>
        /// <param name="output"></param>
        /// <returns></returns>
        private ITimeSeriesOutput GetHistoricData(out string errorMsg, int years, ITimeSeriesInput input, ITimeSeriesOutput output)
        {
            errorMsg = "";

            Precipitation precip = new Precipitation();

            precip.Input  = input;
            precip.Output = output;
            // Historic end date set to simulated data start date minus one day.
            precip.Input.DateTimeSpan.EndDate = precip.Input.DateTimeSpan.StartDate.AddDays(-1);
            // Historic start date set to 20 years before simulated start date.
            precip.Input.DateTimeSpan.StartDate = precip.Input.DateTimeSpan.StartDate.AddYears(-1 * Math.Abs(years));

            if (input.Geometry.GeometryMetadata.ContainsKey("historicSource"))
            {
                switch (input.Geometry.GeometryMetadata["historicSource"])
                {
                case "nldas":
                    input.Source             = "nldas";
                    input.TemporalResolution = "daily";
                    break;

                case "gldas":
                    input.Source             = "gldas";
                    input.TemporalResolution = "daily";
                    break;

                case "daymet":
                default:
                    input.Source = "daymet";
                    break;
                }
            }
            else
            {
                input.Source = "daymet";
            }
            ITimeSeriesInputFactory iFactory  = new TimeSeriesInputFactory();
            ITimeSeriesInput        tempInput = iFactory.SetTimeSeriesInput(input, new List <string>()
            {
                "precip"
            }, out errorMsg);

            precip.Input  = tempInput;
            precip.Output = precip.GetData(out errorMsg);
            if (errorMsg.Contains("ERROR"))
            {
                return(null);
            }
            return(precip.Output);
        }
示例#9
0
        /// <summary>
        /// Checks the data endpoints for the Precipitation component.
        /// </summary>
        /// <returns></returns>
        public async static Task <Dictionary <string, Dictionary <string, string> > > CheckPrecipEndpoints()
        {
            Dictionary <string, Dictionary <string, string> > endpoints = new Dictionary <string, Dictionary <string, string> >();
            List <Precipitation.Precipitation> precips = new List <Precipitation.Precipitation>();
            List <string> sources = new List <string>()
            {
                "nldas", "gldas", "ncdc", "daymet"
            };
            ITimeSeriesInput testInput = new TimeSeriesInput()
            {
                Source       = "nldas",
                DateTimeSpan = new DateTimeSpan()
                {
                    StartDate = new DateTime(2005, 01, 01),
                    EndDate   = new DateTime(2005, 01, 05)
                },
                Geometry = new TimeSeriesGeometry()
                {
                    Point = new PointCoordinate()
                    {
                        Latitude  = 33.925673,
                        Longitude = -83.355723
                    },
                    GeometryMetadata = new Dictionary <string, string>()
                }
            };
            ITimeSeriesInputFactory iFactory = new TimeSeriesInputFactory();

            foreach (string source in sources)
            {
                Precipitation.Precipitation precip = new Precipitation.Precipitation();
                testInput.Source = source;
                precip.Input     = iFactory.SetTimeSeriesInput(testInput, new List <string>()
                {
                    "precipitation"
                }, out string errorMsg);
                if (source.Contains("ncdc"))
                {
                    precip.Input.Geometry.GeometryMetadata["stationID"] = "GHCND:USW00013874";
                    precip.Input.Geometry.GeometryMetadata["token"]     = "RUYNSTvfSvtosAoakBSpgxcHASBxazzP";
                }
                precips.Add(precip);
            }

            Parallel.ForEach(precips, (Precipitation.Precipitation precip) =>
            {
                endpoints.Add(precip.Input.Source, precip.CheckEndpointStatus());
            });
            return(endpoints);
        }
示例#10
0
        /// <summary>
        /// Gets SoilMoisture data using the given TimeSeriesInput parameters.
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public ITimeSeriesOutput GetSoilMoisture(SoilMoistureInput input)
        {
            string errorMsg = "";

            // Constructs default error output object containing error message.
            Utilities.ErrorOutput err = new Utilities.ErrorOutput();

            // Validate SoilMoisture sources.
            errorMsg = (!Enum.TryParse(input.Source, true, out SoilMSources pSource)) ? "ERROR: 'Source' was not found or is invalid." : "";
            if (errorMsg.Contains("ERROR"))
            {
                return(err.ReturnError(errorMsg));
            }

            // SoilMoisture object
            SoilMoisture.SoilMoisture soilM = new SoilMoisture.SoilMoisture()
            {
                Layers = input.Layers
            };
            // Assigning dataset values, used to determine base url
            List <string> dataset = new List <string>();

            foreach (string layer in soilM.Layers)
            {
                string l = layer.Replace('-', '_');
                dataset.Add(l + "_SOILM");
            }

            // ITimeSeriesInputFactory object used to validate and initialize all variables of the input object.
            ITimeSeriesInputFactory iFactory = new TimeSeriesInputFactory();

            soilM.Input = iFactory.SetTimeSeriesInput(input, dataset, out errorMsg);

            // If error occurs in input validation and setup, errorMsg is added to metadata of an empty object.
            if (errorMsg.Contains("ERROR"))
            {
                return(err.ReturnError(errorMsg));
            }

            // Gets the SoilMoisture data.
            ITimeSeriesOutput result = soilM.GetData(out errorMsg);

            if (errorMsg.Contains("ERROR"))
            {
                return(err.ReturnError(errorMsg));
            }

            return(result);
        }
示例#11
0
        public void SetTimeSeriesInputTestInvalidDate()
        {
            string errorMsg = "";
            ITimeSeriesInputFactory iFactory = new TimeSeriesInputFactory();
            TimeSeriesInput         badDate  = new TimeSeriesInput();

            badDate = validInput;
            badDate.DateTimeSpan.StartDate = new DateTime(2015, 01, 10);
            ITimeSeriesInput sampleInput = iFactory.SetTimeSeriesInput(badDate, new List <string>()
            {
                "PRECIP"
            }, out errorMsg);

            Assert.AreEqual("ERROR: Start date must be before end date.", errorMsg);
        }
示例#12
0
        public void SetTimeSeriesInput_SourceTest(string source, string expected)
        {
            string errorMsg = "";
            ITimeSeriesInputFactory iFactory  = new TimeSeriesInputFactory();
            TimeSeriesInput         badSource = new TimeSeriesInput();

            badSource        = validInput;
            badSource.Source = source;
            ITimeSeriesInput sampleInput = iFactory.SetTimeSeriesInput(badSource, new List <string>()
            {
                "precipitation"
            }, out errorMsg);

            Assert.Equal(expected, errorMsg);
        }
示例#13
0
        public void SetTimeSeriesInputTestNoDate()
        {
            string errorMsg = "";
            ITimeSeriesInputFactory iFactory = new TimeSeriesInputFactory();
            TimeSeriesInput         noSDate  = new TimeSeriesInput();

            noSDate = validInput;
            noSDate.DateTimeSpan = null;
            ITimeSeriesInput sampleInput = iFactory.SetTimeSeriesInput(noSDate, new List <string>()
            {
                "PRECIP"
            }, out errorMsg);

            Assert.AreEqual("ERROR: DateTimeSpan object is null. DateTimeSpan, with a StartDate and EndDate, is required.", errorMsg);
        }
示例#14
0
        public void SetTimeSeriesInputTest_GeometryTest()
        {
            string errorMsg = "";
            ITimeSeriesInputFactory iFactory = new TimeSeriesInputFactory();
            TimeSeriesInput         noGeom   = new TimeSeriesInput();

            noGeom          = validInput;
            noGeom.Geometry = null;
            ITimeSeriesInput sampleInput = iFactory.SetTimeSeriesInput(noGeom, new List <string>()
            {
                "precipitation"
            }, out errorMsg);

            Assert.Equal("ERROR: No input geometry was found.", errorMsg);
        }
示例#15
0
        public void SetTimeSeriesInput_DateTimeSpanTest()
        {
            string errorMsg = "";
            ITimeSeriesInputFactory iFactory = new TimeSeriesInputFactory();
            TimeSeriesInput         noSDate  = new TimeSeriesInput();

            noSDate = validInput;
            noSDate.DateTimeSpan = null;
            ITimeSeriesInput sampleInput = iFactory.SetTimeSeriesInput(noSDate, new List <string>()
            {
                "precipitation"
            }, out errorMsg);

            Assert.Equal("ERROR: No DateTimeSpan found.", errorMsg);
        }
示例#16
0
        public void SetTimeSeriesInputTestNoPoint()
        {
            string errorMsg = "";
            ITimeSeriesInputFactory iFactory = new TimeSeriesInputFactory();
            TimeSeriesInput         noPoint  = new TimeSeriesInput();

            noPoint = validInput;
            noPoint.Geometry.Point = null;
            ITimeSeriesInput sampleInput = iFactory.SetTimeSeriesInput(noPoint, new List <string>()
            {
                "PRECIP"
            }, out errorMsg);

            Assert.AreEqual("ERROR: No geometry values found in the provided parameters.", errorMsg);
        }
示例#17
0
        public void SetTimeSeriesInputTestInvalidLongitude()
        {
            string errorMsg = "";
            ITimeSeriesInputFactory iFactory = new TimeSeriesInputFactory();
            TimeSeriesInput         invLon   = new TimeSeriesInput();

            invLon = validInput;
            invLon.Geometry.Point.Latitude = 200;
            ITimeSeriesInput sampleInput = iFactory.SetTimeSeriesInput(invLon, new List <string>()
            {
                "PRECIP"
            }, out errorMsg);

            Assert.AreEqual("ERROR: Latitude or Longitude value is not a valid coordinate.", errorMsg);
        }
示例#18
0
        public void SetTimeSeriesInputTestNoSource()
        {
            string errorMsg = "";
            ITimeSeriesInputFactory iFactory  = new TimeSeriesInputFactory();
            TimeSeriesInput         badSource = new TimeSeriesInput();

            badSource        = validInput;
            badSource.Source = "";
            ITimeSeriesInput sampleInput = iFactory.SetTimeSeriesInput(badSource, new List <string>()
            {
                "PRECIP"
            }, out errorMsg);

            Assert.AreEqual("ERROR: Required 'Source' parameter was not found or is invalid.", errorMsg);
        }
示例#19
0
        public void SetTimeSeriesInputTestInvalidSource()
        {
            string errorMsg = "";
            ITimeSeriesInputFactory iFactory  = new TimeSeriesInputFactory();
            TimeSeriesInput         badSource = new TimeSeriesInput();

            badSource        = validInput;
            badSource.Source = "badSource";
            ITimeSeriesInput sampleInput = iFactory.SetTimeSeriesInput(badSource, new List <string>()
            {
                "PRECIP"
            }, out errorMsg);

            Assert.AreEqual("ERROR: Provided source is not valid. Unable to construct base url.", errorMsg);
        }
示例#20
0
        public void SetTimeSeriesInput_LatLongTest(double latitude, double longitude, string expected)
        {
            string errorMsg = "";
            ITimeSeriesInputFactory iFactory    = new TimeSeriesInputFactory();
            TimeSeriesInput         latLongTest = new TimeSeriesInput();

            latLongTest = validInput;
            latLongTest.Geometry.Point.Latitude  = latitude;
            latLongTest.Geometry.Point.Longitude = longitude;
            ITimeSeriesInput sampleInput = iFactory.SetTimeSeriesInput(latLongTest, new List <string>()
            {
                "precipitation"
            }, out errorMsg);

            Assert.Equal(expected, errorMsg);
        }
示例#21
0
        /// <summary>
        /// Initiates the wgen precip generator.
        /// </summary>
        /// <param name="errorMsg"></param>
        /// <param name="output"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        public ITimeSeriesOutput GetData(out string errorMsg, ITimeSeriesOutput output, ITimeSeriesInput input)
        {
            errorMsg = "";
            Data.Simulate.WGEN wgen      = new Data.Simulate.WGEN();
            IDateTimeSpan      tempDates = new DateTimeSpan()
            {
                StartDate      = input.DateTimeSpan.StartDate,
                EndDate        = input.DateTimeSpan.EndDate,
                DateTimeFormat = input.DateTimeSpan.DateTimeFormat
            };
            // The number of years of historic data can be customized by includead 'yearsHistoric' in Geometry.GeometryMetadata
            int years = (input.Geometry.GeometryMetadata.ContainsKey("yearsHistoric")) ? Convert.ToInt16(input.Geometry.GeometryMetadata["yearsHistoric"]) : 20;
            // Historic Precipitation data.
            ITimeSeriesInputFactory iFactory  = new TimeSeriesInputFactory();
            ITimeSeriesInput        tempInput = input;

            tempInput.Source = "daymet";
            ITimeSeriesInput historicInput = iFactory.SetTimeSeriesInput(tempInput, new List <string>()
            {
                "precipitation"
            }, out errorMsg);
            ITimeSeriesOutput historicData = GetHistoricData(out errorMsg, years, historicInput, output);

            if (errorMsg.Contains("ERROR"))
            {
                return(null);
            }

            // Run wgen
            ITimeSeriesOutput outputData = output;

            input.DateTimeSpan = tempDates as DateTimeSpan;
            outputData         = wgen.Simulate(out errorMsg, years, input, output, historicData);
            if (errorMsg.Contains("ERROR"))
            {
                return(null);
            }

            // Unit conversion and temporal aggregation
            outputData = TemporalAggregation(out errorMsg, outputData, input);
            if (errorMsg.Contains("ERROR"))
            {
                return(null);
            }

            return(outputData);
        }
示例#22
0
        /// <summary>
        /// Gets precipitation data.
        /// </summary>
        /// <param name="errorMsg"></param>
        /// <param name="input"></param>
        /// <param name="output"></param>
        /// <returns></returns>
        private ITimeSeriesOutput GetPrecipData(out string errorMsg, ITimeSeriesInput input, ITimeSeriesOutput output)
        {
            errorMsg = "";

            Precipitation.Precipitation precip = new Precipitation.Precipitation();
            precip.Input  = input;
            precip.Output = output;

            if (input.Geometry.GeometryMetadata.ContainsKey("precipSource"))
            {
                switch (input.Geometry.GeometryMetadata["precipSource"])
                {
                case "nldas":
                    input.Source             = "nldas";
                    input.TemporalResolution = "daily";
                    break;

                case "gldas":
                    input.Source             = "gldas";
                    input.TemporalResolution = "daily";
                    break;

                case "daymet":
                default:
                    input.Source = "daymet";
                    break;
                }
            }
            else
            {
                input.Source = "daymet";
            }
            ITimeSeriesInputFactory iFactory  = new TimeSeriesInputFactory();
            ITimeSeriesInput        tempInput = iFactory.SetTimeSeriesInput(input, new List <string>()
            {
                "precip"
            }, out errorMsg);

            precip.Input  = tempInput;
            precip.Output = precip.GetData(out errorMsg);
            if (errorMsg.Contains("ERROR"))
            {
                return(null);
            }
            return(precip.Output);
        }
示例#23
0
        /// <summary>
        /// Gets precipitation data using the given TimeSeriesInput parameters.
        /// </summary>
        /// <param name="input">ITimeSeriesInput</param>
        /// <returns></returns>
        public ITimeSeriesOutput GetPrecipitation(ITimeSeriesInput input)
        {
            string errorMsg = "";

            // Constructs default error output object containing error message.
            Utilities.ErrorOutput err = new Utilities.ErrorOutput();

            // Validate precipitation sources.
            errorMsg = (!Enum.TryParse(input.Source, true, out PrecipSources pSource)) ? "ERROR: 'Source' was not found or is invalid.": "";
            if (errorMsg.Contains("ERROR"))
            {
                return(err.ReturnError(errorMsg));
            }

            // Precipitation object
            Precipitation.Precipitation precip = new Precipitation.Precipitation();

            // ITimeSeriesInputFactory object used to validate and initialize all variables of the input object.
            ITimeSeriesInputFactory iFactory = new TimeSeriesInputFactory();

            precip.Input = iFactory.SetTimeSeriesInput(input, new List <string>()
            {
                "PRECIP"
            }, out errorMsg);

            // If error occurs in input validation and setup, errorMsg is added to metadata of an empty object.
            if (errorMsg.Contains("ERROR"))
            {
                return(err.ReturnError(errorMsg));
            }

            if (precip.Input.Source.Contains("ncdc"))
            {
                precip.Input.Geometry.GeometryMetadata["token"] = (precip.Input.Geometry.GeometryMetadata.ContainsKey("token")) ? precip.Input.Geometry.GeometryMetadata["token"] : "RUYNSTvfSvtosAoakBSpgxcHASBxazzP";
            }

            // Gets the Precipitation data.
            ITimeSeriesOutput result = precip.GetData(out errorMsg);

            if (errorMsg.Contains("ERROR"))
            {
                return(err.ReturnError(errorMsg));
            }

            return(result);
        }
示例#24
0
        /// <summary>
        /// Checks the data endpoints for the Evapotranspiration component.
        /// </summary>
        /// <returns></returns>
        public static async Task <Dictionary <string, Dictionary <string, string> > > CheckEvapoEndpoints()
        {
            Dictionary <string, Dictionary <string, string> > endpoints = new Dictionary <string, Dictionary <string, string> >();
            List <Evapotranspiration.Evapotranspiration>      evapos    = new List <Evapotranspiration.Evapotranspiration>();
            List <string> sources = new List <string>()
            {
                "nldas", "gldas"
            };
            ITimeSeriesInput testInput = new TimeSeriesInput()
            {
                Source       = "nldas",
                DateTimeSpan = new DateTimeSpan()
                {
                    StartDate = new DateTime(2005, 01, 01),
                    EndDate   = new DateTime(2005, 01, 05)
                },
                Geometry = new TimeSeriesGeometry()
                {
                    Point = new PointCoordinate()
                    {
                        Latitude  = 33.925673,
                        Longitude = -83.355723
                    },
                    GeometryMetadata = new Dictionary <string, string>()
                }
            };
            ITimeSeriesInputFactory iFactory = new TimeSeriesInputFactory();

            foreach (string source in sources)
            {
                Evapotranspiration.Evapotranspiration evapo = new Evapotranspiration.Evapotranspiration();
                testInput.Source = source;
                evapo.Input      = iFactory.SetTimeSeriesInput(testInput, new List <string>()
                {
                    "evapotranspiration"
                }, out string errorMsg);
                evapos.Add(evapo);
            }

            Parallel.ForEach(evapos, (Evapotranspiration.Evapotranspiration evapo) =>
            {
                endpoints.Add(evapo.Input.Source, evapo.CheckEndpointStatus());
            });
            return(endpoints);
        }
示例#25
0
        /// <summary>
        /// Checks the data endpoints for the Sub-Surface Flow component.
        /// </summary>
        /// <returns></returns>
        public static Dictionary <string, Dictionary <string, string> > CheckSubsurfaceEndpoints()
        {
            Dictionary <string, Dictionary <string, string> > endpoints = new Dictionary <string, Dictionary <string, string> >();
            List <SubSurfaceFlow.SubSurfaceFlow> subsurfaces            = new List <SubSurfaceFlow.SubSurfaceFlow>();
            List <string> sources = new List <string>()
            {
                "nldas", "gldas"
            };
            ITimeSeriesInput testInput = new TimeSeriesInput()
            {
                Source       = "nldas",
                DateTimeSpan = new DateTimeSpan()
                {
                    StartDate = new DateTime(2005, 01, 01),
                    EndDate   = new DateTime(2005, 01, 05)
                },
                Geometry = new TimeSeriesGeometry()
                {
                    Point = new PointCoordinate()
                    {
                        Latitude  = 33.925673,
                        Longitude = -83.355723
                    },
                    GeometryMetadata = new Dictionary <string, string>()
                }
            };
            ITimeSeriesInputFactory iFactory = new TimeSeriesInputFactory();

            foreach (string source in sources)
            {
                SubSurfaceFlow.SubSurfaceFlow subsurface = new SubSurfaceFlow.SubSurfaceFlow();
                testInput.Source = source;
                subsurface.Input = iFactory.SetTimeSeriesInput(testInput, new List <string>()
                {
                    "BASEFLOW"
                }, out string errorMsg);
                subsurfaces.Add(subsurface);
            }

            Parallel.ForEach(subsurfaces, (SubSurfaceFlow.SubSurfaceFlow subsurface) =>
            {
                endpoints.Add(subsurface.Input.Source, subsurface.CheckEndpointStatus());
            });
            return(endpoints);
        }
示例#26
0
        /// <summary>
        /// Checks the data endpoints for the Temperature component.
        /// </summary>
        /// <returns></returns>
        public static async Task <Dictionary <string, Dictionary <string, string> > > CheckTempEndpoints()
        {
            Dictionary <string, Dictionary <string, string> > endpoints = new Dictionary <string, Dictionary <string, string> >();
            List <Temperature.Temperature> temps = new List <Temperature.Temperature>();
            List <string> sources = new List <string>()
            {
                "nldas", "gldas", "daymet"
            };
            ITimeSeriesInput testInput = new TimeSeriesInput()
            {
                Source       = "nldas",
                DateTimeSpan = new DateTimeSpan()
                {
                    StartDate = new DateTime(2005, 01, 01),
                    EndDate   = new DateTime(2005, 01, 05)
                },
                Geometry = new TimeSeriesGeometry()
                {
                    Point = new PointCoordinate()
                    {
                        Latitude  = 33.925673,
                        Longitude = -83.355723
                    },
                    GeometryMetadata = new Dictionary <string, string>()
                }
            };
            ITimeSeriesInputFactory iFactory = new TimeSeriesInputFactory();

            foreach (string source in sources)
            {
                Temperature.Temperature temp = new Temperature.Temperature();
                testInput.Source = source;
                temp.Input       = iFactory.SetTimeSeriesInput(testInput, new List <string>()
                {
                    "temperature"
                }, out string errorMsg);
                temps.Add(temp);
            }

            Parallel.ForEach(temps, (Temperature.Temperature temp) =>
            {
                endpoints.Add(temp.Input.Source, temp.CheckEndpointStatus());
            });
            return(endpoints);
        }
示例#27
0
        /// <summary>
        /// Checks the data endpoints for the SurfaceRunoff component.
        /// </summary>
        /// <returns></returns>
        public static async Task <Dictionary <string, Dictionary <string, string> > > CheckRunoffEndpoints()
        {
            Dictionary <string, Dictionary <string, string> > endpoints = new Dictionary <string, Dictionary <string, string> >();
            List <SurfaceRunoff.SurfaceRunoff> runoffs = new List <SurfaceRunoff.SurfaceRunoff>();
            List <string> sources = new List <string>()
            {
                "nldas", "gldas"
            };
            ITimeSeriesInput testInput = new TimeSeriesInput()
            {
                Source       = "nldas",
                DateTimeSpan = new DateTimeSpan()
                {
                    StartDate = new DateTime(2005, 01, 01),
                    EndDate   = new DateTime(2005, 01, 05)
                },
                Geometry = new TimeSeriesGeometry()
                {
                    Point = new PointCoordinate()
                    {
                        Latitude  = 33.925673,
                        Longitude = -83.355723
                    },
                    GeometryMetadata = new Dictionary <string, string>()
                }
            };
            ITimeSeriesInputFactory iFactory = new TimeSeriesInputFactory();

            foreach (string source in sources)
            {
                SurfaceRunoff.SurfaceRunoff runoff = new SurfaceRunoff.SurfaceRunoff();
                testInput.Source = source;
                runoff.Input     = iFactory.SetTimeSeriesInput(testInput, new List <string>()
                {
                    "surfacerunoff"
                }, out string errorMsg);
                runoffs.Add(runoff);
            }

            Parallel.ForEach(runoffs, (SurfaceRunoff.SurfaceRunoff runoff) =>
            {
                endpoints.Add(runoff.Input.Source, runoff.CheckEndpointStatus());
            });
            return(endpoints);
        }
示例#28
0
        /// <summary>
        /// GetData function for curvenumber.
        /// </summary>
        /// <param name="errorMsg"></param>
        /// <param name="output"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        public ITimeSeriesOutput GetData(out string errorMsg, ITimeSeriesOutput output, ITimeSeriesInput input)
        {
            errorMsg = "";

            ITimeSeriesInputFactory iFactory = new TimeSeriesInputFactory();

            // TODO: Add options for different precip inputs
            input.Source = "daymet";
            ITimeSeriesInput precipInput = iFactory.SetTimeSeriesInput(input, new List <string>()
            {
                "precipitation"
            }, out errorMsg);

            // Test comid=718276, latitude=46.69580547, longitude=-69.36054766
            precipInput.Geometry.Point = new PointCoordinate()
            {
                Latitude  = 46.69580547,
                Longitude = -69.36054766
            };
            input.Geometry.ComID = 718276;

            ITimeSeriesOutput precipData = GetPrecipData(out errorMsg, precipInput, output);

            if (errorMsg.Contains("ERROR"))
            {
                return(null);
            }

            Data.Simulate.CurveNumber cn       = new Data.Simulate.CurveNumber();
            ITimeSeriesOutput         cnOutput = cn.Simulate(out errorMsg, input, precipData);

            if (errorMsg.Contains("ERROR"))
            {
                return(null);
            }

            //ITimeSeriesOutput cnOutput = output;
            //cnOutput = cn.SetDataToOutput(out errorMsg, "SurfaceRunoff", data, output, input);
            //if (errorMsg.Contains("ERROR")) { return null; }

            //TODO: add temporal resolution function

            return(cnOutput);
        }
示例#29
0
        /// <summary>
        /// Gets SurfaceRunoff data using the given TimeSeriesInput parameters.
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public ITimeSeriesOutput GetSurfaceRunoff(ITimeSeriesInput input)
        {
            string errorMsg = "";

            // Constructs default error output object containing error message.
            Utilities.ErrorOutput err = new Utilities.ErrorOutput();

            // Validate SurfaceRunoff sources.
            errorMsg = (!Enum.TryParse(input.Source, true, out RunoffSources pSource)) ? "ERROR: 'Source' was not found or is invalid." : "";
            if (errorMsg.Contains("ERROR"))
            {
                return(err.ReturnError(errorMsg));
            }

            // SurfaceRunoff object
            SurfaceRunoff.SurfaceRunoff runoff = new SurfaceRunoff.SurfaceRunoff();

            // ITimeSeriesInputFactory object used to validate and initialize all variables of the input object.
            ITimeSeriesInputFactory iFactory = new TimeSeriesInputFactory();

            runoff.Input = iFactory.SetTimeSeriesInput(input, new List <string>()
            {
                "SURFFLOW"
            }, out errorMsg);

            // If error occurs in input validation and setup, errorMsg is added to metadata of an empty object.
            if (errorMsg.Contains("ERROR"))
            {
                return(err.ReturnError(errorMsg));
            }

            // Gets the SurfaceRunoff data.
            ITimeSeriesOutput result = runoff.GetData(out errorMsg);

            if (errorMsg.Contains("ERROR"))
            {
                return(err.ReturnError(errorMsg));
            }

            return(result);
        }
        /// <summary>
        /// Gets evapotranspiration data using the given TimeSeriesInput parameters.
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public ITimeSeriesOutput GetEvapotranspiration(ITimeSeriesInput input)
        {
            string errorMsg = "";

            // Constructs default error output object containing error message.
            Utilities.ErrorOutput err = new Utilities.ErrorOutput();

            // Validate evapotranspiration sources.
            errorMsg = (!Enum.TryParse(input.Source, true, out EvapoSources pSource)) ? "ERROR: 'Source' was not found or is invalid." : "";
            if (errorMsg.Contains("ERROR"))
            {
                return(err.ReturnError(errorMsg));
            }

            // Evapotranspiration object
            Evapotranspiration.Evapotranspiration evapo = new Evapotranspiration.Evapotranspiration();

            // ITimeSeriesInputFactory object used to validate and initialize all variables of the input object.
            ITimeSeriesInputFactory iFactory = new TimeSeriesInputFactory();

            evapo.Input = iFactory.SetTimeSeriesInput(input, new List <string>()
            {
                "EVAPOT"
            }, out errorMsg);

            // If error occurs in input validation and setup, errorMsg is added to metadata of an empty object.
            if (errorMsg.Contains("ERROR"))
            {
                return(err.ReturnError(errorMsg));
            }

            // Gets the Evapotranspiration data.
            ITimeSeriesOutput result = evapo.GetData(out errorMsg);

            if (errorMsg.Contains("ERROR"))
            {
                return(err.ReturnError(errorMsg));
            }

            return(result);
        }