-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathheightcorrection.js
More file actions
72 lines (63 loc) · 2.05 KB
/
heightcorrection.js
File metadata and controls
72 lines (63 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// windHeightCorrection_mps.js
/**
* Convert wind speed measured at `fromHeight` (m) to `toHeight` (m).
* Supports:
* - log-law with fixed roughness z0 (matches ORC-style assumption)
* - power-law with exponent alpha (marine rule-of-thumb)
*
* @param {number} speed Wind speed at fromHeight [m/s]
* @param {number} fromHeight Sensor height in meters (e.g., 26)
* @param {object} [opts]
* @param {number} [opts.toHeight=10] Target height in meters (default 10 m)
* @param {"log"|"power"} [opts.method="log"] Correction method
* @param {number} [opts.z0=0.005] Roughness length for log-law (meters)
* @param {number} [opts.alpha=0.11] Exponent for power-law
* @returns {number} corrected speed at toHeight [m/s]
*/
function windToHeight(speed, fromHeight, opts = {}) {
const {
toHeight = 10,
method = 'log',
z0 = 0.005,
alpha = 0.11
} = opts;
if (fromHeight <= 0 || toHeight <= 0) {
throw new Error('heights must be > 0 meters');
}
if (method === 'log' && (z0 <= 0 || z0 >= Math.min(fromHeight, toHeight))) {
throw new Error('For log-law, z0 must be > 0 and < both heights');
}
let U_to;
if (method === 'log') {
// Log-law: U(z) ∝ ln(z/z0)
const num = Math.log(toHeight / z0);
const den = Math.log(fromHeight / z0);
U_to = speed * (num / den);
} else if (method === 'power') {
// Power-law: U(z) = U_ref * (z/z_ref)^alpha
U_to = speed * Math.pow(toHeight / fromHeight, alpha);
} else {
throw new Error('method must be "log" or "power"');
}
return U_to;
}
/**
* Convenience wrappers for common cases
*/
// ORC-consistent: convert sensor height -> 10 m using log-law with z0=0.005 m
function to10m_ORC(speed, sensorHeight, z0 = 0.005) {
return windToHeight(speed, sensorHeight, {
toHeight: 10,
method: 'log',
z0
});
}
// Marine power-law: alpha≈0.11
function to10m_Marine(speed, sensorHeight, alpha = 0.11) {
return windToHeight(speed, sensorHeight, {
toHeight: 10,
method: 'power',
alpha
});
}
export { windToHeight, to10m_ORC, to10m_Marine };