Skip to content

Commit

Permalink
Merge pull request #57 from RezareSystems/main
Browse files Browse the repository at this point in the history
Chore: Update Model Nuget Package
  • Loading branch information
HamishBrownPFR authored Jun 12, 2024
2 parents c24802c + aa236c0 commit d1275c1
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 66 deletions.
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.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
$ dotnet nuget push SVSModel/bin/Release/SVSModel.1.1.21.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.20</version>
<version>1.1.21</version>
<authors>PotatoesNZ</authors>
<description>A wrapper of the SVS Model code</description>
<LangVersion>12</LangVersion>
Expand Down
167 changes: 103 additions & 64 deletions SVSModel/Simulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,14 @@ public class Simulation
/// <param name="config">A specific class that holds all the simulation configuration data in the correct types for use in the model</param>
/// <returns>A 2D array of N balance variables</returns>
public static object[,] SimulateField(Dictionary<DateTime, double> meanT,
Dictionary<DateTime, double> meanRain,
Dictionary<DateTime, double> meanPET,
Dictionary<DateTime, double> testResults,
Dictionary<DateTime, double> nAapplied,
Config config,
double initialN,
bool ScheduleFert = true)
Dictionary<DateTime, double> meanRain,
Dictionary<DateTime, double> meanPET,
Dictionary<DateTime, double> testResults,
Dictionary<DateTime, double> nAapplied,
Config config,
double initialN,
bool ScheduleFert = true)
{


DateTime[] simDates = Functions.DateSeries(config.StartDate.AddDays(-1), config.EndDate);

thisSim = new SimulationType(simDates, config, meanT, meanRain, meanPET);
Expand Down Expand Up @@ -61,14 +59,16 @@ public class Simulation
if (d == crop.HarvestDate)
thisSim.ExportN[d.AddDays(1)] = currentCrop.TotalCropN[d];
}

currentCrop.TotalNDemand = currentCrop.TotalCropN;
}

crop.SimResults = currentCrop;
crop.ResRoot = crop.SimResults.RootN[crop.HarvestDate];
crop.ResStover = crop.SimResults.StoverN[crop.HarvestDate];
crop.ResFieldLoss = crop.SimResults.FieldLossN[crop.HarvestDate];
crop.NUptake = crop.SimResults.TotalCropN[crop.HarvestDate];
crop.NDemand = crop.SimResults.TotalNDemand[crop.HarvestDate];
crop.NDemand = crop.SimResults.TotalNDemand[crop.HarvestDate];
}

// Calculate soil water content and drainage
Expand Down Expand Up @@ -125,22 +125,17 @@ private static void doNbalanceSummary(ref SimulationType thisSim)
DateTime End = thisSim.config.Current.HarvestDate;

CropNBalanceSummary CurrentNBalanceSummary = new CropNBalanceSummary(
mineralIn: Constants.InitialN,
cropIn: Functions.sumOverDates(Start, End, thisSim.NTransPlant),
residueIn: Functions.sumOverDates(Start, End, thisSim.NResidues),
sOMIn: Functions.sumOverDates(Start, End, thisSim.NSoilOM),
fertiliserIn: Functions.sumOverDates(Start, End, thisSim.NFertiliser),
minearlOut: thisSim.SoilN[End],
productOut: thisSim.ProductN[End],
stoverOut: thisSim.CropN[End] - thisSim.ProductN[End],
lossesOut: Functions.sumOverDates(Start, End, thisSim.NLost));
mineralIn: Constants.InitialN,
cropIn: Functions.sumOverDates(Start, End, thisSim.NTransPlant),
residueIn: Functions.sumOverDates(Start, End, thisSim.NResidues),
sOMIn: Functions.sumOverDates(Start, End, thisSim.NSoilOM),
fertiliserIn: Functions.sumOverDates(Start, End, thisSim.NFertiliser),
mineralOut: thisSim.SoilN[End],
productOut: thisSim.ProductN[End],
stoverOut: thisSim.CropN[End] - thisSim.ProductN[End],
lossesOut: Functions.sumOverDates(Start, End, thisSim.NLost));
thisSim.CurrentNBalanceSummary = CurrentNBalanceSummary;

}




}

public class SimulationType
Expand Down Expand Up @@ -168,10 +163,12 @@ public class SimulationType
public Dictionary<DateTime, double> CropShortageN;
public CropNBalanceSummary CurrentNBalanceSummary;

public SimulationType(DateTime[] _simDates, Config _config,
Dictionary<DateTime, double> _meanT,
Dictionary<DateTime, double> _meanRain,
Dictionary<DateTime, double> _meanPET)
public SimulationType(
DateTime[] _simDates,
Config _config,
Dictionary<DateTime, double> _meanT,
Dictionary<DateTime, double> _meanRain,
Dictionary<DateTime, double> _meanPET)
{
config = _config;
simDates = _simDates;
Expand Down Expand Up @@ -204,68 +201,110 @@ public class CropNBalanceSummary
public double ResidueIn { get; }
public double SOMIn { get; }
public double FertiliserIn { get; }
public double UncharacterisedIn { get { return Math.Max(0, Outs - Ins); } }

public double UncharacterisedIn
{
get { return Math.Max(0, Outs - Ins); }
}

/// Out
public double MinearlOut { get; }

public double ProductOut { get; }
public double StoverOut { get; }
public double LossesOut { get; }
public double UncharacterisedOut { get { return Math.Max(0,Ins-Outs); } }

public double Ins { get { return MineralIn + CropIn + ResidueIn + SOMIn + FertiliserIn; } }
public double Outs { get { return MinearlOut + ProductOut+ StoverOut + LossesOut; } }
public double UncharacterisedOut
{
get { return Math.Max(0, Ins - Outs); }
}

public double Ins
{
get { return MineralIn + CropIn + ResidueIn + SOMIn + FertiliserIn; }
}

public double Outs
{
get { return MinearlOut + ProductOut + StoverOut + LossesOut; }
}

public double balance { get { return Ins - Outs; } }
public double balance
{
get { return Ins - Outs; }
}

public CropNBalanceSummary(double mineralIn, double cropIn, double residueIn, double sOMIn, double fertiliserIn,
double minearlOut, double productOut, double stoverOut, double lossesOut)
double mineralOut, double productOut, double stoverOut, double lossesOut)
{
MineralIn = mineralIn;
CropIn = cropIn;
ResidueIn = residueIn;
SOMIn = sOMIn;
ResidueIn = residueIn;
SOMIn = sOMIn;
FertiliserIn = fertiliserIn;
MinearlOut = minearlOut;
MinearlOut = mineralOut;
ProductOut = productOut;
StoverOut = stoverOut;
LossesOut = lossesOut;
}
}

public class NBalanceSummary
{
public Dictionary<string,int> Mineral { get; }
public Dictionary<string,int> CropProduct { get;}
public Dictionary<string ,int> OtherCropParts { get;}
{
public Dictionary<string, int> Mineral { get; }
public Dictionary<string, int> CropProduct { get; }
public Dictionary<string, int> OtherCropParts { get; }
public Dictionary<string, int> SoilOrganic { get; }
public Dictionary<string, int> Residues { get; }
public Dictionary<string, int> Fertiliser { get;}
public Dictionary<string, int> Fertiliser { get; }
public Dictionary<string, int> UnCharacterised { get; }
public Dictionary <string, int> Total { get;}
public Dictionary<string, int> Total { get; }

public NBalanceSummary(CropNBalanceSummary nBalance)
{
double resMin = Math.Max(0, nBalance.ResidueIn);
double resImob = Math.Max(0, -nBalance.ResidueIn);
double unCharOut = nBalance.UncharacterisedOut + nBalance.LossesOut;
Mineral = new Dictionary<string, int> { { "In", (int)Math.Round(nBalance.MineralIn,0) },
{ "Out", (int)Math.Round(nBalance.MinearlOut,0) } };
CropProduct = new Dictionary<string, int> { { "In", 0 },
{ "Out", (int)Math.Round(nBalance.ProductOut,0) } };
OtherCropParts = new Dictionary<string, int> { { "In", (int)Math.Round(nBalance.CropIn, 0) },
{ "Out",(int)Math.Round(nBalance.StoverOut, 0)} };
SoilOrganic = new Dictionary<string, int> { { "In", (int)Math.Round(nBalance.SOMIn, 0) },
{ "Out", 0 }};
Residues = new Dictionary<string, int> { { "In", (int)Math.Round(resMin,0) },
{ "Out", (int)Math.Round(resImob,0) } };
Fertiliser = new Dictionary<string, int> { { "In",(int)Math.Round(nBalance.FertiliserIn,0) },
{ "Out",0 }};
UnCharacterised = new Dictionary<string, int> { { "In", (int)Math.Round(nBalance.UncharacterisedIn, 0) },
{ "Out", (int)Math.Round(unCharOut,0) } };
Total = new Dictionary<string, int> { { "In", (int)Math.Round(nBalance.Ins) },
{ "Out", (int)Math.Round(nBalance.Outs) } };
var resMin = Math.Max(0, nBalance.ResidueIn);
var resImob = Math.Max(0, -nBalance.ResidueIn);
var unCharOut = nBalance.UncharacterisedOut + nBalance.LossesOut;
Mineral = new Dictionary<string, int>
{
{ "In", (int)Math.Round(nBalance.MineralIn, 0) },
{ "Out", (int)Math.Round(nBalance.MinearlOut, 0) }
};
CropProduct = new Dictionary<string, int>
{
{ "In", 0 },
{ "Out", (int)Math.Round(nBalance.ProductOut, 0) }
};
OtherCropParts = new Dictionary<string, int>
{
{ "In", (int)Math.Round(nBalance.CropIn, 0) },
{ "Out", (int)Math.Round(nBalance.StoverOut, 0) }
};
SoilOrganic = new Dictionary<string, int>
{
{ "In", (int)Math.Round(nBalance.SOMIn, 0) },
{ "Out", 0 }
};
Residues = new Dictionary<string, int>
{
{ "In", (int)Math.Round(resMin, 0) },
{ "Out", (int)Math.Round(resImob, 0) }
};
Fertiliser = new Dictionary<string, int>
{
{ "In", (int)Math.Round(nBalance.FertiliserIn, 0) },
{ "Out", 0 }
};
UnCharacterised = new Dictionary<string, int>
{
{ "In", (int)Math.Round(nBalance.UncharacterisedIn, 0) },
{ "Out", (int)Math.Round(unCharOut, 0) }
};
Total = new Dictionary<string, int>
{
{ "In", (int)Math.Round(nBalance.Ins) },
{ "Out", (int)Math.Round(nBalance.Outs) }
};
}

}
}
}

0 comments on commit d1275c1

Please sign in to comment.