@@ -53,16 +53,122 @@ wasm-pack publish
53
53
54
54
## Usage
55
55
56
- Once the WASM bindings are implemented, you'll be able to parse OpenDAP data in JavaScript:
56
+ ### Basic Setup
57
57
58
- ** TODO**
58
+ ``` typescript
59
+ import init , { OpenDAPDataset } from ' @readap-wasm/readap-wasm' ;
60
+
61
+ async function main() {
62
+ await init (); // Initialize WASM module
63
+
64
+ // Load dataset with automatic metadata fetching
65
+ const dataset = await OpenDAPDataset .fromURL (' http://example.com/ocean.nc' );
66
+
67
+ // Check available variables
68
+ console .log (' Variables:' , dataset .getVariableNames ());
69
+
70
+ // Get simple variable data
71
+ const tempData = await dataset .getVariable (' temperature' );
72
+ console .log (' Temperature:' , tempData .data ); // Float64Array or appropriate typed array
73
+ }
74
+ ```
75
+
76
+ ### Advanced Data Selection
77
+
78
+ ``` typescript
79
+ // Index-based selection (isel) - select by array indices
80
+ const indexSelection = dataset .isel ({
81
+ time: 0 , // first time step
82
+ lat: [10 , 20 ], // latitude indices 10-20
83
+ lon: 50 // longitude index 50
84
+ });
85
+
86
+ // Value-based selection (sel) - select by coordinate values with nearest neighbor
87
+ await dataset .loadCoordinates (' time' ); // Load coordinates for value lookup
88
+ await dataset .loadCoordinates (' lat' );
89
+ await dataset .loadCoordinates (' lon' );
90
+
91
+ const valueSelection = dataset .sel ({
92
+ time: " 2023-01-15T12:00:00Z" , // nearest time
93
+ lat: [40.0 , 45.0 ], // latitude range 40-45°N
94
+ lon: - 70.0 // nearest to -70°W
95
+ });
96
+
97
+ // Get data with selection applied
98
+ const selectedData = await dataset .getVariable (' temperature' , valueSelection );
99
+
100
+ // Chain selections for complex queries
101
+ const surface = dataset
102
+ .sel ({ depth: 0 }) // surface level
103
+ .isel ({ time: [0 , 1 , 2 ] }) // first 3 time steps
104
+ .sel ({ lat: [35 , 45 ], lon: [- 80 , - 60 ] }); // geographic subset
105
+ ```
106
+
107
+ ### Multiple Variables and Batch Operations
108
+
109
+ ``` typescript
110
+ // Get multiple variables efficiently
111
+ const oceanData = await dataset .getVariables ([' temperature' , ' salinity' , ' velocity' ]);
112
+
113
+ // Access individual variable data
114
+ console .log (' Temperature data:' , oceanData .temperature .data );
115
+ console .log (' Salinity data:' , oceanData .salinity .data );
116
+ ```
117
+
118
+ ### Low-Level API Usage
119
+
120
+ ``` typescript
121
+ // Manual URL building
122
+ const urlBuilder = new OpenDAPUrlBuilder (" http://example.com/data" );
123
+ console .log (urlBuilder .dasUrl ()); // http://example.com/data.das
124
+ console .log (urlBuilder .ddsUrl ()); // http://example.com/data.dds
125
+
126
+ // Direct constraint building
127
+ const constraints = new ConstraintBuilder ()
128
+ .isel ({ time: { type: " single" , value: 0 } })
129
+ .sel ({ lat: { type: " range" , min: 40.0 , max: 50.0 } });
130
+
131
+ const dodsUrl = urlBuilder .dodsUrl (constraints .build ());
132
+
133
+ // Parse formats directly
134
+ const dasResult = OpenDAPDataset .fromDAS (dasText );
135
+ const ddsResult = OpenDAPDataset .fromDDS (ddsText );
136
+ ```
59
137
60
138
## Features
61
139
62
- ** TODO**
63
- * Full WebAssembly compatibility for browser and Node.js environments
64
- * Built with [ ` wasm-bindgen ` ] ( https://github.com/rustwasm/wasm-bindgen ) for seamless JavaScript integration
65
- * Includes [ ` console_error_panic_hook ` ] ( https://github.com/rustwasm/console_error_panic_hook ) for better debugging
140
+ ### 🚀 ** High-Level API**
141
+ * ** Automatic Data Fetching** : Seamless HTTP requests with built-in error handling
142
+ * ** xarray-style Selection** : Intuitive ` isel ` (index) and ` sel ` (value) selection patterns
143
+ * ** Nearest Neighbor Lookup** : Automatic coordinate value → index mapping with binary search
144
+ * ** Lazy Loading** : Coordinates and metadata loaded only when needed for optimal performance
145
+ * ** Typed Arrays** : Efficient JavaScript typed arrays (Float64Array, Int32Array, etc.) for zero-copy data transfer
146
+
147
+ ### 🔧 ** Low-Level Control**
148
+ * ** URL Builder System** : Programmatically construct OpenDAP URLs with constraints
149
+ * ** Direct Format Parsing** : Parse DAS, DDS, and DODS formats independently
150
+ * ** Constraint Building** : Flexible constraint syntax for complex data selections
151
+ * ** Network-Free Core** : Underlying readap library works without network dependencies
152
+
153
+ ### 📊 ** Data Selection Capabilities**
154
+ * ** Index-based Selection (isel)** : Select data by array indices with ranges and multiple values
155
+ * ** Value-based Selection (sel)** : Select data by coordinate values with nearest neighbor matching
156
+ * ** Chained Selections** : Combine multiple selection operations for complex queries
157
+ * ** Range Support** : Efficient range selections for time series and spatial data
158
+ * ** Gridded Coordinates** : Intuitive handling of multi-dimensional coordinate systems
159
+
160
+ ### 🌐 ** Web Compatibility**
161
+ * ** Full WebAssembly compatibility** for browser and Node.js environments
162
+ * ** CORS Support** : Proper handling of cross-origin requests
163
+ * ** Built with [ ` wasm-bindgen ` ] ( https://github.com/rustwasm/wasm-bindgen ) ** for seamless JavaScript integration
164
+ * ** Error Handling** : Comprehensive HTTP and parsing error handling with meaningful messages
165
+ * ** Includes [ ` console_error_panic_hook ` ] ( https://github.com/rustwasm/console_error_panic_hook ) ** for better debugging
166
+
167
+ ### ⚡ ** Performance Features**
168
+ * ** Zero-copy data transfer** between WASM and JavaScript where possible
169
+ * ** Efficient binary search** algorithms for coordinate lookup
170
+ * ** Minimal network requests** through intelligent constraint building
171
+ * ** Smart coordinate caching** to avoid redundant data fetching
66
172
67
173
## License
68
174
0 commit comments