예제 #1
0
파일: NLDAS.cs 프로젝트: quanted/hms
        /// <summary>
        /// Merges all of the soil moisture layers data into a single ITimeSeriesOutput instance.
        /// </summary>
        /// <param name="errorMsg"></param>
        /// <param name="layersData"></param>
        /// <returns></returns>
        public static ITimeSeriesOutput MergeLayers(out string errorMsg, List <ITimeSeriesOutput> layersData, string source)
        {
            errorMsg = "";
            ITimeSeriesOutput output = new TimeSeriesOutput();

            output.Data = new Dictionary <string, List <string> >();
            for (int i = 0; i < layersData[0].Data.Count; i++)
            {
                List <string> data = new List <string>();
                for (int j = 0; j < layersData.Count; j++)
                {
                    data.Add(layersData[j].Data[layersData[j].Data.Keys.ElementAt(i)][0].ToString());
                }
                output.Data.Add(layersData[0].Data.Keys.ElementAt(i), data);
            }
            output.DataSource = source;
            output.Dataset    = "Soil Moisture";
            output.Metadata   = layersData[0].Metadata;
            for (int i = 0; i < layersData.Count; i++)
            {
                string layerName = layersData[i].Metadata[source + "_param_short_name"].Substring(layersData[i].Metadata[source + "_param_short_name"].IndexOf('M') + 1);
                output.Metadata.Add("column_" + (i + 3), layerName);
            }

            return(output);
        }
예제 #2
0
파일: NLDAS.cs 프로젝트: quanted/hms
        /// <summary>
        /// Makes the GetData call to the base NLDAS class.
        /// </summary>
        /// <param name="errorMsg"></param>
        /// <param name="output"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        public ITimeSeriesOutput GetData(out string errorMsg, SoilMoisture input)
        {
            errorMsg = "";
            Data.Source.NLDAS        nldas       = new Data.Source.NLDAS();
            ITimeSeriesOutput        nldasOutput = input.Output;
            List <ITimeSeriesOutput> layersData  = new List <ITimeSeriesOutput>();
            List <string>            urls        = input.Input.BaseURL;

            for (int i = 0; i < input.Layers.Count; i++)
            {
                input.Input.BaseURL = new List <string>()
                {
                    urls[i]
                };
                ITimeSeriesOutputFactory oFactory   = new TimeSeriesOutputFactory();
                ITimeSeriesOutput        tempOutput = new TimeSeriesOutput();
                tempOutput = oFactory.Initialize();
                string data = nldas.GetData(out errorMsg, input.Layers[i].Replace('-', '_') + "_SOILM", input.Input);
                if (errorMsg.Contains("ERROR"))
                {
                    return(null);
                }

                tempOutput = nldas.SetDataToOutput(out errorMsg, "SoilMoisture", data, tempOutput, input.Input);
                if (errorMsg.Contains("ERROR"))
                {
                    return(null);
                }

                tempOutput = TemporalAggregation(out errorMsg, tempOutput, input.Input);
                if (errorMsg.Contains("ERROR"))
                {
                    return(null);
                }
                layersData.Add(tempOutput);
            }

            nldasOutput = MergeLayers(out errorMsg, layersData, "nldas");
            if (errorMsg.Contains("ERROR"))
            {
                return(null);
            }

            return(nldasOutput);
        }
예제 #3
0
        public async Task MeteorologyValidRequests(string inputString)
        {
            string endpoint            = "api/meteorology/solar";
            SolarCalculatorInput input = JsonConvert.DeserializeObject <SolarCalculatorInput>(inputString);

            Debug.WriteLine("Integration Test: Solar controller; Endpoint: " + endpoint + "; Data source: " + input.Model);
            var response = await _client.PostAsync(
                endpoint,
                new StringContent(JsonConvert.SerializeObject(input), Encoding.UTF8, "application/json"));

            response.EnsureSuccessStatusCode();
            var result = await response.Content.ReadAsStringAsync();

            Assert.NotNull(result);
            TimeSeriesOutput resultObj = JsonConvert.DeserializeObject <TimeSeriesOutput>(result);

            Assert.Equal(365, resultObj.Data.Count);
        }
        public async Task ValidRequests(string evapoInputString)
        {
            string endpoint = "api/hydrology/evapotranspiration";
            EvapotranspirationInput input = JsonConvert.DeserializeObject <EvapotranspirationInput>(evapoInputString);

            Debug.WriteLine("Integration Test: Evapotranspiration controller; Endpoint: " + endpoint + "; Data source: " + input.Source);
            string json     = JsonConvert.SerializeObject(input);
            var    response = await _client.PostAsync(
                endpoint,
                new StringContent(json, Encoding.UTF8, "application/json"));

            response.EnsureSuccessStatusCode();
            var result = await response.Content.ReadAsStringAsync();

            Assert.NotNull(result);
            TimeSeriesOutput resultObj = JsonConvert.DeserializeObject <TimeSeriesOutput>(result);

            Assert.Equal(365, resultObj.Data.Count);
        }
        public async Task ValidRequests(string precipInputString, int expected)
        {
            string             endpoint = "api/hydrology/precipitation";
            PrecipitationInput input    = JsonConvert.DeserializeObject <PrecipitationInput>(precipInputString);

            input.TemporalResolution = "daily";
            Debug.WriteLine("Integration Test: Precipitation controller; Endpoint: " + endpoint + "; Data source: " + input.Source);
            var response = await _client.PostAsync(
                endpoint,
                new StringContent(JsonConvert.SerializeObject(input), Encoding.UTF8, "application/json"));

            response.EnsureSuccessStatusCode();
            var result = await response.Content.ReadAsStringAsync();

            Assert.NotNull(result);
            TimeSeriesOutput resultObj = JsonConvert.DeserializeObject <TimeSeriesOutput>(result);

            Assert.Equal(expected, resultObj.Data.Count);
        }
예제 #6
0
        public async Task ValidRequests(string inputString)
        {
            string           endpoint = "api/hydrology/temperature";
            TemperatureInput input    = JsonConvert.DeserializeObject <TemperatureInput>(inputString);

            Debug.WriteLine("Integration Test: Temperature controller; Endpoint: " + endpoint + "; Data source: " + input.Source);
            var response = await _client.PostAsync(
                endpoint,
                new StringContent(JsonConvert.SerializeObject(input), Encoding.UTF8, "application/json"));

            response.EnsureSuccessStatusCode();
            var result = await response.Content.ReadAsStringAsync();

            Assert.NotNull(result);
            TimeSeriesOutput resultObj = JsonConvert.DeserializeObject <TimeSeriesOutput>(result);
            // New nldas/gldas temperature data contains statistics at the end (+3 required)
            int expected = (input.Source.Equals("nldas") || input.Source.Equals("gldas")) ? 368 : 365;

            Assert.Equal(expected, resultObj.Data.Count);
        }