Rip out hardcoded isotherms (for now)
This commit is contained in:
parent
d2417b2000
commit
1cb8875053
1 changed files with 13 additions and 29 deletions
|
@ -13,8 +13,12 @@ PRESSURE_LOG_MAX = math.log(PRESSURE_MAX)
|
||||||
PRESSURE_LOG_MIN = math.log(PRESSURE_MIN)
|
PRESSURE_LOG_MIN = math.log(PRESSURE_MIN)
|
||||||
PRESSURE_LOG_RANGE = PRESSURE_LOG_MAX - PRESSURE_LOG_MIN
|
PRESSURE_LOG_RANGE = PRESSURE_LOG_MAX - PRESSURE_LOG_MIN
|
||||||
|
|
||||||
|
TEMP_MAX = 60
|
||||||
|
TEMP_MIN = -40
|
||||||
|
TEMP_RANGE = TEMP_MAX - TEMP_MIN
|
||||||
TEMP_CENTER = 0 # degrees C
|
TEMP_CENTER = 0 # degrees C
|
||||||
TEMP_STEP = 5
|
TEMP_STEP = 5
|
||||||
|
TEMP_STEP_COUNT = 16
|
||||||
|
|
||||||
def clamp(value, lowest, highest):
|
def clamp(value, lowest, highest):
|
||||||
if value < lowest:
|
if value < lowest:
|
||||||
|
@ -27,25 +31,11 @@ def clamp(value, lowest, highest):
|
||||||
class SkewT():
|
class SkewT():
|
||||||
__slots__ = 'width', 'height', 'temp_step_width',
|
__slots__ = 'width', 'height', 'temp_step_width',
|
||||||
|
|
||||||
ISOTHERM_LINES = (
|
|
||||||
(0, 0, 9, 9), (1, 0, 9, 8), (2, 0, 9, 7), (3, 0, 9, 6),
|
|
||||||
(4, 0, 9, 5), (5, 0, 9, 4), (6, 0, 9, 3), (7, 0, 9, 2),
|
|
||||||
(8, 0, 9, 1), (9, 0, 9, 0),
|
|
||||||
|
|
||||||
(-1, 0, 9, 10), (-2, 0, 8, 10), (-3, 0, 7, 10), (-4, 0, 6, 10),
|
|
||||||
(-5, 0, 5, 10), (-6, 0, 4, 10), (-7, 0, 3, 10), (-8, 0, 2, 10),
|
|
||||||
(-9, 0, 1, 10),
|
|
||||||
|
|
||||||
(-9, 1, 0, 10), (-9, 2, -1, 10), (-9, 3, -2, 10), (-9, 4, -3, 10),
|
|
||||||
(-9, 5, -4, 10), (-9, 6, -5, 10), (-9, 7, -6, 10), (-9, 8, -7, 10),
|
|
||||||
(-9, 9, -8, 10),
|
|
||||||
)
|
|
||||||
|
|
||||||
def __init__(self, width: float, height: float):
|
def __init__(self, width: float, height: float):
|
||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
|
|
||||||
self.temp_step_width = self.height / 10.0
|
self.temp_step_width = min(self.width, self.height) / TEMP_STEP_COUNT
|
||||||
|
|
||||||
def graph_to_screen(self, x, y) -> tuple:
|
def graph_to_screen(self, x, y) -> tuple:
|
||||||
return (self.width / 2) + x, self.height - y
|
return (self.width / 2) + x, self.height - y
|
||||||
|
@ -57,6 +47,8 @@ class SkewT():
|
||||||
return factor * self.height
|
return factor * self.height
|
||||||
|
|
||||||
def draw_isobars(self, cr: cairo.Context, x: float, y: float):
|
def draw_isobars(self, cr: cairo.Context, x: float, y: float):
|
||||||
|
cr.set_source_rgb(0.5, 0.5, 0.5)
|
||||||
|
|
||||||
for pressure in range(PRESSURE_MIN, PRESSURE_MAX+1, PRESSURE_STEP):
|
for pressure in range(PRESSURE_MIN, PRESSURE_MAX+1, PRESSURE_STEP):
|
||||||
coord = self.graph_to_screen(-self.width / 2,
|
coord = self.graph_to_screen(-self.width / 2,
|
||||||
self.pressure_y(pressure))
|
self.pressure_y(pressure))
|
||||||
|
@ -69,24 +61,16 @@ class SkewT():
|
||||||
def draw_isotherms(self, cr: cairo.Context, x: float, y: float):
|
def draw_isotherms(self, cr: cairo.Context, x: float, y: float):
|
||||||
cr.set_source_rgba(0.1, 0.5, 0.1, 0.8)
|
cr.set_source_rgba(0.1, 0.5, 0.1, 0.8)
|
||||||
|
|
||||||
for line in self.ISOTHERM_LINES:
|
pass
|
||||||
x1 = line[0] * self.temp_step_width
|
|
||||||
y1 = line[1] * self.temp_step_width
|
|
||||||
x2 = line[2] * self.temp_step_width
|
|
||||||
y2 = line[3] * self.temp_step_width
|
|
||||||
|
|
||||||
(screen_x1, screen_y1) = self.graph_to_screen(x1, y1)
|
def skew_t_to_graph(self, x: float, y: float):
|
||||||
(screen_x2, screen_y2) = self.graph_to_screen(x2, y2)
|
return (x+y, y)
|
||||||
|
|
||||||
cr.move_to(x + screen_x1, y + screen_y1)
|
|
||||||
cr.line_to(x + screen_x2, y + screen_y2)
|
|
||||||
cr.stroke()
|
|
||||||
|
|
||||||
def sample_to_graph(self, temp: float, pressure: float):
|
def sample_to_graph(self, temp: float, pressure: float):
|
||||||
x = (temp / TEMP_STEP) * self.temp_step_width
|
x = (temp / TEMP_STEP) * self.temp_step_width
|
||||||
y = self.pressure_y(pressure)
|
y = self.pressure_y(pressure)
|
||||||
|
|
||||||
return x + y, y
|
return self.skew_t_to_graph(x, y)
|
||||||
|
|
||||||
def draw_samples(self,
|
def draw_samples(self,
|
||||||
cr: cairo.Context,
|
cr: cairo.Context,
|
||||||
|
|
Loading…
Add table
Reference in a new issue