Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add VegetationLayer #16

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions GeoRasterBlueprint/Model/Bison.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public class Bison : IAgent<LandscapeLayer>, IPositionable, IAnimalAgent {
[PropertyDescription(Name = "Perimeter")]
public Perimeter Perimeter { get; set; }

[PropertyDescription(Name = "VegetationLayer")]
public VegetationLayer VegetationLayer { get; set; }

public Guid ID { get; set; }
private int HoursWithoutWater { get; set; }
private int HoursWithoutFood { get; set; }
Expand All @@ -53,6 +56,7 @@ public class Bison : IAgent<LandscapeLayer>, IPositionable, IAnimalAgent {
public const double MaxSatiety = 100.0;
public const double DehydrationRate = 20.0;
public const double StarvationRate = 1.5;
private int TickSearchForFood = 10;
public const double HoursToDeathWithoutWater = MaxHydration / DehydrationRate;
public const double HoursToDeathWithoutFood = MaxSatiety / StarvationRate;
public const int MaxAge = 175200; // Maximum age in hours (20 years)
Expand All @@ -78,6 +82,11 @@ public void Init(LandscapeLayer landscapeLayer) {
public void Tick() {
UpdateState();
MoveToWaterSource();
if (Satiety < 40) {
if (LandscapeLayer.GetCurrentTick() % TickSearchForFood == 0) {
SearchForFood();
}
}
// if (Age >= MaxAge) {
// DieOfOldAge();
// } else {
Expand Down Expand Up @@ -135,6 +144,29 @@ private void MoveToWaterSource() {
}
}

private void SearchForFood() {
if (VegetationLayer.IsPointInside(Position)) {
var all = VegetationLayer.Explore(Position, double.MaxValue, 4);
var res = all.OrderBy(a => a.Node.Value).Last();
if (res.Node?.NodePosition != null) {

var targetX = res.Node.NodePosition.X;
var targetY = res.Node.NodePosition.Y;

var targetLon = VegetationLayer.LowerLeft.X +
targetX * VegetationLayer.CellWidth;
var targetLat = VegetationLayer.LowerLeft.Y +
targetY * VegetationLayer.CellHeight;

Target = new Position(targetLon, targetLat);

if (Perimeter.IsPointInside(Target)) {
_bearing = Position.GetBearing(Target);
}
}
}
}

public void DieOfOldAge() {
throw new NotImplementedException();
}
Expand Down
2 changes: 1 addition & 1 deletion GeoRasterBlueprint/Model/Perimeter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ public class Perimeter : VectorLayer {
public bool IsPointInside(Position coordinate) {
return Extent.Contains(coordinate.X, coordinate.Y);
}
}
}
15 changes: 15 additions & 0 deletions GeoRasterBlueprint/Model/VegetationLayer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using Mars.Components.Layers;
using Position = Mars.Interfaces.Environments.Position;

namespace GeoRasterBlueprint.Model;

/// <summary>
/// This raster layer provides information about biomass of animals etc.
/// </summary>
///
public class VegetationLayer : RasterLayer {
public bool IsPointInside(Position coordinate) {
return Extent.Contains(coordinate.X, coordinate.Y) && Math.Abs(GetValue(coordinate)) > 0.0;
}
}
1 change: 1 addition & 0 deletions GeoRasterBlueprint/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static void Main(string[] args) {
description.AddLayer<LandscapeLayer>();
description.AddLayer<Perimeter>();
description.AddLayer<WaterLayer>();
description.AddLayer<VegetationLayer>();
description.AddLayer<TemperatureLayer>();

description.AddAgent<Bison, LandscapeLayer>();
Expand Down
576 changes: 576 additions & 0 deletions GeoRasterBlueprint/Resources/ndvi_apr_23.asc

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion GeoRasterBlueprint/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"globals": {
"deltaT": 1,
"startPoint": "2018-11-18T00:00:00",
"endPoint": "2023-11-18T16:00:00",
"endPoint": "2019-11-18T16:00:00",
"deltaTUnit": "hours",
"console": true,
"output": "csv",
Expand All @@ -20,6 +20,10 @@
"name":"WaterLayer",
"file":"Resources/einp_water_spots.geojson"
},
{
"name": "VegetationLayer",
"file": "Resources/ndvi_apr_23.asc"
},
{
"name": "TemperatureLayer",
"file": "Resources/open-meteo-53.60N112.93W736m.csv"
Expand Down