-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.html
More file actions
360 lines (311 loc) · 12.8 KB
/
input.html
File metadata and controls
360 lines (311 loc) · 12.8 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Model Data</title>
<link rel="stylesheet" href="styles.css" />
<script src="https://cdn.plot.ly/plotly-2.27.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/papaparse@5.4.1/papaparse.min.js"></script>
<style>
.slider-container {
margin-top: 1em;
text-align: center;
}
#timeSlider {
width: 80%;
}
#sliderLabel {
font-weight: bold;
display: block;
margin-top: 0.5em;
}
#year-ticks {
width: 80%;
margin: 0 auto;
display: flex;
justify-content: space-between;
font-size: 0.8em;
color: #666;
}
#year-ticks span {
transform: translateX(-50%);
}
</style>
</head>
<body>
<!-- CAL Brand Bar -->
<div class="brandbar">
<img src="assets/cal-logo.svg" alt="CAL" />
<span class="brand-text">Climate Analytics Lab · UC San Diego</span>
</div>
<header class="header">
<div class="header-content">
<h1 class="header-title">ClimateBench 2.0</h1>
<p class="header-subtitle">Climate Model Benchmarking & Analysis Platform</p>
</div>
</header>
<nav class="navigation">
<div class="nav-container">
<ul class="nav-list">
<li class="nav-item">
<a href="index.html" class="nav-link">Overview</a>
</li>
<li class="nav-item">
<a href="scores.html" class="nav-link">Scores</a>
</li>
<li class="nav-item">
<a href="paleo.html" class="nav-link">Paleoclimate</a>
</li>
<li class="nav-item">
<a href="input.html" class="nav-link active">Model Data</a>
</li>
</ul>
</div>
</nav>
<main class="main-content">
<div class="input-section">
<h2 class="section-title">Data Selection</h2>
<div class="widget-menu">
<div class="widget-row">
<div class="widget-group">
<label for="variable-select">Variable</label>
<select id="variable-select" class="widget-select">
<option value="tas" selected>Surface Air Temperature</option>
<option value="pr">Precipitation</option>
<option value="tos">Sea Surface Temperature</option>
<option value="clt">Cloud Area Fraction</option>
<option value="od550aer">Aerosol Optical Depth at 550 nm</option>
</select>
</div>
<div class="widget-group">
<label for="region-select">Region</label>
<select id="region-select" class="widget-select">
<option value="global" selected>Global</option>
<option value="northern_hemisphere">Northern Hemisphere</option>
<option value="southern_hemisphere">Southern Hemisphere</option>
<option value="tropics">Tropics</option>
</select>
</div>
<div class="widget-group">
<label for="model-select">Model</label>
<select id="model-select" class="widget-select">
<option value="CanESM5">CanESM5</option>
<option value="MPI-ESM1-2-LR">MPI-ESM1-2-HR</option>
<option value="IPSL-CM6A-LR">IPSL-CM6A-LR</option>
<option value="CESM2-WACCM">CESM2-WACCM</option>
</select>
</div>
<div class="widget-group">
<label>Time Resolution</label>
<div style="display: flex; gap: 20px; align-items: center; padding: 12px 0;">
<label style="margin: 0; display: flex; align-items: center; gap: 8px;">
<input type="radio" name="resolution" value="annual" checked style="margin: 0;">
Annual
</label>
<label style="margin: 0; display: flex; align-items: center; gap: 8px;">
<input type="radio" name="resolution" value="monthly" style="margin: 0;">
Monthly
</label>
</div>
</div>
</div>
</div>
<h2 class="section-title">Model and Observation Data</h2>
<div class="chart-container">
<h3 class="chart-head" id="timeseries-title">HOLD</h3>
<div id="timeseries-chart" style="width:100%; height:400px; margin-top: 2em;"></div>
</div>
<div class="chart-container">
<h3 class="chart-head" id="map-title">Model Map Images</h3>
<div id="map-image-container" style="display: flex; justify-content: center; gap: 2em; align-items: start; flex-wrap: wrap;">
<div>
<img id="map-image" src="" alt="Model Map" style="width: 49%; height: auto;" />
<img id="error-image" src="" alt="Model Error Map" style="width: 49%; height: auto;" />
</div>
</div>
</div>
<div class="slider-container">
<input type="range" id="timeSlider" min="0" max="239" value="0" />
<div id="year-ticks"></div>
</div>
</div>
</main>
<footer><p>© 2025 CAL.</p></footer>
<script>
const startDate = new Date('2005-01-01');
const monthCount = 240;
const slider = document.getElementById('timeSlider');
function getDateFromSlider(val) {
const resolution = document.querySelector('input[name="resolution"]:checked').value;
const d = new Date(startDate);
if (resolution === 'monthly') {
d.setMonth(d.getMonth() + parseInt(val));
return d.toISOString().slice(0, 7); // "YYYY-MM"
} else {
d.setFullYear(d.getFullYear() + parseInt(val));
return d.getFullYear().toString(); // "YYYY"
}
}
function updateSliderResolution(resolution) {
const max = resolution === 'annual' ? 21 - 1: 240 - 1;
const min = resolution === 'annual' ? 1 : 0;
slider.min = min;
slider.max = max;
slider.value = 0;
generateSliderTicks(resolution);
}
function updateChartTitle() {
const title_var_map = { 'tas': 'surface air temperature (°C)', 'pr': 'precipitation (kg/m2s)', 'clt': 'cloud area fraction (%)', 'tos': 'sea surface temperature (°C)', 'od550aer': 'aerosol optical depth at 550nm' };
const title_region_map = { 'global': 'global', 'northern_hemisphere': 'northern hemisphere', 'southern_hemisphere': 'southern hemisphere', 'tropics': 'tropical',};
const model = document.getElementById('model-select').value;
const region = title_region_map[document.getElementById('region-select').value];
const variable = title_var_map[document.getElementById('variable-select').value];
const resolution = document.querySelector('input[name="resolution"]:checked').value;
document.getElementById('timeseries-title').textContent = `${model} ${region} ${resolution} ${variable}`;
}
function updateMapImage() {
const model = document.getElementById('model-select').value;
const variable = document.getElementById('variable-select').value;
const resolution = document.querySelector('input[name="resolution"]:checked').value;
const rawDate = getDateFromSlider(slider.value);
const date = resolution === 'annual'
? `${rawDate}-01-01`
: `${rawDate}-01`;
const basePath = `data/images/${model}/${resolution}/${variable}`;
const modelPath = `${basePath}/data/${date}.png`;
const errorPath = `${basePath}/error/${date}.png`;
const modelImg = document.getElementById('map-image');
const errorImg = document.getElementById('error-image');
modelImg.src = modelPath;
modelImg.alt = `Model data for ${model} on ${date}`;
errorImg.src = errorPath;
errorImg.alt = `Model error for ${model} on ${date}`;
document.getElementById('map-title').textContent = `${model} ${resolution} data and error for ${date}`;
}
function generateSliderTicks(resolution = 'annual') {
const tickContainer = document.getElementById('year-ticks');
tickContainer.innerHTML = '';
const startYear = 2005;
const endYear = 2025;
const step = 5;
const count = resolution === 'monthly' ? 240 : 20;
for (let y = startYear; y <= endYear; y += step) {
const span = document.createElement('span');
span.textContent = y;
const index = resolution === 'monthly' ? (y - startYear) * 12 : (y - startYear);
span.style.left = `${(index / (count - 1)) * 100}%`;
tickContainer.appendChild(span);
}
}
function renderChart(variable, model, region) {
const modelFiltered = modelData.filter(row =>
row.model === model &&
row.region === region &&
!isNaN(parseFloat(row[variable]))
);
const obsFiltered = obsData.filter(row =>
row.region === region &&
!isNaN(parseFloat(row[variable]))
);
const traceModel = {
x: modelFiltered.map(row => row.time),
y: modelFiltered.map(row => parseFloat(row[variable])),
mode: 'lines',
name: `Model (${model})`,
line: { color: '#1f77b4' }
};
const traceObs = {
x: obsFiltered.map(row => row.time),
y: obsFiltered.map(row => parseFloat(row[variable])),
mode: 'lines',
name: 'Observations',
line: { color: '#ff7f0e' },
fill: 'none'
};
const traces = [traceModel, traceObs];
const errorCol = `${variable}_error`;
if (obsFiltered[0] && errorCol in obsFiltered[0]) {
const x = [], yUpper = [], yLower = [];
obsFiltered.forEach(row => {
const val = parseFloat(row[variable]);
const err = parseFloat(row[errorCol]);
if (!isNaN(val) && !isNaN(err)) {
x.push(row.time);
yUpper.push(val + err);
yLower.push(val - err);
}
});
if (x.length > 0) {
traces.push({
x: x.concat([...x].reverse()),
y: yUpper.concat([...yLower].reverse()),
fill: 'toself',
fillcolor: 'rgba(255,127,14,0.2)',
line: { color: 'transparent' },
name: 'Observation Error',
type: 'scatter',
showlegend: false
});
}
}
const layout = {
xaxis: { type: 'date' },
yaxis: { title: variable.toUpperCase() },
legend: { orientation: 'h', x: 0, y: -0.1 },
margin: { t: 40 }
};
Plotly.newPlot('timeseries-chart', traces, layout, { responsive: true });
}
function applyFilters() {
const variable = document.getElementById('variable-select').value;
const model = document.getElementById('model-select').value;
const region = document.getElementById('region-select').value;
renderChart(variable, model, region);
updateChartTitle();
}
function loadData(resolution) {
const modelFile = `data/model_zonal_mean_${resolution}.csv`;
const obsFile = `data/observation_zonal_mean_${resolution}.csv`;
Promise.all([
fetch(modelFile).then(res => res.text()),
fetch(obsFile).then(res => res.text())
])
.then(([modelCSV, obsCSV]) => {
const modelParsed = Papa.parse(modelCSV, { header: true, dynamicTyping: true, skipEmptyLines: true });
const obsParsed = Papa.parse(obsCSV, { header: true, dynamicTyping: true, skipEmptyLines: true });
modelData = modelParsed.data.filter(row => row.time && row.model && row.region);
obsData = obsParsed.data.filter(row => row.time && row.region);
applyFilters();
})
.catch(err => {
console.error("CSV load error:", err);
document.getElementById('timeseries-chart').innerHTML = "<p>Error loading chart data.</p>";
});
}
let modelData = [], obsData = [];
document.addEventListener('DOMContentLoaded', () => {
loadData('annual');
document.getElementById('variable-select').addEventListener('change', applyFilters);
document.getElementById('region-select').addEventListener('change', applyFilters);
document.getElementById('model-select').addEventListener('change', applyFilters);
document.querySelectorAll('input[name="resolution"]').forEach(input => {
input.addEventListener('change', () => {
const resolution = document.querySelector('input[name="resolution"]:checked').value;
updateSliderResolution(resolution);
loadData(resolution);
updateMapImage();
});
});
document.getElementById('model-select').addEventListener('change', updateMapImage);
document.getElementById('variable-select').addEventListener('change', updateMapImage);
document.querySelectorAll('input[name="resolution"]').forEach(input => {
input.addEventListener('change', updateMapImage);
});
slider.addEventListener('input', updateMapImage);
const resolution = document.querySelector('input[name="resolution"]:checked').value;
updateSliderResolution(resolution);
updateMapImage();
});
</script>
</body>
</html>