small update on DataDownload and GenerelServices
This commit is contained in:
parent
245e82adbc
commit
5da74c2db0
@ -348,7 +348,7 @@ namespace FarmmapsApi.Services
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<Item> FindSatelliteItem(Item cropfieldItem, string satelliteTaskCode) {
|
public async Task<Item> FindSatelliteItem(Item cropfieldItem, string satelliteTaskCode, string FieldName = null, int selectedLayer = 0, bool allItemsStatistics = false, string DownloadFolder = null) {
|
||||||
|
|
||||||
var taskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, satelliteTaskCode);
|
var taskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, satelliteTaskCode);
|
||||||
|
|
||||||
@ -367,6 +367,7 @@ namespace FarmmapsApi.Services
|
|||||||
|
|
||||||
var satelliteTiffs = await _farmmapsApiService.GetItemChildrenAsync(temporalItem.Code);
|
var satelliteTiffs = await _farmmapsApiService.GetItemChildrenAsync(temporalItem.Code);
|
||||||
|
|
||||||
|
if (allItemsStatistics == false) {
|
||||||
_logger.LogInformation("Available satellite images:");
|
_logger.LogInformation("Available satellite images:");
|
||||||
var count = 0;
|
var count = 0;
|
||||||
TimeSpan.FromSeconds(0.5);
|
TimeSpan.FromSeconds(0.5);
|
||||||
@ -383,10 +384,60 @@ namespace FarmmapsApi.Services
|
|||||||
if (selectedSatelliteItem == null) {
|
if (selectedSatelliteItem == null) {
|
||||||
_logger.LogError("Satellite item not found");
|
_logger.LogError("Satellite item not found");
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return selectedSatelliteItem;
|
return selectedSatelliteItem;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allItemsStatistics == true ) {
|
||||||
|
var count = 0;
|
||||||
|
foreach (var item in satelliteTiffs) {
|
||||||
|
var satellitetBand = item.Data["layers"][selectedLayer]["name"];
|
||||||
|
var SatelliteImageYear = (DateTime)item.DataDate;
|
||||||
|
var SatelliteYear = SatelliteImageYear.ToString("yyyy");
|
||||||
|
var SatelliteFile = $"{DownloadFolder}/SatelliteDataStatistics_{SatelliteYear}_{FieldName}_{satellitetBand}.csv";
|
||||||
|
var NewLineField = $"Field,Date,Mean,Min,Max,Standard deviation, ConfidenceInterval low, ConfidenceInterval high" + Environment.NewLine;
|
||||||
|
if (count == 0) {
|
||||||
|
File.AppendAllText(SatelliteFile, NewLineField);
|
||||||
|
var numbervandersat = satelliteTiffs.Count;
|
||||||
|
Console.WriteLine($"{numbervandersat} Satellite images found");
|
||||||
|
}
|
||||||
|
|
||||||
|
var SatelliteStatistics = item.Data["layers"][0]["renderer"]["band"]["statistics"];
|
||||||
|
var SatelliteImageDate = (DateTime)item.DataDate;
|
||||||
|
var satelliteDate = SatelliteImageDate.ToString("yyyy-MM-dd");
|
||||||
|
var NewLineDate = $"\"date\":{satelliteDate}" + Environment.NewLine;
|
||||||
|
if (SatelliteStatistics == null) {
|
||||||
|
Console.WriteLine($"{satelliteDate} no statistics found");
|
||||||
|
//Console.WriteLine($"Available data: {item.Data}");
|
||||||
|
} else {
|
||||||
|
File.AppendAllText(SatelliteFile, $"{FieldName},{satelliteDate},{SatelliteStatistics["mean"]},{SatelliteStatistics["min"]},{SatelliteStatistics["max"]},{SatelliteStatistics["stddev"]},{SatelliteStatistics["confidenceIntervalLow"]},{SatelliteStatistics["confidenceIntervalHigh"]}" + Environment.NewLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
// download the geotiff of needed inputtype
|
||||||
|
var selectedSatelliteItemDate = (DateTime)item.DataDate;
|
||||||
|
var SatelliteDate = selectedSatelliteItemDate.ToString("yyyyMMdd");
|
||||||
|
_logger.LogInformation("Downloading geotiff file");
|
||||||
|
await _farmmapsApiService.DownloadItemAsync(item.Code,
|
||||||
|
Path.Combine(DownloadFolder, $"satelliteGeotiff_{FieldName}_{satellitetBand}_{SatelliteDate}.zip"));
|
||||||
|
}
|
||||||
|
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var selectedSatelliteItemTemp = satelliteTiffs[0];
|
||||||
|
|
||||||
|
if (selectedSatelliteItemTemp == null) {
|
||||||
|
_logger.LogError("Satellite item not found");
|
||||||
|
|
||||||
|
return selectedSatelliteItemTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
return selectedSatelliteItemTemp;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//VanDerSat
|
//VanDerSat
|
||||||
public async Task<string> RunVanDerSatTask(Item cropfieldItem) {
|
public async Task<string> RunVanDerSatTask(Item cropfieldItem) {
|
||||||
|
@ -67,6 +67,7 @@ namespace FarmmapsDataDownload
|
|||||||
var cropYear = input.CropYear;
|
var cropYear = input.CropYear;
|
||||||
var fieldName = input.fieldName;
|
var fieldName = input.fieldName;
|
||||||
bool storeSatelliteStatistics = input.StoreSatelliteStatistics;
|
bool storeSatelliteStatistics = input.StoreSatelliteStatistics;
|
||||||
|
bool storeSatelliteStatisticsCropYear = input.StoreSatelliteStatisticsCropYear;
|
||||||
string settingsfile = $"Settings_{fieldName}.json";
|
string settingsfile = $"Settings_{fieldName}.json";
|
||||||
|
|
||||||
LoadSettings(settingsfile);
|
LoadSettings(settingsfile);
|
||||||
@ -133,19 +134,22 @@ namespace FarmmapsDataDownload
|
|||||||
SaveSettings(settingsfile);
|
SaveSettings(settingsfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select a particular satellite item from satelliteTask
|
|
||||||
Item satalliteItem = await _generalService.FindSatelliteItem(cropfieldItem, _settings.SatelliteTaskCode);
|
|
||||||
int selectedLayer= 2;
|
int selectedLayer= 2;
|
||||||
|
|
||||||
if (input.SatelliteBand == "ndvi") selectedLayer = 0;
|
if (input.SatelliteBand == "ndvi") selectedLayer = 0;
|
||||||
if (input.SatelliteBand == "wdvi") selectedLayer = 1;
|
if (input.SatelliteBand == "wdvi") selectedLayer = 1;
|
||||||
if (input.SatelliteBand == "natural") selectedLayer = 2;
|
if (input.SatelliteBand == "natural") selectedLayer = 2;
|
||||||
|
// Select a particular satellite item from satelliteTask
|
||||||
|
Item satalliteItem = await _generalService.FindSatelliteItem(cropfieldItem, _settings.SatelliteTaskCode, fieldName, selectedLayer, storeSatelliteStatisticsCropYear, DownloadFolder);
|
||||||
|
|
||||||
|
|
||||||
var satelliteBand = satalliteItem.Data["layers"][selectedLayer]["name"];
|
var satelliteBand = satalliteItem.Data["layers"][selectedLayer]["name"];
|
||||||
|
|
||||||
//Store satellite data to csv
|
//Store satellite data to csv
|
||||||
if (storeSatelliteStatistics == true && (selectedLayer == 0 || selectedLayer ==1))
|
if (storeSatelliteStatistics == true && (selectedLayer == 0 || selectedLayer ==1))
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
var satelliteStatistics = satalliteItem.Data["layers"][selectedLayer]["renderer"]["band"]["statistics"];
|
var satelliteStatistics = satalliteItem.Data["layers"][selectedLayer]["renderer"]["band"]["statistics"];
|
||||||
Console.WriteLine($"Satellite image date: {satalliteItem.DataDate}");
|
Console.WriteLine($"Satellite image date: {satalliteItem.DataDate}");
|
||||||
|
|
||||||
@ -160,11 +164,8 @@ namespace FarmmapsDataDownload
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
var inputType = (satalliteItem.Data["layers"] as JArray)?[selectedLayer]["name"].ToString();
|
var inputType = (satalliteItem.Data["layers"] as JArray)?[selectedLayer]["name"].ToString();
|
||||||
if (string.IsNullOrEmpty(inputType))
|
if (string.IsNullOrEmpty(inputType)) {
|
||||||
{
|
|
||||||
_logger.LogError("Could not get the input type name from the satellite item");
|
_logger.LogError("Could not get the input type name from the satellite item");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -176,6 +177,9 @@ namespace FarmmapsDataDownload
|
|||||||
await _farmmapsApiService.DownloadItemAsync(satalliteItem.Code,
|
await _farmmapsApiService.DownloadItemAsync(satalliteItem.Code,
|
||||||
Path.Combine(DownloadFolder, $"satelliteGeotiff_{input.OutputFileName}_{inputType}_{SatelliteDate}.zip"));
|
Path.Combine(DownloadFolder, $"satelliteGeotiff_{input.OutputFileName}_{inputType}_{SatelliteDate}.zip"));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Get vanDerSat data
|
// Get vanDerSat data
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"UseCreatedCropfield": true,
|
"UseCreatedCropfield": true,
|
||||||
"outputFileName": "testSatData",
|
"outputFileName": "testSatData2",
|
||||||
"fieldName": "test_satData",
|
"fieldName": "test_satData2",
|
||||||
"GetShadowData": true,
|
"GetShadowData": false,
|
||||||
"GetSatelliteData": true,
|
"GetSatelliteData": true,
|
||||||
"SatelliteBand": "natural", // "ndvi" or "wdvi"
|
"SatelliteBand": "wdvi", // "natural", "ndvi" or "wdvi"
|
||||||
"StoreSatelliteStatistics": true,
|
"StoreSatelliteStatistics": false,
|
||||||
|
"StoreSatelliteStatisticsCropYear": true,
|
||||||
|
|
||||||
"GetVanDerSatData": false,
|
"GetVanDerSatData": false,
|
||||||
"StoreVanDerSatStatistics": false,
|
"StoreVanDerSatStatistics": false,
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -17,6 +17,7 @@ namespace FarmmapsDataDownload.Models
|
|||||||
public bool GetVanDerSatData { get; set; }
|
public bool GetVanDerSatData { get; set; }
|
||||||
public string SatelliteBand { get; set; }
|
public string SatelliteBand { get; set; }
|
||||||
public bool StoreSatelliteStatistics { get; set; }
|
public bool StoreSatelliteStatistics { get; set; }
|
||||||
|
public bool StoreSatelliteStatisticsCropYear { get; set; }
|
||||||
public bool StoreVanDerSatStatistics { get; set; }
|
public bool StoreVanDerSatStatistics { get; set; }
|
||||||
public bool GetShadowData { get; set; }
|
public bool GetShadowData { get; set; }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user