Skip to content

Commit

Permalink
Fertiliser input.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sasha committed Nov 12, 2023
1 parent 3d3ca1d commit 0b2b34f
Show file tree
Hide file tree
Showing 19 changed files with 379 additions and 830 deletions.
257 changes: 257 additions & 0 deletions Untitled1.ipynb

Large diffs are not rendered by default.

126 changes: 0 additions & 126 deletions modelCsharp/ConsoleAppSVS-test/OutputFiles/test 1.csv

This file was deleted.

126 changes: 0 additions & 126 deletions modelCsharp/ConsoleAppSVS-test/OutputFiles/test 2.csv

This file was deleted.

126 changes: 0 additions & 126 deletions modelCsharp/ConsoleAppSVS-test/OutputFiles/test 3.csv

This file was deleted.

Binary file added modelCsharp/TestModel/Observed/SoilMineralN.xlsx
Binary file not shown.
23 changes: 23 additions & 0 deletions modelCsharp/TestModel/TestModel/FertiliserData.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Site,Date,Nitrogen
8,24/09/2020,46
8,24/09/2020,22
8,15/11/2020,22
8,15/11/2020,16
8,21/11/2020,24
8,20/11/2020,0.75
8,24/11/2020,33.28
8,26/11/2020,54
8,26/11/2020,0.75
8,1/12/2020,24
8,4/12/2020,32
8,12/12/2020,38.4
8,12/12/2020,0.75
8,21/04/2021,8.4
8,3/07/2021,4.2
8,10/09/2021,76
8,26/09/2021,76
8,11/10/2021,76
8,29/09/2022,0.125
8,29/09/2022,0.63
8,30/11/2022,0.39
8,30/11/2022,0.1
70 changes: 62 additions & 8 deletions modelCsharp/TestModel/TestModel/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@
using static IronPython.Modules._ast;
using System.IO;
using CommandLine;
using static IronPython.Modules.PythonDateTime;
using System.Text.RegularExpressions;
using System.Net.Http.Json;
using Microsoft.VisualBasic;
using static IronPython.SQLite.PythonSQLite;


namespace TestModel
{
public class Test
{
/* private static void runPythonScript()
private static void runPythonScript()
{
//that is new with james
//string progToRun = dir + @"/../TestModel/testGraph/testGraph/testGraph.py";
Expand All @@ -41,16 +47,27 @@ public class Test
StreamReader sReader = proc.StandardOutput;
proc.WaitForExit();
Console.ReadLine();
}*/
}
public static void RunTests(Dictionary<string, object> _configDict)

{
string dir = Directory.GetCurrentDirectory();
string resourceName = "TestModel.TestConfig.csv";
string resourceName = "TestModel.actualDataConfig.csv";

// new line
string resourceFertiliser = "TestModel.FertiliserData.csv";

var assembly = Assembly.GetExecutingAssembly();
Stream csv = assembly.GetManifestResourceStream(resourceName);

//new line
Stream csvFertiliser = assembly.GetManifestResourceStream(resourceFertiliser);

DataFrame allTests = DataFrame.LoadCsv(csv);

//new line
DataFrame fertiliser = DataFrame.LoadCsv(csvFertiliser);

List<string> Tests = new List<string>();

foreach (DataFrameRow row in allTests.Rows)
Expand All @@ -66,6 +83,40 @@ public static void RunTests(Dictionary<string, object> _configDict)

Dictionary<DateTime, double> testResults = new Dictionary<DateTime, double>();
Dictionary<DateTime, double> nApplied = new Dictionary<DateTime, double>();

int siteNumber = Int32.Parse(Regex.Match(test, @"\d+").Value);

foreach (DataFrameRow row in fertiliser.Rows)
{

int firstElement = Int32.Parse(row[0].ToString());

DateTime fertDate = Convert.ToDateTime(row[1].ToString());

if (firstElement == siteNumber)

if ((fertDate > _config.Current.EstablishDate) && (fertDate <= _config.Current.HarvestDate))

try
{

if (!nApplied.ContainsKey((DateTime)row[1]))
{
nApplied.Add(fertDate, (Single)row[2]);
}
else
{
nApplied[fertDate]+= (Single)row[2];
}

}

catch (Exception e)
{
Trace.WriteLine(e+"something is not working properly in fertiliser department");

}
}

string weatherStation = allTests["WeatherStation"][testRow].ToString();

Expand Down Expand Up @@ -101,19 +152,23 @@ public static void RunTests(Dictionary<string, object> _configDict)
}
string folderName = "OutputFiles";

if (!Directory.Exists(folderName))
string fertiliserFolder = "NitrogenApplied";

if (!Directory.Exists(folderName) && !Directory.Exists(fertiliserFolder))
{
System.IO.Directory.CreateDirectory("OutputFiles");
System.IO.Directory.CreateDirectory("NitrogenApplied");
}

DataFrame.SaveCsv(newDataframe, dir + "\\OutputFiles\\" + test + ".csv");
DataFrame.SaveCsv(newDataframe, dir + "\\OutputFiles\\" + test + ".csv");
//DataFrame.SaveCsv(newDataframe, dir + "\\NitrogenApplied\\" + test + ".csv");


}
// uncomment it if run is on local machine
//runPythonScript();
runPythonScript();

}

public static SVSModel.Configuration.Config SetConfigFromDataFrame(string test, DataFrame allTests)
{
int testRow = getTestRow(test, allTests);
Expand Down Expand Up @@ -188,7 +243,6 @@ public static SVSModel.Configuration.Config SetConfigFromDataFrame(string test,

return ret;
}

private static int getTestRow(string test, DataFrame allTests)
{
int testRow = 0;
Expand Down
4 changes: 0 additions & 4 deletions modelCsharp/TestModel/TestModel/TestConfig.csv

This file was deleted.

4 changes: 0 additions & 4 deletions modelCsharp/TestModel/TestModel/TestConfigData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@

namespace TestModel
{




public class TestConfigData
{

Expand Down
8 changes: 7 additions & 1 deletion modelCsharp/TestModel/TestModel/TestModel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
</PropertyGroup>

<ItemGroup>
<None Remove="actualDataConfig.csv" />
<None Remove="fert.csv" />
<None Remove="Fertiliser.csv" />
<None Remove="FertiliserData.csv" />
<None Remove="TestConfig.csv" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="TestConfig.csv" />
<EmbeddedResource Include="actualDataConfig.csv" />
<EmbeddedResource Include="FertiliserData.csv" />
</ItemGroup>


Expand All @@ -23,6 +28,7 @@
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="IronPython" Version="3.4.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions modelCsharp/TestModel/TestModel/actualDataConfig.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Property,InitialN,SoilOrder,SampleDepth,BulkDensity,PMNtype,PMN,Trigger,Efficiency,Splits,AWC,PrePlantRain,InCropRain,Irrigation,PriorCropNameFull,PriorSaleableYield,PriorFieldLoss,PriorDressingLoss,PriorMoistureContent,PriorEstablishDate,PriorEstablishYear,PriorEstablishMonth,PriorEstablishDay,PriorEstablishStage,PriorHarvestDate,PriorHarvestYear,PriorHarvestMonth,PriorHarvestDay,PriorHarvestStage,PriorResidueRemoval,PriorResidueIncorporation,CurrentCropNameFull,CurrentSaleableYield,CurrentFieldLoss,CurrentDressingLoss,CurrentMoistureContent,CurrentEstablishDate,CurrentEstablishYear,CurrentEstablishMonth,CurrentEstablishDay,CurrentEstablishStage,CurrentHarvestDate,CurrentHarvestYear,CurrentHarvestMonth,CurrentHarvestDay,CurrentHarvestStage,CurrentResidueRemoval,CurrentResidueIncorporation,FollowingCropNameFull,FollowingSaleableYield,FollowingFieldLoss,FollowingDressingLoss,FollowingMoistureContent,FollowingEstablishDate,FollowingEstablishYear,FollowingEstablishMonth,FollowingEstablishDay,FollowingEstablishStage,FollowingHarvestDate,FollowingHarvestYear,FollowingHarvestMonth,FollowingHarvestDay,FollowingHarvestStage,FollowingResidueRemoval,FollowingResidueIncorporation,WeatherStation
8Wheat,50,Immature Pallic,0-30cm,1.07,PMN,160,30,80,3,148,Typical,Very Dry,Full,Potato Vegetable General,88.4,0,0,30,24/09/2020,2020,9,24,Seed,17/03/2021,2021,3,21,LateReproductive,None removed,Full (Plough),Wheat Grain General,12.7,0,0,30,21/04/2021,2021,4,21,Seed,26/01/2022,2022,1,26,Maturity,Baled,Full (Plough),Pea Grain General,4.7,0,0,30,27/09/2022,2022,9,27,Seed,25/01/2023,2023,1,25,Maturity,None removed,Full (Plough),ashburton
8Peas,50,Immature Pallic,0-30cm,1.22,PMN,120,30,80,3,148,Typical,Very Dry,Full,Wheat Grain General,12.7,0,0,30,21/04/2021,2021,4,21,Seed,26/01/2022,2022,1,26,Maturity,Baled,Full (Plough),Pea Grain General,4.7,0,0,30,27/09/2022,2022,9,27,Seed,25/01/2023,2023,1,25,Maturity,None removed,Full (Plough),Oat Fodder General,10,0,0,40,10/04/2023,2023,4,10,Seed,4/08/2023,2023,8,4,Maturity,None removed,Full (Plough),ashburton
8Oat,50,Immature Pallic,0-30cm,1.31,PMN,80,30,80,3,148,Typical,Very Dry,Full,Pea Grain General,4.7,0,0,30,27/09/2022,2022,9,27,Seed,25/01/2023,2023,1,25,Maturity,None removed,Full (Plough),Oat Fodder General,10,0,0,40,10/04/2023,2023,4,10,Seed,4/08/2023,2023,8,4,Maturity,None removed,Full (Plough),Oat Fodder General,10,0,0,0,1/09/2023,2023,9,1,Seed,1/10/2023,2023,10,1,EarlyReproductive,None removed,Full (Plough),ashburton
30 changes: 0 additions & 30 deletions modelCsharp/TestModel/testGraph/OutputFiles/observed.csv

This file was deleted.

Loading

0 comments on commit 0b2b34f

Please sign in to comment.