Skip to content

Commit

Permalink
Merge pull request #54 from HamishBrownPFR/CropStageTests
Browse files Browse the repository at this point in the history
Fixes to N schedule.  Dont apply rainfall modifiers after today, increment version
  • Loading branch information
HamishBrownPFR authored Jun 9, 2024
2 parents 496ecd6 + a441009 commit ed6db7e
Show file tree
Hide file tree
Showing 25 changed files with 89 additions and 96 deletions.
Binary file modified SVSModel.Excel/TestingFiles/Darians.xlsm
Binary file not shown.
Binary file modified SVSModel.Excel/TestingFiles/Obama.xlsm
Binary file not shown.
Binary file modified SVSModel.Excel/TestingFiles/Wallies.xlsm
Binary file not shown.
2 changes: 1 addition & 1 deletion SVSModel/Configuration/Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public static Dictionary<DateTime, double> ApplyRainfallFactor(Dictionary<DateTi
foreach (DateTime d in meanRain.Keys)
{
double todayRain = meanRain[d];
if ((d>= config.Current.EstablishDate) && (d<= config.Current.HarvestDate))
if ((d>= config.Current.EstablishDate) && (d<= config.Current.HarvestDate) && (d<=DateTime.Today))
todayRain *= config.Field.InCropRainFactor;
adjustedmeanRain.Add(d, todayRain);
}
Expand Down
2 changes: 1 addition & 1 deletion SVSModel/Data/CropCoefficientTableFull.csv
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Wong bok Vegetable General,50,Vegetable,Green,Wong bok,General,Brassicaceae,Bras
Bean Vegetable General,65,Vegetable,Pulse,Bean,General,Fabaceae ,Phaseolus,vulgaris,,Phaseolus vulgaris ,vulgaris ,Seed,Nov,EarlyReproductive,Mar,18,t/ha,Saleable product ,1,Total,0,0,0.44,0.07,89,0.1,1,0.9,1,1.5,2.5,2.8,150,5
Broad bean Vegetable General,69,Vegetable,Pulse,Broad bean,General,Fabaceae ,Vicia,faba,,Vicia faba ,faba ,Seed,May,EarlyReproductive,Nov,11,t/ha,Saleable product ,1,Total,0,0,0.3,0.05,76,0.1,1,0.9,1,1.5,1.7,4.4,75,0
Pea Vegetable General,66,Vegetable,Pulse,Pea,General,Fabaceae ,Pisum,sativum,,Pisum sativum ,sativum ,Seed,Aug,EarlyReproductive,Jan,10,t/ha,Saleable product ,1,Total,0,0,0.34,0.08,77,0.1,0.7,1,1,1.5,2.1,4,150,5
Carrot Vegetable Fresh,59,Vegetable,Root,Carrot,Fresh,Apiaceae ,Daucus,carota,,Daucus carota ,carota ,Seed,Oct,EarlyReproductive,Jun,174,t/ha,Saleable product ,1,Total,0,0,0.88,0.07,89,0.1,1.2,0.9,0.7,0.9,1.2,0.8,150,5
Carrot Vegetable Fresh,59,Vegetable,Root,Carrot,Fresh,Apiaceae ,Daucus,carota,,Daucus carota ,carota ,Seed,Oct,EarlyReproductive,Jun,100,t/ha,Saleable product ,1,Total,0,0,0.88,0.07,89,0.1,1.2,0.9,0.7,0.9,1.2,1.5,150,5
Carrot Vegetable Juicing,57,Vegetable,Root,Carrot,Juicing,Apiaceae ,Daucus,carota,,Daucus carota ,carota ,Seed,Oct,EarlyReproductive,Jun,130,t/ha,Saleable product ,1,Total,0,0,0.86,0.07,88,0.1,1.2,0.9,0.7,0.9,1,1.4,150,5
Carrot Vegetable Processing,58,Vegetable,Root,Carrot,Processing,Apiaceae ,Daucus,carota,,Daucus carota ,carota ,Seed,Oct,EarlyReproductive,Jun,100,t/ha,Saleable product ,1,Total,0,0,0.8,0.07,88,0.1,1.2,0.9,0.7,0.9,1.3,1.6,150,5
Garlic Vegetable General,39,Vegetable,Root,Garlic,General,Amaryllidaceae,Allium,sativum,,Allium sativum ,sativum ,Seed,Jun,Vegetative,Dec,50,t/ha,Saleable product ,1,Total,0,0,0.88,0,87,0.1,0.6,0.7,0.6,1,1.35,1.4,500,5
Expand Down
Binary file modified SVSModel/Data/Observed crop parameters.xlsx
Binary file not shown.
10 changes: 6 additions & 4 deletions SVSModel/Models/Fertiliser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public static void RemainingFertiliserSchedule(DateTime startSchedulleDate,DateT
// Determine dates that each fertiliser application should be made
foreach (DateTime d in schedullingDates)
{
if (thisSim.SoilN[d] < thisSim.NUptake[d]*10)
double trigger = thisSim.NUptake[d] * 10;
if (thisSim.SoilN[d] < trigger)
{
double initialN = thisSim.SoilN[d];
double initialLossEst = thisSim.NLost[d];
Expand All @@ -74,7 +75,7 @@ public static void RemainingFertiliserSchedule(DateTime startSchedulleDate,DateT
for (int passes = 0; passes < 50; passes++)
{
double lastPassLossEst = losses;
double remainingReqN = remainingRequirement(d, endScheduleDate, thisSim) + losses;
double remainingReqN = remainingRequirement(d, endScheduleDate, thisSim, trigger) + losses;
NAppn = remainingReqN / remainingSplits;
SoilNitrogen.UpdateBalance(d, NAppn, initialN, initialLossEst, ref thisSim, true, new Dictionary<DateTime, double>(),true);
losses = anticipatedLosses(d, endScheduleDate, thisSim.NLost);
Expand All @@ -89,12 +90,13 @@ public static void RemainingFertiliserSchedule(DateTime startSchedulleDate,DateT
}
}

private static double remainingRequirement(DateTime startDate, DateTime endDate, SimulationType thisSim)
private static double remainingRequirement(DateTime startDate, DateTime endDate, SimulationType thisSim, double trigger)
{
double remainingCropN = thisSim.CropN[endDate] - thisSim.CropN[startDate];
DateTime[] remainingDates = Functions.DateSeries(startDate, endDate);
double remainingOrgN = remainingMineralisation(remainingDates, thisSim.NResidues, thisSim.NSoilOM);
return Math.Max(0, remainingCropN - remainingOrgN);
double surplussMineralN = Math.Max(0, trigger - Constants.Trigger);
return Math.Max(0, remainingCropN - remainingOrgN - surplussMineralN);
}

private static double remainingMineralisation(DateTime[] remainingDates, Dictionary<DateTime, double> residueMin, Dictionary<DateTime, double> somN)
Expand Down
2 changes: 1 addition & 1 deletion SVSModel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ $ dotnet pack SVSModel/SVSModel.csproj
```

```bash
$ dotnet nuget push SVSModel/bin/Release/SVSModel.1.1.19.nupkg --source "https://pkgs.dev.azure.com/rezaresystems/48ae16c6-5f20-44a0-ad41-e047c311de0a/_packaging/svs-model-calculator/nuget/v3/index.json" --api-key az --interactive
$ dotnet nuget push SVSModel/bin/Release/SVSModel.1.1.20.nupkg --source "https://pkgs.dev.azure.com/rezaresystems/48ae16c6-5f20-44a0-ad41-e047c311de0a/_packaging/svs-model-calculator/nuget/v3/index.json" --api-key az --interactive
```
2 changes: 1 addition & 1 deletion SVSModel/SVSModel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<id>SVSModel</id>
<version>1.1.19</version>
<version>1.1.20</version>
<authors>PotatoesNZ</authors>
<description>A wrapper of the SVS Model code</description>
<LangVersion>12</LangVersion>
Expand Down
4 changes: 2 additions & 2 deletions TestGraphs/MakeGraphs/CropStage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
"plt.text(0.05,0.95,\"Crop Cover with different Establish and Harvest Stages\",fontsize = 16,transform=ax.transAxes)\n",
"Graph.tight_layout(pad=1.5)\n",
"plt.ylim(0,1.1)\n",
"plt.savefig(os.path.join(outPath,'CropStage_Cover.png'))"
"plt.savefig(os.path.join(outPath,'3-CropStage_Cover.png'))"
]
},
{
Expand Down Expand Up @@ -223,7 +223,7 @@
"ax.xaxis.set_major_formatter(mdates.DateFormatter('%#d-%b'))\n",
"plt.text(0.05,0.95,\"NUptake With different establish and harvest stages\",fontsize = 16,transform=ax.transAxes)\n",
"Graph.tight_layout(pad=1.5)\n",
"plt.savefig(os.path.join(outPath,'CropStage_NUptake.png'))"
"plt.savefig(os.path.join(outPath,'3-CropStage_NUptake.png'))"
]
}
],
Expand Down
4 changes: 2 additions & 2 deletions TestGraphs/MakeGraphs/CropStage.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
plt.text(0.05,0.95,"Crop Cover with different Establish and Harvest Stages",fontsize = 16,transform=ax.transAxes)
Graph.tight_layout(pad=1.5)
plt.ylim(0,1.1)
plt.savefig(os.path.join(outPath,'CropStage_Cover.png'))
plt.savefig(os.path.join(outPath,'3-CropStage_Cover.png'))

Graph = plt.figure()
ax = Graph.add_subplot(1,1,1)
Expand All @@ -115,4 +115,4 @@
ax.xaxis.set_major_formatter(mdates.DateFormatter('%#d-%b'))
plt.text(0.05,0.95,"NUptake With different establish and harvest stages",fontsize = 16,transform=ax.transAxes)
Graph.tight_layout(pad=1.5)
plt.savefig(os.path.join(outPath,'CropStage_NUptake.png'))
plt.savefig(os.path.join(outPath,'3-CropStage_NUptake.png'))
28 changes: 14 additions & 14 deletions TestGraphs/MakeGraphs/Location.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 51,
"execution_count": 1,
"id": "dff73729",
"metadata": {
"lines_to_next_cell": 0
Expand All @@ -16,7 +16,7 @@
},
{
"cell_type": "code",
"execution_count": 52,
"execution_count": 2,
"id": "947e15c7-df18-40c1-a19d-516e8ffa9e1f",
"metadata": {
"tags": []
Expand Down Expand Up @@ -53,7 +53,7 @@
},
{
"cell_type": "code",
"execution_count": 53,
"execution_count": 3,
"id": "895d2401-790a-4eb7-be02-b68765e9894e",
"metadata": {
"tags": []
Expand Down Expand Up @@ -91,7 +91,7 @@
},
{
"cell_type": "code",
"execution_count": 54,
"execution_count": 4,
"id": "9623d5e0-0390-4260-9c1a-f65266479f41",
"metadata": {
"tags": []
Expand All @@ -118,7 +118,7 @@
},
{
"cell_type": "code",
"execution_count": 55,
"execution_count": 5,
"id": "c4d5536a-41b0-4141-89c9-e48de4177223",
"metadata": {
"tags": []
Expand All @@ -145,7 +145,7 @@
},
{
"cell_type": "code",
"execution_count": 56,
"execution_count": 6,
"id": "09cdd07b-c2f8-493c-b7d6-a73779f5e531",
"metadata": {},
"outputs": [],
Expand All @@ -156,7 +156,7 @@
},
{
"cell_type": "code",
"execution_count": 57,
"execution_count": 7,
"id": "78701dd5-d75a-4f00-965a-6e0a1812a25c",
"metadata": {
"tags": []
Expand Down Expand Up @@ -186,12 +186,12 @@
"ax.xaxis.set_major_formatter(mdates.DateFormatter('%#d-%b'))\n",
"plt.text(0.05,0.9,\"Locational residue mineralisation tests\",fontsize = 16,transform=ax.transAxes)\n",
"Graph.tight_layout(pad=1.5)\n",
"plt.savefig(os.path.join(outPath,'Location_Residues.png'))"
"plt.savefig(os.path.join(outPath,'7-Location_Residues.png'))"
]
},
{
"cell_type": "code",
"execution_count": 58,
"execution_count": 8,
"id": "389e4bfe-7bd8-4e7b-8a9c-81c10884586a",
"metadata": {
"tags": []
Expand Down Expand Up @@ -221,12 +221,12 @@
"ax.xaxis.set_major_formatter(mdates.DateFormatter('%#d-%b'))\n",
"plt.text(0.05,0.9,\"Locational SOM mineralisation tests\",fontsize = 16,transform=ax.transAxes)\n",
"Graph.tight_layout(pad=1.5)\n",
"plt.savefig(os.path.join(outPath,'Location_SOM.png'))"
"plt.savefig(os.path.join(outPath,'7-Location_SOM.png'))"
]
},
{
"cell_type": "code",
"execution_count": 59,
"execution_count": 9,
"id": "256c9ae1-7379-47f7-b53d-690655dc82c9",
"metadata": {
"tags": []
Expand Down Expand Up @@ -256,12 +256,12 @@
"ax.xaxis.set_major_formatter(mdates.DateFormatter('%#d-%b'))\n",
"plt.text(0.05,0.9,\"Locational cover tests\",fontsize = 16,transform=ax.transAxes)\n",
"Graph.tight_layout(pad=1.5)\n",
"plt.savefig(os.path.join(outPath,'Location_Cover.png'))"
"plt.savefig(os.path.join(outPath,'7-Location_Cover.png'))"
]
},
{
"cell_type": "code",
"execution_count": 60,
"execution_count": 10,
"id": "fde90ecc-7545-440f-962d-f28fdfb9b7ea",
"metadata": {
"tags": []
Expand Down Expand Up @@ -291,7 +291,7 @@
"ax.xaxis.set_major_formatter(mdates.DateFormatter('%#d-%b'))\n",
"plt.text(0.05,0.9,\"Locational CropN tests\",fontsize = 16,transform=ax.transAxes)\n",
"Graph.tight_layout(pad=1.5)\n",
"plt.savefig(os.path.join(outPath,'Location_CropN.png'))"
"plt.savefig(os.path.join(outPath,'7-Location_CropN.png'))"
]
}
],
Expand Down
8 changes: 4 additions & 4 deletions TestGraphs/MakeGraphs/Location.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
ax.xaxis.set_major_formatter(mdates.DateFormatter('%#d-%b'))
plt.text(0.05,0.9,"Locational residue mineralisation tests",fontsize = 16,transform=ax.transAxes)
Graph.tight_layout(pad=1.5)
plt.savefig(os.path.join(outPath,'Location_Residues.png'))
plt.savefig(os.path.join(outPath,'7-Location_Residues.png'))

Graph = plt.figure()
ax = Graph.add_subplot(1,1,1)
Expand All @@ -113,7 +113,7 @@
ax.xaxis.set_major_formatter(mdates.DateFormatter('%#d-%b'))
plt.text(0.05,0.9,"Locational SOM mineralisation tests",fontsize = 16,transform=ax.transAxes)
Graph.tight_layout(pad=1.5)
plt.savefig(os.path.join(outPath,'Location_SOM.png'))
plt.savefig(os.path.join(outPath,'7-Location_SOM.png'))

Graph = plt.figure()
ax = Graph.add_subplot(1,1,1)
Expand All @@ -127,7 +127,7 @@
ax.xaxis.set_major_formatter(mdates.DateFormatter('%#d-%b'))
plt.text(0.05,0.9,"Locational cover tests",fontsize = 16,transform=ax.transAxes)
Graph.tight_layout(pad=1.5)
plt.savefig(os.path.join(outPath,'Location_Cover.png'))
plt.savefig(os.path.join(outPath,'7-Location_Cover.png'))

Graph = plt.figure()
ax = Graph.add_subplot(1,1,1)
Expand All @@ -141,4 +141,4 @@
ax.xaxis.set_major_formatter(mdates.DateFormatter('%#d-%b'))
plt.text(0.05,0.9,"Locational CropN tests",fontsize = 16,transform=ax.transAxes)
Graph.tight_layout(pad=1.5)
plt.savefig(os.path.join(outPath,'Location_CropN.png'))
plt.savefig(os.path.join(outPath,'7-Location_CropN.png'))
16 changes: 8 additions & 8 deletions TestGraphs/MakeGraphs/Losses.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 8,
"id": "ddbd7173",
"metadata": {
"lines_to_next_cell": 0
Expand All @@ -16,7 +16,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 9,
"id": "947e15c7-df18-40c1-a19d-516e8ffa9e1f",
"metadata": {
"tags": []
Expand Down Expand Up @@ -53,7 +53,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 10,
"id": "895d2401-790a-4eb7-be02-b68765e9894e",
"metadata": {
"tags": []
Expand Down Expand Up @@ -91,7 +91,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 11,
"id": "9623d5e0-0390-4260-9c1a-f65266479f41",
"metadata": {
"tags": []
Expand All @@ -118,7 +118,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 12,
"id": "c4d5536a-41b0-4141-89c9-e48de4177223",
"metadata": {
"tags": []
Expand All @@ -137,7 +137,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 13,
"id": "db4bd35f-34b9-4ddd-9287-4ddc065b7753",
"metadata": {
"tags": []
Expand All @@ -162,7 +162,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 14,
"id": "d83f8538-907f-4763-9988-6311d8209eef",
"metadata": {
"tags": []
Expand Down Expand Up @@ -198,7 +198,7 @@
" plt.xticks(rotation=60)\n",
" pos+=1\n",
"Graph.tight_layout(pad=1.5) \n",
"plt.savefig(os.path.join(outPath,'Losses.png')) "
"plt.savefig(os.path.join(outPath,'5-Losses.png')) "
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion TestGraphs/MakeGraphs/Losses.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@
plt.xticks(rotation=60)
pos+=1
Graph.tight_layout(pad=1.5)
plt.savefig(os.path.join(outPath,'Losses.png'))
plt.savefig(os.path.join(outPath,'5-Losses.png'))
10 changes: 5 additions & 5 deletions TestGraphs/MakeGraphs/Moisture.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
"ax.xaxis.set_major_formatter(mdates.DateFormatter('%#d-%b'))\n",
"plt.text(0.05,0.9,\"Moisture SWC tests\",fontsize = 16,transform=ax.transAxes)\n",
"Graph.tight_layout(pad=1.5)\n",
"plt.savefig(os.path.join(outPath,'Moisture_SWC.png'))"
"plt.savefig(os.path.join(outPath,'6-Moisture_SWC.png'))"
]
},
{
Expand Down Expand Up @@ -263,7 +263,7 @@
"ax.xaxis.set_major_formatter(mdates.DateFormatter('%#d-%b'))\n",
"plt.text(0.05,0.9,\"Moisture SOM mineralisation tests\",fontsize = 16,transform=ax.transAxes)\n",
"Graph.tight_layout(pad=1.5)\n",
"plt.savefig(os.path.join(outPath,'Moisture_SOM.png'))"
"plt.savefig(os.path.join(outPath,'6-Moisture_SOM.png'))"
]
},
{
Expand Down Expand Up @@ -298,7 +298,7 @@
"ax.xaxis.set_major_formatter(mdates.DateFormatter('%#d-%b'))\n",
"plt.text(0.05,0.9,\"Moisture SOM mineralisation tests\",fontsize = 16,transform=ax.transAxes)\n",
"Graph.tight_layout(pad=1.5)\n",
"plt.savefig(os.path.join(outPath,'Moisture_redisue.png'))"
"plt.savefig(os.path.join(outPath,'6-Moisture_redisue.png'))"
]
},
{
Expand Down Expand Up @@ -333,7 +333,7 @@
"ax.xaxis.set_major_formatter(mdates.DateFormatter('%#d-%b'))\n",
"plt.text(0.05,0.9,\"Moisture drainage tests\",fontsize = 16,transform=ax.transAxes)\n",
"Graph.tight_layout(pad=1.5)\n",
"plt.savefig(os.path.join(outPath,'Moisture_Drianage.png'))"
"plt.savefig(os.path.join(outPath,'6-Moisture_Drianage.png'))"
]
},
{
Expand Down Expand Up @@ -368,7 +368,7 @@
"ax.xaxis.set_major_formatter(mdates.DateFormatter('%#d-%b'))\n",
"plt.text(0.05,0.9,\"Locational CropN tests\",fontsize = 16,transform=ax.transAxes)\n",
"Graph.tight_layout(pad=1.5)\n",
"plt.savefig(os.path.join(outPath,'Moisture_CropN.png'))"
"plt.savefig(os.path.join(outPath,'6-Moisture_CropN.png'))"
]
}
],
Expand Down
Loading

0 comments on commit ed6db7e

Please sign in to comment.