Skip to content

Commit

Permalink
ICBM swathing update
Browse files Browse the repository at this point in the history
  • Loading branch information
holos-aafc committed Apr 17, 2024
1 parent 4f9f5e5 commit ccb16c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 38 deletions.
40 changes: 5 additions & 35 deletions H.Core.Test/Calculators/ICBMSoilCarbonCalculatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -548,12 +548,7 @@ public void CalculateAboveGroundInputsForGreenManureHarvestMethod()

// Plant C in agricultural product: Cp = 403.92

// Cag = CptoSoil
// = Cp * (Sp / 100)
// = 403.92 * (2 / 100)
// = 8.0784

Assert.AreEqual(8.0784, currentYearViewItem.AboveGroundCarbonInput);
Assert.AreEqual(7.92, currentYearViewItem.AboveGroundCarbonInput);
}

[TestMethod]
Expand Down Expand Up @@ -593,18 +588,7 @@ public void CalculateBelowGroundInputsForGreenManureHarvestMethod()
nextYearViewItem: null,
farm: farm);

// In the case when an annual crop is used and green manure is specified as harvest method Rp is the sum of the Rp and Rs values.

// Plant C in agricultural product: Cp = 403.92

// Cbg = Cr + Ce
// = [Cp * (Rr / Rp) * (Sr / 100)] + [Cp * (Re / Rp)] *** Rp = 0.5 + 0.2 = 0.7 ***
// = [403.92 * (0.4 / 0.7) * (100 / 100)] + [403.92 * (0.3 / 0.7)]
// = [403.92 * 0.571 * 1] + [403.92 * 0.42857]
// = 230.638 + 172.107
// = 402.754

Assert.AreEqual(402.754, currentYearViewItem.BelowGroundCarbonInput, 3);
Assert.AreEqual(396, currentYearViewItem.BelowGroundCarbonInput, 3);
}

#endregion
Expand Down Expand Up @@ -1405,14 +1389,7 @@ public void CalculateAboveGroundCarbonInputFromCoverCropsWhenCoverCropIsUsedAsGr
nextYearViewItem: nextYearViewItem,
farm: farm);

// Plant C in agricultural product: Cp = 594

// Cag = CptoSoil *** Cs is omitted in this situation ***
// = Cp * (Sp / 100)
// = 594 * (50 / 100)
// = 297

Assert.AreEqual(297, currentYearViewItem.AboveGroundCarbonInput, 1);
Assert.AreEqual(198, currentYearViewItem.AboveGroundCarbonInput, 1);
}

/// <summary>
Expand Down Expand Up @@ -1455,16 +1432,9 @@ public void CalculateBelowGroundCarbonInputFromCoverCropsWhenCoverCropIsUsedAsGr
currentYearViewItem: currentYearViewItem,
nextYearViewItem: null,
farm: farm);


// Plant C in agricultural product: Cp = 594

// Cbg = Cr + Ce *** Rp is the combined sum of Rp and Rs in this situation. So, Rp = 0.451 + 0.34 = 0.791 ***
// = [Cp * (Rr / Rp) * (Sr / 100)] + [Cp * (Re / Rp)]
// = [594 * (0.126 / 0.791) * 1] + [594 * (0.082 / 0.791)]
// = 94.619 + 61.577
// = 156.196

Assert.AreEqual(156.196, currentYearViewItem.BelowGroundCarbonInput, 3);
Assert.AreEqual(104.131479140329, currentYearViewItem.BelowGroundCarbonInput, 3);
}

/// <summary>
Expand Down
13 changes: 10 additions & 3 deletions H.Core/Calculators/Carbon/ICBMSoilCarbonCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,14 @@ public double CalculatePlantCarbonInAgriculturalProduct(
}
else
{
result = ((currentYearViewItem.Yield + currentYearViewItem.Yield * (currentYearViewItem.PercentageOfProductYieldReturnedToSoil / 100)) * (1 - currentYearViewItem.MoistureContentOfCrop))* currentYearViewItem.CarbonConcentration;
if (currentYearViewItem.HarvestMethod == HarvestMethods.Swathing || currentYearViewItem.HarvestMethod == HarvestMethods.GreenManure)
{
result = ((currentYearViewItem.Yield) * (1 - currentYearViewItem.MoistureContentOfCrop)) * currentYearViewItem.CarbonConcentration;
}
else
{
result = ((currentYearViewItem.Yield + currentYearViewItem.Yield * (currentYearViewItem.PercentageOfProductYieldReturnedToSoil / 100)) * (1 - currentYearViewItem.MoistureContentOfCrop)) * currentYearViewItem.CarbonConcentration;
}
}

return result;
Expand All @@ -208,8 +215,8 @@ public double CalculateTotalAboveGroundCarbonInput(
CropViewItem cropViewItem,
Farm farm)
{
// There are no inputs from straw when the harvest method is green manure
if (cropViewItem.HarvestMethod == HarvestMethods.GreenManure)
// There are no inputs from straw when the harvest method is green manure or swathing
if (cropViewItem.HarvestMethod == HarvestMethods.GreenManure || cropViewItem.HarvestMethod == HarvestMethods.Swathing)
{
return cropViewItem.CarbonInputFromProduct;
}
Expand Down

0 comments on commit ccb16c8

Please sign in to comment.