Exemplo n.º 1
0
        /// <summary>Checks the sample for missing values.</summary>
        /// <param name="sample">The sample.</param>
        /// <param name="soil">The soil.</param>
        private static void CheckSampleForMissingValues(Sample sample, Soil soil)
        {
            if (!MathUtilities.ValuesInArray(sample.SW))
            {
                sample.SW = null;
            }
            if (sample.NO3 != null && !MathUtilities.ValuesInArray(sample.NO3))
            {
                sample.NO3 = null;
            }
            if (sample.NH4 != null && !MathUtilities.ValuesInArray(sample.NH4))
            {
                sample.NH4 = null;
            }
            if (!MathUtilities.ValuesInArray(sample.CL))
            {
                sample.CL = null;
            }
            if (!MathUtilities.ValuesInArray(sample.EC))
            {
                sample.EC = null;
            }
            if (!MathUtilities.ValuesInArray(sample.ESP))
            {
                sample.ESP = null;
            }
            if (!MathUtilities.ValuesInArray(sample.PH))
            {
                sample.PH = null;
            }
            if (!MathUtilities.ValuesInArray(sample.OC))
            {
                sample.OC = null;
            }

            if (sample.SW != null)
            {
                sample.SW = MathUtilities.FixArrayLength(sample.SW, sample.Thickness.Length);
            }
            if (sample.CL != null)
            {
                sample.CL = MathUtilities.FixArrayLength(sample.CL, sample.Thickness.Length);
            }
            if (sample.EC != null)
            {
                sample.EC = MathUtilities.FixArrayLength(sample.EC, sample.Thickness.Length);
            }
            if (sample.ESP != null)
            {
                sample.ESP = MathUtilities.FixArrayLength(sample.ESP, sample.Thickness.Length);
            }
            if (sample.PH != null)
            {
                sample.PH = MathUtilities.FixArrayLength(sample.PH, sample.Thickness.Length);
            }
            if (sample.OC != null)
            {
                sample.OC = MathUtilities.FixArrayLength(sample.OC, sample.Thickness.Length);
            }

            var physical = soil.FindChild <Physical>();

            if (physical != null)
            {
                double[] ll15 = Layers.LL15Mapped(physical, sample.Thickness);
                for (int i = 0; i < sample.Thickness.Length; i++)
                {
                    if (sample.SW != null && double.IsNaN(sample.SW[i]))
                    {
                        sample.SW[i] = ll15[i];
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Return a predicted SoilCrop for the specified crop name or null if not found.
        /// </summary>
        /// <param name="soil">The soil.</param>
        /// <param name="CropName">Name of the crop.</param>
        /// <returns></returns>
        private static SoilCrop PredictedCrop(Soil soil, string CropName)
        {
            double[] A = null;
            double   B = double.NaN;

            double[] KL = null;

            if (soil.SoilType == null)
            {
                return(null);
            }

            if (soil.SoilType.Equals("Black Vertosol", StringComparison.CurrentCultureIgnoreCase))
            {
                if (CropName.Equals("Cotton", StringComparison.CurrentCultureIgnoreCase))
                {
                    A  = BlackVertosol.CottonA;
                    B  = BlackVertosol.CottonB;
                    KL = CottonKL;
                }
                else if (CropName.Equals("Sorghum", StringComparison.CurrentCultureIgnoreCase))
                {
                    A  = BlackVertosol.SorghumA;
                    B  = BlackVertosol.SorghumB;
                    KL = SorghumKL;
                }
                else if (CropName.Equals("Wheat", StringComparison.CurrentCultureIgnoreCase))
                {
                    A  = BlackVertosol.WheatA;
                    B  = BlackVertosol.WheatB;
                    KL = WheatKL;
                }
            }
            else if (soil.SoilType.Equals("Grey Vertosol", StringComparison.CurrentCultureIgnoreCase))
            {
                if (CropName.Equals("Cotton", StringComparison.CurrentCultureIgnoreCase))
                {
                    A  = GreyVertosol.CottonA;
                    B  = GreyVertosol.CottonB;
                    KL = CottonKL;
                }
                else if (CropName.Equals("Sorghum", StringComparison.CurrentCultureIgnoreCase))
                {
                    A  = GreyVertosol.SorghumA;
                    B  = GreyVertosol.SorghumB;
                    KL = SorghumKL;
                }
                else if (CropName.Equals("Wheat", StringComparison.CurrentCultureIgnoreCase))
                {
                    A  = GreyVertosol.WheatA;
                    B  = GreyVertosol.WheatB;
                    KL = WheatKL;
                }
                else if (CropName.Equals("Barley", StringComparison.CurrentCultureIgnoreCase))
                {
                    A  = GreyVertosol.BarleyA;
                    B  = GreyVertosol.BarleyB;
                    KL = BarleyKL;
                }
                else if (CropName.Equals("Chickpea", StringComparison.CurrentCultureIgnoreCase))
                {
                    A  = GreyVertosol.ChickpeaA;
                    B  = GreyVertosol.ChickpeaB;
                    KL = ChickpeaKL;
                }
                else if (CropName.Equals("Fababean", StringComparison.CurrentCultureIgnoreCase))
                {
                    A  = GreyVertosol.FababeanA;
                    B  = GreyVertosol.FababeanB;
                    KL = FababeanKL;
                }
                else if (CropName.Equals("Mungbean", StringComparison.CurrentCultureIgnoreCase))
                {
                    A  = GreyVertosol.MungbeanA;
                    B  = GreyVertosol.MungbeanB;
                    KL = MungbeanKL;
                }
            }


            if (A == null)
            {
                return(null);
            }

            var physical = soil.FindChild <IPhysical>();

            double[] LL = PredictedLL(physical, A, B);
            LL = Layers.MapConcentration(LL, PredictedThickness, physical.Thickness, LL.Last());
            KL = Layers.MapConcentration(KL, PredictedThickness, physical.Thickness, KL.Last());
            double[] XF       = Layers.MapConcentration(PredictedXF, PredictedThickness, physical.Thickness, PredictedXF.Last());
            string[] Metadata = StringUtilities.CreateStringArray("Estimated", physical.Thickness.Length);

            return(new SoilCrop()
            {
                Name = CropName,
                LL = LL,
                LLMetadata = Metadata,
                KL = KL,
                KLMetadata = Metadata,
                XF = XF,
                XFMetadata = Metadata
            });
        }
Exemplo n.º 3
0
        /// <summary>Checks the sample for missing values.</summary>
        /// <param name="sample">The sample.</param>
        /// <param name="soil">The soil.</param>
        private static void CheckSampleForMissingValues(Sample sample, Soil soil)
        {
            if (!MathUtilities.ValuesInArray(sample.SW))
            {
                sample.SW = null;
            }
            if (sample.NO3N != null && !MathUtilities.ValuesInArray(sample.NO3N))
            {
                sample.NO3N = null;
            }
            if (sample.NH4N != null && !MathUtilities.ValuesInArray(sample.NH4N))
            {
                sample.NH4N = null;
            }
            if (!MathUtilities.ValuesInArray(sample.CL))
            {
                sample.CL = null;
            }
            if (!MathUtilities.ValuesInArray(sample.EC))
            {
                sample.EC = null;
            }
            if (!MathUtilities.ValuesInArray(sample.ESP))
            {
                sample.ESP = null;
            }
            if (!MathUtilities.ValuesInArray(sample.PH))
            {
                sample.PH = null;
            }
            if (!MathUtilities.ValuesInArray(sample.OC))
            {
                sample.OC = null;
            }

            if (sample.SW != null)
            {
                sample.SW = MathUtilities.FixArrayLength(sample.SW, sample.Thickness.Length);
            }
            if (sample.CL != null)
            {
                sample.CL = MathUtilities.FixArrayLength(sample.CL, sample.Thickness.Length);
            }
            if (sample.EC != null)
            {
                sample.EC = MathUtilities.FixArrayLength(sample.EC, sample.Thickness.Length);
            }
            if (sample.ESP != null)
            {
                sample.ESP = MathUtilities.FixArrayLength(sample.ESP, sample.Thickness.Length);
            }
            if (sample.PH != null)
            {
                sample.PH = MathUtilities.FixArrayLength(sample.PH, sample.Thickness.Length);
            }
            if (sample.OC != null)
            {
                sample.OC = MathUtilities.FixArrayLength(sample.OC, sample.Thickness.Length);
            }

            var water = Apsim.Child(soil, typeof(Physical)) as Physical;

            if (water != null)
            {
                double[] ll15 = Layers.LL15Mapped(soil, sample.Thickness);
                for (int i = 0; i < sample.Thickness.Length; i++)
                {
                    if (sample.SW != null && double.IsNaN(sample.SW[i]))
                    {
                        sample.SW[i] = ll15[i];
                    }
                }
            }
        }