Exemple #1
0
        /// <summary>
        /// Return the plant available water CAPACITY. Units: mm/mm
        /// </summary>
        public double[] PAWCCrop(string CropName)
        {
            SoilCrop soilCrop = Apsim.Find(Soil, CropName) as SoilCrop;

            if (soilCrop != null)
            {
                return(Soil.CalcPAWC(Soil.Thickness,
                                     Soil.LL(CropName),
                                     Soil.DUL,
                                     Soil.XF(CropName)));
            }
            else
            {
                return(new double[0]);
            }
        }
Exemple #2
0
        /// <summary>
        /// Return the plant available water CAPACITY. Units: mm/mm
        /// </summary>
        public double[] PAWCCrop(string CropName)
        {
            var soilCrop = Soil.Crop(CropName);

            if (soilCrop != null)
            {
                return(Soil.CalcPAWC(Soil.Thickness,
                                     soilCrop.LL,
                                     Soil.DUL,
                                     soilCrop.XF));
            }
            else
            {
                return(new double[0]);
            }
        }
Exemple #3
0
        /// <summary>
        /// Return the plant available water CAPACITY. Units: mm/mm
        /// </summary>
        public double[] PAWCCrop(string CropName)
        {
            var soilCrop = Soil.FindDescendant <SoilCrop>(CropName + "Soil");

            if (soilCrop == null)
            {
                throw new Exception($"Cannot find a soil crop parameterisation called {CropName}Soil");
            }

            if (soilCrop != null)
            {
                return(SoilUtilities.CalcPAWC(SoilPhysical.Thickness,
                                              soilCrop.LL,
                                              SoilPhysical.DUL,
                                              soilCrop.XF));
            }
            else
            {
                return(new double[0]);
            }
        }
Exemple #4
0
        /// <summary>Convert a table of soils data into a list of soils.</summary>
        public static List <Soil> ToSoils(DataTable table)
        {
            var soils = new List <Soil>();

            // Loop through all blocks of rows in datatable, create a
            // soil and store soil in correct location in the AllSoils XML.
            int row = 0;

            while (row < table.Rows.Count)
            {
                // Find the end of this soil i.e. the row that has a different value for 'Name'
                // to the current row.
                int endRow = row + 1;
                while (endRow < table.Rows.Count &&
                       table.Rows[endRow]["Name"].ToString() == table.Rows[row]["Name"].ToString())
                {
                    endRow++;
                }
                int numLayers = endRow - row;

                var soil = new Soil();
                soil.Name              = table.Rows[row]["Name"].ToString();
                soil.Country           = GetStringValue(table, row, "Country");
                soil.State             = GetStringValue(table, row, "State");
                soil.Region            = GetStringValue(table, row, "Region");
                soil.NearestTown       = GetStringValue(table, row, "NearestTown");
                soil.Site              = GetStringValue(table, row, "Site");
                soil.ApsoilNumber      = GetStringValue(table, row, "APSoilNumber");
                soil.SoilType          = GetStringValue(table, row, "Texture");
                soil.LocalName         = GetStringValue(table, row, "LocalName");
                soil.ASCOrder          = GetStringValue(table, row, "ASC_Order");
                soil.ASCSubOrder       = GetStringValue(table, row, "ASC_Sub-order");
                soil.Latitude          = GetDoubleValue(table, row, "Latitude");
                soil.Longitude         = GetDoubleValue(table, row, "Longitude");
                soil.LocationAccuracy  = GetStringValue(table, row, "LocationAccuracy");
                soil.YearOfSampling    = GetStringValue(table, row, "YearOfSampling");
                soil.DataSource        = GetStringValue(table, row, "DataSource");
                soil.Comments          = GetStringValue(table, row, "Comments");
                soil.NaturalVegetation = GetStringValue(table, row, "NaturalVegetation");
                soil.RecordNumber      = GetIntegerValue(table, row, "RecordNo");

                var physical = new Physical();
                soil.Children.Add(physical);
                physical.Thickness                = MathUtilities.RemoveMissingValuesFromBottom(GetDoubleValues(table, "Thickness (mm)", row, numLayers));
                physical.BD                       = GetDoubleValues(table, "BD", row, numLayers);
                physical.BDMetadata               = GetCodeValues(table, "BDCode", row, numLayers);
                physical.SAT                      = GetDoubleValues(table, "SAT (mm/mm)", row, numLayers);
                physical.SATMetadata              = GetCodeValues(table, "SATCode", row, numLayers);
                physical.DUL                      = GetDoubleValues(table, "DUL (mm/mm)", row, numLayers);
                physical.DULMetadata              = GetCodeValues(table, "DULCode", row, numLayers);
                physical.LL15                     = GetDoubleValues(table, "LL15 (mm/mm)", row, numLayers);
                physical.LL15Metadata             = GetCodeValues(table, "LL15Code", row, numLayers);
                physical.AirDry                   = GetDoubleValues(table, "Airdry (mm/mm)", row, numLayers);
                physical.AirDryMetadata           = GetCodeValues(table, "AirdryCode", row, numLayers);
                physical.KS                       = GetDoubleValues(table, "KS (mm/day)", row, numLayers);
                physical.KSMetadata               = GetCodeValues(table, "KSCode", row, numLayers);
                physical.Rocks                    = GetDoubleValues(table, "Rocks (%)", row, numLayers);
                physical.RocksMetadata            = GetCodeValues(table, "RocksCode", row, numLayers);
                physical.Texture                  = GetStringValues(table, "Texture", row, numLayers);
                physical.TextureMetadata          = GetCodeValues(table, "TextureCode", row, numLayers);
                physical.ParticleSizeSand         = GetDoubleValues(table, "ParticleSizeSand (%)", row, numLayers);
                physical.ParticleSizeSandMetadata = GetCodeValues(table, "ParticleSizeSandCode", row, numLayers);
                physical.ParticleSizeSilt         = GetDoubleValues(table, "ParticleSizeSilt (%)", row, numLayers);
                physical.ParticleSizeSiltMetadata = GetCodeValues(table, "ParticleSizeSiltCode", row, numLayers);
                physical.ParticleSizeClay         = GetDoubleValues(table, "ParticleSizeClay (%)", row, numLayers);
                physical.ParticleSizeClayMetadata = GetCodeValues(table, "ParticleSizeClayCode", row, numLayers);

                var soilWater = new WaterBalance();
                soilWater.ResourceName = "WaterBalance";
                soil.Children.Add(soilWater);
                soilWater.Thickness   = physical.Thickness;
                soilWater.SummerU     = GetDoubleValue(table, row, "SummerU");
                soilWater.SummerCona  = GetDoubleValue(table, row, "SummerCona");
                soilWater.WinterU     = GetDoubleValue(table, row, "WinterU");
                soilWater.WinterCona  = GetDoubleValue(table, row, "WinterCona");
                soilWater.SummerDate  = GetStringValue(table, row, "SummerDate");
                soilWater.WinterDate  = GetStringValue(table, row, "WinterDate");
                soilWater.Salb        = GetDoubleValue(table, row, "Salb");
                soilWater.DiffusConst = GetDoubleValue(table, row, "DiffusConst");
                soilWater.DiffusSlope = GetDoubleValue(table, row, "DiffusSlope");
                soilWater.CN2Bare     = GetDoubleValue(table, row, "Cn2Bare");
                soilWater.CNRed       = GetDoubleValue(table, row, "CnRed");
                soilWater.CNCov       = GetDoubleValue(table, row, "CnCov");
                soilWater.SWCON       = GetDoubleValues(table, "SWCON (0-1)", row, numLayers);

                var organic = new Organic();
                soil.Children.Add(organic);
                organic.Thickness      = physical.Thickness;
                organic.FOMCNRatio     = GetDoubleValue(table, row, "RootCN");
                organic.FOM            = MathUtilities.CreateArrayOfValues(GetDoubleValue(table, row, "RootWt"), numLayers);
                organic.SoilCNRatio    = GetDoubleValues(table, "SoilCN", row, numLayers);
                organic.FBiom          = GetDoubleValues(table, "FBIOM (0-1)", row, numLayers);
                organic.FInert         = GetDoubleValues(table, "FINERT (0-1)", row, numLayers);
                organic.Carbon         = GetDoubleValues(table, "OC", row, numLayers);
                organic.CarbonMetadata = GetCodeValues(table, "OCCode", row, numLayers);

                var chemical = new Chemical();
                soil.Children.Add(chemical);
                chemical.Thickness   = physical.Thickness;
                chemical.EC          = GetDoubleValues(table, "EC (1:5 dS/m)", row, numLayers);
                chemical.ECMetadata  = GetCodeValues(table, "ECCode", row, numLayers);
                chemical.PH          = GetDoubleValues(table, "PH", row, numLayers);
                chemical.PHMetadata  = GetCodeValues(table, "PHCode", row, numLayers);
                chemical.CL          = GetDoubleValues(table, "CL (mg/kg)", row, numLayers);
                chemical.CLMetadata  = GetCodeValues(table, "CLCode", row, numLayers);
                chemical.ESP         = GetDoubleValues(table, "ESP (%)", row, numLayers);
                chemical.ESPMetadata = GetCodeValues(table, "ESPCode", row, numLayers);

                // Add in some necessary models.
                var soilTemp = new CERESSoilTemperature();
                soilTemp.Name = "Temperature";
                soil.Children.Add(soilTemp);
                var nutrient = new Nutrients.Nutrient();
                nutrient.ResourceName = "Nutrient";
                soil.Children.Add(nutrient);
                var initialWater = new InitialWater();
                soil.Children.Add(initialWater);

                // crops
                foreach (DataColumn Col in table.Columns)
                {
                    if (Col.ColumnName.ToLower().Contains(" ll"))
                    {
                        var nameBits = Col.ColumnName.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                        if (nameBits.Length == 3)
                        {
                            string   cropName = nameBits[0];
                            SoilCrop crop     = new SoilCrop();
                            crop.Name       = cropName + "Soil";
                            crop.LL         = GetDoubleValues(table, cropName + " ll (mm/mm)", row, numLayers);
                            crop.LLMetadata = GetCodeValues(table, cropName + " llCode", row, numLayers);
                            crop.KL         = GetDoubleValues(table, cropName + " kl (/day)", row, numLayers);
                            crop.XF         = GetDoubleValues(table, cropName + " xf (0-1)", row, numLayers);
                            if (MathUtilities.ValuesInArray(crop.LL) ||
                                MathUtilities.ValuesInArray(crop.KL))
                            {
                                physical.Children.Add(crop);
                            }
                        }
                    }
                }

                soils.Add(soil);

                row += numLayers;
            }

            return(soils);
        }
Exemple #5
0
            /// <summary>Constructor</summary>
            /// <param name="soil">The soil in the zone.</param>
            /// <param name="depth">Root depth (mm)</param>
            /// <param name="initialDM">Initial dry matter</param>
            /// <param name="population">plant population</param>
            /// <param name="maxNConc">maximum n concentration</param>
            public ZoneState(Soil soil, double depth, double initialDM, double population, double maxNConc)
            {
                this.soil = soil;

                Clear();
                Zone zone = Apsim.Parent(soil, typeof(Zone)) as Zone;
                if (zone == null)
                    throw new Exception("Soil " + soil + " is not in a zone.");
                Name = zone.Name;
                Initialise(depth, initialDM, population, maxNConc);
            }