autumnplot-gl 2.2.3 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -8
- package/dist/110.autumnplot-gl.js +2 -0
- package/dist/110.autumnplot-gl.js.map +1 -0
- package/dist/autumnplot-gl.js +3 -0
- package/dist/autumnplot-gl.js.LICENSE.txt +12 -0
- package/dist/autumnplot-gl.js.map +1 -0
- package/dist/marchingsquares.wasm +0 -0
- package/lib/AutumnTypes.d.ts +14 -13
- package/lib/Barbs.d.ts +10 -5
- package/lib/Barbs.js +22 -5
- package/lib/BillboardCollection.d.ts +11 -7
- package/lib/BillboardCollection.js +52 -30
- package/lib/ColorBar.js +51 -7
- package/lib/Colormap.d.ts +14 -3
- package/lib/Colormap.js +63 -12
- package/lib/Contour.d.ts +73 -18
- package/lib/Contour.js +180 -148
- package/lib/ContourCreator.d.ts +18 -0
- package/lib/ContourCreator.js +23 -0
- package/lib/Fill.d.ts +18 -7
- package/lib/Fill.js +73 -41
- package/lib/Grid.d.ts +167 -0
- package/lib/Grid.js +339 -0
- package/lib/Hodographs.d.ts +13 -6
- package/lib/Hodographs.js +58 -71
- package/lib/Map.d.ts +14 -3
- package/lib/Map.js +9 -0
- package/lib/Paintball.d.ts +11 -5
- package/lib/Paintball.js +35 -15
- package/lib/PlotComponent.d.ts +5 -5
- package/lib/PlotLayer.d.ts +12 -12
- package/lib/PlotLayer.js +16 -14
- package/lib/PlotLayer.worker.d.ts +2 -2
- package/lib/PlotLayer.worker.js +105 -66
- package/lib/PolylineCollection.d.ts +20 -9
- package/lib/PolylineCollection.js +158 -32
- package/lib/RawField.d.ts +11 -167
- package/lib/RawField.js +37 -383
- package/lib/TextCollection.d.ts +31 -0
- package/lib/TextCollection.js +295 -0
- package/lib/cpp/marchingsquares.d.ts +6 -0
- package/lib/cpp/marchingsquares.js +3449 -0
- package/lib/cpp/marchingsquares.wasm +0 -0
- package/lib/cpp/marchingsquares_embind.d.ts +6 -0
- package/lib/index.d.ts +13 -6
- package/lib/index.js +12 -3
- package/lib/utils.d.ts +5 -3
- package/lib/utils.js +17 -6
- package/package.json +14 -9
package/lib/RawField.js
CHANGED
|
@@ -1,313 +1,6 @@
|
|
|
1
1
|
import { Float16Array } from "@petamoriken/float16";
|
|
2
|
-
import {
|
|
3
|
-
import { layer_worker } from "./PlotComponent";
|
|
2
|
+
import { contourCreator } from "./ContourCreator";
|
|
4
3
|
import { Cache, zip } from "./utils";
|
|
5
|
-
import { WGLBuffer } from "autumn-wgl";
|
|
6
|
-
async function makeWGLDomainBuffers(gl, grid, native_grid) {
|
|
7
|
-
native_grid = native_grid !== undefined ? native_grid : grid;
|
|
8
|
-
const texcoord_margin_r = 1 / (2 * native_grid.ni);
|
|
9
|
-
const texcoord_margin_s = 1 / (2 * native_grid.nj);
|
|
10
|
-
const grid_cell_size_multiplier = (grid.ni * grid.nj) / (native_grid.ni * native_grid.nj);
|
|
11
|
-
const { lats: field_lats, lons: field_lons } = grid.getEarthCoords();
|
|
12
|
-
const domain_coords = await layer_worker.makeDomainVerticesAndTexCoords(field_lats, field_lons, grid.ni, grid.nj, texcoord_margin_r, texcoord_margin_s);
|
|
13
|
-
for (let icd = 0; icd < domain_coords['grid_cell_size'].length; icd++) {
|
|
14
|
-
domain_coords['grid_cell_size'][icd] *= grid_cell_size_multiplier;
|
|
15
|
-
}
|
|
16
|
-
const vertices = new WGLBuffer(gl, domain_coords['vertices'], 2, gl.TRIANGLE_STRIP);
|
|
17
|
-
const texcoords = new WGLBuffer(gl, domain_coords['tex_coords'], 2, gl.TRIANGLE_STRIP);
|
|
18
|
-
const grid_cell_size = new WGLBuffer(gl, domain_coords['grid_cell_size'], 1, gl.TRIANGLE_STRIP);
|
|
19
|
-
return { 'vertices': vertices, 'texcoords': texcoords, 'cellsize': grid_cell_size };
|
|
20
|
-
}
|
|
21
|
-
async function makeWGLBillboardBuffers(gl, grid, thin_fac, max_zoom) {
|
|
22
|
-
const { lats: field_lats, lons: field_lons } = grid.getEarthCoords();
|
|
23
|
-
const bb_elements = await layer_worker.makeBBElements(field_lats, field_lons, grid.ni, grid.nj, thin_fac, max_zoom);
|
|
24
|
-
const vertices = new WGLBuffer(gl, bb_elements['pts'], 3, gl.TRIANGLE_STRIP);
|
|
25
|
-
const texcoords = new WGLBuffer(gl, bb_elements['tex_coords'], 2, gl.TRIANGLE_STRIP);
|
|
26
|
-
return { 'vertices': vertices, 'texcoords': texcoords };
|
|
27
|
-
}
|
|
28
|
-
class Grid {
|
|
29
|
-
constructor(type, is_conformal, ni, nj) {
|
|
30
|
-
this.type = type;
|
|
31
|
-
this.is_conformal = is_conformal;
|
|
32
|
-
this.ni = ni;
|
|
33
|
-
this.nj = nj;
|
|
34
|
-
this.buffer_cache = new Cache((gl) => {
|
|
35
|
-
const new_ni = Math.max(Math.floor(this.ni / 50), 20);
|
|
36
|
-
const new_nj = Math.max(Math.floor(this.nj / 50), 20);
|
|
37
|
-
return makeWGLDomainBuffers(gl, this.copy({ ni: new_ni, nj: new_nj }), this);
|
|
38
|
-
});
|
|
39
|
-
this.billboard_buffer_cache = new Cache((gl, thin_fac, max_zoom) => {
|
|
40
|
-
return makeWGLBillboardBuffers(gl, this, thin_fac, max_zoom);
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
async getWGLBuffers(gl) {
|
|
44
|
-
return await this.buffer_cache.getValue(gl);
|
|
45
|
-
}
|
|
46
|
-
async getWGLBillboardBuffers(gl, thin_fac, max_zoom) {
|
|
47
|
-
return await this.billboard_buffer_cache.getValue(gl, thin_fac, max_zoom);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
/** A plate carree (a.k.a. lat/lon) grid with uniform grid spacing */
|
|
51
|
-
class PlateCarreeGrid extends Grid {
|
|
52
|
-
/**
|
|
53
|
-
* Create a plate carree grid
|
|
54
|
-
* @param ni - The number of grid points in the i (longitude) direction
|
|
55
|
-
* @param nj - The number of grid points in the j (latitude) direction
|
|
56
|
-
* @param ll_lon - The longitude of the lower left corner of the grid
|
|
57
|
-
* @param ll_lat - The latitude of the lower left corner of the grid
|
|
58
|
-
* @param ur_lon - The longitude of the upper right corner of the grid
|
|
59
|
-
* @param ur_lat - The latitude of the upper right corner of the grid
|
|
60
|
-
*/
|
|
61
|
-
constructor(ni, nj, ll_lon, ll_lat, ur_lon, ur_lat) {
|
|
62
|
-
super('latlon', true, ni, nj);
|
|
63
|
-
this.ll_lon = ll_lon;
|
|
64
|
-
this.ll_lat = ll_lat;
|
|
65
|
-
this.ur_lon = ur_lon;
|
|
66
|
-
this.ur_lat = ur_lat;
|
|
67
|
-
const dlon = (this.ur_lon - this.ll_lon) / (this.ni - 1);
|
|
68
|
-
const dlat = (this.ur_lat - this.ll_lat) / (this.nj - 1);
|
|
69
|
-
this.ll_cache = new Cache(() => {
|
|
70
|
-
const lons = new Float32Array(this.ni * this.nj);
|
|
71
|
-
const lats = new Float32Array(this.ni * this.nj);
|
|
72
|
-
for (let i = 0; i < this.ni; i++) {
|
|
73
|
-
for (let j = 0; j < this.nj; j++) {
|
|
74
|
-
const idx = i + j * this.ni;
|
|
75
|
-
lons[idx] = this.ll_lon + i * dlon;
|
|
76
|
-
lats[idx] = this.ll_lat + j * dlat;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return { 'lons': lons, 'lats': lats };
|
|
80
|
-
});
|
|
81
|
-
this.gc_cache = new Cache(() => {
|
|
82
|
-
const x = new Float32Array(this.ni);
|
|
83
|
-
const y = new Float32Array(this.nj);
|
|
84
|
-
for (let i = 0; i < this.ni; i++) {
|
|
85
|
-
x[i] = this.ll_lon + i * dlon;
|
|
86
|
-
}
|
|
87
|
-
for (let j = 0; j < this.nj; j++) {
|
|
88
|
-
y[j] = this.ll_lat + j * dlat;
|
|
89
|
-
}
|
|
90
|
-
return { x: x, y: y };
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
copy(opts) {
|
|
94
|
-
opts = opts !== undefined ? opts : {};
|
|
95
|
-
const ni = opts.ni !== undefined ? opts.ni : this.ni;
|
|
96
|
-
const nj = opts.nj !== undefined ? opts.nj : this.nj;
|
|
97
|
-
const ll_lon = opts.ll_lon !== undefined ? opts.ll_lon : this.ll_lon;
|
|
98
|
-
const ll_lat = opts.ll_lat !== undefined ? opts.ll_lat : this.ll_lat;
|
|
99
|
-
const ur_lon = opts.ur_lon !== undefined ? opts.ur_lon : this.ur_lon;
|
|
100
|
-
const ur_lat = opts.ur_lat !== undefined ? opts.ur_lat : this.ur_lat;
|
|
101
|
-
return new PlateCarreeGrid(ni, nj, ll_lon, ll_lat, ur_lon, ur_lat);
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Get a list of longitudes and latitudes on the grid (internal method)
|
|
105
|
-
*/
|
|
106
|
-
getEarthCoords() {
|
|
107
|
-
return this.ll_cache.getValue();
|
|
108
|
-
}
|
|
109
|
-
getGridCoords() {
|
|
110
|
-
return this.gc_cache.getValue();
|
|
111
|
-
}
|
|
112
|
-
transform(x, y, opts) {
|
|
113
|
-
return [x, y];
|
|
114
|
-
}
|
|
115
|
-
getThinnedGrid(thin_x, thin_y) {
|
|
116
|
-
const dlon = (this.ur_lon - this.ll_lon) / this.ni;
|
|
117
|
-
const dlat = (this.ur_lat - this.ll_lat) / this.nj;
|
|
118
|
-
const ni = Math.ceil(this.ni / thin_x);
|
|
119
|
-
const nj = Math.ceil(this.nj / thin_y);
|
|
120
|
-
const ni_remove = (this.ni - 1) % thin_x;
|
|
121
|
-
const nj_remove = (this.nj - 1) % thin_y;
|
|
122
|
-
const ll_lon = this.ll_lon;
|
|
123
|
-
const ll_lat = this.ll_lat;
|
|
124
|
-
const ur_lon = this.ur_lon - ni_remove * dlon;
|
|
125
|
-
const ur_lat = this.ur_lat - nj_remove * dlat;
|
|
126
|
-
return new PlateCarreeGrid(ni, nj, ll_lon, ll_lat, ur_lon, ur_lat);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
/** A rotated lat-lon (plate carree) grid with uniform grid spacing */
|
|
130
|
-
class PlateCarreeRotatedGrid extends Grid {
|
|
131
|
-
/**
|
|
132
|
-
* Create a Lambert conformal conic grid
|
|
133
|
-
* @param ni - The number of grid points in the i (longitude) direction
|
|
134
|
-
* @param nj - The number of grid points in the j (latitude) direction
|
|
135
|
-
* @param np_lon - The longitude of the north pole for the rotated grid
|
|
136
|
-
* @param np_lat - The latitude of the north pole for the rotated grid
|
|
137
|
-
* @param lon_shift - The angle around the rotated north pole to shift the central meridian
|
|
138
|
-
* @param ll_lon - The longitude of the lower left corner of the grid (on the rotated earth)
|
|
139
|
-
* @param ll_lat - The latitude of the lower left corner of the grid (on the rotated earth)
|
|
140
|
-
* @param ur_lon - The longitude of the upper right corner of the grid (on the rotated earth)
|
|
141
|
-
* @param ur_lat - The latitude of the upper right corner of the grid (on the rotated earth)
|
|
142
|
-
*/
|
|
143
|
-
constructor(ni, nj, np_lon, np_lat, lon_shift, ll_lon, ll_lat, ur_lon, ur_lat) {
|
|
144
|
-
super('latlonrot', true, ni, nj);
|
|
145
|
-
this.np_lon = np_lon;
|
|
146
|
-
this.np_lat = np_lat;
|
|
147
|
-
this.lon_shift = lon_shift;
|
|
148
|
-
this.ll_lon = ll_lon;
|
|
149
|
-
this.ll_lat = ll_lat;
|
|
150
|
-
this.ur_lon = ur_lon;
|
|
151
|
-
this.ur_lat = ur_lat;
|
|
152
|
-
this.llrot = rotateSphere({ np_lon: np_lon, np_lat: np_lat, lon_shift: lon_shift });
|
|
153
|
-
const dlon = (this.ur_lon - this.ll_lon) / (this.ni - 1);
|
|
154
|
-
const dlat = (this.ur_lat - this.ll_lat) / (this.nj - 1);
|
|
155
|
-
this.ll_cache = new Cache(() => {
|
|
156
|
-
const lons = new Float32Array(this.ni * this.nj);
|
|
157
|
-
const lats = new Float32Array(this.ni * this.nj);
|
|
158
|
-
for (let i = 0; i < this.ni; i++) {
|
|
159
|
-
const lon_p = this.ll_lon + i * dlon;
|
|
160
|
-
for (let j = 0; j < this.nj; j++) {
|
|
161
|
-
const lat_p = this.ll_lat + j * dlat;
|
|
162
|
-
const [lon, lat] = this.llrot(lon_p, lat_p);
|
|
163
|
-
const idx = i + j * this.ni;
|
|
164
|
-
lons[idx] = lon;
|
|
165
|
-
lats[idx] = lat;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return { lons: lons, lats: lats };
|
|
169
|
-
});
|
|
170
|
-
this.gc_cache = new Cache(() => {
|
|
171
|
-
const x = new Float32Array(this.ni);
|
|
172
|
-
const y = new Float32Array(this.nj);
|
|
173
|
-
for (let i = 0; i < this.ni; i++) {
|
|
174
|
-
x[i] = this.ll_lon + i * dlon;
|
|
175
|
-
}
|
|
176
|
-
for (let j = 0; j < this.nj; j++) {
|
|
177
|
-
y[j] = this.ll_lat + j * dlat;
|
|
178
|
-
}
|
|
179
|
-
return { x: x, y: y };
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
copy(opts) {
|
|
183
|
-
opts = opts !== undefined ? opts : {};
|
|
184
|
-
const ni = opts.ni !== undefined ? opts.ni : this.ni;
|
|
185
|
-
const nj = opts.nj !== undefined ? opts.nj : this.nj;
|
|
186
|
-
const ll_lon = opts.ll_lon !== undefined ? opts.ll_lon : this.ll_lon;
|
|
187
|
-
const ll_lat = opts.ll_lat !== undefined ? opts.ll_lat : this.ll_lat;
|
|
188
|
-
const ur_lon = opts.ur_lon !== undefined ? opts.ur_lon : this.ur_lon;
|
|
189
|
-
const ur_lat = opts.ur_lat !== undefined ? opts.ur_lat : this.ur_lat;
|
|
190
|
-
return new PlateCarreeRotatedGrid(ni, nj, this.np_lon, this.np_lat, this.lon_shift, ll_lon, ll_lat, ur_lon, ur_lat);
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Get a list of longitudes and latitudes on the grid (internal method)
|
|
194
|
-
*/
|
|
195
|
-
getEarthCoords() {
|
|
196
|
-
return this.ll_cache.getValue();
|
|
197
|
-
}
|
|
198
|
-
getGridCoords() {
|
|
199
|
-
return this.gc_cache.getValue();
|
|
200
|
-
}
|
|
201
|
-
transform(x, y, opts) {
|
|
202
|
-
opts = opts === undefined ? {} : opts;
|
|
203
|
-
const inverse = 'inverse' in opts ? opts.inverse : false;
|
|
204
|
-
return this.llrot(x, y, { inverse: !inverse });
|
|
205
|
-
}
|
|
206
|
-
getThinnedGrid(thin_x, thin_y) {
|
|
207
|
-
const dlon = (this.ur_lon - this.ll_lon) / this.ni;
|
|
208
|
-
const dlat = (this.ur_lat - this.ll_lat) / this.nj;
|
|
209
|
-
const ni = Math.ceil(this.ni / thin_x);
|
|
210
|
-
const nj = Math.ceil(this.nj / thin_y);
|
|
211
|
-
const ni_remove = (this.ni - 1) % thin_x;
|
|
212
|
-
const nj_remove = (this.nj - 1) % thin_y;
|
|
213
|
-
const ll_lon = this.ll_lon;
|
|
214
|
-
const ll_lat = this.ll_lat;
|
|
215
|
-
const ur_lon = this.ur_lon - ni_remove * dlon;
|
|
216
|
-
const ur_lat = this.ur_lat - nj_remove * dlat;
|
|
217
|
-
return new PlateCarreeRotatedGrid(ni, nj, this.np_lon, this.np_lat, this.lon_shift, ll_lon, ll_lat, ur_lon, ur_lat);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
/** A Lambert conformal conic grid with uniform grid spacing */
|
|
221
|
-
class LambertGrid extends Grid {
|
|
222
|
-
/**
|
|
223
|
-
* Create a Lambert conformal conic grid
|
|
224
|
-
* @param ni - The number of grid points in the i (longitude) direction
|
|
225
|
-
* @param nj - The number of grid points in the j (latitude) direction
|
|
226
|
-
* @param lon_0 - The standard longitude for the projection; this is also the center longitude for the projection
|
|
227
|
-
* @param lat_0 - The center latitude for the projection
|
|
228
|
-
* @param lat_std - The standard latitudes for the projection
|
|
229
|
-
* @param ll_x - The x coordinate in projection space of the lower-left corner of the grid
|
|
230
|
-
* @param ll_y - The y coordinate in projection space of the lower-left corner of the grid
|
|
231
|
-
* @param ur_x - The x coordinate in projection space of the upper-right corner of the grid
|
|
232
|
-
* @param ur_y - The y coordinate in projection space of the upper-right corner of the grid
|
|
233
|
-
*/
|
|
234
|
-
constructor(ni, nj, lon_0, lat_0, lat_std, ll_x, ll_y, ur_x, ur_y) {
|
|
235
|
-
super('lcc', true, ni, nj);
|
|
236
|
-
this.lon_0 = lon_0;
|
|
237
|
-
this.lat_0 = lat_0;
|
|
238
|
-
this.lat_std = lat_std;
|
|
239
|
-
this.ll_x = ll_x;
|
|
240
|
-
this.ll_y = ll_y;
|
|
241
|
-
this.ur_x = ur_x;
|
|
242
|
-
this.ur_y = ur_y;
|
|
243
|
-
this.lcc = lambertConformalConic({ lon_0: lon_0, lat_0: lat_0, lat_std: lat_std });
|
|
244
|
-
const dx = (this.ur_x - this.ll_x) / (this.ni - 1);
|
|
245
|
-
const dy = (this.ur_y - this.ll_y) / (this.nj - 1);
|
|
246
|
-
this.ll_cache = new Cache(() => {
|
|
247
|
-
const lons = new Float32Array(this.ni * this.nj);
|
|
248
|
-
const lats = new Float32Array(this.ni * this.nj);
|
|
249
|
-
for (let i = 0; i < this.ni; i++) {
|
|
250
|
-
const x = this.ll_x + i * dx;
|
|
251
|
-
for (let j = 0; j < this.nj; j++) {
|
|
252
|
-
const y = this.ll_y + j * dy;
|
|
253
|
-
const [lon, lat] = this.lcc(x, y, { inverse: true });
|
|
254
|
-
const idx = i + j * this.ni;
|
|
255
|
-
lons[idx] = lon;
|
|
256
|
-
lats[idx] = lat;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
return { lons: lons, lats: lats };
|
|
260
|
-
});
|
|
261
|
-
this.gc_cache = new Cache(() => {
|
|
262
|
-
const x = new Float32Array(this.ni);
|
|
263
|
-
const y = new Float32Array(this.nj);
|
|
264
|
-
for (let i = 0; i < this.ni; i++) {
|
|
265
|
-
x[i] = this.ll_x + i * dx;
|
|
266
|
-
}
|
|
267
|
-
for (let j = 0; j < this.nj; j++) {
|
|
268
|
-
y[j] = this.ll_y + j * dy;
|
|
269
|
-
}
|
|
270
|
-
return { x: x, y: y };
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
copy(opts) {
|
|
274
|
-
opts = opts !== undefined ? opts : {};
|
|
275
|
-
const ni = opts.ni !== undefined ? opts.ni : this.ni;
|
|
276
|
-
const nj = opts.nj !== undefined ? opts.nj : this.nj;
|
|
277
|
-
const ll_x = opts.ll_x !== undefined ? opts.ll_x : this.ll_x;
|
|
278
|
-
const ll_y = opts.ll_y !== undefined ? opts.ll_y : this.ll_y;
|
|
279
|
-
const ur_x = opts.ur_x !== undefined ? opts.ur_x : this.ur_x;
|
|
280
|
-
const ur_y = opts.ur_y !== undefined ? opts.ur_y : this.ur_y;
|
|
281
|
-
return new LambertGrid(ni, nj, this.lon_0, this.lat_0, this.lat_std, ll_x, ll_y, ur_x, ur_y);
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Get a list of longitudes and latitudes on the grid (internal method)
|
|
285
|
-
*/
|
|
286
|
-
getEarthCoords() {
|
|
287
|
-
return this.ll_cache.getValue();
|
|
288
|
-
}
|
|
289
|
-
getGridCoords() {
|
|
290
|
-
return this.gc_cache.getValue();
|
|
291
|
-
}
|
|
292
|
-
transform(x, y, opts) {
|
|
293
|
-
opts = opts === undefined ? {} : opts;
|
|
294
|
-
const inverse = 'inverse' in opts ? opts.inverse : false;
|
|
295
|
-
return this.lcc(x, y, { inverse: inverse });
|
|
296
|
-
}
|
|
297
|
-
getThinnedGrid(thin_x, thin_y) {
|
|
298
|
-
const dx = (this.ur_x - this.ll_x) / this.ni;
|
|
299
|
-
const dy = (this.ur_y - this.ll_y) / this.nj;
|
|
300
|
-
const ni = Math.ceil(this.ni / thin_x);
|
|
301
|
-
const nj = Math.ceil(this.nj / thin_y);
|
|
302
|
-
const ni_remove = (this.ni - 1) % thin_x;
|
|
303
|
-
const nj_remove = (this.nj - 1) % thin_y;
|
|
304
|
-
const ll_x = this.ll_x;
|
|
305
|
-
const ll_y = this.ll_y;
|
|
306
|
-
const ur_x = this.ur_x - ni_remove * dx;
|
|
307
|
-
const ur_y = this.ur_y - nj_remove * dy;
|
|
308
|
-
return new LambertGrid(ni, nj, this.lon_0, this.lat_0, this.lat_std, ll_x, ll_y, ur_x, ur_y);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
4
|
function getArrayConstructor(ary) {
|
|
312
5
|
return ary.constructor;
|
|
313
6
|
}
|
|
@@ -324,34 +17,25 @@ class RawScalarField {
|
|
|
324
17
|
if (grid.ni * grid.nj != data.length) {
|
|
325
18
|
throw `Data size (${data.length}) doesn't match the grid dimensions (${grid.ni} x ${grid.nj}; expected ${grid.ni * grid.nj} points)`;
|
|
326
19
|
}
|
|
20
|
+
this.contour_cache = new Cache(async (opts) => {
|
|
21
|
+
return await contourCreator(this.data, this.grid, opts);
|
|
22
|
+
});
|
|
327
23
|
}
|
|
328
24
|
/** @internal */
|
|
329
25
|
getTextureData() {
|
|
330
26
|
// Need to give float16 data as uint16s to make WebGL happy: https://github.com/petamoriken/float16/issues/105
|
|
27
|
+
const raw_data = this.data;
|
|
331
28
|
let data;
|
|
332
|
-
if (
|
|
333
|
-
data =
|
|
29
|
+
if (raw_data instanceof Float32Array) {
|
|
30
|
+
data = raw_data;
|
|
334
31
|
}
|
|
335
32
|
else {
|
|
336
|
-
data = new Uint16Array(
|
|
33
|
+
data = new Uint16Array(raw_data.buffer);
|
|
337
34
|
}
|
|
338
35
|
return data;
|
|
339
36
|
}
|
|
340
|
-
|
|
341
|
-
return
|
|
342
|
-
}
|
|
343
|
-
getThinnedField(thin_x, thin_y) {
|
|
344
|
-
const arrayType = getArrayConstructor(this.data);
|
|
345
|
-
const new_grid = this.grid.getThinnedGrid(thin_x, thin_y);
|
|
346
|
-
const new_data = new arrayType(new_grid.ni * new_grid.nj);
|
|
347
|
-
for (let i = 0; i < new_grid.ni; i++) {
|
|
348
|
-
for (let j = 0; j < new_grid.nj; j++) {
|
|
349
|
-
const idx_old = i * thin_x + this.grid.ni * j * thin_y;
|
|
350
|
-
const idx = i + new_grid.ni * j;
|
|
351
|
-
new_data[idx] = this.data[idx_old];
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
return new RawScalarField(new_grid, new_data);
|
|
37
|
+
async getContours(opts) {
|
|
38
|
+
return await this.contour_cache.getValue(opts);
|
|
355
39
|
}
|
|
356
40
|
/**
|
|
357
41
|
* Create a new field by aggregating a number of fields using a specific function
|
|
@@ -385,70 +69,39 @@ class RawVectorField {
|
|
|
385
69
|
*/
|
|
386
70
|
constructor(grid, u, v, opts) {
|
|
387
71
|
opts = opts === undefined ? {} : opts;
|
|
388
|
-
const arrayType = getArrayConstructor(u);
|
|
389
72
|
this.u = new RawScalarField(grid, u);
|
|
390
73
|
this.v = new RawScalarField(grid, v);
|
|
391
74
|
this.relative_to = opts.relative_to === undefined ? 'grid' : opts.relative_to;
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
const u = this.u.data[icd];
|
|
401
|
-
const v = this.v.data[icd];
|
|
402
|
-
if (Math.abs(u) < 1e-6 && Math.abs(v) < 1e-6) {
|
|
403
|
-
u_rot[icd] = 0;
|
|
404
|
-
v_rot[icd] = 0;
|
|
405
|
-
continue;
|
|
406
|
-
}
|
|
407
|
-
const [x, y] = grid.transform(lon, lat);
|
|
408
|
-
const [x_pertlon, y_pertlon] = grid.transform(lon + 0.01, lat);
|
|
409
|
-
const mag_pertlon = Math.hypot(x - x_pertlon, y - y_pertlon);
|
|
410
|
-
const x_dotlon = (x_pertlon - x) / mag_pertlon;
|
|
411
|
-
const y_dotlon = (y_pertlon - y) / mag_pertlon;
|
|
412
|
-
let x_dotlat, y_dotlat;
|
|
413
|
-
if (grid.is_conformal) {
|
|
414
|
-
// If the grid is conformal, v and u are rotated by the same amount in the same direction.
|
|
415
|
-
x_dotlat = -y_dotlon;
|
|
416
|
-
y_dotlat = x_dotlon;
|
|
417
|
-
}
|
|
418
|
-
else {
|
|
419
|
-
// If the grid is non-conformal, we need a fully general change of basis from grid coordinates to earth coordinates.
|
|
420
|
-
const [x_pertlat, y_pertlat] = grid.transform(lon, lat + 0.01);
|
|
421
|
-
const mag_pertlat = Math.hypot(x - x_pertlat, y - y_pertlat);
|
|
422
|
-
x_dotlat = (x_pertlat - x) / mag_pertlat;
|
|
423
|
-
y_dotlat = (y_pertlat - y) / mag_pertlat;
|
|
424
|
-
}
|
|
425
|
-
u_rot[icd] = x_dotlon * u + y_dotlon * v;
|
|
426
|
-
v_rot[icd] = x_dotlat * u + y_dotlat * v;
|
|
427
|
-
}
|
|
428
|
-
return { u: new RawScalarField(grid, u_rot), v: new RawScalarField(grid, v_rot) };
|
|
429
|
-
});
|
|
75
|
+
}
|
|
76
|
+
getTextureData() {
|
|
77
|
+
// Need to give float16 data as uint16s to make WebGL happy: https://github.com/petamoriken/float16/issues/105
|
|
78
|
+
const raw_u = this.u.data;
|
|
79
|
+
const raw_v = this.v.data;
|
|
80
|
+
const u = raw_u instanceof Float32Array ? raw_u : new Uint16Array(raw_u.buffer);
|
|
81
|
+
const v = raw_v instanceof Float32Array ? raw_v : new Uint16Array(raw_v.buffer);
|
|
82
|
+
return { u: u, v: v };
|
|
430
83
|
}
|
|
431
84
|
getThinnedField(thin_x, thin_y) {
|
|
432
|
-
const
|
|
433
|
-
const
|
|
434
|
-
|
|
85
|
+
const new_grid = this.grid.getThinnedGrid(thin_x, thin_y);
|
|
86
|
+
const thinGrid = (data) => {
|
|
87
|
+
const arrayType = getArrayConstructor(data);
|
|
88
|
+
const new_data = new arrayType(new_grid.ni * new_grid.nj);
|
|
89
|
+
for (let i = 0; i < new_grid.ni; i++) {
|
|
90
|
+
for (let j = 0; j < new_grid.nj; j++) {
|
|
91
|
+
const idx_old = i * thin_x + this.grid.ni * j * thin_y;
|
|
92
|
+
const idx = i + new_grid.ni * j;
|
|
93
|
+
new_data[idx] = data[idx_old];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return new_data;
|
|
97
|
+
};
|
|
98
|
+
const thin_u = thinGrid(this.u.data);
|
|
99
|
+
const thin_v = thinGrid(this.v.data);
|
|
100
|
+
return new RawVectorField(new_grid, thin_u, thin_v, { relative_to: this.relative_to });
|
|
435
101
|
}
|
|
436
102
|
get grid() {
|
|
437
103
|
return this.u.grid;
|
|
438
104
|
}
|
|
439
|
-
toEarthRelative() {
|
|
440
|
-
let u, v;
|
|
441
|
-
if (this.relative_to == 'earth') {
|
|
442
|
-
u = this.u;
|
|
443
|
-
v = this.v;
|
|
444
|
-
}
|
|
445
|
-
else {
|
|
446
|
-
const { u: u_, v: v_ } = this.rotate_cache.getValue();
|
|
447
|
-
u = u_;
|
|
448
|
-
v = v_;
|
|
449
|
-
}
|
|
450
|
-
return new RawVectorField(u.grid, u.data, v.data, { relative_to: 'earth' });
|
|
451
|
-
}
|
|
452
105
|
}
|
|
453
106
|
/** A class grid of wind profiles */
|
|
454
107
|
class RawProfileField {
|
|
@@ -463,9 +116,10 @@ class RawProfileField {
|
|
|
463
116
|
}
|
|
464
117
|
/** Get the gridded storm motion vector field (internal method) */
|
|
465
118
|
getStormMotionGrid() {
|
|
119
|
+
const profiles = this.profiles;
|
|
466
120
|
const u = new Float16Array(this.grid.ni * this.grid.nj).fill(parseFloat('nan'));
|
|
467
121
|
const v = new Float16Array(this.grid.ni * this.grid.nj).fill(parseFloat('nan'));
|
|
468
|
-
|
|
122
|
+
profiles.forEach(prof => {
|
|
469
123
|
const idx = prof.ilon + this.grid.ni * prof.jlat;
|
|
470
124
|
u[idx] = prof.smu;
|
|
471
125
|
v[idx] = prof.smv;
|
|
@@ -473,4 +127,4 @@ class RawProfileField {
|
|
|
473
127
|
return new RawVectorField(this.grid, u, v, { relative_to: 'grid' });
|
|
474
128
|
}
|
|
475
129
|
}
|
|
476
|
-
export { RawScalarField, RawVectorField, RawProfileField
|
|
130
|
+
export { RawScalarField, RawVectorField, RawProfileField };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { WebGLAnyRenderingContext } from "./AutumnTypes";
|
|
2
|
+
import { WGLBuffer, WGLProgram, WGLTexture } from "autumn-wgl";
|
|
3
|
+
interface TextSpec {
|
|
4
|
+
lat: number;
|
|
5
|
+
lon: number;
|
|
6
|
+
text: string;
|
|
7
|
+
min_zoom?: number;
|
|
8
|
+
}
|
|
9
|
+
type HorizontalAlign = 'left' | 'center' | 'right';
|
|
10
|
+
type VerticalAlign = 'baseline' | 'middle' | 'top';
|
|
11
|
+
interface TextCollectionOptions {
|
|
12
|
+
horizontal_align?: HorizontalAlign;
|
|
13
|
+
vertical_align?: VerticalAlign;
|
|
14
|
+
font_size?: number;
|
|
15
|
+
text_color?: [number, number, number];
|
|
16
|
+
halo_color?: [number, number, number];
|
|
17
|
+
halo?: boolean;
|
|
18
|
+
}
|
|
19
|
+
declare class TextCollection {
|
|
20
|
+
readonly program: WGLProgram;
|
|
21
|
+
readonly anchors: WGLBuffer;
|
|
22
|
+
readonly offsets: WGLBuffer;
|
|
23
|
+
readonly texcoords: WGLBuffer;
|
|
24
|
+
readonly texture: WGLTexture;
|
|
25
|
+
readonly opts: Required<TextCollectionOptions>;
|
|
26
|
+
private constructor();
|
|
27
|
+
static make(gl: WebGLAnyRenderingContext, text_locs: TextSpec[], fontstack_url: string, opts?: TextCollectionOptions): Promise<TextCollection>;
|
|
28
|
+
render(gl: WebGLAnyRenderingContext, matrix: number[], [map_width, map_height]: [number, number], map_zoom: number): void;
|
|
29
|
+
}
|
|
30
|
+
export { TextCollection };
|
|
31
|
+
export type { TextSpec, TextCollectionOptions };
|