Skip to content

Commit 06e681f

Browse files
author
Vincent van der Wal
committed
add cape
1 parent 3dec835 commit 06e681f

File tree

4 files changed

+55
-38
lines changed

4 files changed

+55
-38
lines changed

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export interface Domain {
7878
| Function;
7979
};
8080
variables: string[];
81+
windUVComponents: boolean;
8182
}
8283

8384
export interface DomainGroups {

src/utils/domains.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,16 @@ export const domains: Array<Domain> = [
7676
'precipitation',
7777
'pressure_msl',
7878
'relative_humidity_2m',
79-
'shortwave_radiation'
80-
]
79+
'shortwave_radiation',
80+
'temperature_2m',
81+
'visibility',
82+
'wind_10m',
83+
'wind_40m',
84+
'wind_80m',
85+
'wind_120m',
86+
'wind_gusts_10m'
87+
],
88+
windUVComponents: false
8189
},
8290
// DMI
8391
{
@@ -103,7 +111,23 @@ export const domains: Array<Domain> = [
103111
this.center = getCenterPoint(this);
104112
return this;
105113
}
106-
}
114+
},
115+
variables: [
116+
'cape',
117+
'cloud_cover',
118+
'precipitation',
119+
'pressure_msl',
120+
'relative_humidity_2m',
121+
'shortwave_radiation',
122+
'temperature_2m',
123+
'visibility',
124+
'wind_10m',
125+
'wind_40m',
126+
'wind_80m',
127+
'wind_120m',
128+
'wind_gusts_10m'
129+
],
130+
windUVComponents: false
107131
},
108132

109133
// DWD

src/utils/variables.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export const variables = [
2+
{ value: 'cape', label: 'CAPE' },
3+
24
{ value: 'cloud_cover', label: 'Cloud Cover' },
35

46
{ value: 'precipitation', label: 'Precipitation' },
@@ -17,7 +19,6 @@ export const variables = [
1719
{ value: 'wind_40m', label: 'Wind 40m' },
1820
{ value: 'wind_80m', label: 'Wind 80m' },
1921
{ value: 'wind_120m', label: 'Wind 120m' },
20-
2122
{ value: 'wind_gusts_10m', label: 'Wind Gusts 10m' }
2223
];
2324

src/worker.ts

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515

1616
import type { TypedArray } from '@openmeteo/file-reader';
1717
import type { Domain } from './types';
18+
import type { v8 } from 'maplibre-gl';
1819

1920
const TILE_SIZE = Number(import.meta.env.VITE_TILE_SIZE) * 2;
2021
const OPACITY = Number(import.meta.env.VITE_TILE_OPACITY);
@@ -37,8 +38,8 @@ const drawArrow = (
3738
domain: Domain,
3839
projectionGrid: ProjectionGrid,
3940
directions: TypedArray,
40-
boxSize = TILE_SIZE / 16,
41-
arrowTipLength = 6
41+
boxSize = TILE_SIZE / 8,
42+
arrowTipLength = 7
4243
): void => {
4344
const arrowCoords = [];
4445

@@ -53,8 +54,8 @@ const drawArrow = (
5354
const arrowCoordsRotated = [];
5455
const arrowIndices = [];
5556

56-
let iCenter = iBase + boxSize / 2;
57-
let jCenter = jBase + boxSize / 2;
57+
let iCenter = iBase + Math.floor(boxSize / 2);
58+
let jCenter = jBase + Math.floor(boxSize / 2);
5859

5960
const lat = tile2lat(y + iCenter / TILE_SIZE, z);
6061
const lon = tile2lon(x + jCenter / TILE_SIZE, z);
@@ -135,6 +136,16 @@ self.onmessage = async (message) => {
135136
});
136137
} else if (variable.value == 'relative_humidity_2m') {
137138
colors = colorScale({
139+
colorScheme: '',
140+
customColors: [
141+
'#009392',
142+
'#39b185',
143+
'#9ccb86',
144+
'#e9e29c',
145+
'#eeb479',
146+
'#e88471',
147+
'#cf597e'
148+
].reverse(),
138149
min: 0,
139150
max: 100
140151
});
@@ -143,6 +154,11 @@ self.onmessage = async (message) => {
143154
min: 0,
144155
max: 1000
145156
});
157+
} else if (variable.value == 'cape') {
158+
colors = colorScale({
159+
min: 0,
160+
max: 4000
161+
});
146162
} else {
147163
colors = colorScale({
148164
min: -5,
@@ -204,32 +220,6 @@ self.onmessage = async (message) => {
204220
}
205221
}
206222

207-
// if (
208-
// import.meta.env.DEV &&
209-
// (i === 0 ||
210-
// i === TILE_SIZE ||
211-
// j === 0 ||
212-
// j === TILE_SIZE ||
213-
// i % (TILE_SIZE / 16) === 0 ||
214-
// j % (TILE_SIZE / 16) === 0)
215-
// ) {
216-
// if (
217-
// i === 0 ||
218-
// i === TILE_SIZE ||
219-
// j === 0 ||
220-
// j === TILE_SIZE
221-
// ) {
222-
// rgba[4 * ind] = 255;
223-
// rgba[4 * ind + 1] = 0;
224-
// rgba[4 * ind + 2] = 255;
225-
// rgba[4 * ind + 3] = 255;
226-
// } else {
227-
// rgba[4 * ind] = 0;
228-
// rgba[4 * ind + 1] = 0;
229-
// rgba[4 * ind + 2] = 255;
230-
// rgba[4 * ind + 3] = 255;
231-
// }
232-
// } else {
233223
if (isNaN(px) || px === Infinity) {
234224
rgba[4 * ind] = 0;
235225
rgba[4 * ind + 1] = 0;
@@ -254,16 +244,16 @@ self.onmessage = async (message) => {
254244
}
255245
}
256246
}
257-
//}
258247
}
259248
}
260249

261250
if (requestMultiple.includes(variable.value)) {
262251
let reg = new RegExp(/wind_(\d+)m/);
263252
const matches = variable.value.match(reg);
253+
const boxSize = Math.floor(TILE_SIZE / 16);
264254
if (matches[0]) {
265-
for (let i = 0; i < TILE_SIZE; i += TILE_SIZE / 16) {
266-
for (let j = 0; j < TILE_SIZE; j += TILE_SIZE / 16) {
255+
for (let i = 0; i < TILE_SIZE; i += boxSize) {
256+
for (let j = 0; j < TILE_SIZE; j += boxSize) {
267257
drawArrow(
268258
rgba,
269259
i,
@@ -274,7 +264,8 @@ self.onmessage = async (message) => {
274264
nx,
275265
domain,
276266
projectionGrid,
277-
direction
267+
direction,
268+
boxSize
278269
);
279270
}
280271
}

0 commit comments

Comments
 (0)