autumnplot-gl 4.0.0-beta → 4.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.
Files changed (84) hide show
  1. package/README.md +13 -207
  2. package/dist/812.autumnplot-gl.js +2 -0
  3. package/dist/812.autumnplot-gl.js.map +1 -0
  4. package/dist/983.autumnplot-gl.js +2 -0
  5. package/dist/983.autumnplot-gl.js.map +1 -0
  6. package/dist/autumnplot-gl.js +1 -1
  7. package/dist/autumnplot-gl.js.map +1 -1
  8. package/dist/marchingsquares.wasm +0 -0
  9. package/lib/AutumnTypes.d.ts +38 -5
  10. package/lib/AutumnTypes.js +7 -1
  11. package/lib/Barbs.d.ts +12 -2
  12. package/lib/Barbs.js +9 -0
  13. package/lib/BillboardCollection.d.ts +2 -2
  14. package/lib/BillboardCollection.js +14 -14
  15. package/lib/Color.d.ts +1 -0
  16. package/lib/Color.js +1 -0
  17. package/lib/ColorBar.d.ts +14 -0
  18. package/lib/ColorBar.js +15 -8
  19. package/lib/Colormap.d.ts +9 -1
  20. package/lib/Colormap.js +24 -1
  21. package/lib/Contour.d.ts +26 -1
  22. package/lib/Contour.js +24 -2
  23. package/lib/ContourCreator.worker.d.ts +25 -0
  24. package/lib/{ContourCreator.js → ContourCreator.worker.js} +15 -14
  25. package/lib/Fill.d.ts +31 -11
  26. package/lib/Fill.js +38 -18
  27. package/lib/Hodographs.d.ts +19 -3
  28. package/lib/Hodographs.js +45 -20
  29. package/lib/Map.d.ts +13 -1
  30. package/lib/Map.js +62 -8
  31. package/lib/Paintball.d.ts +14 -5
  32. package/lib/Paintball.js +96 -46
  33. package/lib/PlotComponent.d.ts +9 -3
  34. package/lib/PlotComponent.js +36 -1
  35. package/lib/PlotLayer.d.ts +2 -2
  36. package/lib/PlotLayer.js +2 -2
  37. package/lib/PlotLayer.worker.js +9 -3
  38. package/lib/RawField.d.ts +223 -27
  39. package/lib/RawField.js +413 -59
  40. package/lib/StationPlot.d.ts +78 -11
  41. package/lib/StationPlot.js +113 -30
  42. package/lib/TextCollection.d.ts +5 -0
  43. package/lib/TextCollection.js +82 -9
  44. package/lib/WasmInterface.d.ts +7 -0
  45. package/lib/WasmInterface.js +11 -0
  46. package/lib/WorkerPool.d.ts +8 -0
  47. package/lib/WorkerPool.js +77 -0
  48. package/lib/cpp/marchingsquares.js +127 -13
  49. package/lib/cpp/marchingsquares.wasm +0 -0
  50. package/lib/cpp/marchingsquares_embind.d.ts +16 -3
  51. package/lib/grids/AutoZoom.d.ts +21 -0
  52. package/lib/grids/AutoZoom.js +63 -0
  53. package/lib/grids/DomainBuffer.d.ts +14 -0
  54. package/lib/grids/DomainBuffer.js +16 -0
  55. package/lib/grids/Geostationary.d.ts +35 -0
  56. package/lib/grids/Geostationary.js +47 -0
  57. package/lib/grids/Grid.d.ts +36 -0
  58. package/lib/grids/Grid.js +12 -0
  59. package/lib/grids/GridCoordinates.d.ts +10 -0
  60. package/lib/grids/GridCoordinates.js +64 -0
  61. package/lib/grids/LambertGrid.d.ts +73 -0
  62. package/lib/grids/LambertGrid.js +92 -0
  63. package/lib/grids/PlateCarreeGrid.d.ts +46 -0
  64. package/lib/grids/PlateCarreeGrid.js +55 -0
  65. package/lib/grids/PlateCarreeRotatedGrid.d.ts +53 -0
  66. package/lib/grids/PlateCarreeRotatedGrid.js +65 -0
  67. package/lib/grids/RadarSweepGrid.d.ts +46 -0
  68. package/lib/grids/RadarSweepGrid.js +74 -0
  69. package/lib/grids/StructuredGrid.d.ts +49 -0
  70. package/lib/grids/StructuredGrid.js +103 -0
  71. package/lib/grids/UnstructuredGrid.d.ts +56 -0
  72. package/lib/grids/UnstructuredGrid.js +102 -0
  73. package/lib/index.d.ts +23 -6
  74. package/lib/index.js +18 -8
  75. package/lib/utils.d.ts +11 -2
  76. package/lib/utils.js +63 -1
  77. package/package.json +4 -3
  78. package/dist/110.autumnplot-gl.js +0 -2
  79. package/dist/110.autumnplot-gl.js.map +0 -1
  80. package/lib/ContourCreator.d.ts +0 -22
  81. package/lib/Grid.d.ts +0 -263
  82. package/lib/Grid.js +0 -547
  83. package/lib/ParticleTracer.d.ts +0 -19
  84. package/lib/ParticleTracer.js +0 -37
package/lib/RawField.d.ts CHANGED
@@ -1,11 +1,58 @@
1
1
  import { Float16Array } from "@petamoriken/float16";
2
- import { ContourData, TypedArray, WebGLAnyRenderingContext, WindProfile } from "./AutumnTypes";
3
- import { FieldContourOpts } from "./ContourCreator";
4
- import { Grid } from "./Grid";
5
- import { WGLTextureSpec } from "autumn-wgl";
6
- type TextureDataType<ArrayType> = ArrayType extends Float32Array ? Float32Array : (ArrayType extends Uint8Array ? Uint8Array : Uint16Array);
2
+ import { ContourData, TypedArray, TypedArrayStr, WebGLAnyRenderingContext, WindProfile } from "./AutumnTypes";
3
+ import { FieldContourOpts } from "./ContourCreator.worker";
4
+ import { Grid } from "./grids/Grid";
5
+ import { WGLTexture } from "autumn-wgl";
6
+ import { AutoZoomGrid } from "./grids/AutoZoom";
7
+ type TextureDataType<ArrayType> = ArrayType extends Float32Array ? Float32Array : (ArrayType extends Uint8Array ? Uint8Array : (ArrayType extends Uint32Array ? Uint32Array : (ArrayType extends Int32Array ? Int32Array : (ArrayType extends Int16Array ? Int16Array : Uint16Array))));
8
+ declare abstract class ExpressionScalarField<ArrayType extends TypedArray, GridType extends Grid> {
9
+ abstract updateTexImageData(gl: WebGLAnyRenderingContext, image_mag_filter: number, fill_textures: Map<string, WGLTexture> | null): Map<string, WGLTexture>;
10
+ abstract getSamplerIds(): string[];
11
+ abstract getExpression(): string;
12
+ abstract renderCPU(): RawScalarField<ArrayType, GridType>;
13
+ abstract iterateCPU(): Generator<number, void, unknown>;
14
+ abstract get grid(): GridType;
15
+ abstract get aryConstructor(): new (...args: any[]) => ArrayType;
16
+ abstract get dtypes(): TypedArrayStr[];
17
+ private operand;
18
+ /**
19
+ * Multiply this field by another scalar. The computation occurs on the GPU if the resulting field is used in a plot component or on the CPU if
20
+ * {@link ComputedScalarField.renderCPU | renderCPU()} is called on the resulting field.
21
+ * @param other - Scalar to multiply this field by
22
+ * @returns A `ComputedScalarField` representing the multiplied field
23
+ */
24
+ multiply(other: ExpressionScalarField<ArrayType, GridType> | number): ComputedScalarField<ArrayType, GridType>;
25
+ /**
26
+ * Divide this field by another scalar. The computation occurs on the GPU if the resulting field is used in a plot component or on the CPU if
27
+ * {@link ComputedScalarField.renderCPU | renderCPU()} is called on the resulting field.
28
+ * @param other - Scalar to divide this field by
29
+ * @returns A `ComputedScalarField` representing the divided field
30
+ */
31
+ divide(other: ExpressionScalarField<ArrayType, GridType> | number): ComputedScalarField<ArrayType, GridType>;
32
+ /**
33
+ * Add this field to another scalar. The computation occurs on the GPU if the resulting field is used in a plot component or on the CPU if
34
+ * {@link ComputedScalarField.renderCPU | renderCPU()} is called on the resulting field.
35
+ * @param other - Scalar to add to this field
36
+ * @returns A `ComputedScalarField` representing the added field
37
+ */
38
+ add(other: ExpressionScalarField<ArrayType, GridType> | number): ComputedScalarField<ArrayType, GridType>;
39
+ /**
40
+ * Subtract another scalar from this field. The computation occurs on the GPU if the resulting field is used in a plot component or on the CPU if
41
+ * {@link ComputedScalarField.renderCPU | renderCPU()} is called on the resulting field.
42
+ * @param other - Scalar to subtract from this field
43
+ * @returns A `ComputedScalarField` representing the subtracted field
44
+ */
45
+ subtract(other: ExpressionScalarField<ArrayType, GridType> | number): ComputedScalarField<ArrayType, GridType>;
46
+ abstract getThinnedField(thin_fac: number, map_max_zoom: number): this;
47
+ abstract sampleField(lon: number, lat: number): number;
48
+ abstract sampleFieldWithCoord(lon: number, lat: number): {
49
+ sample: number;
50
+ sample_lon: number;
51
+ sample_lat: number;
52
+ };
53
+ }
7
54
  /** A class representing a raw 2D field of gridded data, such as height or u wind. */
8
- declare class RawScalarField<ArrayType extends TypedArray, GridType extends Grid> {
55
+ declare class RawScalarField<ArrayType extends TypedArray, GridType extends Grid> extends ExpressionScalarField<ArrayType, GridType> {
9
56
  readonly grid: GridType;
10
57
  readonly data: ArrayType;
11
58
  private readonly contour_cache;
@@ -16,8 +63,17 @@ declare class RawScalarField<ArrayType extends TypedArray, GridType extends Grid
16
63
  */
17
64
  constructor(grid: GridType, data: ArrayType);
18
65
  /** @internal */
66
+ get aryConstructor(): new (...args: any[]) => ArrayType;
67
+ /** @internal */
68
+ get dtypes(): TypedArrayStr[];
69
+ /** @internal */
19
70
  private getTextureData;
20
- getWGLTextureSpec(gl: WebGLAnyRenderingContext, image_mag_filter: number): WGLTextureSpec;
71
+ private getWGLTextureSpec;
72
+ updateTexImageData(gl: WebGLAnyRenderingContext, image_mag_filter: number, fill_textures: Map<string, WGLTexture> | null): Map<string, WGLTexture>;
73
+ /** @internal */
74
+ getSamplerIds(): string[];
75
+ /** @internal */
76
+ getExpression(): string;
21
77
  /**
22
78
  * Get contour data as an object with each contour level being a separate property.
23
79
  * @param opts - Options for doing the contouring
@@ -25,7 +81,7 @@ declare class RawScalarField<ArrayType extends TypedArray, GridType extends Grid
25
81
  */
26
82
  getContours(opts: FieldContourOpts): Promise<ContourData>;
27
83
  /**
28
- * Create a new field by aggregating a number of fields using a specific function
84
+ * Create a new field by aggregating a number of fields using a specific function. This computation occurs on the CPU.
29
85
  * @param func - A function that will be applied each element of the field. It should take the same number of arguments as fields you have and return a single number.
30
86
  * @param args - The RawScalarFields to aggregate
31
87
  * @returns a new gridded field
@@ -34,9 +90,82 @@ declare class RawScalarField<ArrayType extends TypedArray, GridType extends Grid
34
90
  * wind_speed_field = RawScalarField.aggreateFields(Math.hypot, u_field, v_field);
35
91
  */
36
92
  static aggregateFields<ArrayType extends TypedArray, GridType extends Grid>(func: (...args: number[]) => number, ...args: RawScalarField<ArrayType, GridType>[]): RawScalarField<ArrayType, GridType>;
93
+ /**
94
+ * Run computations on a scalar field on the CPU (for a `RawScalarField`, this is a no-op). The function blocks the main thread, so avoid calling it if possible.
95
+ * @returns The computed grid in a `RawScalarField`
96
+ */
97
+ renderCPU(): RawScalarField<ArrayType, GridType>;
98
+ /** @internal */
99
+ iterateCPU(): Generator<number, void, unknown>;
100
+ /** @internal */
101
+ getThinnedField(thin_fac: number, map_max_zoom: number): this;
102
+ /**
103
+ * Sample this field at a given latitude and longitude.
104
+ * @param lon - Longitude of the sample in degrees east
105
+ * @param lat - Latitude of the sample in degrees north
106
+ * @returns The value of the nearest grid point along with the grid point latitude and longitude, or NaNs if the point is outside the grid.
107
+ */
108
+ sampleFieldWithCoord(lon: number, lat: number): {
109
+ sample: number;
110
+ sample_lon: number;
111
+ sample_lat: number;
112
+ };
113
+ /**
114
+ * Sample this field at a given latitude and longitude.
115
+ * @param lon - Longitude of the sample in degrees east
116
+ * @param lat - Latitude of the sample in degrees north
117
+ * @returns The value of the nearest grid point, or NaN if the point is outside the grid.
118
+ */
119
+ sampleField(lon: number, lat: number): number;
120
+ }
121
+ declare class ComputedScalarField<ArrayType extends TypedArray, GridType extends Grid> extends ExpressionScalarField<ArrayType, GridType> {
122
+ private readonly raw_fields;
123
+ private readonly expression;
124
+ private readonly cpu_func;
125
+ constructor(raw_fields: ExpressionScalarField<ArrayType, GridType>[], expression: string, cpu_func: (...arg: number[]) => number);
126
+ /** @internal */
127
+ get grid(): GridType;
128
+ /** @internal */
129
+ get aryConstructor(): new (...args: any[]) => ArrayType;
130
+ /** @internal */
131
+ get dtypes(): TypedArrayStr[];
132
+ /** @internal */
133
+ updateTexImageData(gl: WebGLAnyRenderingContext, image_mag_filter: number, fill_textures: Map<string, WGLTexture> | null): Map<string, WGLTexture>;
134
+ /** @internal */
135
+ getSamplerIds(): string[];
136
+ /** @internal */
137
+ getExpression(): string;
138
+ /** @internal */
139
+ getThinnedField(thin_fac: number, map_max_zoom: number): this;
140
+ /**
141
+ * Sample this field at a given latitude and longitude.
142
+ * @param lon - Longitude of the sample in degrees east
143
+ * @param lat - Latitude of the sample in degrees north
144
+ * @returns The value of the nearest grid point along with the grid point latitude and longitude, or NaNs if the point is outside the grid.
145
+ */
146
+ sampleFieldWithCoord(lon: number, lat: number): {
147
+ sample: number;
148
+ sample_lon: number;
149
+ sample_lat: number;
150
+ };
151
+ /**
152
+ * Sample this field at a given latitude and longitude.
153
+ * @param lon - Longitude of the sample in degrees east
154
+ * @param lat - Latitude of the sample in degrees north
155
+ * @returns The value of the nearest grid point, or NaN if the point is outside the grid.
156
+ */
37
157
  sampleField(lon: number, lat: number): number;
158
+ /**
159
+ * Run computations on a scalar field on the CPU. The function blocks the main thread, so avoid calling it if possible.
160
+ * @returns The computed grid in a `RawScalarField`
161
+ */
162
+ renderCPU(): RawScalarField<ArrayType, GridType>;
163
+ /** @internal */
164
+ iterateCPU(): Generator<number, void, unknown>;
38
165
  }
166
+ /** The basis vectors for vector fields (i.e, whether vectors a relative to Earth or the grid) */
39
167
  type VectorRelativeTo = 'earth' | 'grid';
168
+ /** Options for {@link RawVectorField}s */
40
169
  interface RawVectorFieldOptions {
41
170
  /**
42
171
  * Whether the vectors are relative to the grid ('grid') or Earth ('earth')
@@ -44,33 +173,100 @@ interface RawVectorFieldOptions {
44
173
  */
45
174
  relative_to?: VectorRelativeTo;
46
175
  }
47
- /** A class representing a 2D gridded field of vectors */
48
- declare class RawVectorField<ArrayType extends TypedArray, GridType extends Grid> {
49
- readonly u: RawScalarField<ArrayType, GridType>;
50
- readonly v: RawScalarField<ArrayType, GridType>;
176
+ declare abstract class ExpressionVectorField<ArrayType extends TypedArray, GridType extends AutoZoomGrid> {
177
+ protected readonly u: ExpressionScalarField<ArrayType, GridType>;
178
+ protected readonly v: ExpressionScalarField<ArrayType, GridType>;
51
179
  readonly relative_to: VectorRelativeTo;
180
+ constructor(u: ExpressionScalarField<ArrayType, GridType>, v: ExpressionScalarField<ArrayType, GridType>, opts?: RawVectorFieldOptions);
181
+ private operandScalar;
182
+ private operandVector;
52
183
  /**
53
- * Create a vector field.
54
- * @param grid - The grid on which the vector components are defined
55
- * @param u - The u (east/west) component of the vectors, which should be given as a 1D array in row-major order, with the first element being at the lower-left corner of the grid
56
- * @param v - The v (north/south) component of the vectors, which should be given as a 1D array in row-major order, with the first element being at the lower-left corner of the grid
57
- * @param opts - Options for creating the vector field.
184
+ * Multiply this vector field by a scalar. The multiplication occurs on the GPU if the resulting field is used in a plot component.
185
+ * @param other - Scalar to multiply by. Can be either a number or a scalar field.
186
+ * @returns A `ComputedVectorField` representing the multiplied vector field
58
187
  */
59
- constructor(grid: GridType, u: ArrayType, v: ArrayType, opts?: RawVectorFieldOptions);
188
+ multiply(other: ExpressionScalarField<ArrayType, GridType> | number): ComputedVectorField<ArrayType, GridType>;
189
+ /**
190
+ * Divide this vector field by a scalar. The division occurs on the GPU if the resulting field is used in a plot component.
191
+ * @param other - Scalar to divide by. Can be either a number or a scalar field.
192
+ * @returns A `ComputedVectorField` representing the divided vector field
193
+ */
194
+ divide(other: ExpressionScalarField<ArrayType, GridType> | number): ComputedVectorField<ArrayType, GridType>;
195
+ /**
196
+ * Add this vector field to another vector field. The addition occurs on the GPU if the resulting field is used in a plot component.
197
+ * @param other Vector field to add.
198
+ * @returns A `ComputedVectorField` representing the added vector field
199
+ */
200
+ add(other: ExpressionVectorField<ArrayType, GridType>): ComputedVectorField<ArrayType, GridType>;
201
+ /**
202
+ * Subtract another vector field from this vector field. The subtraction occurs on the GPU if the resulting field is used in a plot component.
203
+ * @param other Vector field to subtract.
204
+ * @returns A `ComputedVectorField` representing the subtracted vector field
205
+ */
206
+ subtract(other: ExpressionVectorField<ArrayType, GridType>): ComputedVectorField<ArrayType, GridType>;
60
207
  /** @internal */
61
- private getTextureData;
62
- getWGLTextureSpecs(gl: WebGLAnyRenderingContext, mag_filter: number): {
63
- u: WGLTextureSpec;
64
- v: WGLTextureSpec;
208
+ updateTexImageData(gl: WebGLAnyRenderingContext, image_mag_filter: number, fill_textures: {
209
+ u: Map<string, WGLTexture>;
210
+ v: Map<string, WGLTexture>;
211
+ } | null): {
212
+ u: Map<string, WGLTexture>;
213
+ v: Map<string, WGLTexture>;
65
214
  };
215
+ /**
216
+ * Get the magnitude of the vector field as a scalar field. The magnitude calculation occurs on the GPU if this field is used in a plot component.
217
+ * @returns A `ComputedScalarField` representing the subtracted vector field
218
+ */
219
+ magnitude(): ComputedScalarField<ArrayType, GridType>;
66
220
  /** @internal */
67
- getThinnedField(thin_fac: number, map_max_zoom: number): RawVectorField<ArrayType, Grid>;
221
+ getThinnedField(thin_fac: number, map_max_zoom: number): ComputedVectorField<ArrayType, GridType>;
68
222
  /** @internal */
69
223
  get grid(): GridType;
224
+ /**
225
+ * Sample this field at a given latitude and longitude.
226
+ * @param lon - Longitude of the sample in degrees east
227
+ * @param lat - Latitude of the sample in degrees north
228
+ * @returns A tuple containing the [`bearing`, `magnitude`] of the vector field at the nearest grid point. The bearing is given as degrees from north, increasing clockwise.
229
+ * If the point is outside the grid, it returns [NaN, NaN] instead.
230
+ */
70
231
  sampleField(lon: number, lat: number): [number, number];
232
+ /** @internal */
233
+ getSamplerIds(): {
234
+ u: string[];
235
+ v: string[];
236
+ };
237
+ /** @internal */
238
+ getExpressions(): {
239
+ u: string;
240
+ v: string;
241
+ };
242
+ }
243
+ /** A class representing a 2D gridded field of vectors */
244
+ declare class RawVectorField<ArrayType extends TypedArray, GridType extends AutoZoomGrid> extends ExpressionVectorField<ArrayType, GridType> {
245
+ private readonly u_ary;
246
+ private readonly v_ary;
247
+ /**
248
+ * Create a vector field.
249
+ * @param grid - The grid on which the vector components are defined
250
+ * @param u_ary - The u (east/west) component of the vectors, which should be given as a 1D array in row-major order, with the first element being at the lower-left corner of the grid
251
+ * @param v_ary - The v (north/south) component of the vectors, which should be given as a 1D array in row-major order, with the first element being at the lower-left corner of the grid
252
+ * @param opts - Options for creating the vector field.
253
+ */
254
+ constructor(grid: GridType, u_ary: ArrayType, v_ary: ArrayType, opts?: RawVectorFieldOptions);
255
+ /** @internal */
256
+ getSamplerIds(): {
257
+ u: string[];
258
+ v: string[];
259
+ };
260
+ /** @internal */
261
+ getExpressions(): {
262
+ u: string;
263
+ v: string;
264
+ };
265
+ }
266
+ declare class ComputedVectorField<ArrayType extends TypedArray, GridType extends AutoZoomGrid> extends ExpressionVectorField<ArrayType, GridType> {
71
267
  }
72
268
  /** A class grid of wind profiles */
73
- declare class RawProfileField<GridType extends Grid> {
269
+ declare class RawProfileField<GridType extends AutoZoomGrid> {
74
270
  readonly profiles: WindProfile[];
75
271
  readonly grid: GridType;
76
272
  /**
@@ -97,7 +293,7 @@ declare class RawProfileField<GridType extends Grid> {
97
293
  */
98
294
  type ObsRawData<ObsFieldName extends string> = Record<ObsFieldName, string | number | [number, number] | null>;
99
295
  /** Raw observation data, given as a list of objects */
100
- declare class RawObsField<GridType extends Grid, ObsFieldName extends string> {
296
+ declare class RawObsField<GridType extends AutoZoomGrid, ObsFieldName extends string> {
101
297
  readonly grid: GridType;
102
298
  readonly data: ObsRawData<ObsFieldName>[];
103
299
  /**
@@ -122,5 +318,5 @@ declare class RawObsField<GridType extends Grid, ObsFieldName extends string> {
122
318
  */
123
319
  getVector(key: ObsFieldName): RawVectorField<Float16Array, GridType>;
124
320
  }
125
- export { RawScalarField, RawVectorField, RawProfileField, RawObsField };
126
- export type { RawVectorFieldOptions, VectorRelativeTo, TextureDataType, ObsRawData };
321
+ export { RawScalarField, ComputedScalarField, RawVectorField, ComputedVectorField, RawProfileField, RawObsField };
322
+ export type { ExpressionScalarField, RawVectorFieldOptions, ExpressionVectorField, VectorRelativeTo, TextureDataType, ObsRawData };