/// <summary> /// Checks for temporal resolution and runs appropriate aggregation function. /// </summary> /// <param name="errorMsg"></param> /// <param name="output"></param> /// <param name="input"></param> /// <returns></returns> private ITimeSeriesOutput TemporalAggregation(out string errorMsg, ITimeSeriesOutput output, ITimeSeriesInput input) { errorMsg = ""; output.Metadata.Add("gldas_temporalresolution", input.TemporalResolution); output.Metadata.Add("column_1", "Date"); output.Data = ConvertToHourly(out errorMsg, output, input); if (input.Units.Contains("imperial")) { output.Metadata["gldas_unit"] = "in"; } // NLDAS static methods used for aggregation as GLDAS is identical in function. Modifier refers to the 3hr different to nldas's hourly resolution. switch (input.TemporalResolution) { case "daily": output.Data = NLDAS.DailyAggregatedSum(out errorMsg, 7, 3.0, output, input); output.Metadata.Add("column_2", "Daily Total"); return(output); case "weekly": output.Data = NLDAS.WeeklyAggregatedSum(out errorMsg, 3.0, output, input); output.Metadata.Add("column_2", "Weekly Total"); return(output); case "monthly": output.Data = NLDAS.MonthlyAggregatedSum(out errorMsg, 3.0, output, input); output.Metadata.Add("column_2", "Monthly Total"); return(output); default: output.Data = (input.Units.Contains("imperial")) ? NLDAS.UnitConversion(out errorMsg, 3.0, output, input) : output.Data; output.Metadata.Add("column_2", "Hourly Average"); return(output); } }
/// <summary> /// Checks temporal resolution and runs appropriate aggregation function. /// </summary> /// <param name="errorMsg"></param> /// <param name="output"></param> /// <param name="input"></param> /// <returns></returns> private ITimeSeriesOutput TemporalAggregation(out string errorMsg, ITimeSeriesOutput output, ITimeSeriesInput input) { errorMsg = ""; output.Metadata.Add("daymet_temporalresolution", input.TemporalResolution); output.Metadata.Add("column_1", "Date"); switch (input.TemporalResolution) { case "weekly": output.Data = NLDAS.WeeklyAggregatedSum(out errorMsg, 1.0, output, input); output.Metadata.Add("column_2", "Weekly Total"); return(output); case "monthly": output.Data = NLDAS.MonthlyAggregatedSum(out errorMsg, 1.0, output, input); output.Metadata.Add("column_2", "Monthly Total"); return(output); case "daily": default: output.Metadata.Add("column_2", "Daily Total"); return(output); } }
/// <summary> /// Check precipitation data endpoints. /// </summary> /// <returns></returns> public Dictionary <string, string> CheckEndpointStatus() { switch (this.Input.Source) { case "nldas": return(NLDAS.CheckStatus(this.Input)); case "gldas": return(GLDAS.CheckStatus(this.Input)); case "daymet": return(Daymet.CheckStatus(this.Input)); case "ncdc": return(NCDC.CheckStatus(this.Input)); // TODO: Add check status function for PRISM default: return(new Dictionary <string, string>() { { "status", "invalid source" } }); } }
// -------------- Precipitation Functions -------------- // /// <summary> /// Get Precipitation data function. /// </summary> /// <param name="errorMsg"></param> /// <returns></returns> public ITimeSeriesOutput GetData(out string errorMsg) { errorMsg = ""; // If the timezone information is not provided, the tz details are retrieved and set to the geometry.timezone varaible. if (this.Input.Geometry.Timezone.Offset == 0 && !this.Input.Source.Contains("ncdc")) { Utilities.Time tz = new Utilities.Time(); this.Input.Geometry.Timezone = tz.GetTimezone(out errorMsg, this.Input.Geometry.Point) as Timezone; if (errorMsg.Contains("ERROR")) { return(null); } } //TODO: Check Source and run specific subcomponent class for source ITimeSeriesOutputFactory iFactory = new TimeSeriesOutputFactory(); this.Output = iFactory.Initialize(); switch (this.Input.Source) { case "nldas": // NLDAS Precipitation Data call NLDAS nldas = new NLDAS(); this.Output = nldas.GetData(out errorMsg, this.Output, this.Input); if (errorMsg.Contains("ERROR")) { return(null); } break; case "gldas": // GLDAS Precipitation Data call GLDAS gldas = new GLDAS(); this.Output = gldas.GetData(out errorMsg, this.Output, this.Input); if (errorMsg.Contains("ERROR")) { return(null); } break; case "ncdc": // NCDC Precipitation Data call NCDC ncdc = new NCDC(); this.Output = ncdc.GetData(out errorMsg, this.Output, this.Input); if (errorMsg.Contains("ERROR")) { return(null); } break; case "daymet": // daymet Precipitation Data call Daymet daymet = new Daymet(); this.Output = daymet.GetData(out errorMsg, this.Output, this.Input); if (errorMsg.Contains("ERROR")) { return(null); } break; case "wgen": // wgen Precipitation Data call WGEN wgen = new WGEN(); this.Output = wgen.GetData(out errorMsg, this.Output, this.Input); if (errorMsg.Contains("ERROR")) { return(null); } break; case "prism": // PRISM Precipitation Data call PRISM prism = new PRISM(); this.Output = prism.GetData(out errorMsg, this.Output, this.Input); if (errorMsg.Contains("ERROR")) { return(null); } break; default: errorMsg = "ERROR: 'Source' for precipitation was not found among available sources or is invalid."; break; } ; // Adds Geometry metadata to the output metadata. NOT WORKING //this.Output.Metadata.Concat(this.Input.Geometry.GeometryMetadata); // Adds Timezone info to metadata this.Output.Metadata.Add(this.Input.Source + "_timeZone", this.Input.Geometry.Timezone.Name); this.Output.Metadata.Add(this.Input.Source + "_tz_offset", this.Input.Geometry.Timezone.Offset.ToString()); //TODO: Add output format control return(this.Output); }