@wafertools/wafermap 0.38.0 → 0.39.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 (61) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +2 -1
  3. package/dist/packages/canvas-adapter/cellShade.d.ts +21 -0
  4. package/dist/packages/canvas-adapter/cellShade.js +1 -0
  5. package/dist/packages/canvas-adapter/charts/chartShell.d.ts +19 -3
  6. package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
  7. package/dist/packages/canvas-adapter/charts/commonality.js +1 -1
  8. package/dist/packages/canvas-adapter/charts/correlation.d.ts +11 -0
  9. package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
  10. package/dist/packages/canvas-adapter/charts/divergingScale.d.ts +23 -0
  11. package/dist/packages/canvas-adapter/charts/divergingScale.js +1 -0
  12. package/dist/packages/canvas-adapter/charts/groupComparison.js +1 -1
  13. package/dist/packages/canvas-adapter/charts/palette.d.ts +10 -3
  14. package/dist/packages/canvas-adapter/charts/palette.js +1 -1
  15. package/dist/packages/canvas-adapter/charts/plotChart.d.ts +3 -0
  16. package/dist/packages/canvas-adapter/charts/plotChart.js +1 -1
  17. package/dist/packages/canvas-adapter/dataTab.js +1 -1
  18. package/dist/packages/canvas-adapter/differenceMapPanel.d.ts +1 -0
  19. package/dist/packages/canvas-adapter/differenceMapPanel.js +1 -1
  20. package/dist/packages/canvas-adapter/filterJson.d.ts +25 -0
  21. package/dist/packages/canvas-adapter/filterJson.js +5 -0
  22. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  23. package/dist/packages/canvas-adapter/pageFilter.js +2 -2
  24. package/dist/packages/canvas-adapter/plotEditor.js +10 -1
  25. package/dist/packages/canvas-adapter/plotJsonComplete.d.ts +46 -0
  26. package/dist/packages/canvas-adapter/plotJsonComplete.js +4 -0
  27. package/dist/packages/canvas-adapter/plotJsonHistory.d.ts +12 -0
  28. package/dist/packages/canvas-adapter/plotJsonHistory.js +1 -0
  29. package/dist/packages/canvas-adapter/plotJsonSuggest.d.ts +16 -0
  30. package/dist/packages/canvas-adapter/plotJsonSuggest.js +1 -0
  31. package/dist/packages/canvas-adapter/plotModal.js +1 -1
  32. package/dist/packages/canvas-adapter/plotTab.js +1 -1
  33. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  34. package/dist/packages/canvas-adapter/summaryPanel.js +4 -4
  35. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  36. package/dist/packages/canvas-adapter/userGuideHtml.js +40 -18
  37. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  38. package/dist/packages/canvas-adapter/version.js +1 -1
  39. package/dist/packages/canvas-adapter/virtualTable.d.ts +2 -0
  40. package/dist/packages/canvas-adapter/virtualTable.js +1 -1
  41. package/dist/packages/core/utils.d.ts +6 -0
  42. package/dist/packages/core/utils.js +1 -1
  43. package/dist/packages/renderer/fmt.js +1 -1
  44. package/dist/packages/stats/chartCatalogue.js +1 -1
  45. package/dist/packages/stats/coFailure.d.ts +11 -0
  46. package/dist/packages/stats/coFailure.js +1 -0
  47. package/dist/packages/stats/correlation.d.ts +7 -0
  48. package/dist/packages/stats/correlation.js +1 -1
  49. package/dist/packages/stats/differenceMap.d.ts +2 -0
  50. package/dist/packages/stats/differenceMap.js +1 -1
  51. package/dist/packages/stats/plotData.d.ts +11 -2
  52. package/dist/packages/stats/plotData.js +1 -1
  53. package/dist/packages/stats/plotSpec.d.ts +31 -2
  54. package/dist/packages/stats/plotSpec.js +4 -4
  55. package/dist/packages/stats/plotTable.d.ts +18 -0
  56. package/dist/packages/stats/plotTable.js +1 -0
  57. package/dist/packages/stats/synthesis.d.ts +6 -0
  58. package/dist/packages/stats/synthesis.js +1 -1
  59. package/dist/packages/stats/testsByWafer.d.ts +11 -0
  60. package/dist/packages/stats/testsByWafer.js +1 -0
  61. package/package.json +1 -1
@@ -108,6 +108,12 @@ export interface SynthesisContext {
108
108
  */
109
109
  attributes?: Record<string, FacetCuration>;
110
110
  }
111
+ /**
112
+ * A bar of wafers drawn with Group by on takes the group's colours, and the wafers sit under their group on a second level
113
+ * of the X axis: a pattern that belongs to a group (both low wafers are SS) shows as a colour, and the legend switches
114
+ * groups on and off. With no grouping, or any other chart, it is returned as specified.
115
+ */
116
+ export declare function groupColouredChart(chart: Omit<PlotSpec, 'id'>, grouped: boolean): Omit<PlotSpec, 'id'>;
111
117
  /**
112
118
  * The summary a synthesis is written from. A lot of one wafer is that wafer: the lot's own findings need
113
119
  * a signal to recur on two wafers, so on one they are always empty and the lot would read as clean while
@@ -1,2 +1,2 @@
1
- import{maxOf as ge,minOf as be}from"../core/utils.js";import{isPassBin as $e,passBinsLabel as we}from"../core/passBins.js";import{DRIFT_MIN_WAFERS as ye}from"./lotDrift.js";import{isOneBinCluster as ve}from"./filterFindings.js";import{plainBinTerms as Se}from"../renderer/fmt.js";import{benjaminiHochberg as Ne,normalUpperTail as Ie}from"./math.js";import{compareGroups as ke,formatP as re}from"./groupCompare.js";import{attributeLabel as oe,buildFacetTable as xe,facetValueOf as Me}from"./facets.js";const De=1,Be=2,_e=.5,le=3,fe=5,K=.01,Fe=.02,Oe=.04,ze=.15,Le=.4,X=.5,Ee=.1,Te=2,ce=new Set(["ring","quadrant","sector","reticle-position","test-site","cluster","edge-arc"]);function ee(e){const t=e.highlight;return"dieKeysByWafer"in t&&t.dieKeysByWafer?Object.values(t.dieKeysByWafer).reduce((s,i)=>s+i.length,0):"dieKeys"in t&&t.dieKeys&&t.dieKeys.length>0?t.dieKeys.length:e.level==="lot"?void 0:e.stats.sampleSizeLeft}function te(e){const t=e.highlight,s=new Set;if("dieKeysByWafer"in t&&t.dieKeysByWafer)for(const[i,d]of Object.entries(t.dieKeysByWafer))for(const c of d)s.add(`${i}:${c}`);else if("dieKeys"in t&&t.dieKeys)for(const i of t.dieKeys)s.add(i);return s}const D=e=>Math.abs(e.effect.absoluteDelta??0),A=e=>D(e)*(ee(e)??0),E=e=>(e*100).toFixed(1),G=e=>{const t=e.variable.label.replace(/ \(same dies\)$/,"").replace(/^HBin and SBin (\d+)/,"HBin $1").replace(/^(HBin \d+(?: \([^)]*\))?) and SBin .*$/,"$1");return Se(t)},S=e=>Math.round(e).toLocaleString("en-GB"),T=(e,t,s=`${t}s`)=>`${S(e)} ${e===1?t:s}`;function C(e){const t=e.comparison.left;return e.comparison.family==="quadrant"&&!/quadrant/i.test(t)?`${t} quadrant`:t}const de=ve;function Ae(e){const t=e.map((f,a)=>a),s=f=>t[f]===f?f:t[f]=s(t[f]),i=e.map(te),d=(f,a)=>{const u=i[f].size<=i[a].size?i[f]:i[a],b=u===i[f]?i[a]:i[f];let m=0;for(const p of u)b.has(p)&&m++;return m},c=e.map((f,a)=>a).filter(f=>de(e[f])),n=e.map((f,a)=>a).filter(f=>!de(e[f]));for(let f=0;f<n.length;f++)for(let a=f+1;a<n.length;a++){const u=Math.min(i[n[f]].size,i[n[a]].size);u>0&&d(n[f],n[a])>=X*u&&(t[s(n[f])]=s(n[a]))}for(const f of c){let a=-1,u=0;for(const b of n){if(se(e[b])&&e[b].variable.bin!==e[f].variable.bin)continue;const m=d(f,b);m>u&&m>=X*i[f].size&&m>=X*A(e[b])&&(a=b,u=m)}a>=0&&(t[f]=s(a))}const h=new Map;return e.forEach((f,a)=>{const u=s(a);(h.get(u)??h.set(u,[]).get(u)).push(a)}),[...h.values()]}const se=e=>e.variable.kind==="hardBin"||e.variable.kind==="softBin",ie=(e,t)=>e.level===t.level&&e.comparison.family===t.comparison.family&&e.comparison.left===t.comparison.left;function We(e,t,s){const i=c=>t.filter(n=>n.variable.kind===c&&ie(n,e)&&n.effect.direction==="higher"&&s(n));return(i("hardBin").length>0?i("hardBin"):i("softBin")).filter(c=>c!==e).sort((c,n)=>D(n)-D(c))}const je={ring:"rings",quadrant:"quadrants",sector:"sectors","edge-arc":"edge arcs",cluster:"clusters","reticle-position":"reticle positions","test-site":"test sites"},He=2;function ue(e){const t=new Map;for(const i of e){const d=i.comparison.family;(t.get(d)??t.set(d,new Set).get(d)).add(C(i))}const s=[];for(const[i,d]of t)d.size<=He?s.push(...d):s.push(`${d.size} ${je[i]??i}`);return s.join(", ")}const Re=e=>e.charAt(0).toUpperCase()+e.slice(1),P=e=>({kind:"finding",id:e.id}),Ce=e=>({label:Re(G(e)),target:P(e),...e.variable.bin!==void 0&&(e.variable.kind==="hardBin"||e.variable.kind==="softBin")?{bin:{kind:e.variable.kind,bin:e.variable.bin}}:{}});function V(e){const t=e.comparison.family;return{builtin:t==="quadrant"||t==="sector"?"quadrant":t==="reticle-position"?"reticleCell":t==="test-site"?"site":"ring"}}const he=(e,t)=>({chart:"bar",fields:{x:e,y:t,color:{none:!0}},valueLabels:!0,axes:{y:{references:[{stat:"median"}]}}}),J=e=>({test:e}),ne=(e,t=!1)=>({chart:"histogram",fields:{y:J(e),color:{none:!0}},...t?{normalCurve:!0}:{}});function Pe(e,t,s,i){const d=[...e].sort((l,g)=>A(g)-A(l))[0],c=e.find(l=>i.isPassRate(l)&&ie(l,d))??d,n=e.filter(l=>l!==c),h=c.level==="lot"&&"waferIndices"in c.highlight?c.highlight.waferIndices?.length:void 0,f=h!==void 0&&s?` on ${h}/${s} wafers`:"",a=!i.isPassRate(c),u=c.comparison.family==="sector"?"the other sectors":"the rest of the wafer";let b=a?`${C(c)}: ${G(c)} ${E(D(c))} points higher than ${u}${f}`:`${C(c)}: pass rate ${E(D(c))} points below ${u}${f}`;const m=`${b} \u2014 about ${S(A(c))} dies lost`,p=We(c,t,i.isFailBin).map(l=>({f:l,share:D(l)/(D(c)||1)})).filter(l=>a||l.share>=Ee).slice(0,Te);if(a)for(const{f:l}of p)b+=`, ${G(l)} ${E(D(l))} points higher`;else if(p.length>0){const l=p.reduce((N,v)=>N+v.share,0)<=1.000000001,g=l&&p[0].share>.5?"mostly ":"";p.forEach(({f:N},v)=>{b+=v===0?`; ${l?g:""}`:", ",b+=G(N)+(v===0?l?` accounts for ${E(D(N))} of those points`:` is ${E(D(N))} points higher`:l?` for ${E(D(N))}`:` ${E(D(N))} points higher`)})}b+=` \u2014 about ${S(A(c))} dies lost`;const x=n.filter(l=>!ie(l,c));x.length>0&&(b+=` (also seen as ${ue(x)})`);const o=a?G(c):"pass rate";return{kind:"loss",impact:"low",shareOfDies:0,diesLost:A(c),affected:A(c),measure:"",severity:c.severity,text:b,reason:m,brief:`${C(c)}: ${o}, ${S(A(c))} dies`,subject:C(c),target:P(c),chips:[...a?[c]:[],...p.map(({f:l})=>l)].map(Ce),findingIds:[c.id,...n.map(l=>l.id)],testNumbers:[],chart:a?{chart:"bar",fields:{x:V(c),color:{builtin:c.variable.kind==="softBin"?"sbin":"hbin"}},stack:"percent"}:c.level==="lot"?{chart:"heatmap",fields:{x:{builtin:"wafer"},rows:V(c),y:{builtin:"yield"}}}:he(V(c),{builtin:"yield"})}}function Ke(e,t){return e>=Oe||t>=Le?"high":e>=Fe||t>=ze?"medium":"low"}function qe(e){const t=s=>s.stats.yieldPercent==null?0:s.stats.analyzedDies*(1-s.stats.yieldPercent/100);return e.level==="wafer"?t(e):e.perWafer.reduce((s,i)=>s+t(i.summary),0)}function Ge(e){return e.level==="wafer"?e.stats.analyzedDies:e.perWafer.reduce((t,s)=>t+s.summary.stats.analyzedDies,0)}const me=e=>e.id.startsWith("inter-wafer:yield:");function Ye(e){const t=[];for(const s of e.findings){if(!me(s)||s.effect.direction!=="lower")continue;const i="waferIndices"in s.highlight?s.highlight.waferIndices?.[0]:void 0,d=i===void 0?void 0:e.perWafer.find(c=>c.waferIndex===i)?.summary.stats.analyzedDies;d!==void 0&&t.push({kind:"loss",impact:"low",shareOfDies:0,diesLost:D(s)*d,affected:D(s)*d,measure:"",severity:s.severity,text:`${s.summary.replace(/ percentage points lower than the lot median$/," points below the lot median")} \u2014 about ${S(D(s)*d)} dies lost`,reason:`${s.summary.replace(/ percentage points lower than the lot median$/," points below the lot median")} \u2014 about ${S(D(s)*d)} dies lost`,brief:`${s.comparison.left}: yield, ${S(D(s)*d)} dies`,subject:s.comparison.left,target:P(s),chips:[],findingIds:[s.id],testNumbers:[],chart:{chart:"control",fields:{x:{builtin:"waferOrder"},y:{builtin:"yield"}}}})}return t}function Ue(e,t){if(e.level==="wafer"){const c=e.stats.testFailures?.[t];return c?{keys:new Set(c.dieKeys),lost:c.lostDies}:void 0}const s=new Set;let i=0,d=!1;for(const c of e.perWafer){const n=c.summary.stats.testFailures?.[t];if(n){d=!0,i+=n.lostDies;for(const h of n.dieKeys)s.add(`${c.waferIndex}:${h}`)}}return d?{keys:s,lost:i}:void 0}function Xe(e,t){const s=e.stats,i=[],d=n=>he({builtin:e.level==="lot"?"wafer":"ring"},{passRate:n}),c=(n,h,f,a,u,b,m=u,p=!1)=>{if(f<=0||a<=0)return;t.add(n);const x=Ue(e,n),o=x?Math.min(x.lost,f):f,l=f-o,g=f/a*100;i.push({testNumber:n,label:h,verb:u,plainVerb:m,failDies:f,passingDies:l,keys:x?.keys,item:{kind:"loss",impact:"low",shareOfDies:0,diesLost:o,affected:o,measure:"",severity:"info",text:`${h} ${u} on ${S(f)} of ${S(a)} dies (${g.toFixed(1)}%)`+(l>0?`; ${S(l)} of them are binned as passing, so about ${S(o)} dies lost`:""),reason:`${h} ${u} on ${S(f)} of ${S(a)} dies (${g.toFixed(1)}%)`,brief:l>0?`${h}: ${b}, ${S(o)} dies lost`:`${h}: ${S(f)} dies ${b}`,subject:h,target:{kind:"test",testNumber:n},chips:[],findingIds:[],testNumbers:[n],chart:p||e.level==="lot"?d(n):ne(n)}})};for(const n of s.testSpecYield??[]){const h=n.failHighDies===0?"is below its low limit":n.failLowDies===0?"is above its high limit":`is outside its limits (${S(n.failLowDies)} low, ${S(n.failHighDies)} high)`;c(n.testNumber,n.label,n.failLowDies+n.failHighDies,n.totalDies,h,"outside limits",n.failLowDies>0&&n.failHighDies>0?"is outside its limits":h)}for(const n of s.functionalYield??[])c(n.testNumber,n.label,n.failDies,n.totalDies,"fails","fail","fails",!0);return i}const Ve=.5,Je=2,Qe=2,Y=5;function Ze(e,t,s,i){const d=new Set,c=new Map,n=new Map,h=[...e].sort((f,a)=>a.failDies-f.failDies||f.testNumber-a.testNumber);for(const f of h){const a=f.keys;if(i>0&&f.failDies/i<K){d.add(f);continue}let u;if(a&&a.size>0&&i>0)for(const p of t){const x=s.get(p);if(!x||x.size===0)continue;let o=0;for(const g of a)x.has(g)&&o++;const l=o/a.size;l>=Ve&&l>=Je*(x.size/i)&&(!u||o>u.inside)&&(u={item:p,inside:o})}if(!u){d.add(f);continue}const b=c.get(u.item)??0;if(b<Qe){const p=u.inside===f.failDies?"all":S(u.inside);u.item.text+=`. ${f.label} ${f.verb} on ${T(f.failDies,"die")}, ${p} of them in ${u.item.subject}`,c.set(u.item,b+1)}const m=n.get(u.item)??0;m<Y?(u.item.chips.push({label:f.label,target:f.item.target}),n.set(u.item,m+1)):u.item.moreTests=(u.item.moreTests??0)+1,u.item.testNumbers.push(f.testNumber)}return e.filter(f=>d.has(f))}function U(e){return{kind:"signal",impact:"low",shareOfDies:0,diesLost:0,affected:e.affected,measure:e.measure,severity:e.severity,text:e.text,reason:e.reason??e.text,brief:e.brief,subject:e.subject,target:e.target,chips:[],findingIds:e.findingIds??[],testNumbers:e.testNumbers??[],chart:e.chart}}const ae=e=>Math.abs(e)<_e?0:Math.min(1,(Math.abs(e)/Be)**2),j=e=>`${Math.abs(e).toFixed(1)}\u03C3`,et=e=>e.variable.kind==="test"&&e.variable.measure!=="limitFailRate"&&ce.has(e.comparison.family)&&Number.isFinite(e.effect.effectSize??NaN)&&!e.id.startsWith("drift:");function tt(e,t,s){const i=new Map;for(const n of e)!et(n)||n.variable.index===void 0||(i.get(n.variable.index)??i.set(n.variable.index,[]).get(n.variable.index)).push(n);const d=n=>(ee(n)??n.stats.sampleSizeLeft)*ae(n.effect.effectSize??0),c=[];for(const[n,h]of[...i].sort((f,a)=>f[0]-a[0])){const f=[...h].sort((o,l)=>d(l)-d(o)),a=f[0],u=a.effect.effectSize??0;if(d(a)===0)continue;const b=te(a);let m=t.find(o=>o.target.kind==="test"&&o.target.testNumber===n)??t.find(o=>o.testNumbers.includes(n))??t.find(o=>f.some(l=>o.findingIds.includes(l.id))),p=0;for(const o of m?[]:t){const l=s.get(o);if(!l||l.size===0||b.size===0)continue;let g=0;for(const N of b)l.has(N)&&g++;g>=X*Math.min(l.size,b.size)&&g>p&&(p=g,m=o)}if(m){m.text+=`. ${a.summary}`,m.testNumbers.includes(n)||(m.chips.filter(l=>l.target.kind==="test"||l.shift).length<Y?m.chips.push({label:a.variable.label,target:P(a),shift:!0}):m.moreTests=(m.moreTests??0)+1,m.testNumbers.push(n));for(const o of f)m.findingIds.includes(o.id)||m.findingIds.push(o.id);continue}const x=ee(a)??a.stats.sampleSizeLeft;c.push(U({affected:d(a),measure:j(u),severity:a.severity,text:`${a.summary}: a shift of ${j(u)} over ${T(x,"die")}`+(f.length>1?` (also seen as ${ue(f.slice(1))})`:""),reason:`${a.summary}: a shift of ${j(u)} over ${T(x,"die")}`,brief:`${C(a)}: ${a.variable.label} ${a.effect.direction}`,subject:C(a),target:P(a),findingIds:f.map(o=>o.id),testNumbers:[n],chart:{chart:"box",fields:{x:V(a),y:J(n),color:{none:!0}},axes:{y:{references:[{stat:"median"}]}}}}))}return c}function st(e,t){return e.filter(s=>s.id.startsWith("drift:")).map(s=>{const i=s.variable.kind==="yield",d=s.effect.effectSize??0;return U({affected:t*(i?Math.abs(d):ae(d)),measure:i?`${E(Math.abs(d))} pts`:j(d),severity:s.severity,text:s.summary,brief:`${s.variable.label}: drifts across the wafers`,subject:s.variable.label,target:P(s),findingIds:[s.id],...s.variable.index!==void 0?{testNumbers:[s.variable.index]}:{},chart:{chart:"control",fields:{x:{builtin:"waferOrder"},y:i||s.variable.index===void 0?{builtin:"yield"}:J(s.variable.index)}}})})}function it(e,t,s){return(e.stats.capability??[]).filter(i=>i.hasSpec&&i.ppk!==null&&i.ppk!==void 0&&i.ppk<De&&!t.has(i.testNumber)).map(i=>{const d=i.ppk,c=Ie(3*d);return U({affected:s*c,measure:`Ppk ${d.toFixed(2)}`,severity:"notable",text:`${i.label} has Ppk ${d.toFixed(2)} against its limits: a spread that would put about ${E(c)}% of the dies outside them`,brief:`${i.label}: Ppk ${d.toFixed(2)}`,subject:i.label,target:{kind:"test",testNumber:i.testNumber},testNumbers:[i.testNumber],chart:ne(i.testNumber,!0)})})}const nt=.05,at=8;function rt(e,t){const s={items:[],compared:[]},i=e.perWafer;if(i.length<4)return s;const d=xe(i.map(o=>({metadata:o.summary.wafer,dieCount:o.summary.stats.totalDies})),{facetableOnly:!0,curation:t}).filter(o=>o.splittable&&o.values.length<=Math.max(2,Math.floor(i.length/2)));if(d.length===0)return s;const c=o=>e.perWaferTestStats?.find(l=>l.waferIndex===o.waferIndex)?.tests??o.summary.stats.perTestStats??[],n=i.map(o=>new Map(c(o).filter(l=>l.count>=2&&Number.isFinite(l.mean)).map(l=>[l.testNumber,l]))),h=new Map;for(const o of n)for(const[l,g]of o)h.has(l)||h.set(l,g.label);const f=i.map(o=>o.summary.stats.analyzedDies),a=[];for(const o of d){const l=i.map(g=>Me(g.summary.wafer,o.key,t));for(const[g,N]of[...h].sort((v,_)=>v[0]-_[0])){const v=new Map,_=[];if(n.forEach((y,I)=>{const k=y.get(g),$=l[I];!k||$===void 0||((v.get($)??v.set($,[]).get($)).push(I),Number.isFinite(k.stddev)&&_.push(k.stddev**2))}),v.size<2)continue;const F=ke([...v].map(([y,I])=>({key:y,values:I.map(k=>n[k].get(g).mean)}))),z=F.welch?.p??F.kruskal?.p,W=_.length?Math.sqrt(_.reduce((y,I)=>y+I,0)/_.length):NaN;if(z===void 0||!Number.isFinite(z)||!(W>0))continue;let M;for(const[y,I]of v){const k=I.map(r=>n[r].get(g).mean),$=[...v].filter(([r])=>r!==y).flatMap(([,r])=>r.map(w=>n[w].get(g).mean));if(k.length<2||$.length<2)continue;const O=k.reduce((r,w)=>r+w,0)/k.length-$.reduce((r,w)=>r+w,0)/$.length,H=O/W;(!M||Math.abs(H)>Math.abs(M.d)+1e-9||Math.abs(Math.abs(H)-Math.abs(M.d))<=1e-9&&(I.length<M.groupWafers||I.length===M.groupWafers&&O>0))&&(M={testNumber:g,label:N,field:o.key,group:y,groupWafers:I.length,groupDies:I.reduce((r,w)=>r+f[w],0),d:H,higher:O>0,p:z})}if(M&&v.size===2){const[y,I]=[...v].find(([k])=>k!==M.group);M.other={group:y,wafers:I.length}}M&&a.push(M)}}const u=Ne(a.map(o=>o.p)),b=new Map;a.forEach((o,l)=>{const g=o.groupDies*ae(o.d);u[l]>=nt||g===0||(b.get(o.field)??b.set(o.field,[]).get(o.field)).push({c:o,q:u[l],weight:g})});const m=a.length?[...new Set(a.map(o=>o.field))].map(o=>oe(o,t)):[],p=(o,l)=>o.other?`${o.label} is ${o.higher?"higher":"lower"} on ${l} ${o.group} than on ${l} ${o.other.group} (${o.groupWafers} and ${o.other.wafers} wafers)`:`${o.label} is ${o.higher?"higher":"lower"} on ${l} ${o.group} (${o.groupWafers} of ${i.length} wafers) than on the other wafers`;return{items:[...b].map(([o,l])=>{l.sort(($,O)=>Math.abs(O.c.d)-Math.abs($.c.d)||O.weight-$.weight||$.c.testNumber-O.c.testNumber);const g=l.reduce(($,O)=>Math.max($,O.weight),0),N=oe(o,t),[v,..._]=l,F=v.c,z=`${p(F,N)}: a shift of ${j(F.d)}`,W=_.slice(0,2).map(({c:$})=>`${$.label} ${$.higher?"higher":"lower"} on ${$.group} (${j($.d)})`),M=_.length-W.length,y=l.length,I=y===1?`${z}, each wafer one value (q ${re(v.q)})`:`${y} tests differ by ${N}. Largest: ${z}, each wafer one value (q ${re(v.q)}); next: ${W.join(", ")}${M>0?`, and ${M} more`:""}`,k=U({affected:g,measure:j(F.d),severity:v.q<.001?"unusual":"notable",text:I,reason:y===1?z:`${y} tests differ by ${N}. Largest: ${z}`,brief:y===1?`${N} ${F.group}: ${F.label} ${F.higher?"higher":"lower"}`:`${N}: ${y} tests differ`,subject:N,target:{kind:"test",testNumber:F.testNumber},testNumbers:l.map($=>$.c.testNumber),chart:y>1?{chart:"box",level:"wafer",aggregate:"mean",normalize:"zscore",fields:{x:{builtin:"test"},y:{tests:l.slice(0,at).map($=>$.c.testNumber)},color:{meta:o}}}:{chart:"box",level:"wafer",aggregate:"mean",fields:{x:{meta:o},y:J(F.testNumber),color:{meta:o}}}});return y>1&&(k.chips=l.slice(0,Y).map(({c:$})=>({label:`${$.label} ${j($.d)}`,target:{kind:"test",testNumber:$.testNumber}})),y>Y&&(k.moreTests=y-Y)),k}),compared:m}}function ot(e){return e.map(t=>U({affected:t.passingDies,measure:"",severity:"notable",text:`${t.label} ${t.plainVerb} on ${T(t.passingDies,"die")} binned as passing`,brief:`${t.label}: ${S(t.passingDies)} dies out of limits, binned passing`,subject:t.label,target:t.item.target,testNumbers:[t.testNumber],chart:ne(t.testNumber)}))}function lt(e,t){const s=t.passBins&&t.passBins.length>0?`; pass ${we([t.passBins])}`:"";if(e.level==="wafer"){const a=e.stats.yieldPercent;return a==null?`${S(e.stats.totalDies)} dies, no bin data to judge yield by.`:`Yield ${a.toFixed(1)}% (${S(e.stats.totalDies)} dies${s}).`}const i=e.lotYieldSeries.map(a=>a.yieldPercent).filter(a=>typeof a=="number");if(i.length===0)return`${T(e.stats.waferCount,"wafer")}, no bin data to judge yield by.`;const d=i.reduce((a,u)=>a+u,0)/i.length,c=e.perWafer.reduce((a,u)=>a+u.summary.stats.totalDies,0),[n,h]=[be(i).toFixed(1),ge(i).toFixed(1)],f=n!==h?`, range ${n}\u2013${h}%`:"";return`Yield ${d.toFixed(1)}% (mean of ${T(i.length,"wafer")}, ${S(c)} dies${s})${f}.`}function ft(e,t,s=[]){const i=[],d=e.level==="wafer"?e.stats.testsConsidered.length:new Set(e.perWafer.flatMap(a=>a.summary.stats.testsConsidered)).size,c=e.level==="wafer"?e.stats.hardBinsConsidered.length:new Set(e.perWafer.flatMap(a=>a.summary.stats.hardBinsConsidered)).size,n=e.stats.testValueAnalysis?.state;if(d>0&&n!=="off"&&i.push(T(d,"test")+(n==="skipped"?" (against their limits only)":"")),c>0&&i.push(T(c,"hard bin")),i.push("the ring, quadrant and sector regions"),e.level==="lot"&&e.stats.waferCount>=3){const a=e.findings.filter(me);i.push(a.length===0?"wafer-to-wafer yield (no outlier wafers)":`wafer-to-wafer yield (${T(a.length,"outlier wafer")})`),e.stats.waferCount>=ye&&i.push("the yield trend across the wafers (input order)"),s.length&&i.push(`the tests between the groups of ${s.join(", ")} (each wafer one value)`)}const h=e.findings.filter(a=>!t.has(a.id)).length,f=h>0?` ${T(h,"smaller finding")} not listed above.`:" Nothing else was found.";return`Compared: ${i.join(", ")}.${f}`}export function synthesisSource(e){return e.level==="lot"&&e.perWafer.length===1?e.perWafer[0].summary:e}const pe=new WeakMap;export function buildSynthesis(e,t={}){const s=`${t.passBins?.join(",")??"-"}|${t.attributes?JSON.stringify(t.attributes):"-"}`;let i=pe.get(e);i||pe.set(e,i=new Map);const d=i.get(s),c=e.findings;if(d&&d.findings.length===c.length&&d.findings.every((h,f)=>h===c[f]))return d.synthesis;const n=ct(e,t);return Object.freeze(n.items),n.items.forEach(Object.freeze),n.also&&(Object.freeze(n.also.items),n.also.items.forEach(Object.freeze),Object.freeze(n.also)),i.set(s,{findings:[...c],synthesis:Object.freeze(n)}),n}function ct(e,t){const s=synthesisSource(e),i=s.findings,d=s.level==="lot"?s.stats.waferCount:void 0,c=t.passBins,n=new Map(i.map(r=>[r.id,r])),h=(s.level==="wafer"?[s]:s.perWafer.map(r=>r.summary)).every(r=>(r.stats.hardBinsConsidered??[]).length===0),f=r=>c!==void 0&&se(r)&&$e(r.variable.kind,r.variable.bin??NaN,c,!h),a={isPassRate:r=>r.variable.kind==="yield"||c?.length===1&&f(r),isFailBin:r=>c!==void 0&&se(r)&&!f(r)},u=i.filter(r=>ce.has(r.comparison.family)&&A(r)>0&&(a.isPassRate(r)&&r.effect.direction==="lower"||a.isFailBin(r)&&r.effect.direction==="higher")),m=u.some(r=>r.variable.kind==="hardBin")?u.filter(r=>r.variable.kind!=="softBin"):u,p=[],x=new Map,o=new Set;for(const r of Ae(m)){const w=r.map(L=>m[L]),B=Pe(w,i,d,a);p.push(B);const R=B.target.kind==="finding"?B.target.id:void 0;x.set(B,te(w.find(L=>L.id===R)??w[0]))}for(const r of i.filter(w=>w.variable.kind==="spatialPattern")){const w=new Set((r.relatedIds??[]).filter(q=>n.has(q))),B=p.find(q=>q.findingIds.some(Z=>w.has(Z)));if(!B)continue;const R=r.level==="lot"&&"waferIndices"in r.highlight?r.highlight.waferIndices?.length:void 0,L=R!==void 0&&d?` on ${R}/${d} wafers`:"";B.text=`${r.variable.label} pattern${L}. ${B.text}`,B.reason=`${r.variable.label} pattern${L}. ${B.reason}`,B.chips.unshift({label:`${r.variable.label} pattern`,target:P(r)}),B.findingIds.unshift(r.id,...[...w].filter(q=>!p.some(Z=>Z.findingIds.includes(q))))}const l=Ge(s),g=new Set,N=Xe(s,g),v=[...p],_=Ze(N,v,x,l);s.level==="lot"&&p.push(...Ye(s)),p.push(..._.map(r=>r.item));const F=new Set(_.filter(r=>l>0&&r.item.diesLost/l>=K).map(r=>r.testNumber));p.push(...tt(i,[...v,..._.map(r=>r.item)],x),...st(i,l),...it(s,g,l),...ot(N.filter(r=>r.passingDies>0&&!F.has(r.testNumber))));let z=[];if(s.level==="lot"){const r=rt(s,t.attributes);z=r.compared;for(const w of r.items){const B=w.testNumbers[0],R=w.testNumbers.length===1?p.find(L=>L.target.kind==="test"&&L.target.testNumber===B)??p.find(L=>L.testNumbers.includes(B)):void 0;R?R.text+=`. ${w.text}`:p.push(w)}}const W=qe(s),M=p.filter(r=>l>0&&r.affected/l>=K);for(const r of M)r.shareOfDies=r.affected/l,r.impact=Ke(r.shareOfDies,r.kind==="loss"&&W>0?r.diesLost/W:0),r.measure||(r.measure=`${(r.shareOfDies*100).toFixed(1)}%`);const y=r=>`${String(r.testNumbers[0]??"").padStart(10,"0")}${r.findingIds[0]??""}`;M.sort((r,w)=>w.affected-r.affected||(y(r)<y(w)?-1:y(r)>y(w)?1:0));const I=M.slice(0,le),k=M.slice(le);for(const r of[...I,...k])for(const w of r.findingIds)o.add(w);const $=k.length>0?{items:k.slice(0,fe),more:Math.max(0,k.length-fe)}:void 0,O=s.level==="lot"?"region, fail bin or wafer":"region or fail bin",H=i.filter(r=>r.severity==="unusual"&&!o.has(r.id)).length,Q=I.length===0?H>0?`No ${O} costs as much as ${E(K)} yield points, though ${T(H,"finding")} below ${H===1?"is":"are"} marked unusual.`:`Nothing stands out: no ${O} costs as much as ${E(K)} yield points.`:void 0;return{headline:lt(s,t),items:I,...$?{also:$}:{},...Q?{nothing:Q}:{},checked:ft(s,o,z)}}export const synthesisKey=e=>e.target.kind==="finding"?`finding:${e.target.id}`:`test:${e.target.testNumber}`,SYNTHESIS_ALSO_HEADING=`Also, each affecting at least ${(K*100).toFixed(0)}% of the dies`,synthesisRowShare=e=>e.measure,synthesisMoreTests=e=>e.moreTests?`and ${e.moreTests} more test${e.moreTests===1?"":"s"}`:void 0;export function synthesisText(e){return[e.headline,...e.nothing?[e.nothing]:[],...e.items.map((t,s)=>`${s+1}. ${t.text}`),...e.also?[`${SYNTHESIS_ALSO_HEADING}: ${e.also.items.map(t=>`${t.brief} (${synthesisRowShare(t)})`).join("; ")}${e.also.more?`; and ${e.also.more} more`:""}.`]:[],e.checked].join(`
1
+ import{maxOf as ge,minOf as be}from"../core/utils.js";import{isPassBin as $e,passBinsLabel as we}from"../core/passBins.js";import{DRIFT_MIN_WAFERS as ye}from"./lotDrift.js";import{isOneBinCluster as ve}from"./filterFindings.js";import{plainBinTerms as Se}from"../renderer/fmt.js";import{benjaminiHochberg as Ne,normalUpperTail as xe}from"./math.js";import{compareGroups as Ie,formatP as ae}from"./groupCompare.js";import{attributeLabel as oe,buildFacetTable as ke,facetValueOf as Me}from"./facets.js";const De=1,Be=2,_e=.5,le=3,fe=5,K=.01,Fe=.02,Oe=.04,ze=.15,Le=.4,X=.5,Ae=.1,Ee=2,ce=new Set(["ring","quadrant","sector","reticle-position","test-site","cluster","edge-arc"]);function ee(e){const t=e.highlight;return"dieKeysByWafer"in t&&t.dieKeysByWafer?Object.values(t.dieKeysByWafer).reduce((s,i)=>s+i.length,0):"dieKeys"in t&&t.dieKeys&&t.dieKeys.length>0?t.dieKeys.length:e.level==="lot"?void 0:e.stats.sampleSizeLeft}function te(e){const t=e.highlight,s=new Set;if("dieKeysByWafer"in t&&t.dieKeysByWafer)for(const[i,d]of Object.entries(t.dieKeysByWafer))for(const c of d)s.add(`${i}:${c}`);else if("dieKeys"in t&&t.dieKeys)for(const i of t.dieKeys)s.add(i);return s}const D=e=>Math.abs(e.effect.absoluteDelta??0),T=e=>D(e)*(ee(e)??0),A=e=>(e*100).toFixed(1),G=e=>{const t=e.variable.label.replace(/ \(same dies\)$/,"").replace(/^HBin and SBin (\d+)/,"HBin $1").replace(/^(HBin \d+(?: \([^)]*\))?) and SBin .*$/,"$1");return Se(t)},S=e=>Math.round(e).toLocaleString("en-GB"),E=(e,t,s=`${t}s`)=>`${S(e)} ${e===1?t:s}`;function R(e){const t=e.comparison.left;return e.comparison.family==="quadrant"&&!/quadrant/i.test(t)?`${t} quadrant`:t}const de=ve;function Te(e){const t=e.map((f,r)=>r),s=f=>t[f]===f?f:t[f]=s(t[f]),i=e.map(te),d=(f,r)=>{const u=i[f].size<=i[r].size?i[f]:i[r],b=u===i[f]?i[r]:i[f];let m=0;for(const p of u)b.has(p)&&m++;return m},c=e.map((f,r)=>r).filter(f=>de(e[f])),n=e.map((f,r)=>r).filter(f=>!de(e[f]));for(let f=0;f<n.length;f++)for(let r=f+1;r<n.length;r++){const u=Math.min(i[n[f]].size,i[n[r]].size);u>0&&d(n[f],n[r])>=X*u&&(t[s(n[f])]=s(n[r]))}for(const f of c){let r=-1,u=0;for(const b of n){if(se(e[b])&&e[b].variable.bin!==e[f].variable.bin)continue;const m=d(f,b);m>u&&m>=X*i[f].size&&m>=X*T(e[b])&&(r=b,u=m)}r>=0&&(t[f]=s(r))}const h=new Map;return e.forEach((f,r)=>{const u=s(r);(h.get(u)??h.set(u,[]).get(u)).push(r)}),[...h.values()]}const se=e=>e.variable.kind==="hardBin"||e.variable.kind==="softBin",ie=(e,t)=>e.level===t.level&&e.comparison.family===t.comparison.family&&e.comparison.left===t.comparison.left;function We(e,t,s){const i=c=>t.filter(n=>n.variable.kind===c&&ie(n,e)&&n.effect.direction==="higher"&&s(n));return(i("hardBin").length>0?i("hardBin"):i("softBin")).filter(c=>c!==e).sort((c,n)=>D(n)-D(c))}const je={ring:"rings",quadrant:"quadrants",sector:"sectors","edge-arc":"edge arcs",cluster:"clusters","reticle-position":"reticle positions","test-site":"test sites"},He=2;function ue(e){const t=new Map;for(const i of e){const d=i.comparison.family;(t.get(d)??t.set(d,new Set).get(d)).add(R(i))}const s=[];for(const[i,d]of t)d.size<=He?s.push(...d):s.push(`${d.size} ${je[i]??i}`);return s.join(", ")}const Ce=e=>e.charAt(0).toUpperCase()+e.slice(1),P=e=>({kind:"finding",id:e.id}),Re=e=>({label:Ce(G(e)),target:P(e),...e.variable.bin!==void 0&&(e.variable.kind==="hardBin"||e.variable.kind==="softBin")?{bin:{kind:e.variable.kind,bin:e.variable.bin}}:{}});function V(e){const t=e.comparison.family;return{builtin:t==="quadrant"||t==="sector"?"quadrant":t==="reticle-position"?"reticleCell":t==="test-site"?"site":"ring"}}const he=(e,t)=>({chart:"bar",fields:{x:e,y:t,color:{none:!0}},valueLabels:!0,axes:{y:{references:[{stat:"median"}]}}}),J=e=>({test:e}),ne=(e,t=!1)=>({chart:"histogram",fields:{y:J(e),color:{none:!0}},...t?{normalCurve:!0}:{}});function Pe(e,t,s,i){const d=[...e].sort((l,g)=>T(g)-T(l))[0],c=e.find(l=>i.isPassRate(l)&&ie(l,d))??d,n=e.filter(l=>l!==c),h=c.level==="lot"&&"waferIndices"in c.highlight?c.highlight.waferIndices?.length:void 0,f=h!==void 0&&s?` on ${h}/${s} wafers`:"",r=!i.isPassRate(c),u=c.comparison.family==="sector"?"the other sectors":"the rest of the wafer";let b=r?`${R(c)}: ${G(c)} ${A(D(c))} points higher than ${u}${f}`:`${R(c)}: pass rate ${A(D(c))} points below ${u}${f}`;const m=`${b} \u2014 about ${S(T(c))} dies lost`,p=We(c,t,i.isFailBin).map(l=>({f:l,share:D(l)/(D(c)||1)})).filter(l=>r||l.share>=Ae).slice(0,Ee);if(r)for(const{f:l}of p)b+=`, ${G(l)} ${A(D(l))} points higher`;else if(p.length>0){const l=p.reduce((N,v)=>N+v.share,0)<=1.000000001,g=l&&p[0].share>.5?"mostly ":"";p.forEach(({f:N},v)=>{b+=v===0?`; ${l?g:""}`:", ",b+=G(N)+(v===0?l?` accounts for ${A(D(N))} of those points`:` is ${A(D(N))} points higher`:l?` for ${A(D(N))}`:` ${A(D(N))} points higher`)})}b+=` \u2014 about ${S(T(c))} dies lost`;const k=n.filter(l=>!ie(l,c));k.length>0&&(b+=` (also seen as ${ue(k)})`);const o=r?G(c):"pass rate";return{kind:"loss",impact:"low",shareOfDies:0,diesLost:T(c),affected:T(c),measure:"",severity:c.severity,text:b,reason:m,brief:`${R(c)}: ${o}, ${S(T(c))} dies`,subject:R(c),target:P(c),chips:[...r?[c]:[],...p.map(({f:l})=>l)].map(Re),findingIds:[c.id,...n.map(l=>l.id)],testNumbers:[],chart:r?{chart:"bar",fields:{x:V(c),color:{builtin:c.variable.kind==="softBin"?"sbin":"hbin"}},stack:"percent"}:c.level==="lot"?{chart:"heatmap",fields:{x:{builtin:"wafer"},rows:V(c),y:{builtin:"yield"}}}:he(V(c),{builtin:"yield"})}}function Ke(e,t){return e>=Oe||t>=Le?"high":e>=Fe||t>=ze?"medium":"low"}function qe(e){const t=s=>s.stats.yieldPercent==null?0:s.stats.analyzedDies*(1-s.stats.yieldPercent/100);return e.level==="wafer"?t(e):e.perWafer.reduce((s,i)=>s+t(i.summary),0)}function Ge(e){return e.level==="wafer"?e.stats.analyzedDies:e.perWafer.reduce((t,s)=>t+s.summary.stats.analyzedDies,0)}const me=e=>e.id.startsWith("inter-wafer:yield:");function Ye(e){const t=[];for(const s of e.findings){if(!me(s)||s.effect.direction!=="lower")continue;const i="waferIndices"in s.highlight?s.highlight.waferIndices?.[0]:void 0,d=i===void 0?void 0:e.perWafer.find(c=>c.waferIndex===i)?.summary.stats.analyzedDies;d!==void 0&&t.push({kind:"loss",impact:"low",shareOfDies:0,diesLost:D(s)*d,affected:D(s)*d,measure:"",severity:s.severity,text:`${s.summary.replace(/ percentage points lower than the lot median$/," points below the lot median")} \u2014 about ${S(D(s)*d)} dies lost`,reason:`${s.summary.replace(/ percentage points lower than the lot median$/," points below the lot median")} \u2014 about ${S(D(s)*d)} dies lost`,brief:`${s.comparison.left}: yield, ${S(D(s)*d)} dies`,subject:s.comparison.left,target:P(s),chips:[],findingIds:[s.id],testNumbers:[],chart:{chart:"control",fields:{x:{builtin:"waferOrder"},y:{builtin:"yield"}}}})}return t}function Ue(e,t){if(e.level==="wafer"){const c=e.stats.testFailures?.[t];return c?{keys:new Set(c.dieKeys),lost:c.lostDies}:void 0}const s=new Set;let i=0,d=!1;for(const c of e.perWafer){const n=c.summary.stats.testFailures?.[t];if(n){d=!0,i+=n.lostDies;for(const h of n.dieKeys)s.add(`${c.waferIndex}:${h}`)}}return d?{keys:s,lost:i}:void 0}function Xe(e,t){const s=e.stats,i=[],d=n=>he({builtin:e.level==="lot"?"wafer":"ring"},{passRate:n}),c=(n,h,f,r,u,b,m=u,p=!1)=>{if(f<=0||r<=0)return;t.add(n);const k=Ue(e,n),o=k?Math.min(k.lost,f):f,l=f-o,g=f/r*100;i.push({testNumber:n,label:h,verb:u,plainVerb:m,failDies:f,passingDies:l,keys:k?.keys,item:{kind:"loss",impact:"low",shareOfDies:0,diesLost:o,affected:o,measure:"",severity:"info",text:`${h} ${u} on ${S(f)} of ${S(r)} dies (${g.toFixed(1)}%)`+(l>0?`; ${S(l)} of them are binned as passing, so about ${S(o)} dies lost`:""),reason:`${h} ${u} on ${S(f)} of ${S(r)} dies (${g.toFixed(1)}%)`,brief:l>0?`${h}: ${b}, ${S(o)} dies lost`:`${h}: ${S(f)} dies ${b}`,subject:h,target:{kind:"test",testNumber:n},chips:[],findingIds:[],testNumbers:[n],chart:p||e.level==="lot"?d(n):ne(n)}})};for(const n of s.testSpecYield??[]){const h=n.failHighDies===0?"is below its low limit":n.failLowDies===0?"is above its high limit":`is outside its limits (${S(n.failLowDies)} low, ${S(n.failHighDies)} high)`;c(n.testNumber,n.label,n.failLowDies+n.failHighDies,n.totalDies,h,"outside limits",n.failLowDies>0&&n.failHighDies>0?"is outside its limits":h)}for(const n of s.functionalYield??[])c(n.testNumber,n.label,n.failDies,n.totalDies,"fails","fail","fails",!0);return i}const Ve=.5,Je=2,Qe=2,Y=5;function Ze(e,t,s,i){const d=new Set,c=new Map,n=new Map,h=[...e].sort((f,r)=>r.failDies-f.failDies||f.testNumber-r.testNumber);for(const f of h){const r=f.keys;if(i>0&&f.failDies/i<K){d.add(f);continue}let u;if(r&&r.size>0&&i>0)for(const p of t){const k=s.get(p);if(!k||k.size===0)continue;let o=0;for(const g of r)k.has(g)&&o++;const l=o/r.size;l>=Ve&&l>=Je*(k.size/i)&&(!u||o>u.inside)&&(u={item:p,inside:o})}if(!u){d.add(f);continue}const b=c.get(u.item)??0;if(b<Qe){const p=u.inside===f.failDies?"all":S(u.inside);u.item.text+=`. ${f.label} ${f.verb} on ${E(f.failDies,"die")}, ${p} of them in ${u.item.subject}`,c.set(u.item,b+1)}const m=n.get(u.item)??0;m<Y?(u.item.chips.push({label:f.label,target:f.item.target}),n.set(u.item,m+1)):u.item.moreTests=(u.item.moreTests??0)+1,u.item.testNumbers.push(f.testNumber)}return e.filter(f=>d.has(f))}function U(e){return{kind:"signal",impact:"low",shareOfDies:0,diesLost:0,affected:e.affected,measure:e.measure,severity:e.severity,text:e.text,reason:e.reason??e.text,brief:e.brief,subject:e.subject,target:e.target,chips:[],findingIds:e.findingIds??[],testNumbers:e.testNumbers??[],chart:e.chart}}const re=e=>Math.abs(e)<_e?0:Math.min(1,(Math.abs(e)/Be)**2),j=e=>`${Math.abs(e).toFixed(1)}\u03C3`,et=e=>e.variable.kind==="test"&&e.variable.measure!=="limitFailRate"&&ce.has(e.comparison.family)&&Number.isFinite(e.effect.effectSize??NaN)&&!e.id.startsWith("drift:");function tt(e,t,s){const i=new Map;for(const n of e)!et(n)||n.variable.index===void 0||(i.get(n.variable.index)??i.set(n.variable.index,[]).get(n.variable.index)).push(n);const d=n=>(ee(n)??n.stats.sampleSizeLeft)*re(n.effect.effectSize??0),c=[];for(const[n,h]of[...i].sort((f,r)=>f[0]-r[0])){const f=[...h].sort((o,l)=>d(l)-d(o)),r=f[0],u=r.effect.effectSize??0;if(d(r)===0)continue;const b=te(r);let m=t.find(o=>o.target.kind==="test"&&o.target.testNumber===n)??t.find(o=>o.testNumbers.includes(n))??t.find(o=>f.some(l=>o.findingIds.includes(l.id))),p=0;for(const o of m?[]:t){const l=s.get(o);if(!l||l.size===0||b.size===0)continue;let g=0;for(const N of b)l.has(N)&&g++;g>=X*Math.min(l.size,b.size)&&g>p&&(p=g,m=o)}if(m){m.text+=`. ${r.summary}`,m.testNumbers.includes(n)||(m.chips.filter(l=>l.target.kind==="test"||l.shift).length<Y?m.chips.push({label:r.variable.label,target:P(r),shift:!0}):m.moreTests=(m.moreTests??0)+1,m.testNumbers.push(n));for(const o of f)m.findingIds.includes(o.id)||m.findingIds.push(o.id);continue}const k=ee(r)??r.stats.sampleSizeLeft;c.push(U({affected:d(r),measure:j(u),severity:r.severity,text:`${r.summary}: a shift of ${j(u)} over ${E(k,"die")}`+(f.length>1?` (also seen as ${ue(f.slice(1))})`:""),reason:`${r.summary}: a shift of ${j(u)} over ${E(k,"die")}`,brief:`${R(r)}: ${r.variable.label} ${r.effect.direction}`,subject:R(r),target:P(r),findingIds:f.map(o=>o.id),testNumbers:[n],chart:{chart:"box",fields:{x:V(r),y:J(n),color:{none:!0}},axes:{y:{references:[{stat:"median"}]}}}}))}return c}function st(e,t){return e.filter(s=>s.id.startsWith("drift:")).map(s=>{const i=s.variable.kind==="yield",d=s.effect.effectSize??0;return U({affected:t*(i?Math.abs(d):re(d)),measure:i?`${A(Math.abs(d))} pts`:j(d),severity:s.severity,text:s.summary,brief:`${s.variable.label}: drifts across the wafers`,subject:s.variable.label,target:P(s),findingIds:[s.id],...s.variable.index!==void 0?{testNumbers:[s.variable.index]}:{},chart:{chart:"control",fields:{x:{builtin:"waferOrder"},y:i||s.variable.index===void 0?{builtin:"yield"}:J(s.variable.index)}}})})}function it(e,t,s){return(e.stats.capability??[]).filter(i=>i.hasSpec&&i.ppk!==null&&i.ppk!==void 0&&i.ppk<De&&!t.has(i.testNumber)).map(i=>{const d=i.ppk,c=xe(3*d);return U({affected:s*c,measure:`Ppk ${d.toFixed(2)}`,severity:"notable",text:`${i.label} has Ppk ${d.toFixed(2)} against its limits: a spread that would put about ${A(c)}% of the dies outside them`,brief:`${i.label}: Ppk ${d.toFixed(2)}`,subject:i.label,target:{kind:"test",testNumber:i.testNumber},testNumbers:[i.testNumber],chart:ne(i.testNumber,!0)})})}const nt=.05,rt=8;function at(e,t){const s={items:[],compared:[]},i=e.perWafer;if(i.length<4)return s;const d=ke(i.map(o=>({metadata:o.summary.wafer,dieCount:o.summary.stats.totalDies})),{facetableOnly:!0,curation:t}).filter(o=>o.splittable&&o.values.length<=Math.max(2,Math.floor(i.length/2)));if(d.length===0)return s;const c=o=>e.perWaferTestStats?.find(l=>l.waferIndex===o.waferIndex)?.tests??o.summary.stats.perTestStats??[],n=i.map(o=>new Map(c(o).filter(l=>l.count>=2&&Number.isFinite(l.mean)).map(l=>[l.testNumber,l]))),h=new Map;for(const o of n)for(const[l,g]of o)h.has(l)||h.set(l,g.label);const f=i.map(o=>o.summary.stats.analyzedDies),r=[];for(const o of d){const l=i.map(g=>Me(g.summary.wafer,o.key,t));for(const[g,N]of[...h].sort((v,_)=>v[0]-_[0])){const v=new Map,_=[];if(n.forEach((y,x)=>{const I=y.get(g),$=l[x];!I||$===void 0||((v.get($)??v.set($,[]).get($)).push(x),Number.isFinite(I.stddev)&&_.push(I.stddev**2))}),v.size<2)continue;const F=Ie([...v].map(([y,x])=>({key:y,values:x.map(I=>n[I].get(g).mean)}))),z=F.welch?.p??F.kruskal?.p,W=_.length?Math.sqrt(_.reduce((y,x)=>y+x,0)/_.length):NaN;if(z===void 0||!Number.isFinite(z)||!(W>0))continue;let M;for(const[y,x]of v){const I=x.map(a=>n[a].get(g).mean),$=[...v].filter(([a])=>a!==y).flatMap(([,a])=>a.map(w=>n[w].get(g).mean));if(I.length<2||$.length<2)continue;const O=I.reduce((a,w)=>a+w,0)/I.length-$.reduce((a,w)=>a+w,0)/$.length,H=O/W;(!M||Math.abs(H)>Math.abs(M.d)+1e-9||Math.abs(Math.abs(H)-Math.abs(M.d))<=1e-9&&(x.length<M.groupWafers||x.length===M.groupWafers&&O>0))&&(M={testNumber:g,label:N,field:o.key,group:y,groupWafers:x.length,groupDies:x.reduce((a,w)=>a+f[w],0),d:H,higher:O>0,p:z})}if(M&&v.size===2){const[y,x]=[...v].find(([I])=>I!==M.group);M.other={group:y,wafers:x.length}}M&&r.push(M)}}const u=Ne(r.map(o=>o.p)),b=new Map;r.forEach((o,l)=>{const g=o.groupDies*re(o.d);u[l]>=nt||g===0||(b.get(o.field)??b.set(o.field,[]).get(o.field)).push({c:o,q:u[l],weight:g})});const m=r.length?[...new Set(r.map(o=>o.field))].map(o=>oe(o,t)):[],p=(o,l)=>o.other?`${o.label} is ${o.higher?"higher":"lower"} on ${l} ${o.group} than on ${l} ${o.other.group} (${o.groupWafers} and ${o.other.wafers} wafers)`:`${o.label} is ${o.higher?"higher":"lower"} on ${l} ${o.group} (${o.groupWafers} of ${i.length} wafers) than on the other wafers`;return{items:[...b].map(([o,l])=>{l.sort(($,O)=>Math.abs(O.c.d)-Math.abs($.c.d)||O.weight-$.weight||$.c.testNumber-O.c.testNumber);const g=l.reduce(($,O)=>Math.max($,O.weight),0),N=oe(o,t),[v,..._]=l,F=v.c,z=`${p(F,N)}: a shift of ${j(F.d)}`,W=_.slice(0,2).map(({c:$})=>`${$.label} ${$.higher?"higher":"lower"} on ${$.group} (${j($.d)})`),M=_.length-W.length,y=l.length,x=y===1?`${z}, each wafer one value (q ${ae(v.q)})`:`${y} tests differ by ${N}. Largest: ${z}, each wafer one value (q ${ae(v.q)}); next: ${W.join(", ")}${M>0?`, and ${M} more`:""}`,I=U({affected:g,measure:j(F.d),severity:v.q<.001?"unusual":"notable",text:x,reason:y===1?z:`${y} tests differ by ${N}. Largest: ${z}`,brief:y===1?`${N} ${F.group}: ${F.label} ${F.higher?"higher":"lower"}`:`${N}: ${y} tests differ`,subject:N,target:{kind:"test",testNumber:F.testNumber},testNumbers:l.map($=>$.c.testNumber),chart:y>1?{chart:"heatmap",level:"wafer",aggregate:"mean",normalize:"zscore",fields:{x:{meta:o},y:{tests:l.slice(0,rt).map($=>$.c.testNumber)}}}:{chart:"box",level:"wafer",aggregate:"mean",fields:{x:{meta:o},y:J(F.testNumber),color:{meta:o}}}});return y>1&&(I.chips=l.slice(0,Y).map(({c:$})=>({label:`${$.label} ${j($.d)}`,target:{kind:"test",testNumber:$.testNumber}})),y>Y&&(I.moreTests=y-Y)),I}),compared:m}}export function groupColouredChart(e,t){const s=e.fields?.x,i=e.fields?.color;return!t||e.chart!=="bar"||!s||Array.isArray(s)||!("builtin"in s)||s.builtin!=="wafer"||!i||!("none"in i)?e:{...e,fields:{...e.fields,x:[{slot:"groupBy"},{builtin:"wafer"}],color:{follow:"groupBy"}}}}function ot(e){return e.map(t=>U({affected:t.passingDies,measure:"",severity:"notable",text:`${t.label} ${t.plainVerb} on ${E(t.passingDies,"die")} binned as passing`,brief:`${t.label}: ${S(t.passingDies)} dies out of limits, binned passing`,subject:t.label,target:t.item.target,testNumbers:[t.testNumber],chart:ne(t.testNumber)}))}function lt(e,t){const s=t.passBins&&t.passBins.length>0?`; pass ${we([t.passBins])}`:"";if(e.level==="wafer"){const r=e.stats.yieldPercent;return r==null?`${S(e.stats.totalDies)} dies, no bin data to judge yield by.`:`Yield ${r.toFixed(1)}% (${S(e.stats.totalDies)} dies${s}).`}const i=e.lotYieldSeries.map(r=>r.yieldPercent).filter(r=>typeof r=="number");if(i.length===0)return`${E(e.stats.waferCount,"wafer")}, no bin data to judge yield by.`;const d=i.reduce((r,u)=>r+u,0)/i.length,c=e.perWafer.reduce((r,u)=>r+u.summary.stats.totalDies,0),[n,h]=[be(i).toFixed(1),ge(i).toFixed(1)],f=n!==h?`, range ${n}\u2013${h}%`:"";return`Yield ${d.toFixed(1)}% (mean of ${E(i.length,"wafer")}, ${S(c)} dies${s})${f}.`}function ft(e,t,s=[]){const i=[],d=e.level==="wafer"?e.stats.testsConsidered.length:new Set(e.perWafer.flatMap(r=>r.summary.stats.testsConsidered)).size,c=e.level==="wafer"?e.stats.hardBinsConsidered.length:new Set(e.perWafer.flatMap(r=>r.summary.stats.hardBinsConsidered)).size,n=e.stats.testValueAnalysis?.state;if(d>0&&n!=="off"&&i.push(E(d,"test")+(n==="skipped"?" (against their limits only)":"")),c>0&&i.push(E(c,"hard bin")),i.push("the ring, quadrant and sector regions"),e.level==="lot"&&e.stats.waferCount>=3){const r=e.findings.filter(me);i.push(r.length===0?"wafer-to-wafer yield (no outlier wafers)":`wafer-to-wafer yield (${E(r.length,"outlier wafer")})`),e.stats.waferCount>=ye&&i.push("the yield trend across the wafers (input order)"),s.length&&i.push(`the tests between the groups of ${s.join(", ")} (each wafer one value)`)}const h=e.findings.filter(r=>!t.has(r.id)).length,f=h>0?` ${E(h,"smaller finding")} not listed above.`:" Nothing else was found.";return`Compared: ${i.join(", ")}.${f}`}export function synthesisSource(e){return e.level==="lot"&&e.perWafer.length===1?e.perWafer[0].summary:e}const pe=new WeakMap;export function buildSynthesis(e,t={}){const s=`${t.passBins?.join(",")??"-"}|${t.attributes?JSON.stringify(t.attributes):"-"}`;let i=pe.get(e);i||pe.set(e,i=new Map);const d=i.get(s),c=e.findings;if(d&&d.findings.length===c.length&&d.findings.every((h,f)=>h===c[f]))return d.synthesis;const n=ct(e,t);return Object.freeze(n.items),n.items.forEach(Object.freeze),n.also&&(Object.freeze(n.also.items),n.also.items.forEach(Object.freeze),Object.freeze(n.also)),i.set(s,{findings:[...c],synthesis:Object.freeze(n)}),n}function ct(e,t){const s=synthesisSource(e),i=s.findings,d=s.level==="lot"?s.stats.waferCount:void 0,c=t.passBins,n=new Map(i.map(a=>[a.id,a])),h=(s.level==="wafer"?[s]:s.perWafer.map(a=>a.summary)).every(a=>(a.stats.hardBinsConsidered??[]).length===0),f=a=>c!==void 0&&se(a)&&$e(a.variable.kind,a.variable.bin??NaN,c,!h),r={isPassRate:a=>a.variable.kind==="yield"||c?.length===1&&f(a),isFailBin:a=>c!==void 0&&se(a)&&!f(a)},u=i.filter(a=>ce.has(a.comparison.family)&&T(a)>0&&(r.isPassRate(a)&&a.effect.direction==="lower"||r.isFailBin(a)&&a.effect.direction==="higher")),m=u.some(a=>a.variable.kind==="hardBin")?u.filter(a=>a.variable.kind!=="softBin"):u,p=[],k=new Map,o=new Set;for(const a of Te(m)){const w=a.map(L=>m[L]),B=Pe(w,i,d,r);p.push(B);const C=B.target.kind==="finding"?B.target.id:void 0;k.set(B,te(w.find(L=>L.id===C)??w[0]))}for(const a of i.filter(w=>w.variable.kind==="spatialPattern")){const w=new Set((a.relatedIds??[]).filter(q=>n.has(q))),B=p.find(q=>q.findingIds.some(Z=>w.has(Z)));if(!B)continue;const C=a.level==="lot"&&"waferIndices"in a.highlight?a.highlight.waferIndices?.length:void 0,L=C!==void 0&&d?` on ${C}/${d} wafers`:"";B.text=`${a.variable.label} pattern${L}. ${B.text}`,B.reason=`${a.variable.label} pattern${L}. ${B.reason}`,B.chips.unshift({label:`${a.variable.label} pattern`,target:P(a)}),B.findingIds.unshift(a.id,...[...w].filter(q=>!p.some(Z=>Z.findingIds.includes(q))))}const l=Ge(s),g=new Set,N=Xe(s,g),v=[...p],_=Ze(N,v,k,l);s.level==="lot"&&p.push(...Ye(s)),p.push(..._.map(a=>a.item));const F=new Set(_.filter(a=>l>0&&a.item.diesLost/l>=K).map(a=>a.testNumber));p.push(...tt(i,[...v,..._.map(a=>a.item)],k),...st(i,l),...it(s,g,l),...ot(N.filter(a=>a.passingDies>0&&!F.has(a.testNumber))));let z=[];if(s.level==="lot"){const a=at(s,t.attributes);z=a.compared;for(const w of a.items){const B=w.testNumbers[0],C=w.testNumbers.length===1?p.find(L=>L.target.kind==="test"&&L.target.testNumber===B)??p.find(L=>L.testNumbers.includes(B)):void 0;C?C.text+=`. ${w.text}`:p.push(w)}}const W=qe(s),M=p.filter(a=>l>0&&a.affected/l>=K);for(const a of M)a.shareOfDies=a.affected/l,a.impact=Ke(a.shareOfDies,a.kind==="loss"&&W>0?a.diesLost/W:0),a.measure||(a.measure=`${(a.shareOfDies*100).toFixed(1)}%`);const y=a=>`${String(a.testNumbers[0]??"").padStart(10,"0")}${a.findingIds[0]??""}`;M.sort((a,w)=>w.affected-a.affected||(y(a)<y(w)?-1:y(a)>y(w)?1:0));const x=M.slice(0,le),I=M.slice(le);for(const a of[...x,...I])for(const w of a.findingIds)o.add(w);const $=I.length>0?{items:I.slice(0,fe),more:Math.max(0,I.length-fe)}:void 0,O=s.level==="lot"?"region, fail bin or wafer":"region or fail bin",H=i.filter(a=>a.severity==="unusual"&&!o.has(a.id)).length,Q=x.length===0?H>0?`No ${O} costs as much as ${A(K)} yield points, though ${E(H,"finding")} below ${H===1?"is":"are"} marked unusual.`:`Nothing stands out: no ${O} costs as much as ${A(K)} yield points.`:void 0;return{headline:lt(s,t),items:x,...$?{also:$}:{},...Q?{nothing:Q}:{},checked:ft(s,o,z)}}export const synthesisKey=e=>e.target.kind==="finding"?`finding:${e.target.id}`:`test:${e.target.testNumber}`,SYNTHESIS_ALSO_HEADING=`Also, each affecting at least ${(K*100).toFixed(0)}% of the dies`,synthesisRowShare=e=>e.measure,synthesisMoreTests=e=>e.moreTests?`and ${e.moreTests} more test${e.moreTests===1?"":"s"}`:void 0;export function synthesisText(e){return[e.headline,...e.nothing?[e.nothing]:[],...e.items.map((t,s)=>`${s+1}. ${t.text}`),...e.also?[`${SYNTHESIS_ALSO_HEADING}: ${e.also.items.map(t=>`${t.brief} (${synthesisRowShare(t)})`).join("; ")}${e.also.more?`; and ${e.also.more} more`:""}.`]:[],e.checked].join(`
2
2
  `)}
@@ -0,0 +1,11 @@
1
+ import type { Die } from '../core/dies.js';
2
+ /** At most this many dies × tests are read to rank; beyond it the first tests are taken as they come. */
3
+ export declare const RANK_BUDGET = 4000000;
4
+ /**
5
+ * The `limit` tests (of `tests`) with the largest share of variance between wafers, most first. Tests with no spread, or
6
+ * with values on fewer than two wafers, are left out. Past the reading budget the first `limit` tests are returned in order.
7
+ */
8
+ export declare function rankTestsByWaferSpread(wafers: ReadonlyArray<{
9
+ dies: readonly Die[];
10
+ }>, tests: readonly number[], limit: number): number[];
11
+ //# sourceMappingURL=testsByWafer.d.ts.map
@@ -0,0 +1 @@
1
+ import{testValue as b}from"../core/dieTable.js";export const RANK_BUDGET=4e6;export function rankTestsByWaferSpread(o,r,d){if(o.length<2)return[];if(o.reduce((e,n)=>e+n.dies.length,0)*r.length>RANK_BUDGET)return r.slice(0,d);const h=[];for(const e of r){let n=0,a=0,l=0;const i=[],p=[];for(const u of o){let t=0,f=0;for(const _ of u.dies){const s=b(_,e);s===void 0||!Number.isFinite(s)||(t++,f+=s,l+=s*s)}t&&(i.push(f/t),p.push(t),n+=t,a+=f)}if(i.length<2||n<2)continue;const c=a/n,m=l-n*c*c;if(!(m>0))continue;let g=0;i.forEach((u,t)=>{g+=p[t]*(u-c)**2}),h.push({test:e,share:g/m})}return h.sort((e,n)=>n.share-e.share).slice(0,d).map(e=>e.test)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wafertools/wafermap",
3
- "version": "0.38.0",
3
+ "version": "0.39.0",
4
4
  "description": "Interactive wafer map visualization and yield analysis for semiconductor test data. Hard bins, soft bins, test values, retests, edge exclusion, reticle overlays, spatial statistics, failure clustering, and lot-level trend analysis — pure ES modules, no runtime dependencies, no server required.",
5
5
  "type": "module",
6
6
  "license": "MIT",