Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
0
        /// <summary>
        /// Gets workflow data.
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public ITimeSeriesOutput GetWorkFlowData(WorkFlowCompareInput input)
        {
            string errorMsg = "";

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

            input.SourceList = new List <string>()
            {
                { "ncdc" },
                { "nldas" },
                { "gldas" },
                { "daymet" }
            };

            ITimeSeriesOutputFactory oFactory = new TimeSeriesOutputFactory();
            ITimeSeriesOutput        output   = oFactory.Initialize();

            output.DataSource = string.Join(" - ", input.SourceList.ToArray());

            if (input.Dataset.Contains("Precipitation"))
            {
                input.SourceList = new List <string>()
                {
                    { "nldas" },
                    { "gldas" },
                    { "daymet" }
                };
                input.Source = "ncdc";
                // 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));
                }

                List <Precipitation.Precipitation> precipList = new List <Precipitation.Precipitation>();
                List <ITimeSeriesOutput>           outputList = new List <ITimeSeriesOutput>();

                // NCDC Call
                Precipitation.Precipitation ncdc = new Precipitation.Precipitation();
                // ITimeSeriesInputFactory object used to validate and initialize all variables of the input object.
                ITimeSeriesInputFactory nFactory = new TimeSeriesInputFactory();
                ITimeSeriesInput        nInput   = nFactory.SetTimeSeriesInput(input, new List <string>()
                {
                    "PRECIP"
                }, out errorMsg);
                if (errorMsg.Contains("ERROR"))
                {
                    return(err.ReturnError(errorMsg));
                }

                // Set input to precip object.
                ncdc.Input = nInput;
                ncdc.Input.TemporalResolution = "daily";
                ncdc.Input.Geometry.GeometryMetadata["token"] = (ncdc.Input.Geometry.GeometryMetadata.ContainsKey("token")) ? ncdc.Input.Geometry.GeometryMetadata["token"] : "RUYNSTvfSvtosAoakBSpgxcHASBxazzP";
                ITimeSeriesOutput nResult = ncdc.GetData(out errorMsg);
                if (errorMsg.Contains("ERROR"))
                {
                    return(err.ReturnError(errorMsg));
                }
                output = nResult;

                // Construct Precipitation objects for Parallel execution in the preceeding Parallel.ForEach statement.
                foreach (string source in input.SourceList)
                {
                    // Precipitation object
                    Precipitation.Precipitation precip = new Precipitation.Precipitation();
                    if (output.Metadata.ContainsKey("ncdc_latitude") && output.Metadata.ContainsKey("ncdc_longitude"))
                    {
                        input.Geometry.Point = new PointCoordinate
                        {
                            Latitude  = Convert.ToDouble(output.Metadata["ncdc_latitude"]),
                            Longitude = Convert.ToDouble(output.Metadata["ncdc_longitude"])
                        };
                    }
                    else
                    {
                        errorMsg = "ERROR: Coordinate information was not found or is invalid for the specified NCDC station.";
                    }
                    // ITimeSeriesInputFactory object used to validate and initialize all variables of the input object.
                    ITimeSeriesInputFactory iFactory = new TimeSeriesInputFactory();
                    input.Source = source;
                    ITimeSeriesInput sInput = iFactory.SetTimeSeriesInput(input, new List <string>()
                    {
                        "PRECIP"
                    }, out errorMsg);
                    if (errorMsg.Contains("ERROR"))
                    {
                        return(err.ReturnError(errorMsg));
                    }

                    // Set input to precip object.
                    precip.Input = sInput;
                    precip.Input.TemporalResolution = "daily";

                    precip.Input.DateTimeSpan.EndDate = precip.Input.DateTimeSpan.EndDate.AddDays(1);
                    if (!precip.Input.Geometry.GeometryMetadata.ContainsKey("leapYear"))
                    {
                        precip.Input.Geometry.GeometryMetadata.Add("leapYear", "correction");
                    }
                    precipList.Add(precip);
                }

                List <string> errorList = new List <string>();
                Parallel.ForEach(precipList, (Precipitation.Precipitation precip) =>
                {
                    // Gets the Precipitation data.
                    string errorM            = "";
                    ITimeSeriesOutput result = precip.GetData(out errorM);
                    errorList.Add(errorM);
                    outputList.Add(result);
                });

                foreach (ITimeSeriesOutput result in outputList)
                {
                    output = Utilities.Merger.MergeTimeSeries(output, result);
                }

                output.Metadata.Add("column_1", "date");
                output.Metadata.Add("column_2", "ncdc");
                output = Utilities.Statistics.GetStatistics(out errorMsg, output);

                return(output);
            }
            else if (input.Dataset.Contains("SurfaceRunoff"))
            {
                //TODO: Do runoff source iteration.
                return(err.ReturnError("ERROR. Workflow has not yet been implemented."));
            }
            else
            {
                return(err.ReturnError("ERROR: WorkFlow source not found or is invalid."));
            }
        }