-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDCSWeatherFileConverter.py
More file actions
144 lines (115 loc) · 4.77 KB
/
Copy pathDCSWeatherFileConverter.py
File metadata and controls
144 lines (115 loc) · 4.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import configparser
import random
import inspect
class DCSWeatherFileConverter(object):
"""
Enrichment procedures are mostly based on dcs_weather from here https://forums.eagle.ru/showthread.php?t=198402.
Some other things are new, deterministic randomness, temperature correction for sea level, etc.
"""
weatherdata = None
weatherfile = None
def __init__(self, weatherfile):
self.weatherfile = weatherfile
self.weatherdata = configparser.RawConfigParser()
self.weatherdata.read(weatherfile)
def seedRandom(self):
"""
Seeds the PRNG deterministically for repeatable same randoms
:return: None
"""
callingFunc = inspect.stack()[1].function
random.seed(self.getWeatherText() + callingFunc)
def getDeterministicRandomFloat(self, min, max):
"""
Returns a deterministic random value for a given function calling it and the underlaying weather data.
:param min: minimum float
:param max: maximum float
:return: float between min and max randomly chosen in a repeatable way
"""
assert max >= min
randval = random.random()
return min + ((max-min)*randval)
def getDeterministicRandomInt(self, min, max):
"""
Returns a deterministic random value for a given function calling it and the underlaying weather data.
:param min: minimum int
:param max: maximum int
:return: int between min and max randomly chosen in a repeatable way
"""
return random.randint(min, max)
def normalizeDegrees(self, angle):
retangle = angle
if retangle < 0:
retangle += 360
if retangle >= 360:
retangle -= 360
return retangle
def getWeatherText(self):
return 'weather from file: '+self.weatherfile
def getWeatherCached(self):
return False
def getLastWeather(self):
return None
def getClosestResult(self):
return None
def getStationElevation(self):
return self.weatherdata.getint('Weather', 'station_elevation')
def getBarometerMMHg(self):
return self.weatherdata.getfloat('Weather', 'barometer') * 25.4
def getTemperature(self):
return self.weatherdata.getfloat('Weather', 'temperature')
def getTemperatureASL(self):
"""
The higher the elevation of the reporting station, the higher the sea level temperature really is.
This is using https://sciencing.com/tutorial-calculate-altitude-temperature-8788701.html as formula
to adjust the temperature for sea level.
:return: estimated temperature at sea level
"""
temperatureDelta = self.getStationElevation() * 0.0065
return self.getTemperature() + temperatureDelta
def getWindASL(self):
return {'direction': self.weatherdata.getint('Wind', 'asl_direction'),
'speed': self.weatherdata.getfloat('Wind', 'asl_speed')}
def getWind2000(self):
return {'direction': self.weatherdata.getint('Wind', 'a2000_direction'),
'speed': self.weatherdata.getfloat('Wind', 'a2000_speed')}
def getWind8000(self):
return {'direction': self.weatherdata.getint('Wind', 'a8000_direction'),
'speed': self.weatherdata.getfloat('Wind', 'a8000_speed')}
def getGroundTurbulence(self):
return self.weatherdata.getfloat('Wind', 'asl_gusts') * 0.514444
def getCloudMinMax(self):
return {'min': self.weatherdata.getint('Clouds', 'floor') + self.getStationElevation(),
'max': self.weatherdata.getint('Clouds', 'ceiling') + self.getStationElevation()}
def getCloudBase(self):
return max(300, self.getCloudMinMax()['min'])
def getCloudThickness(self):
minmaxclouds = self.getCloudMinMax()
return minmaxclouds['max']-minmaxclouds['min']
def getCloudDensity(self):
return self.weatherdata.getint('Clouds', 'density')
def getWeatherType(self):
return self.weatherdata.getint('Weather', 'precipitation')
def getFogEnabled(self):
return self.weatherdata.getboolean('Weather', 'fog')
def getFogVisibility(self):
if self.getFogEnabled():
self.seedRandom()
return self.getDeterministicRandomInt(800, 1000)
else:
return 0
def getFogThickness(self):
if self.getFogEnabled():
self.seedRandom()
return self.getDeterministicRandomInt(100, 300)
else:
return 0
def getVisibility(self):
try:
visibility = self.weatherdata.getint('Weather', 'visibility')
if visibility >= 9000:
return 80000
else:
return visibility
except:
return 80000