-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAlgebra.ts
38 lines (33 loc) · 1.22 KB
/
Algebra.ts
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
export function mean(values: number[]) {
let s = 0;
for(let i = 0; i < values.length; ++i) {
s += values[i];
}
return s/values.length;
}
export function kapaFilteredMean(values: number[], sigma:number, iter:number) {
if (values.length === 0) return NaN;
for(let i = 0; i < iter; ++i) {
let moy = mean(values);
const stddev = Math.sqrt(values.reduce((c, s)=>c + (s - moy)*(s - moy), 0) / values.length);
const stddevSeuil = sigma * stddev;
const newValues = values.filter(s=>Math.abs(s - moy) < stddevSeuil);
if (newValues.length === values.length) {
return moy;
}
if (newValues.length === 0) {
return moy;
}
values = newValues;
}
return mean(values);
}
export function starConsideredForFwhm(stars: Array<{fwhm: number, peak:number}>) {
return stars = stars.filter(star=>star.peak < 0.9);
}
// Compute global FWHM for a starfield, excluding saturated stars and outliers
// Return NaN if impossible (no unsaturated star)
export function starFieldFwhm(stars: Array<{fwhm: number, peak:number}>) {
stars = starConsideredForFwhm(stars);
return kapaFilteredMean(stars.map(star=>star.fwhm), 5, 1.5);
}