Skip to content

Commit 3dec835

Browse files
author
Vincent van der Wal
committed
add more wind vars and color scales
1 parent fd24e31 commit 3dec835

File tree

6 files changed

+64
-29
lines changed

6 files changed

+64
-29
lines changed

src/main.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,6 @@ let showTemp = false;
125125
if (mapContainer) {
126126
maplibregl.addProtocol('om', omProtocol);
127127

128-
console.log(domains);
129-
130128
map = new maplibregl.Map({
131129
container: mapContainer,
132130
style: `https://maptiler.servert.nl/styles/basic-world-maps/style.json`,

src/om-protocol.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,15 @@ const initOMFile = async (url: string) => {
220220
}
221221

222222
if (requestMultiple.includes(variable.value)) {
223+
let reg = new RegExp(/wind_(\d+)m\.om/);
224+
const matches = url.match(reg);
225+
223226
fileReader.backendu = new MemoryHttpBackend({
224-
url: omUrl.replace('wind.om', 'wind_u_component_10m.om'),
227+
url: omUrl.replace(matches[0], `wind_u_component_${matches[1]}m.om`),
225228
maxFileSize: 500 * 1024 * 1024 // 500 MB
226229
});
227230
fileReader.backendv = new MemoryHttpBackend({
228-
url: omUrl.replace('wind.om', 'wind_v_component_10m.om'),
231+
url: omUrl.replace(matches[0], `wind_v_component_${matches[1]}m.om`),
229232
maxFileSize: 500 * 1024 * 1024 // 500 MB
230233
});
231234
fileReader.readeru = await OmFileReader.create(fileReader.backendu).catch(() => {
@@ -244,7 +247,7 @@ const initOMFile = async (url: string) => {
244247
const datau = await fileReader.readeru.read(OmDataType.FloatArray, ranges);
245248
const datav = await fileReader.readerv.read(OmDataType.FloatArray, ranges);
246249

247-
const dataValues = [];
250+
const dataValues: Float32Array<ArrayBuffer> = [];
248251
const dataDirection: Float32Array<ArrayBuffer> = [];
249252

250253
for (let [i, dp] of datau.entries()) {

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export interface Domain {
7777
}
7878
| Function;
7979
};
80+
variables: string[];
8081
}
8182

8283
export interface DomainGroups {

src/utils/domains.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,14 @@ export const domains: Array<Domain> = [
7070
this.center = getCenterPoint(this);
7171
return this;
7272
}
73-
}
73+
},
74+
variables: [
75+
'cloud_cover',
76+
'precipitation',
77+
'pressure_msl',
78+
'relative_humidity_2m',
79+
'shortwave_radiation'
80+
]
7481
},
7582
// DMI
7683
{

src/utils/variables.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
export const variables = [
2-
{ value: 'temperature_2m', label: 'Temperature 2m' },
3-
{ value: 'temperature_120m', label: 'Temperature 120m' },
2+
{ value: 'cloud_cover', label: 'Cloud Cover' },
43

54
{ value: 'precipitation', label: 'Precipitation' },
6-
{ value: 'cloud_cover', label: 'Cloud Cover' },
75
{ value: 'pressure_msl', label: 'Pressure Main Sea Level' },
8-
{ value: 'wind', label: 'Wind 10m' },
6+
7+
{ value: 'relative_humidity_2m', label: 'Relative Humidity 2m' },
8+
9+
{ value: 'shortwave_radiation', label: 'Shortwave Solar Radiation' },
10+
11+
{ value: 'temperature_2m', label: 'Temperature 2m' },
12+
{ value: 'temperature_120m', label: 'Temperature 120m' },
13+
14+
{ value: 'visibility', label: 'Visibility' },
15+
16+
{ value: 'wind_10m', label: 'Wind 10m' },
17+
{ value: 'wind_40m', label: 'Wind 40m' },
18+
{ value: 'wind_80m', label: 'Wind 80m' },
19+
{ value: 'wind_120m', label: 'Wind 120m' },
20+
921
{ value: 'wind_gusts_10m', label: 'Wind Gusts 10m' }
1022
];
1123

1224
export const hideZero = ['precipitation', 'cloud_cover'];
13-
export const requestMultiple = ['wind'];
25+
export const requestMultiple = ['wind_10m', 'wind_40m', 'wind_80m', 'wind_120m'];

src/worker.ts

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { colorScale } from './utils/color-scales';
22

3-
import { hideZero } from './utils/variables';
3+
import { hideZero, requestMultiple } from './utils/variables';
44

55
import { DynamicProjection, ProjectionGrid, type Projection } from './utils/projection';
66

@@ -133,10 +133,20 @@ self.onmessage = async (message) => {
133133
min: 990,
134134
max: 1020
135135
});
136-
} else {
136+
} else if (variable.value == 'relative_humidity_2m') {
137+
colors = colorScale({
138+
min: 0,
139+
max: 100
140+
});
141+
} else if (variable.value == 'shortwave_radiation') {
137142
colors = colorScale({
138143
min: 0,
139-
max: 30
144+
max: 1000
145+
});
146+
} else {
147+
colors = colorScale({
148+
min: -5,
149+
max: 40
140150
});
141151
}
142152

@@ -248,21 +258,25 @@ self.onmessage = async (message) => {
248258
}
249259
}
250260

251-
if (variable.value === 'wind') {
252-
for (let i = 0; i < TILE_SIZE; i += TILE_SIZE / 16) {
253-
for (let j = 0; j < TILE_SIZE; j += TILE_SIZE / 16) {
254-
drawArrow(
255-
rgba,
256-
i,
257-
j,
258-
x,
259-
y,
260-
z,
261-
nx,
262-
domain,
263-
projectionGrid,
264-
direction
265-
);
261+
if (requestMultiple.includes(variable.value)) {
262+
let reg = new RegExp(/wind_(\d+)m/);
263+
const matches = variable.value.match(reg);
264+
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) {
267+
drawArrow(
268+
rgba,
269+
i,
270+
j,
271+
x,
272+
y,
273+
z,
274+
nx,
275+
domain,
276+
projectionGrid,
277+
direction
278+
);
279+
}
266280
}
267281
}
268282
}

0 commit comments

Comments
 (0)