-
Notifications
You must be signed in to change notification settings - Fork 0
/
exercise_01.jl
107 lines (95 loc) · 2.79 KB
/
exercise_01.jl
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
using DataFrames
using Gadfly
using Pipe
# import Cairo, Fontconfig
Gadfly.push_theme(:dark)
# Gadfly.push_theme(style(background_color=nothing))
include("components.jl")
dfs = [atmosphere, hydrosphere, cryosphere, land_surface, biosphere]
ids = ["atmosphere", "hydrosphere", "cryosphere", "land surface", "biosphere"]
for i in eachindex(dfs)
transform!(dfs[i], :Process => (x -> ids[i]) => :component)
end
df = vcat(atmosphere, hydrosphere, cryosphere, land_surface, biosphere)
margin(x) = x[1] == x[2] ? [log10(x[1]) - 0.5, log10(x[1]) + 0.5].^10 : x
function bound(x)
highest = maximum(filter(!=(Inf), x))
lowest = minimum(filter(!=(0.0), x))
for i in eachindex(x)
if x[i] == Inf
x[i] = 1e5^ceil(log(1e5, highest))
elseif x[i] == 0.0
x[i] = 1e5^floor(log(1e5, lowest))
end
end
return x
end
@pipe df |>
transform!(
_,
["Characteristic Time Scale", "Characteristic Spatial Scale"] => ByRow((x, y) -> [margin(x), margin(y)]) => ["Characteristic Time Scale", "Characteristic Spatial Scale"]
) |>
transform!(
_,
["Characteristic Time Scale", "Characteristic Spatial Scale"] => ByRow((x, y) -> [x..., y...]) => [:x_min, :x_max, :y_min, :y_max]
) |>
transform!(
_,
[:x_min, :x_max, :y_min, :y_max] => (u, x, y, z) -> bound.([u, x, y, z]) => [:x_min, :x_max, :y_min, :y_max]
)
# plot(
# atmosphere,
# x="Characteristic Time Scale",
# y="Characteristic Spatial Scale",
# # color=:id,
# alpha=[0.3],
# linestyle=[:dash],
# Geom.polygon(fill=true),
# Scale.color_discrete,
# Theme(line_width=2pt,
# lowlight_color=identity,
# discrete_highlight_color=identity)
# )
# plot(
# df,
# xmin=:x_min,
# xmax=:x_max,
# ymin=:y_min,
# ymax=:y_max,
# color=:component,
# alpha=[0.8],
# Geom.rect,
# Scale.x_log10, Scale.y_log10,
# Guide.xlabel("Characteristic Time Scale"),
# Guide.ylabel("Characteristic Spatial Scale")
# )
p = plot(
df,
xmin=:x_min,
xmax=:x_max,
ymin=:y_min,
ymax=:y_max,
color=:Process,
alpha=[0.5],
ygroup=:component,
Geom.subplot_grid(Geom.rect),
Scale.x_log10, Scale.y_log10,
Guide.xlabel("Characteristic Time Scale in s"),
Guide.ylabel("Characteristic Spatial Scale in m")
)
draw(SVG("./exercises/components.svg", 20cm, 20cm), p)
# TODO: fix ^ Unicode
# @pipe df |> subset(_, :component => ByRow(==("atmosphere"))) |>
# plot(
# _,
# xmin=:x_min,
# xmax=:x_max,
# ymin=:y_min,
# ymax=:y_max,
# color=:Process,
# alpha=[0.5],
# Geom.rect,
# Scale.x_log10, Scale.y_log10,
# Guide.xlabel("Characteristic Time Scale"),
# Guide.ylabel("Characteristic Spatial Scale")
# )