-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Face prevailing wind based on ERA5 data
- Loading branch information
Showing
8 changed files
with
104 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using GameRealisticMap.Reporting; | ||
using WeatherStats.Databases; | ||
|
||
namespace GameRealisticMap.Nature.Weather | ||
{ | ||
internal class WeatherBuilder : IDataBuilder<WeatherData> | ||
{ | ||
private readonly IProgressSystem progress; | ||
|
||
public WeatherBuilder(IProgressSystem progress) | ||
{ | ||
this.progress = progress; | ||
} | ||
|
||
public WeatherData Build(IBuildContext context) | ||
{ | ||
var db = WeatherStatsDatabase.Create("https://weatherdata.pmad.net/ERA5AVG/"); | ||
|
||
var center = context.Area.TerrainPointToLatLng( | ||
new Geometries.TerrainPoint( | ||
context.Area.SizeInMeters / 2, | ||
context.Area.SizeInMeters / 2)); | ||
|
||
using var report = progress.CreateStep("WeatherStats", 1); | ||
|
||
var data = db.GetStats(center.Y, center.X).Result; | ||
|
||
return new WeatherData(data); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using WeatherStats; | ||
using WeatherStats.Stats; | ||
|
||
namespace GameRealisticMap.Nature.Weather | ||
{ | ||
public class WeatherData | ||
{ | ||
public WeatherData(YearWeatherStatsPoint? data) | ||
{ | ||
Data = data; | ||
} | ||
|
||
public YearWeatherStatsPoint? Data { get; } | ||
|
||
public float GetPrevailingWindAngle() | ||
{ | ||
if ( Data == null ) | ||
{ | ||
return ToAngle(WindDirection8.West); | ||
} | ||
var perMonth = Data.Months.Select(m => m.WindDirection.Prevailing).ToList(); | ||
return ToAngle(perMonth.Distinct().OrderByDescending(m => perMonth.Count(e => e == m)).First()); | ||
} | ||
|
||
private static float ToAngle(WindDirection8 direction) | ||
{ | ||
switch (direction) | ||
{ | ||
case WindDirection8.North: | ||
return 0; | ||
case WindDirection8.NorthEast: | ||
return -45; | ||
case WindDirection8.East: | ||
return -90; | ||
case WindDirection8.SouthEast: | ||
return -135; | ||
case WindDirection8.South: | ||
return 180; | ||
case WindDirection8.NorthWest: | ||
return 45; | ||
case WindDirection8.West: | ||
return 90; | ||
case WindDirection8.SouthWest: | ||
return 135; | ||
} | ||
return -90; | ||
} | ||
} | ||
} |
Submodule weatherstats
added at
861c54