@wafertools/wafermap 0.36.0 → 0.37.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 (158) hide show
  1. package/AGENTS.md +2 -2
  2. package/CHANGELOG.md +357 -0
  3. package/README.md +7 -7
  4. package/dist/packages/canvas-adapter/charts/capability.js +1 -1
  5. package/dist/packages/canvas-adapter/charts/cardAbout.d.ts +21 -0
  6. package/dist/packages/canvas-adapter/charts/cardAbout.js +1 -0
  7. package/dist/packages/canvas-adapter/charts/chartShell.d.ts +65 -12
  8. package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
  9. package/dist/packages/canvas-adapter/charts/commonality.d.ts +18 -0
  10. package/dist/packages/canvas-adapter/charts/commonality.js +1 -0
  11. package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
  12. package/dist/packages/canvas-adapter/charts/groupComparison.d.ts +31 -0
  13. package/dist/packages/canvas-adapter/charts/groupComparison.js +1 -0
  14. package/dist/packages/canvas-adapter/charts/index.d.ts +0 -10
  15. package/dist/packages/canvas-adapter/charts/index.js +1 -1
  16. package/dist/packages/canvas-adapter/charts/patCard.d.ts +21 -0
  17. package/dist/packages/canvas-adapter/charts/patCard.js +1 -0
  18. package/dist/packages/canvas-adapter/charts/plotChart.d.ts +56 -2
  19. package/dist/packages/canvas-adapter/charts/plotChart.js +1 -1
  20. package/dist/packages/canvas-adapter/charts/pointInteractions.d.ts +2 -0
  21. package/dist/packages/canvas-adapter/charts/pointInteractions.js +1 -1
  22. package/dist/packages/canvas-adapter/charts/regionYieldDiagram.js +1 -1
  23. package/dist/packages/canvas-adapter/charts/sweep.js +1 -1
  24. package/dist/packages/canvas-adapter/dataTab.d.ts +3 -0
  25. package/dist/packages/canvas-adapter/dataTab.js +1 -1
  26. package/dist/packages/canvas-adapter/dieList.d.ts +12 -0
  27. package/dist/packages/canvas-adapter/dieList.js +2 -2
  28. package/dist/packages/canvas-adapter/differenceMapPanel.d.ts +26 -0
  29. package/dist/packages/canvas-adapter/differenceMapPanel.js +1 -0
  30. package/dist/packages/canvas-adapter/drilldown.d.ts +3 -0
  31. package/dist/packages/canvas-adapter/drilldown.js +1 -1
  32. package/dist/packages/canvas-adapter/filterButton.d.ts +3 -0
  33. package/dist/packages/canvas-adapter/filterButton.js +1 -0
  34. package/dist/packages/canvas-adapter/filterEditor.d.ts +53 -0
  35. package/dist/packages/canvas-adapter/filterEditor.js +1 -0
  36. package/dist/packages/canvas-adapter/guideWindow.d.ts +9 -1
  37. package/dist/packages/canvas-adapter/guideWindow.js +1 -1
  38. package/dist/packages/canvas-adapter/icons.js +1 -1
  39. package/dist/packages/canvas-adapter/insightsTab.d.ts +50 -2
  40. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  41. package/dist/packages/canvas-adapter/pageFilter.d.ts +84 -0
  42. package/dist/packages/canvas-adapter/pageFilter.js +2 -0
  43. package/dist/packages/canvas-adapter/patMaps.d.ts +26 -0
  44. package/dist/packages/canvas-adapter/patMaps.js +1 -0
  45. package/dist/packages/canvas-adapter/plotCard.d.ts +67 -0
  46. package/dist/packages/canvas-adapter/plotCard.js +1 -0
  47. package/dist/packages/canvas-adapter/plotEditor.d.ts +13 -2
  48. package/dist/packages/canvas-adapter/plotEditor.js +1 -1
  49. package/dist/packages/canvas-adapter/plotModal.js +1 -1
  50. package/dist/packages/canvas-adapter/plotStore.js +1 -1
  51. package/dist/packages/canvas-adapter/plotTab.d.ts +6 -0
  52. package/dist/packages/canvas-adapter/plotTab.js +1 -1
  53. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  54. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  55. package/dist/packages/canvas-adapter/summaryPanel.d.ts +15 -5
  56. package/dist/packages/canvas-adapter/summaryPanel.js +4 -4
  57. package/dist/packages/canvas-adapter/toolbar.d.ts +12 -0
  58. package/dist/packages/canvas-adapter/toolbar.js +2 -2
  59. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  60. package/dist/packages/canvas-adapter/userGuideHtml.js +598 -115
  61. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  62. package/dist/packages/canvas-adapter/version.js +1 -1
  63. package/dist/packages/core/classify.d.ts +11 -0
  64. package/dist/packages/core/classify.js +1 -1
  65. package/dist/packages/core/dies.d.ts +2 -0
  66. package/dist/packages/core/dies.js +1 -1
  67. package/dist/packages/core/wafer.d.ts +2 -2
  68. package/dist/packages/renderer/buildView.js +1 -1
  69. package/dist/packages/renderer/buildWaferMap.d.ts +2 -0
  70. package/dist/packages/renderer/buildWaferMap.js +1 -1
  71. package/dist/packages/renderer/deprecate.d.ts +2 -8
  72. package/dist/packages/renderer/deprecate.js +1 -1
  73. package/dist/packages/renderer/fmt.js +1 -1
  74. package/dist/packages/renderer/testLabel.d.ts +0 -11
  75. package/dist/packages/renderer/testLabel.js +1 -1
  76. package/dist/packages/stats/analyzeWaferLot.d.ts +6 -0
  77. package/dist/packages/stats/analyzeWaferLot.js +1 -1
  78. package/dist/packages/stats/analyzeWaferMap.d.ts +8 -0
  79. package/dist/packages/stats/analyzeWaferMap.js +1 -1
  80. package/dist/packages/stats/binPareto.d.ts +2 -54
  81. package/dist/packages/stats/binPareto.js +1 -1
  82. package/dist/packages/stats/binRows.js +1 -1
  83. package/dist/packages/stats/capability.d.ts +10 -0
  84. package/dist/packages/stats/capability.js +1 -1
  85. package/dist/packages/stats/cardSpec.d.ts +53 -0
  86. package/dist/packages/stats/cardSpec.js +1 -0
  87. package/dist/packages/stats/chartCatalogue.d.ts +37 -0
  88. package/dist/packages/stats/chartCatalogue.js +1 -0
  89. package/dist/packages/stats/clusterDetection.d.ts +9 -0
  90. package/dist/packages/stats/clusterDetection.js +1 -1
  91. package/dist/packages/stats/commonality.d.ts +62 -0
  92. package/dist/packages/stats/commonality.js +1 -0
  93. package/dist/packages/stats/control.d.ts +21 -0
  94. package/dist/packages/stats/control.js +1 -0
  95. package/dist/packages/stats/correlation.d.ts +9 -3
  96. package/dist/packages/stats/correlation.js +1 -1
  97. package/dist/packages/stats/dieRegions.d.ts +4 -1
  98. package/dist/packages/stats/dieRegions.js +1 -1
  99. package/dist/packages/stats/differenceMap.d.ts +22 -0
  100. package/dist/packages/stats/differenceMap.js +1 -0
  101. package/dist/packages/stats/examplePicks.d.ts +22 -0
  102. package/dist/packages/stats/examplePicks.js +1 -0
  103. package/dist/packages/stats/filterFile.d.ts +41 -0
  104. package/dist/packages/stats/filterFile.js +2 -0
  105. package/dist/packages/stats/filterFindings.d.ts +20 -5
  106. package/dist/packages/stats/filterFindings.js +1 -1
  107. package/dist/packages/stats/groupCompare.d.ts +87 -0
  108. package/dist/packages/stats/groupCompare.js +1 -0
  109. package/dist/packages/stats/guideSections.d.ts +55 -0
  110. package/dist/packages/stats/guideSections.js +1 -0
  111. package/dist/packages/stats/index.d.ts +3 -1
  112. package/dist/packages/stats/index.js +1 -1
  113. package/dist/packages/stats/math.d.ts +29 -4
  114. package/dist/packages/stats/math.js +1 -1
  115. package/dist/packages/stats/metadataColumns.d.ts +3 -0
  116. package/dist/packages/stats/metadataColumns.js +1 -1
  117. package/dist/packages/stats/pat.d.ts +58 -0
  118. package/dist/packages/stats/pat.js +1 -0
  119. package/dist/packages/stats/patSummary.d.ts +45 -0
  120. package/dist/packages/stats/patSummary.js +1 -0
  121. package/dist/packages/stats/patternClassification.d.ts +3 -3
  122. package/dist/packages/stats/patternClassification.js +1 -1
  123. package/dist/packages/stats/plotData.d.ts +294 -17
  124. package/dist/packages/stats/plotData.js +1 -1
  125. package/dist/packages/stats/plotId.d.ts +2 -0
  126. package/dist/packages/stats/plotId.js +1 -1
  127. package/dist/packages/stats/plotReferences.d.ts +17 -0
  128. package/dist/packages/stats/plotReferences.js +1 -0
  129. package/dist/packages/stats/plotSpec.d.ts +239 -3
  130. package/dist/packages/stats/plotSpec.js +4 -4
  131. package/dist/packages/stats/regions.js +1 -1
  132. package/dist/packages/stats/renderSummaryReport.js +31 -31
  133. package/dist/packages/stats/reportHtml.js +9 -13
  134. package/dist/packages/stats/synthesis.d.ts +44 -16
  135. package/dist/packages/stats/synthesis.js +1 -1
  136. package/dist/packages/stats/testPassRate.d.ts +7 -0
  137. package/dist/packages/stats/testPassRate.js +1 -1
  138. package/dist/packages/stats/types.d.ts +13 -8
  139. package/dist/packages/stats/yield.d.ts +3 -11
  140. package/dist/packages/stats/yield.js +1 -1
  141. package/llms.txt +1 -1
  142. package/package.json +2 -1
  143. package/dist/packages/canvas-adapter/charts/barPanel.d.ts +0 -83
  144. package/dist/packages/canvas-adapter/charts/barPanel.js +0 -1
  145. package/dist/packages/canvas-adapter/charts/binCluster.d.ts +0 -27
  146. package/dist/packages/canvas-adapter/charts/binCluster.js +0 -1
  147. package/dist/packages/canvas-adapter/charts/boxplot.d.ts +0 -72
  148. package/dist/packages/canvas-adapter/charts/boxplot.js +0 -1
  149. package/dist/packages/canvas-adapter/charts/groupedBarPlot.d.ts +0 -53
  150. package/dist/packages/canvas-adapter/charts/groupedBarPlot.js +0 -1
  151. package/dist/packages/canvas-adapter/charts/histogram.d.ts +0 -61
  152. package/dist/packages/canvas-adapter/charts/histogram.js +0 -1
  153. package/dist/packages/canvas-adapter/charts/scatter.d.ts +0 -80
  154. package/dist/packages/canvas-adapter/charts/scatter.js +0 -1
  155. package/dist/packages/canvas-adapter/charts/testPassRate.d.ts +0 -27
  156. package/dist/packages/canvas-adapter/charts/testPassRate.js +0 -1
  157. package/dist/packages/canvas-adapter/charts/trend.d.ts +0 -50
  158. package/dist/packages/canvas-adapter/charts/trend.js +0 -1
@@ -1,3 +1,3 @@
1
- export declare const WMAP_VERSION = "0.36.0";
2
- export declare const WMAP_BUILD_TIME = "2026-10-13T15:03:19.319Z";
1
+ export declare const WMAP_VERSION = "0.37.0";
2
+ export declare const WMAP_BUILD_TIME = "2026-10-20T13:45:09.045Z";
3
3
  //# sourceMappingURL=version.d.ts.map
@@ -1 +1 @@
1
- export const WMAP_VERSION="0.36.0",WMAP_BUILD_TIME="2026-10-13T15:03:19.319Z";
1
+ export const WMAP_VERSION="0.37.0",WMAP_BUILD_TIME="2026-10-20T13:45:09.045Z";
@@ -14,6 +14,17 @@ export interface ClassifyOptions {
14
14
  * the radius, a point on a boundary in the outer ring. The one ring rule; the edge ring is `ringCount`.
15
15
  */
16
16
  export declare function ringOf(dx: number, dy: number, radius: number, ringCount: number): number;
17
+ /**
18
+ * A die's offset from the wafer centre, in the wafer's own units, from its physical position (which follows the
19
+ * wafer's orientation, not the view's rotation). The one source of every radial and angular rule: ring, quadrant and
20
+ * radial position all read it.
21
+ */
22
+ export declare function centreOffset(die: PositionedDie, wafer: Wafer): {
23
+ dx: number;
24
+ dy: number;
25
+ };
26
+ /** A die's distance from the wafer centre as a share of the wafer radius: 0 at the centre, 1 at the edge. */
27
+ export declare function radialPosition(die: PositionedDie, wafer: Wafer): number;
17
28
  /**
18
29
  * Classify a die by its radial ring (1 = innermost) and physical wafer quadrant.
19
30
  *
@@ -1 +1 @@
1
- import{requireRingCount as h}from"./ringCount.js";export function ringOf(t,n,e,r){const a=Math.sqrt(t*t+n*n)/e;return Math.min(r,Math.max(1,Math.floor(a*r)+1))}const u=["NE","NW","SW","SE"];export function classifyDie(t,n,e){const r=Math.max(1,h(e,"classifyDie")),a=t.physX-n.center.x,o=t.physY-n.center.y,i=ringOf(a,o,n.radius,r),c=(Math.atan2(o,a)+2*Math.PI)%(2*Math.PI),s=u[Math.min(3,Math.floor(c/(Math.PI/2)))];return{ring:i,quadrant:s}}export function getRingLabel(t,n){return n===1?"Full Wafer":t===1?"Ring 1 (core)":t===n?`Ring ${t} (edge)`:`Ring ${t}`}
1
+ import{requireRingCount as u}from"./ringCount.js";export function ringOf(t,n,e,r){const o=Math.sqrt(t*t+n*n)/e;return Math.min(r,Math.max(1,Math.floor(o*r)+1))}export function centreOffset(t,n){return{dx:t.physX-n.center.x,dy:t.physY-n.center.y}}export function radialPosition(t,n){const{dx:e,dy:r}=centreOffset(t,n);return Math.sqrt(e*e+r*r)/n.radius}const f=["NE","NW","SW","SE"];export function classifyDie(t,n,e){const r=Math.max(1,u(e,"classifyDie")),{dx:o,dy:a}=centreOffset(t,n),i=ringOf(o,a,n.radius,r),s=(Math.atan2(a,o)+2*Math.PI)%(2*Math.PI),c=f[Math.min(3,Math.floor(s/(Math.PI/2)))];return{ring:i,quadrant:c}}export function getRingLabel(t,n){return n===1?"Full Wafer":t===1?"Ring 1 (core)":t===n?`Ring ${t} (edge)`:`Ring ${t}`}
@@ -45,6 +45,8 @@ export interface Die {
45
45
  insideWafer?: boolean;
46
46
  partial?: boolean;
47
47
  edgeExcluded?: boolean;
48
+ /** True on a die the page filter drops: a map draws it dimmed and no count, yield or statistic includes it. */
49
+ filteredOut?: boolean;
48
50
  probeIndex?: number;
49
51
  /** Number of times this die position appeared in the input results. Only set when > 1. */
50
52
  retestCount?: number;
@@ -1 +1 @@
1
- export function hasPosition(t){return t.x!=null&&t.y!=null}export function isPositionedDie(t){return t.x!=null&&t.y!=null}export function getDieKey(t){return hasPosition(t)?`${t.x},${t.y}`:`id:${t.id}`}export function gridKey(t,e){return t*4294967296+e}export function positionKey(t){const{x:e,y:n}=t;return Number.isInteger(e)&&Number.isInteger(n)&&Math.abs(e)<=32767&&Math.abs(n)<=32767?gridKey(e,n):getDieKey(t)}export function isYieldEligibleDie(t,e={}){return!(t.partial||!e.includeEdgeExcluded&&t.edgeExcluded)}export function diePassStatus(t,e){const n=t.hbin??t.sbin;return n===void 0?void 0:e.has(n)}export function generateDies(t,e){const{width:n,height:o,offset:s={x:0,y:0}}=e,u=e.gridSize??Math.ceil(t.radius/Math.min(n,o))+1,c=[];for(let r=-u;r<=u;r++)for(let i=-u;i<=u;i++){const l=t.center.x+i*n+s.x,x=t.center.y+r*o+s.y;c.push({id:`${i}_${r}`,x:i,y:r,physX:l,physY:x,width:n,height:o})}return c}
1
+ export function hasPosition(t){return t.x!=null&&t.y!=null}export function isPositionedDie(t){return t.x!=null&&t.y!=null}export function getDieKey(t){return hasPosition(t)?`${t.x},${t.y}`:`id:${t.id}`}export function gridKey(t,e){return t*4294967296+e}export function positionKey(t){const{x:e,y:n}=t;return Number.isInteger(e)&&Number.isInteger(n)&&Math.abs(e)<=32767&&Math.abs(n)<=32767?gridKey(e,n):getDieKey(t)}export function isYieldEligibleDie(t,e={}){return!(t.partial||t.filteredOut||!e.includeEdgeExcluded&&t.edgeExcluded)}export function diePassStatus(t,e){const n=t.hbin??t.sbin;return n===void 0?void 0:e.has(n)}export function generateDies(t,e){const{width:n,height:o,offset:s={x:0,y:0}}=e,u=e.gridSize??Math.ceil(t.radius/Math.min(n,o))+1,c=[];for(let r=-u;r<=u;r++)for(let i=-u;i<=u;i++){const l=t.center.x+i*n+s.x,x=t.center.y+r*o+s.y;c.push({id:`${i}_${r}`,x:i,y:r,physX:l,physY:x,width:n,height:o})}return c}
@@ -26,8 +26,8 @@ export interface WaferSpec {
26
26
  /**
27
27
  * What `diameter` is measured in. `'normalized'` (die pitches, when no physical
28
28
  * size is known) keeps the orientation mark's direction but gives it length 0:
29
- * the SEMI flat and notch sizes are millimetres, and a millimetre table applied
30
- * to a pitch count cut a third of a small wafer off. Default `'mm'`.
29
+ * the SEMI flat and notch sizes are millimetres, and applied to a pitch count
30
+ * they would cut deep into a small wafer. Default `'mm'`.
31
31
  */
32
32
  units?: 'mm' | 'normalized';
33
33
  center?: {
@@ -1 +1 @@
1
- import{requirePassBins as ge}from"../core/passBins.js";import{requireRingCount as ye}from"../core/ringCount.js";import{hasPosition as be}from"../core/dies.js";import{dieValueEntries as xe,dieVerdictEntries as Me,excludedBy as Se,excludedValue as ve,recordedVerdict as Be,testsPresent as wt}from"../core/dieTable.js";import{limitSetName as $e}from"./valueFilter.js";import{getReticleCell as ke}from"../core/reticle.js";import{metadataCategoricalValue as Ie,metadataDisplayValue as Te}from"../core/metadata.js";import{affineRotation as xt,affineMirror as qt,affineCompose as ot,affinePoint as Y,affineVector as De,affineSwapsAxes as Ve}from"../core/transforms.js";import{contrastTextColor as Q,SPEC_PASS_FILL as Mt,SPEC_FAIL_LOW as Ce,SPEC_FAIL_HIGH as St}from"./colorMap.js";import{resolveValueColorFn as Fe}from"./colorSchemes.js";import{resolveBinColors as Le,binColorsCover as Re}from"./binColors.js";import{NO_DATA_FILL as z}from"./colorMap.js";import{diePassStatus as Pe}from"../core/dies.js";import{compactView as Ne}from"./compactView.js";import{buildXYIndicator as Ee}from"./xyIndicator.js";import{getDieTestValue as L,getTestPassStatus as U,isParametricTest as vt}from"./buildWaferMap.js";import{classifySpec as rt}from"./spec.js";export{rt as classifySpec};import{fmt as lt,fmtColorbarAxis as Bt,fmtAggregationMethod as Kt}from"./fmt.js";import{metadataValueColor as Ae}from"./colorMap.js";import{asList as Wt,clamp01 as zt,compareNatural as He,escHtml as R}from"../core/utils.js";import{prettyKey as jt}from"../core/utils.js";import{testLabel as ct,markedTestLabel as J,derivedTestNote as Gt,isDerivedTest as _e,DERIVED_MARK as Oe,DERIVED_KEY as we}from"./testLabel.js";export function resolveTestNumber(t,e){return e?.length?{testNumber:(findTestDef(e,t)??e[0]).testNumber}:{testNumber:t}}export function collectMetadataValues(t,e){const n=new Set;for(const i of t){if(i.partial||i.edgeExcluded)continue;const s=ut(i,e);s!==void 0&&n.add(s)}return[...n].sort(He)}export function findTestDef(t,e){return t?.find(n=>n.testNumber===e)}export function getUniqueTestNumbers(t){return wt(t,"values")}const qe="#d3d6db",Xt="#e8e9ea",Ke="#aab0ba";function ut(t,e){return e?Ie(t.metadata?.[e]):void 0}function We(t,e,n){const{x:i,y:s}=t.center,a=xt(t.orientation,i,s),o=ot(qt(e?.x??!1,e?.y??!1,i,s),xt(t.orientation,i,s)),r=ot(qt(n?.flipX??!1,n?.flipY??!1,i,s),xt(n?.rotation??0,i,s));return{bakedToScreen:r,physicalToScreen:ot(r,a),gridToScreen:ot(r,o)}}function X(t,e=!1){return{points:[t],closed:e}}function ze(t,e){const{center:n,radius:i,notch:s}=t;let a=n.x+i*Math.cos(e),o=n.y+i*Math.sin(e);if(!s)return{x:a,y:o};const r=Math.sqrt(i**2-(s.length/2)**2),d=s.length/2,p=a-n.x,x=o-n.y;return s.type==="bottom"&&x<-r?(o=n.y-r,a=n.x+Math.max(-d,Math.min(d,p))):s.type==="top"&&x>r?(o=n.y+r,a=n.x+Math.max(-d,Math.min(d,p))):s.type==="left"&&p<-r?(a=n.x-r,o=n.y+Math.max(-d,Math.min(d,x))):s.type==="right"&&p>r&&(a=n.x+r,o=n.y+Math.max(-d,Math.min(d,x))),{x:a,y:o}}function Yt(t,e){return t.map(e).join(" / ")}function je(t,e=256){const n=Array.from({length:e},(i,s)=>t(s/(e-1)));return i=>n[Math.min(e-1,Math.max(0,Math.round(i*(e-1))))]}function Ge(t,e){const n=Math.max(1,Math.min(t.width,t.height)),i=t.width/Math.max(e.length,1);return Math.max(8,Math.min(16,Math.round(Math.min(n*.55,i*1.8))))}function Xe(t,e,n){if(e?.length){const a=e.flatMap(o=>{const r=o.testNumber;if(!vt(o)){const p=U(t,r,o);return p===void 0?[]:[{key:r,label:J(o,r),value:p?"Pass":"Fail"}]}const d=L(t,r);if(d===void 0){const p=ve(t,r);return p===void 0?[]:[{key:r,label:J(o,r),value:lt(p,o.unit,n),excludedBy:Se(t)}]}return[{key:r,label:J(o,r),value:lt(d,o.unit,n),recordedFail:Be(t,r)===!1}]});if(a.length)return a}const i=xe(t);if(i.length)return i.map(([a,o])=>({key:a,label:ct(void 0,a),value:lt(o,void 0,n)}));const s=Me(t);return s.length?s.map(([a,o])=>({key:a,label:ct(void 0,a),value:o?"Pass":"Fail"})):[]}export function buildHoverText(t,e,n={}){const{testDefs:i,hbinDefs:s,sbinDefs:a,fallbackFormat:o,aggrMethod:r,lotSize:d,activeTest:p,reticleConfig:x,metadataFields:$}=n,V=s?new Map(s.map(f=>[f.bin,f])):null,I=a?new Map(a.map(f=>[f.bin,f])):null,y=[R(`Die (${t.x}, ${t.y})`)];if(x&&be(t)){const f=ke(t,x);y.push(R(`Reticle (${f.column}, ${f.row})`))}if(e==="stackedValues"){const f=L(t,0);if(f!==void 0){const u=i?.[0],m=u?J(u,u.testNumber):"Value",S=r?` (${r})`:"";y.push(R(`${m}${S}: ${lt(f,u?.unit,o)}`));const h=Gt(u);h&&y.push(`<i>${R(h)}</i>`)}}else if(e==="stackedBins"||e==="stackedSoftBins"){const f=L(t,0),u=e==="stackedSoftBins"?t.sbin:t.hbin;if(f!==void 0){const m=e==="stackedSoftBins"?I:V,S=u!==void 0?m?.get(u)?.name?`${u} \xB7 ${m.get(u).name}`:`Bin ${u}`:"Bin";let h;if(r==="percent")h=`${f.toFixed(0)}%`;else{const D=d?` (${(f/d*100).toFixed(0)}% of stacked wafers)`:"";h=`${f}${D}`}const b=r?` [${Kt(r)}]`:"";y.push(R(`${S}: ${h}${b}`))}}else{const f=Xe(t,i,o);if(e==="value"&&f.length){const{testNumber:u}=resolveTestNumber(p??0,i),m=findTestDef(i,u),S=L(t,u);let h=f.findIndex(A=>A.key===u);h<0&&(h=0);const b=f[h];let D=`<b>${R(`${b.label}: ${b.value}`)}${b.recordedFail?" <i>(recorded fail)</i>":""}</b>`;if(b.key===u&&m){const A=rt(S,m);(A==="failLow"||A==="failHigh")&&(D+=" <i>(outside test limits)</i>")}b.excludedBy&&(D+=` <i>(outside ${$e(b.excludedBy)}, excluded)</i>`),y.push(D);const E=Gt(findTestDef(i,b.key));E&&y.push(`<i>${R(E)}</i>`);const g=f.length-1;g>0&&y.push(`<i>+${g} more test${g===1?"":"s"}</i>`)}else if(f.length){const u=f.length;y.push(`<i>${u} test result${u===1?"":"s"} recorded</i>`)}if(t.hbin!==void 0||t.sbin!==void 0){const u=[];if(t.hbin!==void 0){const m=V?.get(t.hbin)?.name,S=m?`${t.hbin} \xB7 ${m}`:String(t.hbin);u.push(`HBin: ${S}`)}if(t.sbin!==void 0){const m=I?.get(t.sbin)?.name,S=m?`${t.sbin} \xB7 ${m}`:String(t.sbin);u.push(`SBin: ${S}`)}y.push(u.map(R).join(" &nbsp;\xB7&nbsp; "))}}t.retestCount!==void 0&&y.push(R(`Retests: ${t.retestCount}`)),t.siteNum!==void 0&&y.push(R(`Site: ${t.siteNum}`)),t.partId!==void 0&&y.push(R(`Part ID: ${t.partId}`)),t.partial&&y.push("<i>partial die</i>"),t.probeIndex!==void 0&&y.push(R(`Probe: #${t.probeIndex}`));const B={...t.metadata??{}};for(const[f,u]of Object.entries(B)){const m=Te(u);if(m===void 0)continue;const S=$?.find(h=>h.key===f)?.label??jt(f);y.push(R(`${S}: ${m}`))}return y.join("<br>")}function $t(t){return t?.name?J(t,t.testNumber):void 0}function kt(t){return _e(t)?{note:`${Oe} ${we}`}:{}}export function buildMapTitle(t,e="engineering",n){const i=t.isLotStack&&t.lotSize!==void 0?`stacked (${t.lotSize} ${t.lotSize===1?"wafer":"wafers"})`:"stacked",s=a=>{const o=n?.length===1?n[0]:void 0;return o===void 0?`${a} Bin`:o.name?`${a} Bin ${o.bin} \xB7 ${o.name}`:`${a} Bin ${o.bin}`};switch(t.plotMode){case"hardBin":return{primary:"Hard Bin",secondary:""};case"softBin":return{primary:"Soft Bin",secondary:""};case"stackedBins":return{primary:s("Hard"),secondary:i};case"stackedSoftBins":return{primary:s("Soft"),secondary:i};case"metadata":{const a=t.metadataFields?.find(r=>r.key===t.activeMetadataKey),o=t.activeMetadataKey?jt(t.activeMetadataKey):"Metadata";return{primary:a?.label??o,secondary:""}}case"stackedValues":{const a=t.testDefs?.[0],o=t.valueRange[1]||t.valueRange[0]||0,{axisLabel:r}=Bt(o,$t(a),a?.unit,e),d=r||"Value",p=t.aggrMethod?` \xB7 ${Kt(t.aggrMethod)}`:"";return{primary:`${d}${p}`,secondary:i,...kt(a)}}default:{const a=findTestDef(t.testDefs,t.activeTest),o=t.valueRange[1]||t.valueRange[0]||0,{axisLabel:r}=Bt(o,$t(a),a?.unit,e),d=r||$t(a);if(t.passFailDisplay!=="off"){const p=a?.testNumber??t.activeTest,x=d?`${d} \xB7 #${p}`:ct(void 0,p),$=t.passFailDisplay==="spec"?"Limit pass/fail":a!==void 0&&!vt(a)?"Functional pass/fail":"Tester pass/fail";return{primary:x,secondary:$,...kt(a)}}return{primary:d??ct(void 0,t.activeTest),secondary:"",...kt(a)}}}}export function generateTextOverlay(t,e,n){const{plotMode:i,colorFns:s,normalize:a,activeTest:o,valueRange:r,testDefs:d,fallbackFormat:p,passFailDisplay:x="off",activeMetadataKey:$,metadataColorMap:V,allIntegerValues:I}=n,y=findTestDef(d,o),{tickFmt:B}=Bt(r[1],y?.name,y?.unit,p),f=I?m=>String(Math.round(m)):B,{testNumber:u}=resolveTestNumber(o,d);return t.flatMap((m,S)=>{let h="",b="#111111";if(i==="value"&&x==="test"){const g=U(m,u,y);if(g===void 0)return[];h=g?"P":"F",b=Q(g?Mt:St)}else if(i==="value"){const g=L(m,u);if(g===void 0)return[];h=Yt([g],f),b=Q(s.forValue(a(g)))}else if(i==="hardBin"||i==="softBin"){const g=i==="softBin"?m.sbin:m.hbin;if(g===void 0)return[];h=String(g),b=Q(s.forBin(g))}else if(i==="metadata"){const g=ut(m,$);if(g===void 0)return[];h=g,b=Q(V?.get(h)??z)}else{const g=L(m,0);if(g===void 0)return[];h=Yt([g],f),b=Q(s.forValue(a(g)))}const D=e?e[S*2]:m.physX,E=e?e[S*2+1]:m.physY;return[{x:D,y:E,text:h,fontSize:Ge(m,h),color:b,align:"center"}]})}function Qt(t){return t==="top"?Math.PI/2:t==="bottom"?-Math.PI/2:t==="left"?Math.PI:0}function Ye(t,e,n=720){const{center:i,radius:s,notch:a}=t,o=B=>Y(e,B.x,B.y);if(!(a!==void 0&&a.length>0&&t.diameter>150)){const B=[];for(let f=0;f<=n;f++){const u=2*Math.PI*f/n;B.push(o(ze(t,u)))}return[{kind:"wafer-boundary",...X(B,!0),lineColor:"#888888",lineWidth:1}]}const d=1.25,p=a.length,x=Qt(a.type),$=Math.atan2(p,s),V=s-d,I=[];let y=!1;for(let B=0;B<=n;B++){const f=2*Math.PI*B/n;let u=f-x;for(;u>Math.PI;)u-=2*Math.PI;for(;u<-Math.PI;)u+=2*Math.PI;if(Math.abs(u)<=$){if(!y){y=!0;const m={x:i.x+s*Math.cos(x-$),y:i.y+s*Math.sin(x-$)},S={x:i.x+V*Math.cos(x),y:i.y+V*Math.sin(x)},h={x:i.x+s*Math.cos(x+$),y:i.y+s*Math.sin(x+$)};I.push(o(m),o(S),o(h))}continue}I.push(o({x:i.x+s*Math.cos(f),y:i.y+s*Math.sin(f)}))}return[{kind:"wafer-boundary",...X(I,!0),lineColor:"#888888",lineWidth:1}]}function Qe(t,e,n,i=360){const s=[],a=Math.max(1,Math.floor(n));for(let o=1;o<a;o++){const r=t.radius*o/a,d=[];for(let p=0;p<=i;p++){const x=2*Math.PI*p/i,$={x:t.center.x+r*Math.cos(x),y:t.center.y+r*Math.sin(x)};d.push(Y(e,$.x,$.y))}s.push({kind:"ring-boundary",...X(d,!0),lineColor:"rgba(255,255,255,0.7)",lineWidth:1.5})}return s}function Ue(t,e,n,i){const{x:s,y:a}=t.center,o=t.radius,r=(f,u)=>Y(e,f,u),d=n-s,p=Math.sqrt(Math.max(0,o*o-d*d)),x=r(n,a-p),$=r(n,a+p),V=i-a,I=Math.sqrt(Math.max(0,o*o-V*V)),y=r(s-I,i),B=r(s+I,i);return[{kind:"quadrant-boundary",...X([x,$]),lineColor:"rgba(255,255,255,0.7)",lineWidth:1.5},{kind:"quadrant-boundary",...X([y,B]),lineColor:"rgba(255,255,255,0.7)",lineWidth:1.5}]}function Je(t,e){return t.map(n=>{const i=n.width/2,s=n.height/2;return{kind:"reticle",points:[[[n.x-i,n.y-s],[n.x+i,n.y-s],[n.x+i,n.y+s],[n.x-i,n.y+s]].map(([o,r])=>Y(e,o,r))],closed:!0,lineColor:"rgba(255,255,255,0.7)",lineWidth:1.5,fill:"rgba(0,0,0,0)"}})}function Ze(t){const e=t.filter(n=>n.probeIndex!==void 0).sort((n,i)=>(n.probeIndex??0)-(i.probeIndex??0));return e.length?[{kind:"probe-path",...X(e.map(n=>({x:n.physX,y:n.physY}))),lineColor:"rgba(220,80,0,0.55)",lineWidth:1}]:[]}function tn(t,e,n,i,s,a,o,r,d,p,x,$,V,I,y="off",B,f,u){const m=e.width-o,S=e.height-o,h=a?S:m,b=a?m:S,D=M=>s==="softBin"?M.sbin:M.hbin,E=M=>ut(M,B);if(e.partial){t.push({x:n,y:i,width:h,height:b,fill:qe,type:"stacked",metadata:e.metadata});return}if(e.edgeExcluded){t.push({x:n,y:i,width:h,height:b,fill:Ke,type:"stacked",metadata:e.metadata});return}if(d!==void 0&&(s==="hardBin"||s==="softBin")&&!d.has(D(e))){t.push({x:n,y:i,width:h,height:b,fill:Xt,type:"hardBin",metadata:e.metadata});return}if(u!==void 0&&s==="metadata"&&!u.has(E(e))){t.push({x:n,y:i,width:h,height:b,fill:Xt,type:"metadata",metadata:e.metadata});return}if(s==="value"){if(y==="test"){const q=U(e,x,I),ft=q===void 0?z:q?Mt:St;t.push({x:n,y:i,width:h,height:b,fill:ft,type:"value",metadata:e.metadata});return}const M=L(e,x),P=rt(M,I);let w,Z;M===void 0?w=z:y==="spec"?w=P==="failLow"?Ce:P==="failHigh"?St:Mt:(w=r.forValue(p(M)),(P==="failLow"||P==="failHigh")&&(Z=P)),t.push({x:n,y:i,width:h,height:b,fill:w,type:"value",specMark:Z,metadata:e.metadata});return}if(s==="hardBin"||s==="softBin"){const M=D(e),P=M!=null?r.forBin(M):z,w=M!=null&&Pe(e,V)===!1?!0:void 0;t.push({x:n,y:i,width:h,height:b,fill:P,type:s,binFail:w,metadata:e.metadata});return}if(s==="metadata"){const M=E(e),P=M!==void 0?f?.get(M)??z:z;t.push({x:n,y:i,width:h,height:b,fill:P,type:"metadata",metadata:e.metadata});return}const g=L(e,0),A=g!==void 0?r.forValue(p(g)):z;t.push({x:n,y:i,width:h,height:b,fill:A,type:"value",metadata:e.metadata})}function en(t,e,n){const i=t.radius;return Ee(e,i*.15,(s,a)=>({x:t.center.x+s*i*.9,y:t.center.y+a*i*.9}),n).overlays}export function buildView(t,e,n={},i){const s=n.reticles??[],{plotMode:a="value",showDieLabels:o=!1,showReticle:r=!1,showProbePath:d=!1,ringCount:p,showRingBoundaries:x=!1,showQuadrantBoundaries:$=!1,showXYIndicator:V=!1,binColorScheme:I="default",valueColorScheme:y="default",reverseValueScheme:B=!1,useDefinedBinColors:f=!0,binColors:u,passBins:m,highlightBin:S,highlightMetadataValue:h,interactiveTransform:b,valueRange:D,metadataValueOrder:E,testDefs:g,activeTest:A=0,activeMetadataKey:M,fallbackFormat:P="engineering",aggregationMethod:w,lotSize:Z,dataAxisFlip:q,isLotStack:ft=!1,logScale:Ut,colorbarRangeMode:Jt="spec",passFailDisplay:Zt}=n,It=Zt??"off",dt=i?.hbinDefs,ht=i?.sbinDefs,Tt=i?.metadataFields,te=Tt?.find(l=>l.key===M),ee={x:(q?.x??!1)!==(b?.flipX??!1),y:(q?.y??!1)!==(b?.flipY??!1)},ne=dt?new Map(dt.map(l=>[l.bin,l])):null,ae=ht?new Map(ht.map(l=>[l.bin,l])):null,ie=a==="softBin"?ae:ne,Dt=ge({passBins:m},"buildView"),se=new Set(Dt),mt=u&&Re(u,e)?u:Le(e,{passBins:Dt,binColorScheme:I,hbinDefs:dt,sbinDefs:ht,useDefinedBinColors:f}),oe=a==="softBin"?mt.soft:mt.hard,Vt={forValue:je(Fe(y,B)),forBin:l=>oe.get(l)??z};let{testNumber:H}=resolveTestNumber(A,g);if(!g?.length&&a==="value"){const l=wt(e,"values");!l.includes(H)&&l.length&&(H=l[0])}let tt;if(Array.isArray(D))tt=D;else if(D){const{testNumber:l}=resolveTestNumber(D.test,g);tt=l===H?D.range:void 0}const T=findTestDef(g,H),Ct=a==="value"&&T!==void 0&&!vt(T),re=T!==void 0&&(T.limitLow!==void 0||T.limitHigh!==void 0);let O="off";a==="value"&&(Ct?O="test":It==="spec"&&re?O="spec":It==="test"&&e.some(l=>U(l,H,T)!==void 0)&&(O="test"));const Ft=O==="spec"?"spec":Jt,pt=a==="stackedValues"||a==="stackedBins"||a==="stackedSoftBins";let N,_,et=!1;if(tt){[N,_]=tt;let l=!0,c=!1;for(const v of e){const F=pt?L(v,0):L(v,H);if(F!==void 0&&(c=!0,!Number.isInteger(F))){l=!1;break}}et=c&&l}else{const l=!pt&&a==="value"&&Ft==="spec"&&T&&(T.limitLow!==void 0||T.limitHigh!==void 0);let c=1/0,v=-1/0,F=!0;for(const k of e){const W=pt?L(k,0):L(k,H);W!==void 0&&(W<c&&(c=W),W>v&&(v=W),Number.isInteger(W)||(F=!1))}isFinite(c)||(F=!1),et=F,l?(N=T.limitLow!==void 0?T.limitLow:isFinite(c)?c:0,_=T.limitHigh!==void 0?T.limitHigh:isFinite(v)?v:1):(N=isFinite(c)?c:0,_=isFinite(v)?v:1)}N===_&&(_=N+1);const Lt=Ct?!1:Ut??T?.logScale??!1,Rt=Lt&&N>0&&_>0,le=Rt;let nt;if(Rt){const l=Math.log10(N),c=Math.log10(_)-l;nt=v=>v<=0?0:zt((Math.log10(v)-l)/c)}else nt=l=>zt((l-N)/(_-N));const C=We(t,q,b);let Pt=null;if(t.notch){const l=Qt(t.notch.type),c=De(C.physicalToScreen,Math.cos(l)*t.radius,Math.sin(l)*t.radius),v=Math.hypot(c.x,c.y);v>0&&(Pt={x:c.x/v,y:c.y/v})}let j=1/0;for(let l=0;l<e.length;l++){const c=e[l];c.width<j&&(j=c.width),c.height<j&&(j=c.height)}const Nt=1,Et=j!==1/0?Math.min(Nt,j*.12):Nt,At=[],gt=[],ce=C.bakedToScreen.a===1&&C.bakedToScreen.b===0&&C.bakedToScreen.c===0&&C.bakedToScreen.d===1&&C.bakedToScreen.e===0&&C.bakedToScreen.f===0;let K=null;if(!ce){K=new Float64Array(e.length*2);for(let l=0;l<e.length;l++){const c=Y(C.bakedToScreen,e[l].physX,e[l].physY);K[l*2]=c.x,K[l*2+1]=c.y}}const ue=Ve(C.gridToScreen),fe=a==="hardBin"||a==="softBin"||a==="stackedBins"||a==="stackedSoftBins",de=a==="softBin"||a==="stackedSoftBins";let at=fe?new Map:void 0;const yt=a==="value"&&O==="spec"?{pass:0,failHigh:0,failLow:0}:void 0,bt=a==="value"&&O==="test"?{pass:0,fail:0}:void 0,Ht=a==="metadata";let it=Ht?new Map:void 0,st=null;if(Ht&&M){const l=collectMetadataValues(e,M),c=E?.key===M?E.values:void 0,v=c?[...c,...l.filter(F=>!c.includes(F))]:l;st=new Map(v.map((F,k)=>[F,te?.values?.find(W=>W.value===F)?.color??Ae(k)]))}const he=S===void 0?void 0:new Set(Wt(S)),me=h===void 0?void 0:new Set(Wt(h));for(let l=0;l<e.length;l++){const c=e[l],v=K?K[l*2]:c.physX,F=K?K[l*2+1]:c.physY;if(gt.push({x:v,y:F}),at&&!c.partial&&!c.edgeExcluded){const k=de?c.sbin:c.hbin;k!=null&&at.set(k,(at.get(k)??0)+1)}if(yt&&!c.partial&&!c.edgeExcluded){const k=rt(L(c,H),T);k&&yt[k]++}if(bt&&!c.partial&&!c.edgeExcluded){const k=U(c,H,T);k!==void 0&&bt[k?"pass":"fail"]++}if(it&&!c.partial&&!c.edgeExcluded){const k=ut(c,M);k!==void 0&&it.set(k,(it.get(k)??0)+1)}tn(At,c,v,F,a,ue,Et,Vt,he,nt,H,ie,se,T,O,M,st,me)}const _t=o?generateTextOverlay(e,K,{plotMode:a,colorFns:Vt,normalize:nt,activeTest:A,valueRange:[N,_],testDefs:g,fallbackFormat:P,passFailDisplay:O,activeMetadataKey:M,metadataColorMap:st,allIntegerValues:et}):[],G=Ye(t,C.physicalToScreen);x&&G.push(...Qe(t,C.physicalToScreen,ye({ringCount:p},"buildView"))),$&&G.push(...Ue(t,C.physicalToScreen,t.center.x,t.center.y)),r&&G.push(...Je(s,C.gridToScreen)),d&&G.push(...Ze(e)),V&&G.push(...en(t,C.gridToScreen,_t));const pe=gt.length>0?{minX:t.center.x-t.radius,maxX:t.center.x+t.radius,minY:t.center.y-t.radius,maxY:t.center.y+t.radius}:null,Ot={rectangles:At,dieGap:Et,hoverPoints:gt,texts:_t,overlays:G,plotMode:a,binColorScheme:I,valueColorScheme:y,reverseValueScheme:B,binColors:mt,metadata:t.metadata??null,dies:e,valueRange:[N,_],allIntegerValues:et,testDefs:g,activeTest:A,logScale:le,logScaleRequested:Lt,aggrMethod:w,lotSize:Z,axisFlip:ee,dataAxisFlip:{x:q?.x??!1,y:q?.y??!1},gridToScreen:C.gridToScreen,rotation:((t.orientation+(b?.rotation??0))%360+360)%360,hasReticle:s.length>0,isLotStack:ft,passFailDisplay:O,colorbarRangeMode:Ft,waferCenter:t.center,waferRadius:t.radius,notchDir:Pt,binCounts:at,metadataCounts:it,metadataColorMap:st,activeMetadataKey:M,metadataFields:Tt,specCounts:yt,passFailCounts:bt,dieBounds:pe};return n.compact?Ne(Ot,n.compact,{showXYIndicator:V}):Ot}export{getDieKey}from"../core/dies.js";
1
+ import{requirePassBins as ye}from"../core/passBins.js";import{requireRingCount as be}from"../core/ringCount.js";import{hasPosition as xe}from"../core/dies.js";import{dieValueEntries as Me,dieVerdictEntries as Se,excludedBy as ve,excludedValue as Be,recordedVerdict as $e,testsPresent as qt}from"../core/dieTable.js";import{limitSetName as ke}from"./valueFilter.js";import{getReticleCell as Ie}from"../core/reticle.js";import{metadataCategoricalValue as Te,metadataDisplayValue as De}from"../core/metadata.js";import{affineRotation as Mt,affineMirror as Kt,affineCompose as rt,affinePoint as U,affineVector as Ve,affineSwapsAxes as Ce}from"../core/transforms.js";import{contrastTextColor as X,SPEC_PASS_FILL as St,SPEC_FAIL_LOW as Fe,SPEC_FAIL_HIGH as vt}from"./colorMap.js";import{resolveValueColorFn as Le}from"./colorSchemes.js";import{resolveBinColors as Re,binColorsCover as Pe}from"./binColors.js";import{NO_DATA_FILL as z}from"./colorMap.js";import{diePassStatus as Ne,isYieldEligibleDie as Q}from"../core/dies.js";import{compactView as Ee}from"./compactView.js";import{buildXYIndicator as Ae}from"./xyIndicator.js";import{getDieTestValue as L,getTestPassStatus as J,isParametricTest as Bt}from"./buildWaferMap.js";import{classifySpec as lt}from"./spec.js";export{lt as classifySpec};import{fmt as ct,fmtColorbarAxis as $t,fmtAggregationMethod as Wt}from"./fmt.js";import{metadataValueColor as _e}from"./colorMap.js";import{asList as zt,clamp01 as jt,compareNatural as Oe,escHtml as R}from"../core/utils.js";import{prettyKey as Gt}from"../core/utils.js";import{testLabel as ut,markedTestLabel as Z,derivedTestNote as Yt,isDerivedTest as He,DERIVED_MARK as we,DERIVED_KEY as qe}from"./testLabel.js";export function resolveTestNumber(t,e){return e?.length?{testNumber:(findTestDef(e,t)??e[0]).testNumber}:{testNumber:t}}export function collectMetadataValues(t,e){const n=new Set;for(const i of t){if(!Q(i))continue;const s=ft(i,e);s!==void 0&&n.add(s)}return[...n].sort(Oe)}export function findTestDef(t,e){return t?.find(n=>n.testNumber===e)}export function getUniqueTestNumbers(t){return qt(t,"values")}const Ke="#d3d6db",Ut="#e8e9ea",We="#d9dcdf",ze="#aab0ba";function ft(t,e){return e?Te(t.metadata?.[e]):void 0}function je(t,e,n){const{x:i,y:s}=t.center,a=Mt(t.orientation,i,s),o=rt(Kt(e?.x??!1,e?.y??!1,i,s),Mt(t.orientation,i,s)),r=rt(Kt(n?.flipX??!1,n?.flipY??!1,i,s),Mt(n?.rotation??0,i,s));return{bakedToScreen:r,physicalToScreen:rt(r,a),gridToScreen:rt(r,o)}}function Y(t,e=!1){return{points:[t],closed:e}}function Ge(t,e){const{center:n,radius:i,notch:s}=t;let a=n.x+i*Math.cos(e),o=n.y+i*Math.sin(e);if(!s)return{x:a,y:o};const r=Math.sqrt(i**2-(s.length/2)**2),h=s.length/2,p=a-n.x,x=o-n.y;return s.type==="bottom"&&x<-r?(o=n.y-r,a=n.x+Math.max(-h,Math.min(h,p))):s.type==="top"&&x>r?(o=n.y+r,a=n.x+Math.max(-h,Math.min(h,p))):s.type==="left"&&p<-r?(a=n.x-r,o=n.y+Math.max(-h,Math.min(h,x))):s.type==="right"&&p>r&&(a=n.x+r,o=n.y+Math.max(-h,Math.min(h,x))),{x:a,y:o}}function Xt(t,e){return t.map(e).join(" / ")}function Ye(t,e=256){const n=Array.from({length:e},(i,s)=>t(s/(e-1)));return i=>n[Math.min(e-1,Math.max(0,Math.round(i*(e-1))))]}function Ue(t,e){const n=Math.max(1,Math.min(t.width,t.height)),i=t.width/Math.max(e.length,1);return Math.max(8,Math.min(16,Math.round(Math.min(n*.55,i*1.8))))}function Xe(t,e,n){if(e?.length){const a=e.flatMap(o=>{const r=o.testNumber;if(!Bt(o)){const p=J(t,r,o);return p===void 0?[]:[{key:r,label:Z(o,r),value:p?"Pass":"Fail"}]}const h=L(t,r);if(h===void 0){const p=Be(t,r);return p===void 0?[]:[{key:r,label:Z(o,r),value:ct(p,o.unit,n),excludedBy:ve(t)}]}return[{key:r,label:Z(o,r),value:ct(h,o.unit,n),recordedFail:$e(t,r)===!1}]});if(a.length)return a}const i=Me(t);if(i.length)return i.map(([a,o])=>({key:a,label:ut(void 0,a),value:ct(o,void 0,n)}));const s=Se(t);return s.length?s.map(([a,o])=>({key:a,label:ut(void 0,a),value:o?"Pass":"Fail"})):[]}export function buildHoverText(t,e,n={}){const{testDefs:i,hbinDefs:s,sbinDefs:a,fallbackFormat:o,aggrMethod:r,lotSize:h,activeTest:p,reticleConfig:x,metadataFields:$}=n,V=s?new Map(s.map(u=>[u.bin,u])):null,I=a?new Map(a.map(u=>[u.bin,u])):null,b=[R(`Die (${t.x}, ${t.y})`)];if(x&&xe(t)){const u=Ie(t,x);b.push(R(`Reticle (${u.column}, ${u.row})`))}if(e==="stackedValues"){const u=L(t,0);if(u!==void 0){const c=i?.[0],m=c?Z(c,c.testNumber):"Value",S=r?` (${r})`:"";b.push(R(`${m}${S}: ${ct(u,c?.unit,o)}`));const d=Yt(c);d&&b.push(`<i>${R(d)}</i>`)}}else if(e==="stackedBins"||e==="stackedSoftBins"){const u=L(t,0),c=e==="stackedSoftBins"?t.sbin:t.hbin;if(u!==void 0){const m=e==="stackedSoftBins"?I:V,S=c!==void 0?m?.get(c)?.name?`${c} \xB7 ${m.get(c).name}`:`Bin ${c}`:"Bin";let d;if(r==="percent")d=`${u.toFixed(0)}%`;else{const D=h?` (${(u/h*100).toFixed(0)}% of stacked wafers)`:"";d=`${u}${D}`}const g=r?` [${Wt(r)}]`:"";b.push(R(`${S}: ${d}${g}`))}}else{const u=Xe(t,i,o);if(e==="value"&&u.length){const{testNumber:c}=resolveTestNumber(p??0,i),m=findTestDef(i,c),S=L(t,c);let d=u.findIndex(A=>A.key===c);d<0&&(d=0);const g=u[d];let D=`<b>${R(`${g.label}: ${g.value}`)}${g.recordedFail?" <i>(recorded fail)</i>":""}</b>`;if(g.key===c&&m){const A=lt(S,m);(A==="failLow"||A==="failHigh")&&(D+=" <i>(outside test limits)</i>")}g.excludedBy&&(D+=` <i>(outside ${ke(g.excludedBy)}, excluded)</i>`),b.push(D);const E=Yt(findTestDef(i,g.key));E&&b.push(`<i>${R(E)}</i>`);const y=u.length-1;y>0&&b.push(`<i>+${y} more test${y===1?"":"s"}</i>`)}else if(u.length){const c=u.length;b.push(`<i>${c} test result${c===1?"":"s"} recorded</i>`)}if(t.hbin!==void 0||t.sbin!==void 0){const c=[];if(t.hbin!==void 0){const m=V?.get(t.hbin)?.name,S=m?`${t.hbin} \xB7 ${m}`:String(t.hbin);c.push(`HBin: ${S}`)}if(t.sbin!==void 0){const m=I?.get(t.sbin)?.name,S=m?`${t.sbin} \xB7 ${m}`:String(t.sbin);c.push(`SBin: ${S}`)}b.push(c.map(R).join(" &nbsp;\xB7&nbsp; "))}}t.retestCount!==void 0&&b.push(R(`Retests: ${t.retestCount}`)),t.siteNum!==void 0&&b.push(R(`Site: ${t.siteNum}`)),t.partId!==void 0&&b.push(R(`Part ID: ${t.partId}`)),t.partial&&b.push("<i>partial die</i>"),t.probeIndex!==void 0&&b.push(R(`Probe: #${t.probeIndex}`));const B={...t.metadata??{}};for(const[u,c]of Object.entries(B)){const m=De(c);if(m===void 0)continue;const S=$?.find(d=>d.key===u)?.label??Gt(u);b.push(R(`${S}: ${m}`))}return b.join("<br>")}function kt(t){return t?.name?Z(t,t.testNumber):void 0}function It(t){return He(t)?{note:`${we} ${qe}`}:{}}export function buildMapTitle(t,e="engineering",n){const i=t.isLotStack&&t.lotSize!==void 0?`stacked (${t.lotSize} ${t.lotSize===1?"wafer":"wafers"})`:"stacked",s=a=>{const o=n?.length===1?n[0]:void 0;return o===void 0?`${a} Bin`:o.name?`${a} Bin ${o.bin} \xB7 ${o.name}`:`${a} Bin ${o.bin}`};switch(t.plotMode){case"hardBin":return{primary:"Hard Bin",secondary:""};case"softBin":return{primary:"Soft Bin",secondary:""};case"stackedBins":return{primary:s("Hard"),secondary:i};case"stackedSoftBins":return{primary:s("Soft"),secondary:i};case"metadata":{const a=t.metadataFields?.find(r=>r.key===t.activeMetadataKey),o=t.activeMetadataKey?Gt(t.activeMetadataKey):"Metadata";return{primary:a?.label??o,secondary:""}}case"stackedValues":{const a=t.testDefs?.[0],o=t.valueRange[1]||t.valueRange[0]||0,{axisLabel:r}=$t(o,kt(a),a?.unit,e),h=r||"Value",p=t.aggrMethod?` \xB7 ${Wt(t.aggrMethod)}`:"";return{primary:`${h}${p}`,secondary:i,...It(a)}}default:{const a=findTestDef(t.testDefs,t.activeTest),o=t.valueRange[1]||t.valueRange[0]||0,{axisLabel:r}=$t(o,kt(a),a?.unit,e),h=r||kt(a);if(t.passFailDisplay!=="off"){const p=a?.testNumber??t.activeTest,x=h?`${h} \xB7 #${p}`:ut(void 0,p),$=t.passFailDisplay==="spec"?"Limit pass/fail":a!==void 0&&!Bt(a)?"Functional pass/fail":"Tester pass/fail";return{primary:x,secondary:$,...It(a)}}return{primary:h??ut(void 0,t.activeTest),secondary:"",...It(a)}}}}export function generateTextOverlay(t,e,n){const{plotMode:i,colorFns:s,normalize:a,activeTest:o,valueRange:r,testDefs:h,fallbackFormat:p,passFailDisplay:x="off",activeMetadataKey:$,metadataColorMap:V,allIntegerValues:I}=n,b=findTestDef(h,o),{tickFmt:B}=$t(r[1],b?.name,b?.unit,p),u=I?m=>String(Math.round(m)):B,{testNumber:c}=resolveTestNumber(o,h);return t.flatMap((m,S)=>{let d="",g="#111111";if(i==="value"&&x==="test"){const y=J(m,c,b);if(y===void 0)return[];d=y?"P":"F",g=X(y?St:vt)}else if(i==="value"){const y=L(m,c);if(y===void 0)return[];d=Xt([y],u),g=X(s.forValue(a(y)))}else if(i==="hardBin"||i==="softBin"){const y=i==="softBin"?m.sbin:m.hbin;if(y===void 0)return[];d=String(y),g=X(s.forBin(y))}else if(i==="metadata"){const y=ft(m,$);if(y===void 0)return[];d=y,g=X(V?.get(d)??z)}else{const y=L(m,0);if(y===void 0)return[];d=Xt([y],u),g=X(s.forValue(a(y)))}const D=e?e[S*2]:m.physX,E=e?e[S*2+1]:m.physY;return[{x:D,y:E,text:d,fontSize:Ue(m,d),color:g,align:"center"}]})}function Qt(t){return t==="top"?Math.PI/2:t==="bottom"?-Math.PI/2:t==="left"?Math.PI:0}function Qe(t,e,n=720){const{center:i,radius:s,notch:a}=t,o=B=>U(e,B.x,B.y);if(!(a!==void 0&&a.length>0&&t.diameter>150)){const B=[];for(let u=0;u<=n;u++){const c=2*Math.PI*u/n;B.push(o(Ge(t,c)))}return[{kind:"wafer-boundary",...Y(B,!0),lineColor:"#888888",lineWidth:1}]}const h=1.25,p=a.length,x=Qt(a.type),$=Math.atan2(p,s),V=s-h,I=[];let b=!1;for(let B=0;B<=n;B++){const u=2*Math.PI*B/n;let c=u-x;for(;c>Math.PI;)c-=2*Math.PI;for(;c<-Math.PI;)c+=2*Math.PI;if(Math.abs(c)<=$){if(!b){b=!0;const m={x:i.x+s*Math.cos(x-$),y:i.y+s*Math.sin(x-$)},S={x:i.x+V*Math.cos(x),y:i.y+V*Math.sin(x)},d={x:i.x+s*Math.cos(x+$),y:i.y+s*Math.sin(x+$)};I.push(o(m),o(S),o(d))}continue}I.push(o({x:i.x+s*Math.cos(u),y:i.y+s*Math.sin(u)}))}return[{kind:"wafer-boundary",...Y(I,!0),lineColor:"#888888",lineWidth:1}]}function Je(t,e,n,i=360){const s=[],a=Math.max(1,Math.floor(n));for(let o=1;o<a;o++){const r=t.radius*o/a,h=[];for(let p=0;p<=i;p++){const x=2*Math.PI*p/i,$={x:t.center.x+r*Math.cos(x),y:t.center.y+r*Math.sin(x)};h.push(U(e,$.x,$.y))}s.push({kind:"ring-boundary",...Y(h,!0),lineColor:"rgba(255,255,255,0.7)",lineWidth:1.5})}return s}function Ze(t,e,n,i){const{x:s,y:a}=t.center,o=t.radius,r=(u,c)=>U(e,u,c),h=n-s,p=Math.sqrt(Math.max(0,o*o-h*h)),x=r(n,a-p),$=r(n,a+p),V=i-a,I=Math.sqrt(Math.max(0,o*o-V*V)),b=r(s-I,i),B=r(s+I,i);return[{kind:"quadrant-boundary",...Y([x,$]),lineColor:"rgba(255,255,255,0.7)",lineWidth:1.5},{kind:"quadrant-boundary",...Y([b,B]),lineColor:"rgba(255,255,255,0.7)",lineWidth:1.5}]}function tn(t,e){return t.map(n=>{const i=n.width/2,s=n.height/2;return{kind:"reticle",points:[[[n.x-i,n.y-s],[n.x+i,n.y-s],[n.x+i,n.y+s],[n.x-i,n.y+s]].map(([o,r])=>U(e,o,r))],closed:!0,lineColor:"rgba(255,255,255,0.7)",lineWidth:1.5,fill:"rgba(0,0,0,0)"}})}function en(t){const e=t.filter(n=>n.probeIndex!==void 0).sort((n,i)=>(n.probeIndex??0)-(i.probeIndex??0));return e.length?[{kind:"probe-path",...Y(e.map(n=>({x:n.physX,y:n.physY}))),lineColor:"rgba(220,80,0,0.55)",lineWidth:1}]:[]}function nn(t,e,n,i,s,a,o,r,h,p,x,$,V,I,b="off",B,u,c){const m=e.width-o,S=e.height-o,d=a?S:m,g=a?m:S,D=M=>s==="softBin"?M.sbin:M.hbin,E=M=>ft(M,B);if(e.partial){t.push({x:n,y:i,width:d,height:g,fill:Ke,type:"stacked",metadata:e.metadata});return}if(e.filteredOut){t.push({x:n,y:i,width:d,height:g,fill:We,type:"stacked",metadata:e.metadata});return}if(e.edgeExcluded){t.push({x:n,y:i,width:d,height:g,fill:ze,type:"stacked",metadata:e.metadata});return}if(h!==void 0&&(s==="hardBin"||s==="softBin")&&!h.has(D(e))){t.push({x:n,y:i,width:d,height:g,fill:Ut,type:"hardBin",metadata:e.metadata});return}if(c!==void 0&&s==="metadata"&&!c.has(E(e))){t.push({x:n,y:i,width:d,height:g,fill:Ut,type:"metadata",metadata:e.metadata});return}if(s==="value"){if(b==="test"){const q=J(e,x,I),dt=q===void 0?z:q?St:vt;t.push({x:n,y:i,width:d,height:g,fill:dt,type:"value",metadata:e.metadata});return}const M=L(e,x),P=lt(M,I);let w,tt;M===void 0?w=z:b==="spec"?w=P==="failLow"?Fe:P==="failHigh"?vt:St:(w=r.forValue(p(M)),(P==="failLow"||P==="failHigh")&&(tt=P)),t.push({x:n,y:i,width:d,height:g,fill:w,type:"value",specMark:tt,metadata:e.metadata});return}if(s==="hardBin"||s==="softBin"){const M=D(e),P=M!=null?r.forBin(M):z,w=M!=null&&Ne(e,V)===!1?!0:void 0;t.push({x:n,y:i,width:d,height:g,fill:P,type:s,binFail:w,metadata:e.metadata});return}if(s==="metadata"){const M=E(e),P=M!==void 0?u?.get(M)??z:z;t.push({x:n,y:i,width:d,height:g,fill:P,type:"metadata",metadata:e.metadata});return}const y=L(e,0),A=y!==void 0?r.forValue(p(y)):z;t.push({x:n,y:i,width:d,height:g,fill:A,type:"value",metadata:e.metadata})}function an(t,e,n){const i=t.radius;return Ae(e,i*.15,(s,a)=>({x:t.center.x+s*i*.9,y:t.center.y+a*i*.9}),n).overlays}export function buildView(t,e,n={},i){const s=n.reticles??[],{plotMode:a="value",showDieLabels:o=!1,showReticle:r=!1,showProbePath:h=!1,ringCount:p,showRingBoundaries:x=!1,showQuadrantBoundaries:$=!1,showXYIndicator:V=!1,binColorScheme:I="default",valueColorScheme:b="default",reverseValueScheme:B=!1,useDefinedBinColors:u=!0,binColors:c,passBins:m,highlightBin:S,highlightMetadataValue:d,interactiveTransform:g,valueRange:D,metadataValueOrder:E,testDefs:y,activeTest:A=0,activeMetadataKey:M,fallbackFormat:P="engineering",aggregationMethod:w,lotSize:tt,dataAxisFlip:q,isLotStack:dt=!1,logScale:Jt,colorbarRangeMode:Zt="spec",passFailDisplay:te}=n,Tt=te??"off",ht=i?.hbinDefs,mt=i?.sbinDefs,Dt=i?.metadataFields,ee=Dt?.find(l=>l.key===M),ne={x:(q?.x??!1)!==(g?.flipX??!1),y:(q?.y??!1)!==(g?.flipY??!1)},ae=ht?new Map(ht.map(l=>[l.bin,l])):null,ie=mt?new Map(mt.map(l=>[l.bin,l])):null,se=a==="softBin"?ie:ae,Vt=ye({passBins:m},"buildView"),oe=new Set(Vt),pt=c&&Pe(c,e)?c:Re(e,{passBins:Vt,binColorScheme:I,hbinDefs:ht,sbinDefs:mt,useDefinedBinColors:u}),re=a==="softBin"?pt.soft:pt.hard,Ct={forValue:Ye(Le(b,B)),forBin:l=>re.get(l)??z};let{testNumber:_}=resolveTestNumber(A,y);if(!y?.length&&a==="value"){const l=qt(e,"values");!l.includes(_)&&l.length&&(_=l[0])}let et;if(Array.isArray(D))et=D;else if(D){const{testNumber:l}=resolveTestNumber(D.test,y);et=l===_?D.range:void 0}const T=findTestDef(y,_),Ft=a==="value"&&T!==void 0&&!Bt(T),le=T!==void 0&&(T.limitLow!==void 0||T.limitHigh!==void 0);let H="off";a==="value"&&(Ft?H="test":Tt==="spec"&&le?H="spec":Tt==="test"&&e.some(l=>J(l,_,T)!==void 0)&&(H="test"));const Lt=H==="spec"?"spec":Zt,gt=a==="stackedValues"||a==="stackedBins"||a==="stackedSoftBins";let N,O,nt=!1;if(et){[N,O]=et;let l=!0,f=!1;for(const v of e){const F=gt?L(v,0):L(v,_);if(F!==void 0&&(f=!0,!Number.isInteger(F))){l=!1;break}}nt=f&&l}else{const l=!gt&&a==="value"&&Lt==="spec"&&T&&(T.limitLow!==void 0||T.limitHigh!==void 0);let f=1/0,v=-1/0,F=!0;for(const k of e){const W=gt?L(k,0):L(k,_);W!==void 0&&(W<f&&(f=W),W>v&&(v=W),Number.isInteger(W)||(F=!1))}isFinite(f)||(F=!1),nt=F,l?(N=T.limitLow!==void 0?T.limitLow:isFinite(f)?f:0,O=T.limitHigh!==void 0?T.limitHigh:isFinite(v)?v:1):(N=isFinite(f)?f:0,O=isFinite(v)?v:1)}N===O&&(O=N+1);const Rt=Ft?!1:Jt??T?.logScale??!1,Pt=Rt&&N>0&&O>0,ce=Pt;let at;if(Pt){const l=Math.log10(N),f=Math.log10(O)-l;at=v=>v<=0?0:jt((Math.log10(v)-l)/f)}else at=l=>jt((l-N)/(O-N));const C=je(t,q,g);let Nt=null;if(t.notch){const l=Qt(t.notch.type),f=Ve(C.physicalToScreen,Math.cos(l)*t.radius,Math.sin(l)*t.radius),v=Math.hypot(f.x,f.y);v>0&&(Nt={x:f.x/v,y:f.y/v})}let j=1/0;for(let l=0;l<e.length;l++){const f=e[l];f.width<j&&(j=f.width),f.height<j&&(j=f.height)}const Et=1,At=j!==1/0?Math.min(Et,j*.12):Et,_t=[],yt=[],ue=C.bakedToScreen.a===1&&C.bakedToScreen.b===0&&C.bakedToScreen.c===0&&C.bakedToScreen.d===1&&C.bakedToScreen.e===0&&C.bakedToScreen.f===0;let K=null;if(!ue){K=new Float64Array(e.length*2);for(let l=0;l<e.length;l++){const f=U(C.bakedToScreen,e[l].physX,e[l].physY);K[l*2]=f.x,K[l*2+1]=f.y}}const fe=Ce(C.gridToScreen),de=a==="hardBin"||a==="softBin"||a==="stackedBins"||a==="stackedSoftBins",he=a==="softBin"||a==="stackedSoftBins";let it=de?new Map:void 0;const bt=a==="value"&&H==="spec"?{pass:0,failHigh:0,failLow:0}:void 0,xt=a==="value"&&H==="test"?{pass:0,fail:0}:void 0,Ot=a==="metadata";let st=Ot?new Map:void 0,ot=null;if(Ot&&M){const l=collectMetadataValues(e,M),f=E?.key===M?E.values:void 0,v=f?[...f,...l.filter(F=>!f.includes(F))]:l;ot=new Map(v.map((F,k)=>[F,ee?.values?.find(W=>W.value===F)?.color??_e(k)]))}const me=S===void 0?void 0:new Set(zt(S)),pe=d===void 0?void 0:new Set(zt(d));for(let l=0;l<e.length;l++){const f=e[l],v=K?K[l*2]:f.physX,F=K?K[l*2+1]:f.physY;if(yt.push({x:v,y:F}),it&&Q(f)){const k=he?f.sbin:f.hbin;k!=null&&it.set(k,(it.get(k)??0)+1)}if(bt&&Q(f)){const k=lt(L(f,_),T);k&&bt[k]++}if(xt&&Q(f)){const k=J(f,_,T);k!==void 0&&xt[k?"pass":"fail"]++}if(st&&Q(f)){const k=ft(f,M);k!==void 0&&st.set(k,(st.get(k)??0)+1)}nn(_t,f,v,F,a,fe,At,Ct,me,at,_,se,oe,T,H,M,ot,pe)}const Ht=o?generateTextOverlay(e,K,{plotMode:a,colorFns:Ct,normalize:at,activeTest:A,valueRange:[N,O],testDefs:y,fallbackFormat:P,passFailDisplay:H,activeMetadataKey:M,metadataColorMap:ot,allIntegerValues:nt}):[],G=Qe(t,C.physicalToScreen);x&&G.push(...Je(t,C.physicalToScreen,be({ringCount:p},"buildView"))),$&&G.push(...Ze(t,C.physicalToScreen,t.center.x,t.center.y)),r&&G.push(...tn(s,C.gridToScreen)),h&&G.push(...en(e)),V&&G.push(...an(t,C.gridToScreen,Ht));const ge=yt.length>0?{minX:t.center.x-t.radius,maxX:t.center.x+t.radius,minY:t.center.y-t.radius,maxY:t.center.y+t.radius}:null,wt={rectangles:_t,dieGap:At,hoverPoints:yt,texts:Ht,overlays:G,plotMode:a,binColorScheme:I,valueColorScheme:b,reverseValueScheme:B,binColors:pt,metadata:t.metadata??null,dies:e,valueRange:[N,O],allIntegerValues:nt,testDefs:y,activeTest:A,logScale:ce,logScaleRequested:Rt,aggrMethod:w,lotSize:tt,axisFlip:ne,dataAxisFlip:{x:q?.x??!1,y:q?.y??!1},gridToScreen:C.gridToScreen,rotation:((t.orientation+(g?.rotation??0))%360+360)%360,hasReticle:s.length>0,isLotStack:dt,passFailDisplay:H,colorbarRangeMode:Lt,waferCenter:t.center,waferRadius:t.radius,notchDir:Nt,binCounts:it,metadataCounts:st,metadataColorMap:ot,activeMetadataKey:M,metadataFields:Dt,specCounts:bt,passFailCounts:xt,dieBounds:ge};return n.compact?Ee(wt,n.compact,{showXYIndicator:V}):wt}export{getDieKey}from"../core/dies.js";
@@ -804,6 +804,8 @@ export interface WaferMapResult {
804
804
  * structured clone, which is why it tests a field and not object identity.
805
805
  */
806
806
  export declare function isBuiltMap(map: object): map is WaferMapResult;
807
+ export declare function computeCoverage(dies: Die[]): WaferMapResult['dataCoverage'];
808
+ export declare function computeYield(dies: Die[], passBins: number[], edgeDieYieldMode?: 'exclude' | 'denominator-only', binsAreData?: boolean): YieldSummary;
807
809
  /** Read a test value from a die by test number. */
808
810
  export declare function getDieTestValue(die: Die, testNumber: number): number | undefined;
809
811
  /**
@@ -1 +1 @@
1
- import{createWafer as Q}from"../core/wafer.js";import{isYieldEligibleDie as Ce,getDieKey as X,hasPosition as W,positionKey as ke}from"../core/dies.js";import{applyOrientation as se,transformDies as Oe,clipDiesToWafer as Ae}from"../core/transforms.js";import{generateDies as $e}from"../core/dies.js";import{dieHasAnyTestData as Ne,dieLink as U,finaliseDie as z,linkDie as Re,recordedVerdict as Fe,recordedVerdictsReader as Ee,tableFromRows as Te,testValue as Z,testsPresent as We,VERDICT_FAIL as Ie,VERDICT_NONE as _e,VERDICT_PASS as Pe}from"../core/dieTable.js";import{isDieColumns as Ve,linkColumns as Be,linkRows as re,relink as oe}from"./columnarInput.js";import{affineRotation as Le,affineMirror as Ye,affineCompose as Xe,affinePoint as Ke}from"../core/transforms.js";import{inferWaferFromXY as je}from"../core/inference/wafer.js";import{resolveGridPitch as He}from"../core/inference/pitch.js";import{assignGridIndices as Ue}from"../core/inference/grid.js";import{generateReticleGrid as ze}from"../core/reticle.js";import{applyDerivedTests as Ge}from"./derivedTests/apply.js";import{isStdfBin as qe,isStdfCoord as ae,isStdfTestNumber as de,isStdfSite as Je,STDF_BIN_MAX as Qe,STDF_COORD_MAX as fe,STDF_TEST_NUM_MAX as Ze,STDF_SITE_MAX as et}from"../core/stdf.js";import{hasAnyKey as tt,maxOf as ee,minOf as le,modeOf as nt}from"../core/utils.js";import{aggregateValues as ue,aggregateBinCounts as it,stackHoldsMeasurements as st,stackBinsAreData as rt}from"../core/aggregates.js";import{normalizePassBins as ce}from"../core/passBins.js";import{defaultRingCount as te}from"../core/ringCount.js";import{applyValueFilter as ot,mergeValueFilterTests as at,valueFilterWarning as dt}from"./valueFilter.js";export function isParametricTest(n){return n?.testType!=="F"}export function isBuiltMap(n){return"wafer"in n&&"dies"in n&&"dataAxisFlip"in n}function ft(n){const e=(i,a)=>({ringCount:i,ringCountWarning:{code:"analysis-option-corrected",severity:"warning",message:`ringCount=${String(n)} ${a} (using ${i}).`}});if(n===void 0)return{ringCount:te(),ringCountWarning:void 0};if(typeof n!="number"||!Number.isFinite(n))return e(te(),"is not a finite number");const t=Math.max(1,Math.round(n));return t===n?{ringCount:n,ringCountWarning:void 0}:e(t,"is not a whole number of at least 1")}function lt(n,e){const t=Array.isArray(n)?{}:n,i={hbin:0,sbin:0,siteNum:0,testValues:0,testPass:0};let a;const d=(u,C)=>{i[u]++,a??=`${u} ${JSON.stringify(C)}`},o={bins:0,positions:0,values:0,sites:0,orientation:0},r=new Set;let p=0;if(e){i.testValues+=e.wrongValues,i.testPass+=e.wrongVerdicts,e.example!==void 0&&(a??=e.example),o.values+=e.nonFinite;for(const u of e.badTestNumbers)r.add(u)}const h=u=>u==null?!0:typeof u!="number"?!1:Number.isNaN(u)?(p++,!1):qe(u)?!0:(o.bins++,!1);function l(u){const C=new Set,D=new Set;for(let S=0;S<u.length;S+=S<50?1:100){const N=u[S];if(!(N===null||typeof N!="object")){if(N.testValues&&typeof N.testValues=="object")for(const M of Object.keys(N.testValues))C.add(M);if(N.testPass&&typeof N.testPass=="object")for(const M of Object.keys(N.testPass))D.add(M)}}const g=[...C],b=[...D],k=S=>de(Number(S));for(const S of new Set([...g,...b]))k(S)||r.add(S);const R=g.map(k),v=b.map(k),T=g.map(Number),L=b.map(Number);let K;for(let S=0;S<u.length;S++){const N=u[S];if(N===null||typeof N!="object")continue;const M=N;let F;const $=()=>F??={...M};M.hbin!=null&&typeof M.hbin!="number"&&d("hbin",M.hbin),M.sbin!=null&&typeof M.sbin!="number"&&d("sbin",M.sbin),h(M.hbin)||($().hbin=void 0),h(M.sbin)||($().sbin=void 0);const Y=typeof M.x=="number"&&!ae(M.x),j=typeof M.y=="number"&&!ae(M.y);if(Y||j){o.positions+=(Y?1:0)+(j?1:0);const s=$();s.x=void 0,s.y=void 0}M.siteNum!=null&&typeof M.siteNum!="number"?(d("siteNum",M.siteNum),$().siteNum=void 0):typeof M.siteNum=="number"&&!Je(M.siteNum)&&(o.sites++,$().siteNum=void 0);const P=M.testValues;if(P&&typeof P=="object"){let s;for(let x=0;x<g.length;x++){const A=g[x],O=P[T[x]];if(O!=null){if(!R[x]){s??={...P},delete s[A];continue}typeof O!="number"?(d("testValues",O),s??={...P},delete s[A]):Number.isFinite(O)||(o.values++,s??={...P},delete s[A])}}s&&($().testValues=s)}const I=M.testPass;if(I&&typeof I=="object"){let s;for(let x=0;x<b.length;x++){const A=b[x],O=I[L[x]];if(O!=null){if(!v[x]){s??={...I},delete s[A];continue}typeof O!="boolean"&&(d("testPass",O),s??={...I},delete s[A])}}s&&($().testPass=s)}F&&((K??=u.slice())[S]=F)}return K}const f={warnings:[]};if(Array.isArray(n))f.results=l(n);else{Array.isArray(t.results)&&(f.results=l(t.results)),Array.isArray(t.dies)&&(f.dies=l(t.dies));const u=t.lotStack?.results;if(Array.isArray(u)){const C=u.map(D=>Array.isArray(D)?l(D):void 0);C.some(Boolean)&&(f.stackResults=C.map((D,g)=>D??u[g]))}}if(Array.isArray(t.testDefs)){const u=t.testDefs,C=u.filter(D=>D==null||typeof D.testNumber!="number"||de(D.testNumber));for(const D of u)C.includes(D)||r.add(String(D.testNumber));C.length!==u.length&&(f.testDefs=C)}const y=t.waferConfig?.orientation;if(typeof y=="number"){const u=Number.isFinite(y)?(y%360+360)%360:NaN;u===0||u===90||u===180||u===270?f.orientation=u:(o.orientation++,f.orientation=0)}const m=(u,C,D=`${C}s`)=>`${u} ${u===1?C:D}`,c=[];if(i.hbin&&c.push(m(i.hbin,"hard bin")),i.sbin&&c.push(m(i.sbin,"soft bin")),i.siteNum&&c.push(m(i.siteNum,"site number")),i.testValues&&c.push(m(i.testValues,"test value")),i.testPass&&c.push(m(i.testPass,"pass/fail verdict")),c.length){const u=`buildWaferMap received ${c.join(", ")} of the wrong type (for example ${a}), treated as missing. Bins, sites and test values must be numbers and verdicts true/false \u2014 a bin of "1" is not pass bin 1 \u2014 so those dies have no bin, no site, no value or no verdict, and yield and every chart leave them out. Convert them with Number() (and verdicts to booleans) and rebuild.`;console.warn(`[wafermap] ${u}`),f.warnings.push({code:"input-values-not-numbers",message:u,severity:"error"})}const w=[];if(o.bins&&w.push(`${m(o.bins,"bin")} (legal: whole numbers 0\u2013${Qe}) \u2014 those dies have no bin`),o.positions&&w.push(`${m(o.positions,"coordinate")} (legal: whole numbers \u2212${fe} to ${fe}) \u2014 those dies have no position`),r.size&&w.push(`${m(r.size,"test number")} (legal: whole numbers 0\u2013${Ze}) \u2014 those tests are left out`),o.values&&w.push(`${m(o.values,"test value")} that ${o.values===1?"is":"are"} not finite \u2014 left out`),o.sites&&w.push(`${m(o.sites,"site number")} (legal: 0\u2013${et}) \u2014 those dies have no site`),o.orientation&&w.push("a waferConfig.orientation other than 0, 90, 180 or 270 \u2014 the map is built at 0"),w.length||p){const u=[];w.length&&u.push(`buildWaferMap received values outside the STDF V4 ranges, treated as missing: ${w.join("; ")}.`),p&&u.push(`${m(p,"bin was","bins were")} NaN and ${p===1?"is":"are"} treated as no bin.`);const C=u.join(" ");console.warn(`[wafermap] ${C}`),f.warnings.push({code:"input-values-outside-stdf",message:C,severity:"warning"})}return f}function pe(n){const e=(h,l)=>h!==null&&typeof h=="object"&&h[l]!==void 0,t=Array.isArray(n)?{}:n,i=[],a=(h,l,f)=>{h&&i.push(`\`${l}\` (now \`${f}\`)`)};a(e(t,"data"),"data","results"),a(e(t,"die"),"die","dieConfig"),a(e(t,"stack"),"stack","lotStack"),a(e(t.dieConfig,"origin"),"dieConfig.origin","dieConfig.coordinateOrigin"),a(e(t.waferConfig,"flat"),"waferConfig.flat","waferConfig.notch"),a(e(t.reticleConfig,"anchor"),"reticleConfig.anchor","reticleConfig.anchorDie"),a(e(t.lotStack,"aggr"),"lotStack.aggr","lotStack.method"),a(Array.isArray(t.testDefs)&&t.testDefs.some(h=>e(h,"index")&&!e(h,"testNumber")),"TestDef.index","TestDef.testNumber");const d=e(t.lotStack,"results")?t.lotStack.results:[],o=(Array.isArray(n)?[n]:[t.results,...Array.isArray(d)?d:[]]).filter(h=>Array.isArray(h));if(a(o.some(h=>h.slice(0,100).some(l=>e(l,"values"))),"values","testValues"),!i.length)return;const r=i.length>1,p=`buildWaferMap ignored ${i.join(", ")}: ${r?"these names were":"that name was"} removed in an earlier release, so what ${r?"they":"it"} described is not on this map. Rename and rebuild.`;return console.warn(`[wafermap] ${p}`),{code:"input-field-removed",message:p,severity:"error"}}function ut(n){if(n.results!==void 0||n.lotStack!==void 0)throw new Error("buildWaferMap: pass `layout`, `results` or `lotStack` \u2014 only one.");const e=n.waferConfig?.diameter,t=n.dieConfig?.width,i=n.dieConfig?.height;if(!(e>0&&t>0&&i>0))throw new Error("buildWaferMap: `layout` needs waferConfig.diameter and dieConfig.width and height, all positive.");const a=Q({diameter:e,notch:n.waferConfig?.notch,orientation:0}),d=Ae($e(a,{width:t,height:i}),a,{width:t,height:i}).filter(l=>!l.partial),{flipX:o,flipY:r}=me(n.dieConfig,{type:"center"}),{layout:p,...h}=n;return{...h,results:d.map(l=>({x:o?-l.x:l.x,y:r?-l.y:l.y})),waferConfig:{...n.waferConfig,center:{x:0,y:0}},dieConfig:{...n.dieConfig,coordinateOrigin:{type:"center"}}}}function ct(n){if(!Array.isArray(n)&&"results"in n&&n.results!==void 0&&"lotStack"in n&&n.lotStack!==void 0)throw new Error("buildWaferMap: pass either `results` or `lotStack`, not both.");const e={wrongVerdicts:0,wrongValues:0,nonFinite:0,badTestNumbers:[]},t=!Array.isArray(n)&&Ve(n.results)?{...n,results:Be(n.results,e).records}:n,i=lt(t,e);return Array.isArray(t)?{results:ne(i.results??t),waferOpts:void 0,dieOpts:void 0,explicitDies:void 0,reticleOpts:void 0,lotStackOpts:void 0,passBins:ce(void 0),ringCount:te(),valueFilter:"validity",ringCountWarning:void 0,removedFieldWarning:pe(t),inputValueWarnings:i.warnings,standardDiameters:void 0,testDefs:void 0,hbinDefs:void 0,sbinDefs:void 0,metadataFields:void 0,derivedTests:void 0,retestPolicy:"last",edgeDieYieldMode:"exclude"}:{results:ne(i.results??t.results??[]),waferOpts:i.orientation===void 0||t.waferConfig===void 0?t.waferConfig:{...t.waferConfig,orientation:i.orientation},dieOpts:t.dieConfig,explicitDies:i.dies??t.dies,reticleOpts:t.reticleConfig,lotStackOpts:t.lotStack?{...t.lotStack,results:(i.stackResults??t.lotStack.results).map(ne)}:void 0,passBins:ce(t.passBins),valueFilter:t.valueFilter??"validity",...ft(t.ringCount),removedFieldWarning:pe(t),inputValueWarnings:i.warnings,standardDiameters:t.standardDiameters,testDefs:(i.testDefs??t.testDefs)?.length?i.testDefs??t.testDefs:void 0,hbinDefs:t.hbinDefs,sbinDefs:t.sbinDefs,metadataFields:t.metadataFields,derivedTests:t.derivedTests?.length?t.derivedTests:void 0,retestPolicy:t.retestPolicy??"last",edgeDieYieldMode:t.edgeDieYieldMode??"exclude"}}function ne(n){return n.length>0&&U(n[0])!==void 0?n:re(n).records}function pt(n,e){return e?.coordinateOrigin?e.coordinateOrigin:{type:"center"}}function ht(n,e,t){if(e.type==="custom"&&e.offset)return{offsetX:e.offset.x,offsetY:e.offset.y};if(e.type!=="center"){let i=1/0,a=-1/0,d=1/0,o=-1/0;for(const r of n)r.x<i&&(i=r.x),r.x>a&&(a=r.x),r.y<d&&(d=r.y),r.y>o&&(o=r.y);return{offsetX:Math.round((a+i)/2),offsetY:Math.round((o+d)/2)}}return{offsetX:t.offsetX,offsetY:t.offsetY}}function mt(n,e){if(n.length<Me)return!1;const t=he(n),i=(a,d,o)=>{const r=o-d+1;return a<d-r||a>o+r};return i(Math.round(e.x),t.xMin,t.xMax)||i(Math.round(e.y),t.yMin,t.yMax)}function he(n){let e=1/0,t=-1/0,i=1/0,a=-1/0;for(const d of n){const o=Math.round(d.x),r=Math.round(d.y);o<e&&(e=o),o>t&&(t=o),r<i&&(i=r),r>a&&(a=r)}return{xMin:e,xMax:t,yMin:i,yMax:a}}const gt="The supplied wafer centre";function yt(n,e){const t=he(n);return`${gt} (${e.x}, ${e.y}) is far outside the probed dies (X ${t.xMin}\u2026${t.xMax}, Y ${t.yMin}\u2026${t.yMax}), so it was ignored and the centre was inferred from the dies. Used as given, it would draw a wafer many times the die extent with the dies in one corner. If it is the real centre, supply waferConfig.diameter as well.`}function bt(n,e,t,i,a,d){if(d)return{colMidX:(Math.round(d.x)-e)*i,colMidY:(Math.round(d.y)-t)*a,anchored:!0};if(n.length===0)return{colMidX:0,colMidY:0,anchored:!1};let o=1/0,r=-1/0,p=1/0,h=-1/0;for(const l of n){const f=Math.round(l.x)-e,y=Math.round(l.y)-t;f<o&&(o=f),f>r&&(r=f),y<p&&(p=y),y>h&&(h=y)}return{colMidX:(o+r)/2*i,colMidY:(p+h)/2*a,anchored:!1}}function wt(n,e,t){let i=1/0,a=-1/0,d=1/0,o=-1/0,r=0,p=0;for(const f of n){const y=Math.round(f.x)-e,m=Math.round(f.y)-t;r+=y,p+=m,y<i&&(i=y),y>a&&(a=y),m<d&&(d=m),m>o&&(o=m)}const h=n.length,l=(f,y,m)=>{const c=(m-y)/2;return c<=0?0:Math.abs(f/h-(y+m)/2)/c};return l(r,i,a)>.11||l(p,d,o)>.11}function me(n,e){let t=n?.xAxisDirection==="left",i=n?.yAxisDirection==="down";return(e.type==="UL"||e.type==="UR")&&(i=!0),(e.type==="LR"||e.type==="UR")&&(t=!0),{flipX:t,flipY:i}}function xt(n){const e={...n};return delete e.limitLow,delete e.limitHigh,delete e.limitLowInclusive,delete e.limitHighInclusive,delete e.specLow,delete e.specHigh,e}function Dt(n,e){const{method:t,targetBin:i}=n,a=n.results.map(d=>d.filter(W));if(t==="mean"||t==="median"||t==="stddev"||t==="min"||t==="max"||t==="count"){const d=new Set((e??[]).filter(l=>!isParametricTest(l)).map(l=>l.testNumber)),o=new Set;for(const l of a)for(const f of We(l,"values"))d.has(f)||o.add(f);if(o.size===0)return ue(a,t);const r=[...o],p=r.map(l=>ue(a,t,l)),h=new Map;for(let l=0;l<r.length;l++){const f=r[l];for(const y of p[l]){const m=X(y);h.has(m)||h.set(m,{template:y,testValues:{}});const c=h.get(m),w=y.testValues?.[0];w!==void 0&&(c.testValues[f]=w)}}return[...h.values()].map(({template:l,testValues:f})=>({...l,testValues:tt(f)?f:void 0}))}if(t==="countBin"||t==="percent"){if(i===void 0)return[];const d=it(a,i,"hard");if(t==="countBin")return d;const o=a.length;return d.map(r=>({...r,testValues:{0:o>0?(r.testValues?.[0]??0)/o*100:0}}))}if(t==="mode"){const d=new Map;for(const r of a)for(const p of r){const h=X(p);d.has(h)||d.set(h,[]),d.get(h).push(p)}const o=[];for(const[r,p]of d){const h=r.split(","),l=Number(h[0]),f=Number(h[1]),y=p.map(c=>c.hbin).filter(c=>c!==void 0),m=nt(y);m!==null&&o.push({x:l,y:f,hbin:m})}return o}return[]}function ge(n){const e=n.filter(W),t=e.length,i=e.filter(d=>d.edgeExcluded).length,a=e.filter(d=>d.hbin!==void 0||d.sbin!==void 0||dieHasTestData(d)).length;return{filledDies:a,totalDies:t,edgeExcludedDies:i,unpositionedDies:n.length-e.length,ratio:t>0?a/t:0}}function ye(n,e,t="exclude",i=!0){const a=new Set(e),o=n.filter(c=>!c.partial).filter(c=>c.edgeExcluded).length,r=n.filter(c=>c.partial).length;if(!i)return{passDies:0,failDies:0,edgeExcludedDies:o,partialDies:r,totalDies:0,yieldPercent:null,yieldPercentGross:null};let p=0,h=0,l=!1;for(const c of n){if(!Ce(c))continue;const w=c.hbin??c.sbin;w!==void 0&&(l=!0,a.has(w)?p++:h++)}const f=p+h,y=l&&f>0?p/f*100:null;let m=null;if(t==="denominator-only"){const c=f+o;m=l&&c>0?p/c*100:null}return{passDies:p,failDies:h,edgeExcludedDies:o,partialDies:r,totalDies:f,yieldPercent:y,yieldPercentGross:m}}function be(n,e,t,i,a,d=0,o=0,r=0,p=0,h=0,l=!1,f=!1){if(!n)return[];const y=n.anchorDie??{x:0,y:0},m=ze(e,{width:n.width,height:n.height,diePitchX:i,diePitchY:a,anchorDie:{x:y.x-d,y:y.y-o},gridOrigin:{x:-r,y:-p}}),c=Xe(Ye(l,f,e.center.x,e.center.y),Le(h,e.center.x,e.center.y));return m.filter(w=>{const u=w.width/2,C=w.height/2,D=[[w.x-u,w.y-C],[w.x+u,w.y-C],[w.x+u,w.y+C],[w.x-u,w.y+C]].map(([v,T])=>Ke(c,v,T)),g=le(D.map(v=>v.x)),b=ee(D.map(v=>v.x)),k=le(D.map(v=>v.y)),R=ee(D.map(v=>v.y));return t.some(v=>v.physX>=g&&v.physX<b&&v.physY>=k&&v.physY<R)})}function Mt(n,e,t){const a=Math.max(0,e.radius-t)**2;return n.map(d=>{const o=d.physX-e.center.x,r=d.physY-e.center.y;return o*o+r*r>a?{...d,edgeExcluded:!0}:d})}const vt=.2;function St(n){const e=new Set;for(const t of n){if(t.supersedes!==void 0||!W(t))return!1;const i=ke(t);if(e.has(i))return!1;e.add(i)}return!0}function Ct(n,e,t){if(St(n))return{results:n.slice(),warning:void 0};const i=new Set(t);function a(g,b){if(e==="last")return!0;if(e==="first")return!1;const k=G(g.hbin),R=G(b.hbin);if(k===void 0||R===void 0)return!1;const v=i.has(k),T=i.has(R);return e==="best"?T!==v?T:R<k:T!==v?v:R>k}const d=(g,b)=>b.supersedes!==void 0||a(g,b),o=g=>{const b=g.partId===void 0?"":String(g.partId).trim();return b===""?void 0:b},r=n.filter(g=>!W(g)),p=new Map;for(const g of r){const b=o(g);b!==void 0&&p.set(b,(p.get(b)??0)+1)}const l=(r.length===0?0:Math.max(0,...p.values())/r.length)<=vt,f=new Map,y=[],m=new Map;let c=0,w=0;for(const g of n){const b=o(g);let k;if(W(g)?k=`p:${X(g)}`:l&&b!==void 0?k=`i:${b}`:k=`u:${w++}`,g.supersedes==="partId"&&b!==void 0){const v=m.get(b);v!==void 0&&v!==k&&f.has(v)&&f.delete(v)}const R=f.get(k);R===void 0?(f.set(k,{winner:g,count:1}),y.push(k)):(R.count++,k.startsWith("i:")&&c++,d(R.winner,g)&&(R.winner=g)),b!==void 0&&m.set(b,k)}const u=[],C=[...y.filter(g=>g.startsWith("p:")),...y.filter(g=>!g.startsWith("p:"))];for(const g of C){const b=f.get(g);b!==void 0&&u.push(b.count>1?{...b.winner,retestCount:b.count}:b.winner)}const D=c>0?{code:"retests-by-part-id",severity:"info",message:`${c} record${c===1?"":"s"} with no position shared a part ID with an earlier record and ${c===1?"was":"were"} treated as a retest of it.`}:void 0;return{results:u,warning:D}}export function getDieTestValue(n,e){return Z(n,e)}export function getTestPassStatus(n,e,t){const i=Fe(n,e);return i!==void 0?i:t!==void 0&&!isParametricTest(t)?we(Z(n,e)):void 0}function we(n){return n===0||n===1?n===1:void 0}export function testPassStatusReader(n){const e=n.map(a=>a.testNumber),t=Ee(e),i=n.map(a=>!isParametricTest(a));return function(d,o){t(d,o);for(let r=0;r<o.length;r++){if(o[r]!==_e||!i[r])continue;const p=we(Z(d,e[r]));p!==void 0&&(o[r]=p?Pe:Ie)}return o}}export function dieHasTestData(n){return Ne(n)}function G(n){return n===void 0||Number.isNaN(n)?void 0:n}function q(n,e){const t={},i=G(e.hbin),a=G(e.sbin);i!==void 0&&(t.hbin=i),a!==void 0&&(t.sbin=a),e.retestCount!==void 0&&(t.retestCount=e.retestCount),e.siteNum!==void 0&&(t.siteNum=e.siteNum),e.partId!==void 0&&(t.partId=e.partId),e.metadata!==void 0&&(t.metadata=e.metadata);const d=U(e);return Re({...n,...t},d.table,d.row)}function xe(n){return n.some(dieHasTestData)?"value":defaultBinMode([n])}export function defaultBinMode(n){const e=t=>n.some(i=>i.some(a=>t(a)!=null));return e(t=>t.hbin)?"hardBin":e(t=>t.sbin)?"softBin":"hardBin"}function De(n,e){return n.map(({code:t,message:i})=>({code:t,message:i,severity:t==="non-standard-diameter"||t==="diameter-exceeds-die-extent"||t==="implausible-center"?"warning":"error",confidence:e.wafer.confidence}))}const kt="do not fit inside the supplied",Ot="Inferred wafer diameter",At="The probed dies reach only",$t=.75,Me=20;export const STANDARD_WAFER_DIAMETERS_MM=[100,125,150,200,300];const Nt=.02;function ve(n,e){return e.reduce((t,i)=>Math.abs(i-n)<Math.abs(t-n)?i:t)}function Rt(n,e){if(!e.length)return!0;const t=ve(n,e);return Math.abs(t-n)/t<=Nt}function Ft(n){return n===void 0?STANDARD_WAFER_DIAMETERS_MM:n.filter(e=>Number.isFinite(e)&&e>0)}export function buildWaferMap(n){const e=ct(!Array.isArray(n)&&n.layout?ut(n):n),t=[];let i;if(e.valueFilter!=="none"&&e.testDefs){const s=e.valueFilter,x=(e.lotStackOpts?e.lotStackOpts.results:[e.results]).map(O=>{const _=O.length>0?U(O[0]):void 0;if(!_)return[];const E=ot(_.table,e.testDefs,s);return E.tests.length>0&&oe(O,E.table),E.tests}),A=at(x);if(A.length>0){i={mode:s,tests:A};const O=dt(s,A,e.testDefs);O&&t.push(O)}}if(e.derivedTests){const s=new Set(e.passBins),x=_=>{const E=_.length>0?U(_[0]):void 0,H=Ge(_,E?.table??Te([]),e.testDefs,e.derivedTests,s);return E&&oe(_,H.table),H},O=(e.lotStackOpts?e.lotStackOpts.results:[e.results]).map(x);e.testDefs=O[0]?.testDefs??e.testDefs,t.push(...O[0]?.warnings??[])}e.lotStackOpts&&!st(e.lotStackOpts.method)&&(e.testDefs=e.testDefs?.map(xt));const a=e.lotStackOpts?re(Dt(e.lotStackOpts,e.testDefs)).records:e.results;for(let s=0;s<Math.min(5,a.length);s++){const x=a[s];if(typeof x.x=="string"||typeof x.y=="string")throw new TypeError("buildWaferMap: x and y must be numbers, received strings. Did you forget to cast CSV values? e.g. { x: +row.x, y: +row.y }")}for(const s of a)if(s.x==null!=(s.y==null))throw new TypeError(`buildWaferMap: die has only one of x/y set (x=${String(s.x)}, y=${String(s.y)}). A die must be either fully positioned (both x and y) or fully unpositioned (neither) \u2014 omit both to mark a die as having no reported position.`);const{results:d,warning:o}=Ct(a,e.retestPolicy,e.passBins),r={wafer:{confidence:1,method:"provided"},diePitch:{confidence:1,units:"mm"},grid:{confidence:1}},p=[];if(e.explicitDies){let s=e.explicitDies.filter(W);const x=e.explicitDies.filter(B=>!W(B)),A=d.filter(W),O=d.filter(B=>!W(B));if(A.length>0){const B=new Map(A.map(V=>[X(V),V]));s=s.map(V=>{const ie=B.get(X(V));return ie?q(V,ie):V})}const _=e.waferOpts?.diameter??300,E=Q({diameter:_,notch:e.waferOpts?.notch,orientation:e.waferOpts?.orientation??0,metadata:e.waferOpts?.metadata,reticle:e.reticleOpts});E.orientation!==0&&(s=se(s,E)),s=s.map(z);const H=be(e.reticleOpts,E,s,1,1,0,0,0,0,E.orientation),Se=O.map((B,V)=>z(q({id:`unpositioned_${V}`,width:s[0]?.width??1,height:s[0]?.height??1},B))),J=[...s,...x,...Se];return{wafer:E,dies:J,dataAxisFlip:{x:!1,y:!1},reticleConfig:e.reticleOpts,units:"mm",inference:r,warnings:[...e.removedFieldWarning?[e.removedFieldWarning]:[],...e.inputValueWarnings,...o?[o]:[],...De(p,r),...t,...e.ringCountWarning?[e.ringCountWarning]:[]],plotMode:xe(d),metadata:E.metadata??null,isLotStack:!1,dataCoverage:ge(J),passBins:e.passBins,...i?{valueFilter:i}:{},ringCount:e.ringCount,yield:ye(J,e.passBins,e.edgeDieYieldMode),reticles:H,hbinDefs:e.hbinDefs,sbinDefs:e.sbinDefs,testDefs:e.testDefs,metadataFields:e.metadataFields}}const h=d.filter(W),l=d.filter(s=>!W(s)),f=h.map(s=>({x:s.x,y:s.y})),y=He(f,e.dieOpts,e.waferOpts?.diameter);r.diePitch={confidence:y.confidence,units:y.units};const{pitchX:m,pitchY:c}=y,w=y.units,u=pt(h,e.dieOpts),C=Ue(f);r.grid={confidence:C.confidence};const{offsetX:D,offsetY:g}=ht(f,u,C),{flipX:b,flipY:k}=me(e.dieOpts,u),R=e.waferOpts?.diameter===void 0&&e.waferOpts?.center!==void 0&&mt(f,e.waferOpts.center),v=R?void 0:e.waferOpts?.center;R&&p.push({code:"implausible-center",message:yt(f,e.waferOpts.center)});const{colMidX:T,colMidY:L,anchored:K}=bt(f,D,g,m,c,v);let S=e.waferOpts?.diameter;const N=f.map(s=>({x:(Math.round(s.x)-D)*m-T,y:(Math.round(s.y)-g)*c-L})),M=ee(N.map(({x:s,y:x})=>Math.hypot(Math.abs(s)+m/2,Math.abs(x)+c/2)));if(S===void 0)if(f.length>0)if(w==="mm"){const s=je(N,{minRadius:M});S=s.diameter,r.wafer={confidence:s.confidence,method:s.method};const x=Ft(e.standardDiameters);if(!Rt(S,x)){const A=ve(S,x);p.push({code:"non-standard-diameter",message:`${Ot} ${S.toFixed(1)} mm is not a standard wafer size (nearest is ${A} mm). The diameter was derived from the die extent, which assumes the probed grid reaches the wafer edge \u2014 a non-standard result usually means it does not, because the outer dies were never probed. Every die is then placed against a wafer that is too small, which moves dies between rings and changes ring and edge findings. Supply waferConfig.diameter.`})}}else S=M*2,r.wafer={confidence:y.confidence*.8,method:"extent"};else S=w==="mm"?300:30,r.wafer={confidence:0,method:"default"};if(!K&&f.length>0&&wt(f,D,g)&&(r.wafer.method="inferred-partial",p.push({code:"partial-coverage",message:"Wafer geometry was inferred from die positions alone. The data does not span a full symmetric wafer, so the inferred diameter and centre may be wrong and dies may be mis-positioned relative to the true wafer boundary. Supply waferConfig.diameter and waferConfig.center (the prober coordinate of the wafer centre) to position partial data correctly."})),e.waferOpts?.diameter!==void 0&&v===void 0&&M>0&&f.length>=Me){const s=M/(S/2);s<$t&&p.push({code:"diameter-exceeds-die-extent",message:`${At} ${(s*100).toFixed(0)}% of the ${S} mm wafer's radius. Either the diameter is larger than the real one, or this is a partial map covering only part of the wafer. Ring bands are equal-radius, so the outer rings are mostly or entirely empty and ring, quadrant and edge findings describe the assumed wafer rather than the probed area. Check waferConfig.diameter, or drop it and let the diameter be inferred from the die extent.`})}if(e.waferOpts?.diameter!==void 0){const s=e.dieOpts?.width!==void 0&&e.dieOpts?.height!==void 0;if(s&&M>S/2+1e-9){const x=N.filter(({x:A,y:O})=>Math.hypot(Math.abs(A)+m/2,Math.abs(O)+c/2)>S/2+1e-9).length;p.push({code:"geometry-conflict",message:`${x} of ${N.length} probed die positions ${kt} ${S} mm wafer at the supplied die pitch of ${m} \xD7 ${c} mm. A die with test results is a real prober position and is always fully on the wafer, so one of the two supplied values must be wrong: containing these dies at this pitch would need a diameter of at least ${(M*2).toFixed(1)} mm. Check waferConfig.diameter and dieConfig.width/height against the real device.`})}}const F=Q({diameter:S,units:w,notch:e.waferOpts?.notch,orientation:e.waferOpts?.orientation??0,metadata:e.waferOpts?.metadata,reticle:e.reticleOpts});let $=h.map(s=>{const x=Math.round(s.x)-D,A=Math.round(s.y)-g,O={id:`${x}_${A}`,x,y:A,physX:x*m-T,physY:A*c-L,width:m,height:c,insideWafer:!0,partial:!1};return q(O,s)});(D!==0||g!==0)&&($=$.map(s=>({...s,x:s.x+D,y:s.y+g,id:`${s.x+D}_${s.y+g}`}))),$=se($,F),(b||k)&&($=Oe($,{flipX:b,flipY:k},F.center));const Y=[];e.waferOpts?.edgeExclusion&&e.waferOpts.edgeExclusion>0&&($=Mt($,F,e.waferOpts.edgeExclusion),e.waferOpts.edgeExclusion>F.radius&&Y.push({code:"edge-exclusion-exceeds-radius",message:`edgeExclusion (${e.waferOpts.edgeExclusion}mm) exceeds the resolved wafer radius (${F.radius}mm) \u2014 the entire wafer is excluded.`,severity:"warning"})),$=$.map(z);const j=be(e.reticleOpts,F,$,m,c,D,g,T,L,F.orientation,b,k),P=l.map((s,x)=>z(q({id:`unpositioned_${x}`,width:m,height:c},s))),I=[...$,...P];return{wafer:F,dies:I,dataAxisFlip:{x:b,y:k},reticleConfig:e.reticleOpts,units:w,inference:r,warnings:[...e.removedFieldWarning?[e.removedFieldWarning]:[],...e.inputValueWarnings,...o?[o]:[],...De(p,r),...Y,...t,...e.ringCountWarning?[e.ringCountWarning]:[]],plotMode:xe(d),metadata:F.metadata??null,isLotStack:e.lotStackOpts!==void 0,dataCoverage:ge(I),passBins:e.passBins,...i?{valueFilter:i}:{},ringCount:e.ringCount,yield:ye(I,e.passBins,e.edgeDieYieldMode,rt(e.lotStackOpts!==void 0,e.lotStackOpts?.method)),reticles:j,hbinDefs:e.hbinDefs,sbinDefs:e.sbinDefs,testDefs:e.testDefs,metadataFields:e.metadataFields,aggrMethod:e.lotStackOpts?.method,lotSize:e.lotStackOpts?.results.length}}
1
+ import{createWafer as Q}from"../core/wafer.js";import{isYieldEligibleDie as ve,getDieKey as X,hasPosition as W,positionKey as Se}from"../core/dies.js";import{applyOrientation as se,transformDies as Ce,clipDiesToWafer as ke}from"../core/transforms.js";import{generateDies as Oe}from"../core/dies.js";import{dieHasAnyTestData as Ae,dieLink as U,finaliseDie as z,linkDie as $e,recordedVerdict as Ne,recordedVerdictsReader as Re,tableFromRows as Fe,testValue as Z,testsPresent as Ee,VERDICT_FAIL as Te,VERDICT_NONE as We,VERDICT_PASS as Ie}from"../core/dieTable.js";import{isDieColumns as _e,linkColumns as Pe,linkRows as re,relink as oe}from"./columnarInput.js";import{affineRotation as Ve,affineMirror as Be,affineCompose as Le,affinePoint as Ye}from"../core/transforms.js";import{inferWaferFromXY as Xe}from"../core/inference/wafer.js";import{resolveGridPitch as Ke}from"../core/inference/pitch.js";import{assignGridIndices as je}from"../core/inference/grid.js";import{generateReticleGrid as He}from"../core/reticle.js";import{applyDerivedTests as Ue}from"./derivedTests/apply.js";import{isStdfBin as ze,isStdfCoord as ae,isStdfTestNumber as de,isStdfSite as Ge,STDF_BIN_MAX as qe,STDF_COORD_MAX as fe,STDF_TEST_NUM_MAX as Je,STDF_SITE_MAX as Qe}from"../core/stdf.js";import{hasAnyKey as Ze,maxOf as ee,minOf as le,modeOf as et}from"../core/utils.js";import{aggregateValues as ue,aggregateBinCounts as tt,stackHoldsMeasurements as nt,stackBinsAreData as it}from"../core/aggregates.js";import{normalizePassBins as ce}from"../core/passBins.js";import{defaultRingCount as te}from"../core/ringCount.js";import{applyValueFilter as st,mergeValueFilterTests as rt,valueFilterWarning as ot}from"./valueFilter.js";export function isParametricTest(n){return n?.testType!=="F"}export function isBuiltMap(n){return"wafer"in n&&"dies"in n&&"dataAxisFlip"in n}function at(n){const e=(i,a)=>({ringCount:i,ringCountWarning:{code:"analysis-option-corrected",severity:"warning",message:`ringCount=${String(n)} ${a} (using ${i}).`}});if(n===void 0)return{ringCount:te(),ringCountWarning:void 0};if(typeof n!="number"||!Number.isFinite(n))return e(te(),"is not a finite number");const t=Math.max(1,Math.round(n));return t===n?{ringCount:n,ringCountWarning:void 0}:e(t,"is not a whole number of at least 1")}function dt(n,e){const t=Array.isArray(n)?{}:n,i={hbin:0,sbin:0,siteNum:0,testValues:0,testPass:0};let a;const d=(u,C)=>{i[u]++,a??=`${u} ${JSON.stringify(C)}`},o={bins:0,positions:0,values:0,sites:0,orientation:0},r=new Set;let p=0;if(e){i.testValues+=e.wrongValues,i.testPass+=e.wrongVerdicts,e.example!==void 0&&(a??=e.example),o.values+=e.nonFinite;for(const u of e.badTestNumbers)r.add(u)}const h=u=>u==null?!0:typeof u!="number"?!1:Number.isNaN(u)?(p++,!1):ze(u)?!0:(o.bins++,!1);function l(u){const C=new Set,D=new Set;for(let S=0;S<u.length;S+=S<50?1:100){const N=u[S];if(!(N===null||typeof N!="object")){if(N.testValues&&typeof N.testValues=="object")for(const M of Object.keys(N.testValues))C.add(M);if(N.testPass&&typeof N.testPass=="object")for(const M of Object.keys(N.testPass))D.add(M)}}const g=[...C],b=[...D],k=S=>de(Number(S));for(const S of new Set([...g,...b]))k(S)||r.add(S);const R=g.map(k),v=b.map(k),T=g.map(Number),L=b.map(Number);let K;for(let S=0;S<u.length;S++){const N=u[S];if(N===null||typeof N!="object")continue;const M=N;let F;const $=()=>F??={...M};M.hbin!=null&&typeof M.hbin!="number"&&d("hbin",M.hbin),M.sbin!=null&&typeof M.sbin!="number"&&d("sbin",M.sbin),h(M.hbin)||($().hbin=void 0),h(M.sbin)||($().sbin=void 0);const Y=typeof M.x=="number"&&!ae(M.x),j=typeof M.y=="number"&&!ae(M.y);if(Y||j){o.positions+=(Y?1:0)+(j?1:0);const s=$();s.x=void 0,s.y=void 0}M.siteNum!=null&&typeof M.siteNum!="number"?(d("siteNum",M.siteNum),$().siteNum=void 0):typeof M.siteNum=="number"&&!Ge(M.siteNum)&&(o.sites++,$().siteNum=void 0);const P=M.testValues;if(P&&typeof P=="object"){let s;for(let x=0;x<g.length;x++){const A=g[x],O=P[T[x]];if(O!=null){if(!R[x]){s??={...P},delete s[A];continue}typeof O!="number"?(d("testValues",O),s??={...P},delete s[A]):Number.isFinite(O)||(o.values++,s??={...P},delete s[A])}}s&&($().testValues=s)}const I=M.testPass;if(I&&typeof I=="object"){let s;for(let x=0;x<b.length;x++){const A=b[x],O=I[L[x]];if(O!=null){if(!v[x]){s??={...I},delete s[A];continue}typeof O!="boolean"&&(d("testPass",O),s??={...I},delete s[A])}}s&&($().testPass=s)}F&&((K??=u.slice())[S]=F)}return K}const f={warnings:[]};if(Array.isArray(n))f.results=l(n);else{Array.isArray(t.results)&&(f.results=l(t.results)),Array.isArray(t.dies)&&(f.dies=l(t.dies));const u=t.lotStack?.results;if(Array.isArray(u)){const C=u.map(D=>Array.isArray(D)?l(D):void 0);C.some(Boolean)&&(f.stackResults=C.map((D,g)=>D??u[g]))}}if(Array.isArray(t.testDefs)){const u=t.testDefs,C=u.filter(D=>D==null||typeof D.testNumber!="number"||de(D.testNumber));for(const D of u)C.includes(D)||r.add(String(D.testNumber));C.length!==u.length&&(f.testDefs=C)}const y=t.waferConfig?.orientation;if(typeof y=="number"){const u=Number.isFinite(y)?(y%360+360)%360:NaN;u===0||u===90||u===180||u===270?f.orientation=u:(o.orientation++,f.orientation=0)}const m=(u,C,D=`${C}s`)=>`${u} ${u===1?C:D}`,c=[];if(i.hbin&&c.push(m(i.hbin,"hard bin")),i.sbin&&c.push(m(i.sbin,"soft bin")),i.siteNum&&c.push(m(i.siteNum,"site number")),i.testValues&&c.push(m(i.testValues,"test value")),i.testPass&&c.push(m(i.testPass,"pass/fail verdict")),c.length){const u=`buildWaferMap received ${c.join(", ")} of the wrong type (for example ${a}), treated as missing. Bins, sites and test values must be numbers and verdicts true/false \u2014 a bin of "1" is not pass bin 1 \u2014 so those dies have no bin, no site, no value or no verdict, and yield and every chart leave them out. Convert them with Number() (and verdicts to booleans) and rebuild.`;console.warn(`[wafermap] ${u}`),f.warnings.push({code:"input-values-not-numbers",message:u,severity:"error"})}const w=[];if(o.bins&&w.push(`${m(o.bins,"bin")} (legal: whole numbers 0\u2013${qe}) \u2014 those dies have no bin`),o.positions&&w.push(`${m(o.positions,"coordinate")} (legal: whole numbers \u2212${fe} to ${fe}) \u2014 those dies have no position`),r.size&&w.push(`${m(r.size,"test number")} (legal: whole numbers 0\u2013${Je}) \u2014 those tests are left out`),o.values&&w.push(`${m(o.values,"test value")} that ${o.values===1?"is":"are"} not finite \u2014 left out`),o.sites&&w.push(`${m(o.sites,"site number")} (legal: 0\u2013${Qe}) \u2014 those dies have no site`),o.orientation&&w.push("a waferConfig.orientation other than 0, 90, 180 or 270 \u2014 the map is built at 0"),w.length||p){const u=[];w.length&&u.push(`buildWaferMap received values outside the STDF V4 ranges, treated as missing: ${w.join("; ")}.`),p&&u.push(`${m(p,"bin was","bins were")} NaN and ${p===1?"is":"are"} treated as no bin.`);const C=u.join(" ");console.warn(`[wafermap] ${C}`),f.warnings.push({code:"input-values-outside-stdf",message:C,severity:"warning"})}return f}function pe(n){const e=(h,l)=>h!==null&&typeof h=="object"&&h[l]!==void 0,t=Array.isArray(n)?{}:n,i=[],a=(h,l,f)=>{h&&i.push(`\`${l}\` (now \`${f}\`)`)};a(e(t,"data"),"data","results"),a(e(t,"die"),"die","dieConfig"),a(e(t,"stack"),"stack","lotStack"),a(e(t.dieConfig,"origin"),"dieConfig.origin","dieConfig.coordinateOrigin"),a(e(t.waferConfig,"flat"),"waferConfig.flat","waferConfig.notch"),a(e(t.reticleConfig,"anchor"),"reticleConfig.anchor","reticleConfig.anchorDie"),a(e(t.lotStack,"aggr"),"lotStack.aggr","lotStack.method"),a(Array.isArray(t.testDefs)&&t.testDefs.some(h=>e(h,"index")&&!e(h,"testNumber")),"TestDef.index","TestDef.testNumber");const d=e(t.lotStack,"results")?t.lotStack.results:[],o=(Array.isArray(n)?[n]:[t.results,...Array.isArray(d)?d:[]]).filter(h=>Array.isArray(h));if(a(o.some(h=>h.slice(0,100).some(l=>e(l,"values"))),"values","testValues"),!i.length)return;const r=i.length>1,p=`buildWaferMap ignored ${i.join(", ")}: ${r?"these names were":"that name was"} removed in an earlier release, so what ${r?"they":"it"} described is not on this map. Rename and rebuild.`;return console.warn(`[wafermap] ${p}`),{code:"input-field-removed",message:p,severity:"error"}}function ft(n){if(n.results!==void 0||n.lotStack!==void 0)throw new Error("buildWaferMap: pass `layout`, `results` or `lotStack` \u2014 only one.");const e=n.waferConfig?.diameter,t=n.dieConfig?.width,i=n.dieConfig?.height;if(!(e>0&&t>0&&i>0))throw new Error("buildWaferMap: `layout` needs waferConfig.diameter and dieConfig.width and height, all positive.");const a=Q({diameter:e,notch:n.waferConfig?.notch,orientation:0}),d=ke(Oe(a,{width:t,height:i}),a,{width:t,height:i}).filter(l=>!l.partial),{flipX:o,flipY:r}=me(n.dieConfig,{type:"center"}),{layout:p,...h}=n;return{...h,results:d.map(l=>({x:o?-l.x:l.x,y:r?-l.y:l.y})),waferConfig:{...n.waferConfig,center:{x:0,y:0}},dieConfig:{...n.dieConfig,coordinateOrigin:{type:"center"}}}}function lt(n){if(!Array.isArray(n)&&"results"in n&&n.results!==void 0&&"lotStack"in n&&n.lotStack!==void 0)throw new Error("buildWaferMap: pass either `results` or `lotStack`, not both.");const e={wrongVerdicts:0,wrongValues:0,nonFinite:0,badTestNumbers:[]},t=!Array.isArray(n)&&_e(n.results)?{...n,results:Pe(n.results,e).records}:n,i=dt(t,e);return Array.isArray(t)?{results:ne(i.results??t),waferOpts:void 0,dieOpts:void 0,explicitDies:void 0,reticleOpts:void 0,lotStackOpts:void 0,passBins:ce(void 0),ringCount:te(),valueFilter:"validity",ringCountWarning:void 0,removedFieldWarning:pe(t),inputValueWarnings:i.warnings,standardDiameters:void 0,testDefs:void 0,hbinDefs:void 0,sbinDefs:void 0,metadataFields:void 0,derivedTests:void 0,retestPolicy:"last",edgeDieYieldMode:"exclude"}:{results:ne(i.results??t.results??[]),waferOpts:i.orientation===void 0||t.waferConfig===void 0?t.waferConfig:{...t.waferConfig,orientation:i.orientation},dieOpts:t.dieConfig,explicitDies:i.dies??t.dies,reticleOpts:t.reticleConfig,lotStackOpts:t.lotStack?{...t.lotStack,results:(i.stackResults??t.lotStack.results).map(ne)}:void 0,passBins:ce(t.passBins),valueFilter:t.valueFilter??"validity",...at(t.ringCount),removedFieldWarning:pe(t),inputValueWarnings:i.warnings,standardDiameters:t.standardDiameters,testDefs:(i.testDefs??t.testDefs)?.length?i.testDefs??t.testDefs:void 0,hbinDefs:t.hbinDefs,sbinDefs:t.sbinDefs,metadataFields:t.metadataFields,derivedTests:t.derivedTests?.length?t.derivedTests:void 0,retestPolicy:t.retestPolicy??"last",edgeDieYieldMode:t.edgeDieYieldMode??"exclude"}}function ne(n){return n.length>0&&U(n[0])!==void 0?n:re(n).records}function ut(n,e){return e?.coordinateOrigin?e.coordinateOrigin:{type:"center"}}function ct(n,e,t){if(e.type==="custom"&&e.offset)return{offsetX:e.offset.x,offsetY:e.offset.y};if(e.type!=="center"){let i=1/0,a=-1/0,d=1/0,o=-1/0;for(const r of n)r.x<i&&(i=r.x),r.x>a&&(a=r.x),r.y<d&&(d=r.y),r.y>o&&(o=r.y);return{offsetX:Math.round((a+i)/2),offsetY:Math.round((o+d)/2)}}return{offsetX:t.offsetX,offsetY:t.offsetY}}function pt(n,e){if(n.length<xe)return!1;const t=he(n),i=(a,d,o)=>{const r=o-d+1;return a<d-r||a>o+r};return i(Math.round(e.x),t.xMin,t.xMax)||i(Math.round(e.y),t.yMin,t.yMax)}function he(n){let e=1/0,t=-1/0,i=1/0,a=-1/0;for(const d of n){const o=Math.round(d.x),r=Math.round(d.y);o<e&&(e=o),o>t&&(t=o),r<i&&(i=r),r>a&&(a=r)}return{xMin:e,xMax:t,yMin:i,yMax:a}}const ht="The supplied wafer centre";function mt(n,e){const t=he(n);return`${ht} (${e.x}, ${e.y}) is far outside the probed dies (X ${t.xMin}\u2026${t.xMax}, Y ${t.yMin}\u2026${t.yMax}), so it was ignored and the centre was inferred from the dies. Used as given, it would draw a wafer many times the die extent with the dies in one corner. If it is the real centre, supply waferConfig.diameter as well.`}function gt(n,e,t,i,a,d){if(d)return{colMidX:(Math.round(d.x)-e)*i,colMidY:(Math.round(d.y)-t)*a,anchored:!0};if(n.length===0)return{colMidX:0,colMidY:0,anchored:!1};let o=1/0,r=-1/0,p=1/0,h=-1/0;for(const l of n){const f=Math.round(l.x)-e,y=Math.round(l.y)-t;f<o&&(o=f),f>r&&(r=f),y<p&&(p=y),y>h&&(h=y)}return{colMidX:(o+r)/2*i,colMidY:(p+h)/2*a,anchored:!1}}function yt(n,e,t){let i=1/0,a=-1/0,d=1/0,o=-1/0,r=0,p=0;for(const f of n){const y=Math.round(f.x)-e,m=Math.round(f.y)-t;r+=y,p+=m,y<i&&(i=y),y>a&&(a=y),m<d&&(d=m),m>o&&(o=m)}const h=n.length,l=(f,y,m)=>{const c=(m-y)/2;return c<=0?0:Math.abs(f/h-(y+m)/2)/c};return l(r,i,a)>.11||l(p,d,o)>.11}function me(n,e){let t=n?.xAxisDirection==="left",i=n?.yAxisDirection==="down";return(e.type==="UL"||e.type==="UR")&&(i=!0),(e.type==="LR"||e.type==="UR")&&(t=!0),{flipX:t,flipY:i}}function bt(n){const e={...n};return delete e.limitLow,delete e.limitHigh,delete e.limitLowInclusive,delete e.limitHighInclusive,delete e.specLow,delete e.specHigh,e}function wt(n,e){const{method:t,targetBin:i}=n,a=n.results.map(d=>d.filter(W));if(t==="mean"||t==="median"||t==="stddev"||t==="min"||t==="max"||t==="count"){const d=new Set((e??[]).filter(l=>!isParametricTest(l)).map(l=>l.testNumber)),o=new Set;for(const l of a)for(const f of Ee(l,"values"))d.has(f)||o.add(f);if(o.size===0)return ue(a,t);const r=[...o],p=r.map(l=>ue(a,t,l)),h=new Map;for(let l=0;l<r.length;l++){const f=r[l];for(const y of p[l]){const m=X(y);h.has(m)||h.set(m,{template:y,testValues:{}});const c=h.get(m),w=y.testValues?.[0];w!==void 0&&(c.testValues[f]=w)}}return[...h.values()].map(({template:l,testValues:f})=>({...l,testValues:Ze(f)?f:void 0}))}if(t==="countBin"||t==="percent"){if(i===void 0)return[];const d=tt(a,i,"hard");if(t==="countBin")return d;const o=a.length;return d.map(r=>({...r,testValues:{0:o>0?(r.testValues?.[0]??0)/o*100:0}}))}if(t==="mode"){const d=new Map;for(const r of a)for(const p of r){const h=X(p);d.has(h)||d.set(h,[]),d.get(h).push(p)}const o=[];for(const[r,p]of d){const h=r.split(","),l=Number(h[0]),f=Number(h[1]),y=p.map(c=>c.hbin).filter(c=>c!==void 0),m=et(y);m!==null&&o.push({x:l,y:f,hbin:m})}return o}return[]}export function computeCoverage(n){const e=n.filter(W),t=e.length,i=e.filter(d=>d.edgeExcluded).length,a=e.filter(d=>d.hbin!==void 0||d.sbin!==void 0||dieHasTestData(d)).length;return{filledDies:a,totalDies:t,edgeExcludedDies:i,unpositionedDies:n.length-e.length,ratio:t>0?a/t:0}}export function computeYield(n,e,t="exclude",i=!0){const a=new Set(e),o=n.filter(c=>!c.partial).filter(c=>c.edgeExcluded).length,r=n.filter(c=>c.partial).length;if(!i)return{passDies:0,failDies:0,edgeExcludedDies:o,partialDies:r,totalDies:0,yieldPercent:null,yieldPercentGross:null};let p=0,h=0,l=!1;for(const c of n){if(!ve(c))continue;const w=c.hbin??c.sbin;w!==void 0&&(l=!0,a.has(w)?p++:h++)}const f=p+h,y=l&&f>0?p/f*100:null;let m=null;if(t==="denominator-only"){const c=f+o;m=l&&c>0?p/c*100:null}return{passDies:p,failDies:h,edgeExcludedDies:o,partialDies:r,totalDies:f,yieldPercent:y,yieldPercentGross:m}}function ge(n,e,t,i,a,d=0,o=0,r=0,p=0,h=0,l=!1,f=!1){if(!n)return[];const y=n.anchorDie??{x:0,y:0},m=He(e,{width:n.width,height:n.height,diePitchX:i,diePitchY:a,anchorDie:{x:y.x-d,y:y.y-o},gridOrigin:{x:-r,y:-p}}),c=Le(Be(l,f,e.center.x,e.center.y),Ve(h,e.center.x,e.center.y));return m.filter(w=>{const u=w.width/2,C=w.height/2,D=[[w.x-u,w.y-C],[w.x+u,w.y-C],[w.x+u,w.y+C],[w.x-u,w.y+C]].map(([v,T])=>Ye(c,v,T)),g=le(D.map(v=>v.x)),b=ee(D.map(v=>v.x)),k=le(D.map(v=>v.y)),R=ee(D.map(v=>v.y));return t.some(v=>v.physX>=g&&v.physX<b&&v.physY>=k&&v.physY<R)})}function xt(n,e,t){const a=Math.max(0,e.radius-t)**2;return n.map(d=>{const o=d.physX-e.center.x,r=d.physY-e.center.y;return o*o+r*r>a?{...d,edgeExcluded:!0}:d})}const Dt=.2;function Mt(n){const e=new Set;for(const t of n){if(t.supersedes!==void 0||!W(t))return!1;const i=Se(t);if(e.has(i))return!1;e.add(i)}return!0}function vt(n,e,t){if(Mt(n))return{results:n.slice(),warning:void 0};const i=new Set(t);function a(g,b){if(e==="last")return!0;if(e==="first")return!1;const k=G(g.hbin),R=G(b.hbin);if(k===void 0||R===void 0)return!1;const v=i.has(k),T=i.has(R);return e==="best"?T!==v?T:R<k:T!==v?v:R>k}const d=(g,b)=>b.supersedes!==void 0||a(g,b),o=g=>{const b=g.partId===void 0?"":String(g.partId).trim();return b===""?void 0:b},r=n.filter(g=>!W(g)),p=new Map;for(const g of r){const b=o(g);b!==void 0&&p.set(b,(p.get(b)??0)+1)}const l=(r.length===0?0:Math.max(0,...p.values())/r.length)<=Dt,f=new Map,y=[],m=new Map;let c=0,w=0;for(const g of n){const b=o(g);let k;if(W(g)?k=`p:${X(g)}`:l&&b!==void 0?k=`i:${b}`:k=`u:${w++}`,g.supersedes==="partId"&&b!==void 0){const v=m.get(b);v!==void 0&&v!==k&&f.has(v)&&f.delete(v)}const R=f.get(k);R===void 0?(f.set(k,{winner:g,count:1}),y.push(k)):(R.count++,k.startsWith("i:")&&c++,d(R.winner,g)&&(R.winner=g)),b!==void 0&&m.set(b,k)}const u=[],C=[...y.filter(g=>g.startsWith("p:")),...y.filter(g=>!g.startsWith("p:"))];for(const g of C){const b=f.get(g);b!==void 0&&u.push(b.count>1?{...b.winner,retestCount:b.count}:b.winner)}const D=c>0?{code:"retests-by-part-id",severity:"info",message:`${c} record${c===1?"":"s"} with no position shared a part ID with an earlier record and ${c===1?"was":"were"} treated as a retest of it.`}:void 0;return{results:u,warning:D}}export function getDieTestValue(n,e){return Z(n,e)}export function getTestPassStatus(n,e,t){const i=Ne(n,e);return i!==void 0?i:t!==void 0&&!isParametricTest(t)?ye(Z(n,e)):void 0}function ye(n){return n===0||n===1?n===1:void 0}export function testPassStatusReader(n){const e=n.map(a=>a.testNumber),t=Re(e),i=n.map(a=>!isParametricTest(a));return function(d,o){t(d,o);for(let r=0;r<o.length;r++){if(o[r]!==We||!i[r])continue;const p=ye(Z(d,e[r]));p!==void 0&&(o[r]=p?Ie:Te)}return o}}export function dieHasTestData(n){return Ae(n)}function G(n){return n===void 0||Number.isNaN(n)?void 0:n}function q(n,e){const t={},i=G(e.hbin),a=G(e.sbin);i!==void 0&&(t.hbin=i),a!==void 0&&(t.sbin=a),e.retestCount!==void 0&&(t.retestCount=e.retestCount),e.siteNum!==void 0&&(t.siteNum=e.siteNum),e.partId!==void 0&&(t.partId=e.partId),e.metadata!==void 0&&(t.metadata=e.metadata);const d=U(e);return $e({...n,...t},d.table,d.row)}function be(n){return n.some(dieHasTestData)?"value":defaultBinMode([n])}export function defaultBinMode(n){const e=t=>n.some(i=>i.some(a=>t(a)!=null));return e(t=>t.hbin)?"hardBin":e(t=>t.sbin)?"softBin":"hardBin"}function we(n,e){return n.map(({code:t,message:i})=>({code:t,message:i,severity:t==="non-standard-diameter"||t==="diameter-exceeds-die-extent"||t==="implausible-center"?"warning":"error",confidence:e.wafer.confidence}))}const St="do not fit inside the supplied",Ct="Inferred wafer diameter",kt="The probed dies reach only",Ot=.75,xe=20;export const STANDARD_WAFER_DIAMETERS_MM=[100,125,150,200,300];const At=.02;function De(n,e){return e.reduce((t,i)=>Math.abs(i-n)<Math.abs(t-n)?i:t)}function $t(n,e){if(!e.length)return!0;const t=De(n,e);return Math.abs(t-n)/t<=At}function Nt(n){return n===void 0?STANDARD_WAFER_DIAMETERS_MM:n.filter(e=>Number.isFinite(e)&&e>0)}export function buildWaferMap(n){const e=lt(!Array.isArray(n)&&n.layout?ft(n):n),t=[];let i;if(e.valueFilter!=="none"&&e.testDefs){const s=e.valueFilter,x=(e.lotStackOpts?e.lotStackOpts.results:[e.results]).map(O=>{const _=O.length>0?U(O[0]):void 0;if(!_)return[];const E=st(_.table,e.testDefs,s);return E.tests.length>0&&oe(O,E.table),E.tests}),A=rt(x);if(A.length>0){i={mode:s,tests:A};const O=ot(s,A,e.testDefs);O&&t.push(O)}}if(e.derivedTests){const s=new Set(e.passBins),x=_=>{const E=_.length>0?U(_[0]):void 0,H=Ue(_,E?.table??Fe([]),e.testDefs,e.derivedTests,s);return E&&oe(_,H.table),H},O=(e.lotStackOpts?e.lotStackOpts.results:[e.results]).map(x);e.testDefs=O[0]?.testDefs??e.testDefs,t.push(...O[0]?.warnings??[])}e.lotStackOpts&&!nt(e.lotStackOpts.method)&&(e.testDefs=e.testDefs?.map(bt));const a=e.lotStackOpts?re(wt(e.lotStackOpts,e.testDefs)).records:e.results;for(let s=0;s<Math.min(5,a.length);s++){const x=a[s];if(typeof x.x=="string"||typeof x.y=="string")throw new TypeError("buildWaferMap: x and y must be numbers, received strings. Did you forget to cast CSV values? e.g. { x: +row.x, y: +row.y }")}for(const s of a)if(s.x==null!=(s.y==null))throw new TypeError(`buildWaferMap: die has only one of x/y set (x=${String(s.x)}, y=${String(s.y)}). A die must be either fully positioned (both x and y) or fully unpositioned (neither) \u2014 omit both to mark a die as having no reported position.`);const{results:d,warning:o}=vt(a,e.retestPolicy,e.passBins),r={wafer:{confidence:1,method:"provided"},diePitch:{confidence:1,units:"mm"},grid:{confidence:1}},p=[];if(e.explicitDies){let s=e.explicitDies.filter(W);const x=e.explicitDies.filter(B=>!W(B)),A=d.filter(W),O=d.filter(B=>!W(B));if(A.length>0){const B=new Map(A.map(V=>[X(V),V]));s=s.map(V=>{const ie=B.get(X(V));return ie?q(V,ie):V})}const _=e.waferOpts?.diameter??300,E=Q({diameter:_,notch:e.waferOpts?.notch,orientation:e.waferOpts?.orientation??0,metadata:e.waferOpts?.metadata,reticle:e.reticleOpts});E.orientation!==0&&(s=se(s,E)),s=s.map(z);const H=ge(e.reticleOpts,E,s,1,1,0,0,0,0,E.orientation),Me=O.map((B,V)=>z(q({id:`unpositioned_${V}`,width:s[0]?.width??1,height:s[0]?.height??1},B))),J=[...s,...x,...Me];return{wafer:E,dies:J,dataAxisFlip:{x:!1,y:!1},reticleConfig:e.reticleOpts,units:"mm",inference:r,warnings:[...e.removedFieldWarning?[e.removedFieldWarning]:[],...e.inputValueWarnings,...o?[o]:[],...we(p,r),...t,...e.ringCountWarning?[e.ringCountWarning]:[]],plotMode:be(d),metadata:E.metadata??null,isLotStack:!1,dataCoverage:computeCoverage(J),passBins:e.passBins,...i?{valueFilter:i}:{},ringCount:e.ringCount,yield:computeYield(J,e.passBins,e.edgeDieYieldMode),reticles:H,hbinDefs:e.hbinDefs,sbinDefs:e.sbinDefs,testDefs:e.testDefs,metadataFields:e.metadataFields}}const h=d.filter(W),l=d.filter(s=>!W(s)),f=h.map(s=>({x:s.x,y:s.y})),y=Ke(f,e.dieOpts,e.waferOpts?.diameter);r.diePitch={confidence:y.confidence,units:y.units};const{pitchX:m,pitchY:c}=y,w=y.units,u=ut(h,e.dieOpts),C=je(f);r.grid={confidence:C.confidence};const{offsetX:D,offsetY:g}=ct(f,u,C),{flipX:b,flipY:k}=me(e.dieOpts,u),R=e.waferOpts?.diameter===void 0&&e.waferOpts?.center!==void 0&&pt(f,e.waferOpts.center),v=R?void 0:e.waferOpts?.center;R&&p.push({code:"implausible-center",message:mt(f,e.waferOpts.center)});const{colMidX:T,colMidY:L,anchored:K}=gt(f,D,g,m,c,v);let S=e.waferOpts?.diameter;const N=f.map(s=>({x:(Math.round(s.x)-D)*m-T,y:(Math.round(s.y)-g)*c-L})),M=ee(N.map(({x:s,y:x})=>Math.hypot(Math.abs(s)+m/2,Math.abs(x)+c/2)));if(S===void 0)if(f.length>0)if(w==="mm"){const s=Xe(N,{minRadius:M});S=s.diameter,r.wafer={confidence:s.confidence,method:s.method};const x=Nt(e.standardDiameters);if(!$t(S,x)){const A=De(S,x);p.push({code:"non-standard-diameter",message:`${Ct} ${S.toFixed(1)} mm is not a standard wafer size (nearest is ${A} mm). The diameter was derived from the die extent, which assumes the probed grid reaches the wafer edge \u2014 a non-standard result usually means it does not, because the outer dies were never probed. Every die is then placed against a wafer that is too small, which moves dies between rings and changes ring and edge findings. Supply waferConfig.diameter.`})}}else S=M*2,r.wafer={confidence:y.confidence*.8,method:"extent"};else S=w==="mm"?300:30,r.wafer={confidence:0,method:"default"};if(!K&&f.length>0&&yt(f,D,g)&&(r.wafer.method="inferred-partial",p.push({code:"partial-coverage",message:"Wafer geometry was inferred from die positions alone. The data does not span a full symmetric wafer, so the inferred diameter and centre may be wrong and dies may be mis-positioned relative to the true wafer boundary. Supply waferConfig.diameter and waferConfig.center (the prober coordinate of the wafer centre) to position partial data correctly."})),e.waferOpts?.diameter!==void 0&&v===void 0&&M>0&&f.length>=xe){const s=M/(S/2);s<Ot&&p.push({code:"diameter-exceeds-die-extent",message:`${kt} ${(s*100).toFixed(0)}% of the ${S} mm wafer's radius. Either the diameter is larger than the real one, or this is a partial map covering only part of the wafer. Ring bands are equal-radius, so the outer rings are mostly or entirely empty and ring, quadrant and edge findings describe the assumed wafer rather than the probed area. Check waferConfig.diameter, or drop it and let the diameter be inferred from the die extent.`})}if(e.waferOpts?.diameter!==void 0){const s=e.dieOpts?.width!==void 0&&e.dieOpts?.height!==void 0;if(s&&M>S/2+1e-9){const x=N.filter(({x:A,y:O})=>Math.hypot(Math.abs(A)+m/2,Math.abs(O)+c/2)>S/2+1e-9).length;p.push({code:"geometry-conflict",message:`${x} of ${N.length} probed die positions ${St} ${S} mm wafer at the supplied die pitch of ${m} \xD7 ${c} mm. A die with test results is a real prober position and is always fully on the wafer, so one of the two supplied values must be wrong: containing these dies at this pitch would need a diameter of at least ${(M*2).toFixed(1)} mm. Check waferConfig.diameter and dieConfig.width/height against the real device.`})}}const F=Q({diameter:S,units:w,notch:e.waferOpts?.notch,orientation:e.waferOpts?.orientation??0,metadata:e.waferOpts?.metadata,reticle:e.reticleOpts});let $=h.map(s=>{const x=Math.round(s.x)-D,A=Math.round(s.y)-g,O={id:`${x}_${A}`,x,y:A,physX:x*m-T,physY:A*c-L,width:m,height:c,insideWafer:!0,partial:!1};return q(O,s)});(D!==0||g!==0)&&($=$.map(s=>({...s,x:s.x+D,y:s.y+g,id:`${s.x+D}_${s.y+g}`}))),$=se($,F),(b||k)&&($=Ce($,{flipX:b,flipY:k},F.center));const Y=[];e.waferOpts?.edgeExclusion&&e.waferOpts.edgeExclusion>0&&($=xt($,F,e.waferOpts.edgeExclusion),e.waferOpts.edgeExclusion>F.radius&&Y.push({code:"edge-exclusion-exceeds-radius",message:`edgeExclusion (${e.waferOpts.edgeExclusion}mm) exceeds the resolved wafer radius (${F.radius}mm) \u2014 the entire wafer is excluded.`,severity:"warning"})),$=$.map(z);const j=ge(e.reticleOpts,F,$,m,c,D,g,T,L,F.orientation,b,k),P=l.map((s,x)=>z(q({id:`unpositioned_${x}`,width:m,height:c},s))),I=[...$,...P];return{wafer:F,dies:I,dataAxisFlip:{x:b,y:k},reticleConfig:e.reticleOpts,units:w,inference:r,warnings:[...e.removedFieldWarning?[e.removedFieldWarning]:[],...e.inputValueWarnings,...o?[o]:[],...we(p,r),...Y,...t,...e.ringCountWarning?[e.ringCountWarning]:[]],plotMode:be(d),metadata:F.metadata??null,isLotStack:e.lotStackOpts!==void 0,dataCoverage:computeCoverage(I),passBins:e.passBins,...i?{valueFilter:i}:{},ringCount:e.ringCount,yield:computeYield(I,e.passBins,e.edgeDieYieldMode,it(e.lotStackOpts!==void 0,e.lotStackOpts?.method)),reticles:j,hbinDefs:e.hbinDefs,sbinDefs:e.sbinDefs,testDefs:e.testDefs,metadataFields:e.metadataFields,aggrMethod:e.lotStackOpts?.method,lotSize:e.lotStackOpts?.results.length}}
@@ -13,11 +13,10 @@ export declare const DEPRECATED_REMOVAL_VERSION = "0.32.0";
13
13
  */
14
14
  export declare const DEPRECATED_REMOVALS: Map<string, string>;
15
15
  /**
16
- * @internal Every name deprecated through this module, and whether it is a function
17
- * (which logs a notice) or a value (which cannot). tests/deprecations.test.mjs pins
16
+ * @internal Every name deprecated through this module. tests/deprecations.test.mjs pins
18
17
  * it to the announced list, so a deprecation cannot be added or dropped silently.
19
18
  */
20
- export declare const DEPRECATED_EXPORTS: Map<string, "function" | "value">;
19
+ export declare const DEPRECATED_EXPORTS: Map<string, "function">;
21
20
  /**
22
21
  * @internal Log `message` once per `key` for the life of the page — the one
23
22
  * copy of the once-only rule, for export deprecations (`deprecated`) and for
@@ -31,9 +30,4 @@ export declare function noticeOnce(key: string, message: string): void;
31
30
  * deprecated export's signature does not change until it is removed.
32
31
  */
33
32
  export declare function deprecated<F extends (...args: never[]) => unknown>(fn: F, name: string, advice: string, removal?: string): F;
34
- /**
35
- * @internal Register a deprecated constant. A value cannot log on use, so its
36
- * `@deprecated` tag and the changelog are the only announcement.
37
- */
38
- export declare function deprecatedValue<T>(value: T, name: string, removal?: string): T;
39
33
  //# sourceMappingURL=deprecate.d.ts.map
@@ -1 +1 @@
1
- export const DEPRECATED_REMOVAL_VERSION="0.32.0",DEPRECATED_REMOVALS=new Map,DEPRECATED_EXPORTS=new Map;const r=new Set;export function noticeOnce(t,e){r.has(t)||(r.add(t),console.warn(`[wafermap] ${e}`))}export function deprecated(t,e,n,o=DEPRECATED_REMOVAL_VERSION){DEPRECATED_EXPORTS.set(e,"function"),DEPRECATED_REMOVALS.set(e,o);const c=t;return((...E)=>(noticeOnce(e,`${e} is deprecated and will be removed in ${o}. ${n}`),c(...E)))}export function deprecatedValue(t,e,n=DEPRECATED_REMOVAL_VERSION){return DEPRECATED_EXPORTS.set(e,"value"),DEPRECATED_REMOVALS.set(e,n),t}
1
+ export const DEPRECATED_REMOVAL_VERSION="0.32.0",DEPRECATED_REMOVALS=new Map,DEPRECATED_EXPORTS=new Map;const o=new Set;export function noticeOnce(t,e){o.has(t)||(o.add(t),console.warn(`[wafermap] ${e}`))}export function deprecated(t,e,c,n=DEPRECATED_REMOVAL_VERSION){DEPRECATED_EXPORTS.set(e,"function"),DEPRECATED_REMOVALS.set(e,n);const r=t;return((...E)=>(noticeOnce(e,`${e} is deprecated and will be removed in ${n}. ${c}`),r(...E)))}
@@ -1 +1 @@
1
- import{stepDecimals as m}from"./axisTicks.js";const p=[[1e12,"T"],[1e9,"G"],[1e6,"M"],[1e3,"k"],[1,""],[.001,"m"],[1e-6,"\xB5"],[1e-9,"n"],[1e-12,"p"],[1e-15,"f"]];export const SI_PREFIX_SCALE={T:1e12,G:1e9,M:1e6,k:1e3,m:.001,\u00B5:1e-6,u:1e-6,n:1e-9,p:1e-12,f:1e-15},KNOWN_BASE_UNITS=["Hz","V","A","W","F","\u03A9","Ohm","ohm","S","H","J","C","s"];function M(t){for(const e of KNOWN_BASE_UNITS)if(t.length===e.length+1&&t.endsWith(e)){const r=t[0];if(r in SI_PREFIX_SCALE)return{preScale:SI_PREFIX_SCALE[r],base:e}}return{preScale:1,base:t}}function F(t,e){const{preScale:r,base:n}=M(e),o=t*r,i=Math.abs(o),[c,b]=p.find(([s])=>i>=s*.9999)??[1e-15,"f"],f=o/c,h=Math.abs(f),u=h>=100?0:h>=10?1:2;return`${f.toFixed(u)} ${b}${n}`}function $(t){const e=Math.abs(t),r=Math.floor(Math.log10(e)/3)*3,n=Math.max(-15,Math.min(12,r)),o=t/Math.pow(10,n),i=Math.abs(o),c=i>=100?0:i>=10?1:2,b=n===0?"":`E${n>0?"+":""}${n}`;return`${o.toFixed(c)}${b}`}export const AGGREGATION_METHOD_LABELS={mean:"mean",median:"median",stddev:"std dev",min:"min",max:"max",count:"count",countBin:"occurrence count",percent:"occurrence %"};export function fmtAggregationMethod(t){return AGGREGATION_METHOD_LABELS[t??""]??t??"aggregated"}export function plainBinTerms(t){return t.replace(/\bHBin\b/g,"hard bin").replace(/\bSBin\b/g,"soft bin")}export function fmtExact(t){if(!Number.isFinite(t)||Math.fround(t)!==t)return String(t);for(let e=1;e<=9;e++){const r=Number(t.toPrecision(e));if(Math.fround(r)===t)return String(r)}return String(t)}export function fmt(t,e,r){if(!isFinite(t))return String(t);const n=Math.abs(t);return n===0?e?`0 ${e}`:"0":e!==void 0?F(t,e):r==="si"?F(t,""):n>=.1&&n<1e4?n>=1e3?t.toFixed(0):n>=100?t.toFixed(1):n>=10?t.toFixed(2):t.toFixed(3):$(t)}function E(t,e){const r=e!==void 0&&e>0?m(e/t):void 0;return n=>{if(!isFinite(n))return String(n);if(n===0)return"0";const o=n/t;if(r!==void 0)return o.toFixed(r);const i=Math.abs(o),c=i>=100?0:i>=10?1:2;return o.toFixed(c)}}function A(t,e,r){if(e===void 0||!(e>0))return r;const n=m(e/t)+1;return o=>{if(!isFinite(o))return String(o);if(o===0)return"0";const i=(o/t).toFixed(n);return i.endsWith("0")?i.slice(0,n===1?-2:-1):i}}export function fmtColorbarAxis(t,e,r,n="engineering",o){const i=Math.abs(t),c=(s,d,a,x)=>{const g=x&&o===void 0?x:E(s,o);return{tickFmt:g,edgeFmt:A(s,o,g),axisLabel:d,scaledUnit:a}};if(r){const{preScale:s,base:d}=M(r),a=i*s,[x,g]=a===0?[1,""]:p.find(([S])=>a>=S*.9999)??[1e-15,"f"],l=`${g}${d}`;return c(x/s,e?`${e} (${l})`:l,l)}if(i===0||i>=.1&&i<1e4)return c(1,e??"","",s=>fmt(s,void 0,n));if(n==="si"){const[s]=p.find(([x])=>i>=x*.9999)??[1e-15,"f"],d=Math.round(Math.log10(s)),a=d===0?"":`\xD710E${d}`;return c(s,e?a?`${e} (${a})`:e:a,a)}const b=Math.floor(Math.log10(i)/3)*3,f=Math.max(-15,Math.min(12,b)),h=Math.pow(10,f),u=f===0?"":`\xD710E${f}`;return c(h,e?u?`${e} (${u})`:e:u,u)}
1
+ import{stepDecimals as p}from"./axisTicks.js";const M=[[1e12,"T"],[1e9,"G"],[1e6,"M"],[1e3,"k"],[1,""],[.001,"m"],[1e-6,"\xB5"],[1e-9,"n"],[1e-12,"p"],[1e-15,"f"]];export const SI_PREFIX_SCALE={T:1e12,G:1e9,M:1e6,k:1e3,m:.001,\u00B5:1e-6,u:1e-6,n:1e-9,p:1e-12,f:1e-15},KNOWN_BASE_UNITS=["Hz","V","A","W","F","\u03A9","Ohm","ohm","S","H","J","C","s"];function m(t){for(const e of KNOWN_BASE_UNITS)if(t.length===e.length+1&&t.endsWith(e)){const r=t[0];if(r in SI_PREFIX_SCALE)return{preScale:SI_PREFIX_SCALE[r],base:e}}return{preScale:1,base:t}}function F(t,e){const{preScale:r,base:n}=m(e),o=t*r,i=Math.abs(o),[c,h]=M.find(([s])=>i>=s*.9999)??[1e-15,"f"],f=o/c,b=Math.abs(f),u=b>=100?0:b>=10?1:2;return`${f.toFixed(u)} ${h}${n}`}function $(t){const e=Math.abs(t);if(e===0)return"0%";const r=e>=100?0:e>=10?1:e>=1?2:Math.min(6,1-Math.floor(Math.log10(e)));return`${t.toFixed(r)}%`}function E(t){const e=Math.abs(t),r=Math.floor(Math.log10(e)/3)*3,n=Math.max(-15,Math.min(12,r)),o=t/Math.pow(10,n),i=Math.abs(o),c=i>=100?0:i>=10?1:2,h=n===0?"":`E${n>0?"+":""}${n}`;return`${o.toFixed(c)}${h}`}export const AGGREGATION_METHOD_LABELS={mean:"mean",median:"median",stddev:"std dev",min:"min",max:"max",count:"count",countBin:"occurrence count",percent:"occurrence %"};export function fmtAggregationMethod(t){return AGGREGATION_METHOD_LABELS[t??""]??t??"aggregated"}export function plainBinTerms(t){return t.replace(/\bHBin\b/g,"hard bin").replace(/\bSBin\b/g,"soft bin")}export function fmtExact(t){if(!Number.isFinite(t)||Math.fround(t)!==t)return String(t);for(let e=1;e<=9;e++){const r=Number(t.toPrecision(e));if(Math.fround(r)===t)return String(r)}return String(t)}export function fmt(t,e,r){if(!isFinite(t))return String(t);if(e==="%")return $(t);const n=Math.abs(t);return n===0?e?`0 ${e}`:"0":e!==void 0?F(t,e):r==="si"?F(t,""):n>=.1&&n<1e4?n>=1e3?t.toFixed(0):n>=100?t.toFixed(1):n>=10?t.toFixed(2):t.toFixed(3):E(t)}function A(t,e){const r=e!==void 0&&e>0?p(e/t):void 0;return n=>{if(!isFinite(n))return String(n);if(n===0)return"0";const o=n/t;if(r!==void 0)return o.toFixed(r);const i=Math.abs(o),c=i>=100?0:i>=10?1:2;return o.toFixed(c)}}function T(t,e,r){if(e===void 0||!(e>0))return r;const n=p(e/t)+1;return o=>{if(!isFinite(o))return String(o);if(o===0)return"0";const i=(o/t).toFixed(n);return i.endsWith("0")?i.slice(0,n===1?-2:-1):i}}export function fmtColorbarAxis(t,e,r,n="engineering",o){const i=Math.abs(t),c=(s,d,a,x)=>{const g=x&&o===void 0?x:A(s,o);return{tickFmt:g,edgeFmt:T(s,o,g),axisLabel:d,scaledUnit:a}};if(r==="%")return c(1,e?`${e} (%)`:"%","%");if(r){const{preScale:s,base:d}=m(r),a=i*s,[x,g]=a===0?[1,""]:M.find(([S])=>a>=S*.9999)??[1e-15,"f"],l=`${g}${d}`;return c(x/s,e?`${e} (${l})`:l,l)}if(i===0||i>=.1&&i<1e4)return c(1,e??"","",s=>fmt(s,void 0,n));if(n==="si"){const[s]=M.find(([x])=>i>=x*.9999)??[1e-15,"f"],d=Math.round(Math.log10(s)),a=d===0?"":`\xD710E${d}`;return c(s,e?a?`${e} (${a})`:e:a,a)}const h=Math.floor(Math.log10(i)/3)*3,f=Math.max(-15,Math.min(12,h)),b=Math.pow(10,f),u=f===0?"":`\xD710E${f}`;return c(b,e?u?`${e} (${u})`:e:u,u)}
@@ -140,15 +140,4 @@ export declare function derivedKeyText(entries: ReadonlyArray<{
140
140
  derived?: true;
141
141
  expression?: string;
142
142
  }>): string | undefined;
143
- /**
144
- * True when any test in this population is derived — the gate for reserving a
145
- * marker gutter in a view.
146
- *
147
- * Reserving it per view rather than per row is what keeps the marker from
148
- * shifting content relative to itself: every row of a view indents equally, so
149
- * the markers align in a column instead of leaving a ragged edge, and a
150
- * population with no derived tests — the common case — is unchanged to the
151
- * pixel.
152
- */
153
- export declare function hasDerivedTests(defs: readonly TestDef[] | undefined): boolean;
154
143
  //# sourceMappingURL=testLabel.d.ts.map
@@ -1 +1 @@
1
- export const DERIVED_MARK="\u2020",DERIVED_KEY="Derived, not measured";export function isDerivedTest(e){return e?.derived===!0}export function testLabel(e,r){const t=e?.name;return t!==void 0&&t!==""?t:`Test ${r}`}export function markedTestLabel(e,r){const t=testLabel(e,r);return e?.derived===!0?`\u2020 ${t}`:t}export const DERIVED_LANE_PAD="\u2007\u2009";export function derivedTestNote(e){if(!isDerivedTest(e))return;const r=derivedTestSource(e);return r?`\u2020 ${DERIVED_KEY}: ${r}`:`\u2020 ${DERIVED_KEY}`}export function derivedTestSource(e){if(!(!isDerivedTest(e)||!e?.expression))return e.expression}export function derivedFields(e){return isDerivedTest(e)?e.expression!==void 0?{derived:!0,expression:e.expression}:{derived:!0}:{}}export function unmarkedLabel(e){return e.startsWith("\u2020 ")?e.slice(2):e}export const DERIVED_CSV_HEADER="Derived from";export function derivedCsvCell(e){return isDerivedTest(e)?derivedTestSource(e)??DERIVED_KEY:""}export function derivedKeyText(e){const r=new Map;for(const n of e){if(!isDerivedTest(n))continue;const i=unmarkedLabel(n.label);r.has(i)||r.set(i,n.expression)}if(r.size===0)return;const t=[...r].map(([n,i])=>i?`${n}: ${i}`:n);return`\u2020 ${DERIVED_KEY} \u2014 ${t.join("; ")}`}export function hasDerivedTests(e){return(e??[]).some(isDerivedTest)}
1
+ export const DERIVED_MARK="\u2020",DERIVED_KEY="Derived, not measured";export function isDerivedTest(e){return e?.derived===!0}export function testLabel(e,r){const n=e?.name;return n!==void 0&&n!==""?n:`Test ${r}`}export function markedTestLabel(e,r){const n=testLabel(e,r);return e?.derived===!0?`\u2020 ${n}`:n}export const DERIVED_LANE_PAD="\u2007\u2009";export function derivedTestNote(e){if(!isDerivedTest(e))return;const r=derivedTestSource(e);return r?`\u2020 ${DERIVED_KEY}: ${r}`:`\u2020 ${DERIVED_KEY}`}export function derivedTestSource(e){if(!(!isDerivedTest(e)||!e?.expression))return e.expression}export function derivedFields(e){return isDerivedTest(e)?e.expression!==void 0?{derived:!0,expression:e.expression}:{derived:!0}:{}}export function unmarkedLabel(e){return e.startsWith("\u2020 ")?e.slice(2):e}export const DERIVED_CSV_HEADER="Derived from";export function derivedCsvCell(e){return isDerivedTest(e)?derivedTestSource(e)??DERIVED_KEY:""}export function derivedKeyText(e){const r=new Map;for(const t of e){if(!isDerivedTest(t))continue;const i=unmarkedLabel(t.label);r.has(i)||r.set(i,t.expression)}if(r.size===0)return;const n=[...r].map(([t,i])=>i?`${t}: ${i}`:t);return`\u2020 ${DERIVED_KEY} \u2014 ${n.join("; ")}`}
@@ -46,4 +46,10 @@ export interface AnalyzeWaferLotAsyncOptions extends AnalyzeWaferMapOptions {
46
46
  * and before the lot-level pass.
47
47
  */
48
48
  export declare function analyzeWaferLotAsync(items: AnalyzeWaferLotInput, options?: AnalyzeWaferLotAsyncOptions): Promise<LotStatsSummary>;
49
+ /**
50
+ * A lot analysed over some of a caller's wafers, with every wafer index put back to the caller's own: `positions[i]` is
51
+ * where the wafer given i-th sits in the caller's list. A filter's lot analysis covers only the wafers it keeps, yet
52
+ * the gallery's cards, rows and highlights are numbered by the whole list.
53
+ */
54
+ export declare function remapLotWaferIndices(lot: LotStatsSummary, positions: readonly number[]): LotStatsSummary;
49
55
  //# sourceMappingURL=analyzeWaferLot.d.ts.map
@@ -1 +1 @@
1
- import{waferDisplayLabel as oe}from"../core/waferLabel.js";import{requireRingCount as ce}from"../core/ringCount.js";import{analyzeWaferMapDecided as T,candidatesOf as H,describeRegional as U,resolveOptions as le,adjustPValues as fe,testValueSize as de,recordedOptions as ue,twoProportionZ as Q,welchOfSums as X,rateRelativeEffect as me,passesRateGate as pe,severityForFinding as Z,severityForScore as J,collapseRedundantFindings as ge,findContiguousRuns as he,mergedRegionLabel as ye}from"./analyzeWaferMap.js";import{normalizeInput as ee}from"./normalizeInput.js";import{autoDecision as we,lotTestValueStatus as be}from"./testValueBudget.js";import{poolCapability as Se,poolRegionYield as ve,poolPassRates as ze}from"./summaryFigures.js";import{mergeTestDefs as Ie}from"./mergeTestDefs.js";import{findingPatternKey as ke}from"./filterFindings.js";import{median as te}from"../core/utils.js";import{robustFence as ne,zPValue as F}from"./math.js";import{findLotPattern as Pe}from"./lotPattern.js";import{buildDriftFindings as Re}from"./lotDrift.js";import{claimForPattern as Me,confirmRegionalFindings as xe,weakestMultiplier as $e}from"./analyzeWaferMap.js";import{PATTERN_LABELS as De}from"./patternClassification.js";import{describeWaferPopulation as Be,populationStat as Le}from"./population.js";const W=8,Ee={3:[.97,.994],4:[.829,.926],5:[.71,.821],6:[.625,.74],7:[.568,.68]},qe=3;export function outlierWafers(e){const a=e.length;if(a<3)return null;const s=te([...e]),o=t=>Math.abs(t-s)>=qe;if(a>=W){const t=ne(e,1.5,W),d=ne(e,3,W);if(!t||!d)return null;const u=(t.hi-t.lo)/4,w=[];return e.forEach((y,l)=>{if(y>=t.lo&&y<=t.hi||!o(y))return;const f=y<d.lo||y>d.hi?"unusual":"notable";w.push({index:l,severity:f,statistic:(y-s)/u})}),{method:"tukey-fence",outliers:w}}const r=e.map((t,d)=>d).sort((t,d)=>e[t]-e[d]),m=e[r[a-1]]-e[r[0]];if(m===0)return null;const[i,c]=Ee[a],p=[],h=(t,d)=>{const u=Math.abs(e[t]-e[d])/m;u>i&&o(e[t])&&p.push({index:t,severity:u>c?"unusual":"notable",statistic:u})};return h(r[0],r[1]),h(r[a-1],r[a-2]),{method:"dixon-q",outliers:p}}const K=2;function O(e,a){const s={info:0,notable:1,unusual:2};return s[e]>=s[a]?e:a}const Ae=new Set(["ring","quadrant","sector"]),Fe=new Set(["ring","quadrant","sector","reticle-position","test-site"]),Ke=new Set(["yield","hardBin","softBin","functionalTest","test"]);function Ne(e){return Fe.has(e.comparison.family)&&Ke.has(e.variable.kind)}function Te(e,a){const s=e.map(i=>i.facts);if(!s.length||s.some(i=>!i))return{coincident:new Set,yieldSoftBin:void 0,passBins:[],sectorCount:a};const[o,...r]=s,m=r.every(i=>i.passBins.length===o.passBins.length&&i.passBins.every(c=>o.passBins.includes(c)));return{coincident:new Set([...o.coincident].filter(i=>r.every(c=>c.coincident.has(i)))),yieldSoftBin:r.every(i=>i.yieldSoftBin===o.yieldSoftBin)?o.yieldSoftBin:void 0,passBins:m?o.passBins:[],sectorCount:a}}function V(e,a){let s=0,o=0,r=0,m=0,i=0,c=0,p=0,h=0,t=0,d=!0,u=0;for(const{waferIndex:l,c:f}of e){const n=a(l,f),g=f.rate??f.mean,b=Math.sqrt(g.n+n.n);if(f.rate)s+=b*Q(f.rate.hits,f.rate.n,n.hits,n.n),r+=f.rate.hits,m+=f.rate.n,i+=n.hits,c+=n.n;else{const v=X(f.mean,n.n,n.sum,n.sq);s+=b*v.z,p+=f.mean.n*v.effectSize,h+=f.mean.n*v.delta,u+=f.mean.n,f.relativeDelta===void 0?d=!1:t+=f.mean.n*f.relativeDelta}o+=b*b}const w=o>0?s/Math.sqrt(o):0,y=e[0].c;if(y.rate){const l=i/c,f=r/m-l;return{z:w,delta:f,relativeDelta:l===0?void 0:f/l,size:me({hits:r,n:m,restHits:i,restN:c,passRate:y.rate.passRate})}}return{z:w,delta:h/u,relativeDelta:d?t/u:void 0,size:p/u}}function _(e,a,s,o){return e.rate?pe(a,s.delta,s.size,o):a<=o.significanceLevel&&Math.abs(s.size)>=o.minimumEffectSize}function We(e,a,s,o){const r=new Map;for(const{waferIndex:l,byKey:f}of e)for(const n of f.values())(r.get(n.key)??r.set(n.key,[]).get(n.key)).push({waferIndex:l,c:n});const m=new Map(e.map(l=>[l.waferIndex,l.byKey])),i=(l,f)=>f.rate?{hits:f.rate.restHits,n:f.rate.restN,sum:0,sq:0}:{hits:0,n:f.mean.restN,sum:f.mean.restSum,sq:f.mean.restSq},c=[];for(const[l,f]of r){if(f.length<K)continue;const n=V(f,i);if(n.z===0)continue;const g=f[0].c;c.push({key:l,entries:f,combined:n,finding:{id:`lot-region:${l}`,level:"lot",severity:"info",variable:{...g.variable,label:g.label},comparison:{...g.comparison},effect:{direction:n.z>0?"higher":"lower",absoluteDelta:n.delta,relativeDelta:n.relativeDelta,effectSize:g.rate?n.delta:n.size},stats:{method:"stouffer-z",pValue:F(n.z),sampleSizeLeft:0,sampleSizeRight:0},summary:"",highlight:{kind:"wafer",waferIndices:[]}}})}fe(c.map(l=>l.finding));const p=c.filter(l=>_(l.entries[0].c,l.finding.stats.adjustedPValue??1,l.combined,a)),d=xe(p,l=>{const f=l.entries[0].c;return[f.source,f.variable.kind,f.variable.bin??"",f.variable.index??"",f.region.family].join("\0")},(l,f)=>{const n=(M,D)=>{const k=i(M,D);for(const z of f){const R=m.get(M)?.get(z.key);R&&(R.rate?(k.hits-=R.rate.hits,k.n-=R.rate.n):(k.n-=R.mean.n,k.sum-=R.mean.sum,k.sq-=R.mean.sq))}return k},g=l.entries.filter(M=>n(M.waferIndex,M.c).n>=a.minimumSampleSize);if(!g.length)return"baseline-too-small";const b=V(g,n),v=l.finding.stats.pValue??1,P=v>0?(l.finding.stats.adjustedPValue??v)/v:1,S=Math.min(1,F(b.z)*P);return{pValue:S,passes:Math.sign(b.z)===Math.sign(l.combined.z)&&_(l.entries[0].c,S,b,a)}},l=>{const f=l.entries[0].c.rate;return f!==void 0&&(f.passRate?l.combined.z<0:l.combined.z>0)},c),u=[],w=new Map;for(const l of p){if(!d.has(l))continue;const f=l.finding.stats.pValue??1,n=Math.sign(l.combined.z),g=l.entries.filter(z=>Math.sign(z.c.delta)===n),b=e.length,v=l.entries[0].c,P=l.finding.stats.adjustedPValue??f,S=v.rate?Z(P,l.combined.delta,l.combined.size):J(P,l.combined.size),M=O(S,g.length/b>=.6?"unusual":"info"),D={};for(const z of g)D[z.waferIndex]=[...z.c.region.dieKeys];const k={...l.finding,severity:M,stats:{...l.finding.stats,sampleSizeLeft:g.length,sampleSizeRight:b-g.length},summary:`${U(v,l.combined.delta,l.combined.relativeDelta)} \u2014 ${l.finding.effect.direction} on ${g.length}/${b} wafers, all wafers' data combined`,highlight:{kind:"wafer",waferIndices:g.map(z=>z.waferIndex),dieKeysByWafer:D}};u.push(k),w.set(k,l)}const y=Oe(w,m,e.length,a,o,i);return u.splice(0,u.length,...u.filter(l=>!y.replaced.has(l)),...y.findings),ge(u,s),u}function Oe(e,a,s,o,r,m){const i=new Map;for(const[h,t]of e){const d=t.entries[0].c;if(!Ae.has(d.region.family))continue;const u=[d.source,d.variable.kind,d.variable.bin??"",d.variable.index??"",d.region.family,h.effect.direction].join("|");(i.get(u)??i.set(u,[]).get(u)).push({finding:h,c:d,key:t.key})}const c=[],p=new Set;for(const h of i.values()){if(h.length<2)continue;const t=h[0].c.region.family;for(const d of he(h,t,o.sectorCount,u=>u.c.region.key)){if(d.length<2)continue;const u=Ve(d,a,s,o,r,m);if(u){c.push(u);for(const w of d)p.add(w.finding)}}}return{findings:c,replaced:p}}function Ve(e,a,s,o,r,m){const i=e[0].c,c=e[0].finding.effect.direction==="higher"?1:-1,p=ye(i.region.family,e.map(S=>S.c.region.key),r),h=[];for(const[S,M]of a){const D=e.map(I=>M.get(I.key));if(D.some(I=>!I))continue;const k=D,z=k[0];let R,N;if(z.rate){const I=k.reduce(($,B)=>$+B.rate.hits,0),x=k.reduce(($,B)=>$+B.rate.n,0),E=z.rate.hits+z.rate.restHits-I,L=z.rate.n+z.rate.restN-x;if(x<o.minimumSampleSize||L<o.minimumSampleSize)continue;R={...z,rate:{hits:I,n:x,restHits:E,restN:L,passRate:z.rate.passRate}},N=Q(I,x,E,L)}else{const I=z.mean,x=k.reduce((q,A)=>q+A.mean.n,0),E=k.reduce((q,A)=>q+A.mean.sum,0),L=k.reduce((q,A)=>q+A.mean.sq,0),$=I.n+I.restN-x,B=I.sum+I.restSum-E,j=I.sq+I.restSq-L;if(x<o.minimumSampleSize||$<o.minimumSampleSize)continue;const C={n:x,sum:E,sq:L,restN:$,restSum:B,restSq:j,shift:I.shift},Y=X(C,$,B,j),G=B/$+I.shift;R={...z,mean:C,relativeDelta:G!==0?Y.delta/Math.abs(G):void 0},N=Y.z}const re=[...new Set(k.flatMap(I=>[...I.region.dieKeys]))];h.push({waferIndex:S,c:R,z:N,dieKeys:re})}if(h.length<K)return;const t=V(h,m);if(t.z===0||Math.sign(t.z)!==c)return;const d=F(t.z),u=$e(e.map(S=>S.finding)),w=Math.min(1,d*u);if(!_(i,w,t,o))return;const y=h.filter(S=>Math.sign(S.z)===c&&F(S.z)<=o.significanceLevel);if(!y.length)return;const l=i.rate?Z(w,t.delta,t.size):J(w,t.size),f=O(l,y.length/s>=.6?"unusual":"info"),n={};for(const S of y)n[S.waferIndex]=S.dieKeys;const g=e.map(S=>S.c.region.key.slice(S.c.region.key.indexOf(":")+1)).join("-"),b={...i,comparison:{...i.comparison,left:p}},v=e[0].finding,P=v.effect.direction;return{...v,id:`lot-region:${e[0].key.split("|").slice(0,-1).join("|")}|${i.region.family}:${g}`,severity:f,comparison:{...v.comparison,left:p},effect:{direction:P,absoluteDelta:t.delta,relativeDelta:t.relativeDelta,effectSize:i.rate?t.delta:t.size},stats:{method:"stouffer-z",pValue:d,adjustedPValue:w,sampleSizeLeft:y.length,sampleSizeRight:s-y.length},summary:`${U(b,t.delta,t.relativeDelta)} \u2014 ${P} on ${y.length}/${s} wafers, all wafers' data combined`,highlight:{kind:"wafer",waferIndices:y.map(S=>S.waferIndex),dieKeysByWafer:n},relatedIds:e.map(S=>S.finding.id)}}const ie={"Edge-ring":"edge","Edge-local":"edge","Center cluster":"centre or donut",Donut:"centre or donut"};function _e(e,a){const s=new Map,o=i=>{const c=i.variable.kind==="spatialPattern"?ie[i.comparison.left]:void 0;return c?`spatialPattern|${c}`:ke(i)};for(const i of e){const c=new Set,p=new Map;for(const t of i.summary.findings)if(t.variable.kind==="spatialPattern")for(const d of t.relatedIds??[])p.set(d,o(t));const h=new Set(i.summary.findings.flatMap(t=>t.absorbedIds??[]));for(const t of i.summary.findings){if(h.has(t.id)||Ne(t)||t.variable.kind==="spatialPattern"&&a?.carriers.has(i.waferIndex))continue;const d=o(t);if(c.has(d))continue;c.add(d);const u=s.get(d)??{finding:t,waferIndices:[],severity:t.severity,labels:new Map,dieKeysByWafer:{},explainedBy:new Map};u.waferIndices.push(i.waferIndex);const w=p.get(t.id);if(w&&u.explainedBy.set(w,(u.explainedBy.get(w)??0)+1),t.variable.kind==="spatialPattern"){u.labels.set(t.comparison.left,(u.labels.get(t.comparison.left)??0)+1);const y=t.highlight.dieKeys;y&&(u.dieKeysByWafer[i.waferIndex]=y)}u.severity=O(u.severity,t.severity),s.set(d,u)}}const r=[];for(const[i,c]of s){if(c.waferIndices.length<K)continue;const p=c.waferIndices.length/Math.max(1,e.length),h=p>=.6||c.severity==="unusual"?"unusual":"notable",t=c.finding;r.push({id:`lot-repeat:${i}`,level:"lot",severity:h,variable:{...t.variable},comparison:{...t.comparison},effect:{direction:t.effect.direction,absoluteDelta:t.effect.absoluteDelta,relativeDelta:t.effect.relativeDelta,effectSize:t.effect.effectSize},stats:{method:"wafer-finding-frequency",sampleSizeLeft:c.waferIndices.length,sampleSizeRight:e.length-c.waferIndices.length},summary:`${Ye(t,c.labels)} \u2014 seen on ${c.waferIndices.length}/${e.length} wafers (${Math.round(p*100)}%)`,highlight:{kind:"wafer",waferIndices:c.waferIndices,...c.labels.size?{dieKeysByWafer:c.dieKeysByWafer}:{}}})}const m=new Map(r.map(i=>[i.id,i]));for(const[i,c]of s){const p=m.get(`lot-repeat:${i}`);if(p)for(const[h,t]of c.explainedBy){const d=m.get(`lot-repeat:${h}`);!d||t!==c.waferIndices.length||(d.relatedIds??=[]).push(p.id)}}return r}function je(e,a){const{classification:s,carriers:o}=e,r=De[s.pattern],m=o.size/Math.max(1,a),i={};for(const[c,p]of o)i[c]=p;return{id:"lot-repeat:spatialPattern|lot",level:"lot",severity:m>=.6||s.confidence==="high"?"unusual":"notable",variable:{kind:"spatialPattern",label:r},comparison:{family:"spatial-pattern",left:r,right:"Wafer"},effect:{direction:"different",effectSize:s.features.globalRdd},stats:{method:"wafer-finding-frequency",sampleSizeLeft:o.size,sampleSizeRight:a-o.size},summary:`Spatial pattern: ${r.toLowerCase()} \u2014 seen on ${o.size}/${a} wafers (${Math.round(m*100)}%)`,highlight:{kind:"wafer",waferIndices:[...o.keys()].sort((c,p)=>c-p),dieKeysByWafer:i}}}function Ce(e){const a=/^Rings? (\d+)(?:\s*[–-]\s*(\d+))?/.exec(e.comparison.left);if(!a)return[];const s=+a[1],o=a[2]?+a[2]:s;return Array.from({length:Math.max(0,o-s+1)},(r,m)=>s+m)}function Ye(e,a){if(!a.size)return e.summary;const s=m=>m.toLowerCase();if(a.size===1)return`Spatial pattern: ${s([...a.keys()][0])}`;const o=ie[e.comparison.left],r=[...a].sort((m,i)=>i[1]-m[1]).map(([m,i])=>`${s(m)} on ${i}`);return`Spatial pattern: ${o} (${r.join(", ")})`}function Ge(e,a){const s=Le(a,"median"),o=e.map(p=>({waferIndex:p.waferIndex,yieldPercent:p.summary.stats.yieldPercent})).filter(p=>p.yieldPercent!==null),r=o.map(p=>p.yieldPercent),m=outlierWafers(r);if(!m)return[];const i=te(r),c=[];for(const{index:p,severity:h,statistic:t}of m.outliers){const d=o[p],u=d.yieldPercent-i,w=oe({wafer:{metadata:e.find(y=>y.waferIndex===d.waferIndex)?.summary.wafer}},d.waferIndex);c.push({id:`inter-wafer:yield:${d.waferIndex}`,level:"inter-wafer",severity:h,variable:{kind:"yield",label:"Yield"},comparison:{family:"wafer",left:w,right:s.charAt(0).toUpperCase()+s.slice(1)},effect:{direction:u>0?"higher":"lower",absoluteDelta:u/100,relativeDelta:i===0?void 0:u/i,effectSize:t},stats:{method:m.method,sampleSizeLeft:1,sampleSizeRight:o.length-1},summary:`${w} yield is ${Math.abs(u).toFixed(1)} percentage points ${u>0?"higher":"lower"} than the ${s}`,highlight:{kind:"wafer",waferIndices:[d.waferIndex]}})}return c}function se(e,a){if((a.enableTestValueAnalysis??"auto")!=="auto")return;let s=0;for(const o of e){const{tests:r,dies:m}=de(o,a);s+=r*m}return we(s)}export function analyzeWaferLot(e,a={}){const s=e.map(ee),o=se(s,a),r=s.map((n,g)=>({waferIndex:g,summary:a.perWaferSummaries?.[g]??T(n,a,o)})),m=r.map(({waferIndex:n,summary:g})=>H(g)??H(T(s[n],a,o))),i=m.map((n,g)=>({waferIndex:g,byKey:new Map(n.candidates.map(b=>[b.key,b]))})),c=le(a).resolved,p=s.length>0?ce(s[0],"analyzeWaferLot"):void 0,h=Pe(s,c),t=h&&h.carriers.size>=K?h:null,d=[...p===void 0?[]:We(i,c,Te(m,c.sectorCount),p),..._e(r,t),...Ge(r,Be(r.map(n=>n.summary.wafer))),...Re(r,c.significanceLevel)];if(t&&p!==void 0){const n=je(t,r.length);n.relatedIds=Me([t.classification.pattern],n.severity,d,Ce,p),n.relatedIds.length||delete n.relatedIds,d.push(n)}d.sort((n,g)=>{const b=n.severity==="unusual"?2:n.severity==="notable"?1:0,v=g.severity==="unusual"?2:g.severity==="notable"?1:0;return b!==v?v-b:n.summary.localeCompare(g.summary,"en")});const u=r.map(n=>n.summary.wafer).filter(n=>!!n),w={},y=[];if(u.length>0){const n=new Set;for(const g of u)for(const b of Object.keys(g))n.add(b);n.delete("wafer"),n.delete("waferId");for(const g of n){const b=u.filter(P=>g in P).map(P=>P[g]);b.every(P=>P===b[0])?w[g]=b[0]:y.push(g)}}const l=r.map(({waferIndex:n,summary:g})=>({waferIndex:n,yieldPercent:g.stats.yieldPercent})),f=r.map(({waferIndex:n,summary:g})=>g.stats.perTestStats?.length?{waferIndex:n,tests:g.stats.perTestStats}:null).filter(n=>n!==null);return{level:"lot",hasNotableFindings:d.some(n=>n.severity!=="info")||r.some(n=>n.summary.hasNotableFindings),findings:d,lot:Object.keys(w).length>0?w:void 0,...y.length>0?{mixedIdentityFields:y}:{},analysisOptions:ue(a),stats:{waferCount:e.length,...He(s,r.map(n=>n.summary)),...Ue(be(r.map(n=>n.summary)))},lotYieldSeries:l,perWafer:r,...f.length>0?{perWaferTestStats:f}:{}}}function He(e,a){const s={...ze(a)},o=Se(a,Ie(e).defs);o&&(s.capability=o);const r=ve(a,e.map(m=>m.ringCount));return r&&(s.regionYield=r),s}const Ue=e=>e?{testValueAnalysis:e}:{},ae=()=>new Promise(e=>setTimeout(e,0));export async function analyzeWaferLotAsync(e,a={}){const{onProgress:s,signal:o,...r}=a,m=e.map(ee),i=se(m,r),c=[];let p=Date.now();for(let h=0;h<m.length;h++)o?.throwIfAborted(),c.push(r.perWaferSummaries?.[h]??T(m[h],r,i)),s?.(h+1,m.length),Date.now()-p>100&&(await ae(),p=Date.now());return await ae(),o?.throwIfAborted(),analyzeWaferLot(m,{...r,perWaferSummaries:c})}
1
+ import{waferDisplayLabel as oe}from"../core/waferLabel.js";import{requireRingCount as ce}from"../core/ringCount.js";import{analyzeWaferMapDecided as F,candidatesOf as H,describeRegional as U,resolveOptions as le,adjustPValues as fe,testValueSize as de,recordedOptions as ue,twoProportionZ as Q,welchOfSums as X,rateRelativeEffect as me,passesRateGate as pe,severityForFinding as Z,severityForScore as J,collapseRedundantFindings as ge,findContiguousRuns as he,mergedRegionLabel as ye}from"./analyzeWaferMap.js";import{normalizeInput as ee}from"./normalizeInput.js";import{autoDecision as we,lotTestValueStatus as be}from"./testValueBudget.js";import{poolCapability as Se,poolRegionYield as ve,poolPassRates as ze}from"./summaryFigures.js";import{mergeTestDefs as Ie}from"./mergeTestDefs.js";import{findingPatternKey as ke}from"./filterFindings.js";import{median as te}from"../core/utils.js";import{robustFence as ne,zPValue as T}from"./math.js";import{findLotPattern as xe}from"./lotPattern.js";import{buildDriftFindings as Pe}from"./lotDrift.js";import{claimForPattern as Re,confirmRegionalFindings as Me,weakestMultiplier as $e}from"./analyzeWaferMap.js";import{PATTERN_LABELS as De}from"./patternClassification.js";import{describeWaferPopulation as Be,populationStat as We}from"./population.js";const N=8,Le={3:[.97,.994],4:[.829,.926],5:[.71,.821],6:[.625,.74],7:[.568,.68]},Ke=3;export function outlierWafers(e){const o=e.length;if(o<3)return null;const s=te([...e]),t=n=>Math.abs(n-s)>=Ke;if(o>=N){const n=ne(e,1.5,N),d=ne(e,3,N);if(!n||!d)return null;const m=(n.hi-n.lo)/4,w=[];return e.forEach((y,l)=>{if(y>=n.lo&&y<=n.hi||!t(y))return;const f=y<d.lo||y>d.hi?"unusual":"notable";w.push({index:l,severity:f,statistic:(y-s)/m})}),{method:"tukey-fence",outliers:w}}const a=e.map((n,d)=>d).sort((n,d)=>e[n]-e[d]),u=e[a[o-1]]-e[a[0]];if(u===0)return null;const[r,c]=Le[o],p=[],h=(n,d)=>{const m=Math.abs(e[n]-e[d])/u;m>r&&t(e[n])&&p.push({index:n,severity:m>c?"unusual":"notable",statistic:m})};return h(a[0],a[1]),h(a[o-1],a[o-2]),{method:"dixon-q",outliers:p}}const q=2;function O(e,o){const s={info:0,notable:1,unusual:2};return s[e]>=s[o]?e:o}const Ee=new Set(["ring","quadrant","sector"]),Te=new Set(["ring","quadrant","sector","reticle-position","test-site"]),qe=new Set(["yield","hardBin","softBin","functionalTest","test"]);function Ae(e){return Te.has(e.comparison.family)&&qe.has(e.variable.kind)}function Fe(e,o){const s=e.map(r=>r.facts);if(!s.length||s.some(r=>!r))return{coincident:new Set,yieldSoftBin:void 0,passBins:[],sectorCount:o};const[t,...a]=s,u=a.every(r=>r.passBins.length===t.passBins.length&&r.passBins.every(c=>t.passBins.includes(c)));return{coincident:new Set([...t.coincident].filter(r=>a.every(c=>c.coincident.has(r)))),yieldSoftBin:a.every(r=>r.yieldSoftBin===t.yieldSoftBin)?t.yieldSoftBin:void 0,passBins:u?t.passBins:[],sectorCount:o}}function j(e,o){let s=0,t=0,a=0,u=0,r=0,c=0,p=0,h=0,n=0,d=!0,m=0;for(const{waferIndex:l,c:f}of e){const i=o(l,f),g=f.rate??f.mean,b=Math.sqrt(g.n+i.n);if(f.rate)s+=b*Q(f.rate.hits,f.rate.n,i.hits,i.n),a+=f.rate.hits,u+=f.rate.n,r+=i.hits,c+=i.n;else{const v=X(f.mean,i.n,i.sum,i.sq);s+=b*v.z,p+=f.mean.n*v.effectSize,h+=f.mean.n*v.delta,m+=f.mean.n,f.relativeDelta===void 0?d=!1:n+=f.mean.n*f.relativeDelta}t+=b*b}const w=t>0?s/Math.sqrt(t):0,y=e[0].c;if(y.rate){const l=r/c,f=a/u-l;return{z:w,delta:f,relativeDelta:l===0?void 0:f/l,size:me({hits:a,n:u,restHits:r,restN:c,passRate:y.rate.passRate})}}return{z:w,delta:h/m,relativeDelta:d?n/m:void 0,size:p/m}}function V(e,o,s,t){return e.rate?pe(o,s.delta,s.size,t):o<=t.significanceLevel&&Math.abs(s.size)>=t.minimumEffectSize}function Ne(e,o,s,t){const a=new Map;for(const{waferIndex:l,byKey:f}of e)for(const i of f.values())(a.get(i.key)??a.set(i.key,[]).get(i.key)).push({waferIndex:l,c:i});const u=new Map(e.map(l=>[l.waferIndex,l.byKey])),r=(l,f)=>f.rate?{hits:f.rate.restHits,n:f.rate.restN,sum:0,sq:0}:{hits:0,n:f.mean.restN,sum:f.mean.restSum,sq:f.mean.restSq},c=[];for(const[l,f]of a){if(f.length<q)continue;const i=j(f,r);if(i.z===0)continue;const g=f[0].c;c.push({key:l,entries:f,combined:i,finding:{id:`lot-region:${l}`,level:"lot",severity:"info",variable:{...g.variable,label:g.label},comparison:{...g.comparison},effect:{direction:i.z>0?"higher":"lower",absoluteDelta:i.delta,relativeDelta:i.relativeDelta,effectSize:g.rate?i.delta:i.size},stats:{method:"stouffer-z",pValue:T(i.z),sampleSizeLeft:0,sampleSizeRight:0},summary:"",highlight:{kind:"wafer",waferIndices:[]}}})}fe(c.map(l=>l.finding));const p=c.filter(l=>V(l.entries[0].c,l.finding.stats.adjustedPValue??1,l.combined,o)),d=Me(p,l=>{const f=l.entries[0].c;return[f.source,f.variable.kind,f.variable.bin??"",f.variable.index??"",f.region.family].join("\0")},(l,f)=>{const i=(R,D)=>{const k=r(R,D);for(const z of f){const P=u.get(R)?.get(z.key);P&&(P.rate?(k.hits-=P.rate.hits,k.n-=P.rate.n):(k.n-=P.mean.n,k.sum-=P.mean.sum,k.sq-=P.mean.sq))}return k},g=l.entries.filter(R=>i(R.waferIndex,R.c).n>=o.minimumSampleSize);if(!g.length)return"baseline-too-small";const b=j(g,i),v=l.finding.stats.pValue??1,x=v>0?(l.finding.stats.adjustedPValue??v)/v:1,S=Math.min(1,T(b.z)*x);return{pValue:S,passes:Math.sign(b.z)===Math.sign(l.combined.z)&&V(l.entries[0].c,S,b,o)}},l=>{const f=l.entries[0].c.rate;return f!==void 0&&(f.passRate?l.combined.z<0:l.combined.z>0)},c),m=[],w=new Map;for(const l of p){if(!d.has(l))continue;const f=l.finding.stats.pValue??1,i=Math.sign(l.combined.z),g=l.entries.filter(z=>Math.sign(z.c.delta)===i),b=e.length,v=l.entries[0].c,x=l.finding.stats.adjustedPValue??f,S=v.rate?Z(x,l.combined.delta,l.combined.size):J(x,l.combined.size),R=O(S,g.length/b>=.6?"unusual":"info"),D={};for(const z of g)D[z.waferIndex]=[...z.c.region.dieKeys];const k={...l.finding,severity:R,stats:{...l.finding.stats,sampleSizeLeft:g.length,sampleSizeRight:b-g.length},summary:`${U(v,l.combined.delta,l.combined.relativeDelta)} \u2014 ${l.finding.effect.direction} on ${g.length}/${b} wafers, all wafers' data combined`,highlight:{kind:"wafer",waferIndices:g.map(z=>z.waferIndex),dieKeysByWafer:D}};m.push(k),w.set(k,l)}const y=Oe(w,u,e.length,o,t,r);return m.splice(0,m.length,...m.filter(l=>!y.replaced.has(l)),...y.findings),ge(m,s),m}function Oe(e,o,s,t,a,u){const r=new Map;for(const[h,n]of e){const d=n.entries[0].c;if(!Ee.has(d.region.family))continue;const m=[d.source,d.variable.kind,d.variable.bin??"",d.variable.index??"",d.region.family,h.effect.direction].join("|");(r.get(m)??r.set(m,[]).get(m)).push({finding:h,c:d,key:n.key})}const c=[],p=new Set;for(const h of r.values()){if(h.length<2)continue;const n=h[0].c.region.family;for(const d of he(h,n,t.sectorCount,m=>m.c.region.key)){if(d.length<2)continue;const m=je(d,o,s,t,a,u);if(m){c.push(m);for(const w of d)p.add(w.finding)}}}return{findings:c,replaced:p}}function je(e,o,s,t,a,u){const r=e[0].c,c=e[0].finding.effect.direction==="higher"?1:-1,p=ye(r.region.family,e.map(S=>S.c.region.key),a),h=[];for(const[S,R]of o){const D=e.map(I=>R.get(I.key));if(D.some(I=>!I))continue;const k=D,z=k[0];let P,A;if(z.rate){const I=k.reduce(($,B)=>$+B.rate.hits,0),M=k.reduce(($,B)=>$+B.rate.n,0),L=z.rate.hits+z.rate.restHits-I,W=z.rate.n+z.rate.restN-M;if(M<t.minimumSampleSize||W<t.minimumSampleSize)continue;P={...z,rate:{hits:I,n:M,restHits:L,restN:W,passRate:z.rate.passRate}},A=Q(I,M,L,W)}else{const I=z.mean,M=k.reduce((K,E)=>K+E.mean.n,0),L=k.reduce((K,E)=>K+E.mean.sum,0),W=k.reduce((K,E)=>K+E.mean.sq,0),$=I.n+I.restN-M,B=I.sum+I.restSum-L,_=I.sq+I.restSq-W;if(M<t.minimumSampleSize||$<t.minimumSampleSize)continue;const Y={n:M,sum:L,sq:W,restN:$,restSum:B,restSq:_,shift:I.shift},C=X(Y,$,B,_),G=B/$+I.shift;P={...z,mean:Y,relativeDelta:G!==0?C.delta/Math.abs(G):void 0},A=C.z}const re=[...new Set(k.flatMap(I=>[...I.region.dieKeys]))];h.push({waferIndex:S,c:P,z:A,dieKeys:re})}if(h.length<q)return;const n=j(h,u);if(n.z===0||Math.sign(n.z)!==c)return;const d=T(n.z),m=$e(e.map(S=>S.finding)),w=Math.min(1,d*m);if(!V(r,w,n,t))return;const y=h.filter(S=>Math.sign(S.z)===c&&T(S.z)<=t.significanceLevel);if(!y.length)return;const l=r.rate?Z(w,n.delta,n.size):J(w,n.size),f=O(l,y.length/s>=.6?"unusual":"info"),i={};for(const S of y)i[S.waferIndex]=S.dieKeys;const g=e.map(S=>S.c.region.key.slice(S.c.region.key.indexOf(":")+1)).join("-"),b={...r,comparison:{...r.comparison,left:p}},v=e[0].finding,x=v.effect.direction;return{...v,id:`lot-region:${e[0].key.split("|").slice(0,-1).join("|")}|${r.region.family}:${g}`,severity:f,comparison:{...v.comparison,left:p},effect:{direction:x,absoluteDelta:n.delta,relativeDelta:n.relativeDelta,effectSize:r.rate?n.delta:n.size},stats:{method:"stouffer-z",pValue:d,adjustedPValue:w,sampleSizeLeft:y.length,sampleSizeRight:s-y.length},summary:`${U(b,n.delta,n.relativeDelta)} \u2014 ${x} on ${y.length}/${s} wafers, all wafers' data combined`,highlight:{kind:"wafer",waferIndices:y.map(S=>S.waferIndex),dieKeysByWafer:i},relatedIds:e.map(S=>S.finding.id)}}const ie={"Edge-ring":"edge","Edge-local":"edge","Center cluster":"centre or donut",Donut:"centre or donut"};function Ve(e,o){const s=new Map,t=r=>{const c=r.variable.kind==="spatialPattern"?ie[r.comparison.left]:void 0;return c?`spatialPattern|${c}`:ke(r)};for(const r of e){const c=new Set,p=new Map;for(const n of r.summary.findings)if(n.variable.kind==="spatialPattern")for(const d of n.relatedIds??[])p.set(d,t(n));const h=new Set(r.summary.findings.flatMap(n=>n.absorbedIds??[]));for(const n of r.summary.findings){if(h.has(n.id)||Ae(n)||n.variable.kind==="spatialPattern"&&o?.carriers.has(r.waferIndex))continue;const d=t(n);if(c.has(d))continue;c.add(d);const m=s.get(d)??{finding:n,waferIndices:[],severity:n.severity,labels:new Map,dieKeysByWafer:{},explainedBy:new Map};m.waferIndices.push(r.waferIndex);const w=p.get(n.id);if(w&&m.explainedBy.set(w,(m.explainedBy.get(w)??0)+1),n.variable.kind==="spatialPattern"){m.labels.set(n.comparison.left,(m.labels.get(n.comparison.left)??0)+1);const y=n.highlight.dieKeys;y&&(m.dieKeysByWafer[r.waferIndex]=y)}m.severity=O(m.severity,n.severity),s.set(d,m)}}const a=[];for(const[r,c]of s){if(c.waferIndices.length<q)continue;const p=c.waferIndices.length/Math.max(1,e.length),h=p>=.6||c.severity==="unusual"?"unusual":"notable",n=c.finding;a.push({id:`lot-repeat:${r}`,level:"lot",severity:h,variable:{...n.variable},comparison:{...n.comparison},effect:{direction:n.effect.direction,absoluteDelta:n.effect.absoluteDelta,relativeDelta:n.effect.relativeDelta,effectSize:n.effect.effectSize},stats:{method:"wafer-finding-frequency",sampleSizeLeft:c.waferIndices.length,sampleSizeRight:e.length-c.waferIndices.length},summary:`${Ce(n,c.labels)} \u2014 seen on ${c.waferIndices.length}/${e.length} wafers (${Math.round(p*100)}%)`,highlight:{kind:"wafer",waferIndices:c.waferIndices,...c.labels.size?{dieKeysByWafer:c.dieKeysByWafer}:{}}})}const u=new Map(a.map(r=>[r.id,r]));for(const[r,c]of s){const p=u.get(`lot-repeat:${r}`);if(p)for(const[h,n]of c.explainedBy){const d=u.get(`lot-repeat:${h}`);!d||n!==c.waferIndices.length||(d.relatedIds??=[]).push(p.id)}}return a}function _e(e,o){const{classification:s,carriers:t}=e,a=De[s.pattern],u=t.size/Math.max(1,o),r={};for(const[c,p]of t)r[c]=p;return{id:"lot-repeat:spatialPattern|lot",level:"lot",severity:u>=.6||s.confidence==="high"?"unusual":"notable",variable:{kind:"spatialPattern",label:a},comparison:{family:"spatial-pattern",left:a,right:"Wafer"},effect:{direction:"different",effectSize:s.features.globalRdd},stats:{method:"wafer-finding-frequency",sampleSizeLeft:t.size,sampleSizeRight:o-t.size},summary:`Spatial pattern: ${a.toLowerCase()} \u2014 seen on ${t.size}/${o} wafers (${Math.round(u*100)}%)`,highlight:{kind:"wafer",waferIndices:[...t.keys()].sort((c,p)=>c-p),dieKeysByWafer:r}}}function Ye(e){const o=/^Rings? (\d+)(?:\s*[–-]\s*(\d+))?/.exec(e.comparison.left);if(!o)return[];const s=+o[1],t=o[2]?+o[2]:s;return Array.from({length:Math.max(0,t-s+1)},(a,u)=>s+u)}function Ce(e,o){if(!o.size)return e.summary;const s=u=>u.toLowerCase();if(o.size===1)return`Spatial pattern: ${s([...o.keys()][0])}`;const t=ie[e.comparison.left],a=[...o].sort((u,r)=>r[1]-u[1]).map(([u,r])=>`${s(u)} on ${r}`);return`Spatial pattern: ${t} (${a.join(", ")})`}function Ge(e,o){const s=We(o,"median"),t=e.map(p=>({waferIndex:p.waferIndex,yieldPercent:p.summary.stats.yieldPercent})).filter(p=>p.yieldPercent!==null),a=t.map(p=>p.yieldPercent),u=outlierWafers(a);if(!u)return[];const r=te(a),c=[];for(const{index:p,severity:h,statistic:n}of u.outliers){const d=t[p],m=d.yieldPercent-r,w=oe({wafer:{metadata:e.find(y=>y.waferIndex===d.waferIndex)?.summary.wafer}},d.waferIndex);c.push({id:`inter-wafer:yield:${d.waferIndex}`,level:"inter-wafer",severity:h,variable:{kind:"yield",label:"Yield"},comparison:{family:"wafer",left:w,right:s.charAt(0).toUpperCase()+s.slice(1)},effect:{direction:m>0?"higher":"lower",absoluteDelta:m/100,relativeDelta:r===0?void 0:m/r,effectSize:n},stats:{method:u.method,sampleSizeLeft:1,sampleSizeRight:t.length-1},summary:`${w} yield is ${Math.abs(m).toFixed(1)} percentage points ${m>0?"higher":"lower"} than the ${s}`,highlight:{kind:"wafer",waferIndices:[d.waferIndex]}})}return c}function se(e,o){if((o.enableTestValueAnalysis??"auto")!=="auto")return;let s=0;for(const t of e){const{tests:a,dies:u}=de(t,o);s+=a*u}return we(s)}export function analyzeWaferLot(e,o={}){const s=e.map(ee),t=se(s,o),a=s.map((i,g)=>({waferIndex:g,summary:o.perWaferSummaries?.[g]??F(i,o,t)})),u=a.map(({waferIndex:i,summary:g})=>H(g)??H(F(s[i],o,t))),r=u.map((i,g)=>({waferIndex:g,byKey:new Map(i.candidates.map(b=>[b.key,b]))})),c=le(o).resolved,p=s.length>0?ce(s[0],"analyzeWaferLot"):void 0,h=xe(s,c),n=h&&h.carriers.size>=q?h:null,d=[...p===void 0?[]:Ne(r,c,Fe(u,c.sectorCount),p),...Ve(a,n),...Ge(a,Be(a.map(i=>i.summary.wafer))),...Pe(a,c.significanceLevel)];if(n&&p!==void 0){const i=_e(n,a.length);i.relatedIds=Re([n.classification.pattern],i.severity,d,Ye,p),i.relatedIds.length||delete i.relatedIds,d.push(i)}d.sort((i,g)=>{const b=i.severity==="unusual"?2:i.severity==="notable"?1:0,v=g.severity==="unusual"?2:g.severity==="notable"?1:0;return b!==v?v-b:i.summary.localeCompare(g.summary,"en")});const m=a.map(i=>i.summary.wafer).filter(i=>!!i),w={},y=[];if(m.length>0){const i=new Set;for(const g of m)for(const b of Object.keys(g))i.add(b);i.delete("wafer"),i.delete("waferId");for(const g of i){const b=m.filter(x=>g in x).map(x=>x[g]);b.every(x=>x===b[0])?w[g]=b[0]:y.push(g)}}const l=a.map(({waferIndex:i,summary:g})=>({waferIndex:i,yieldPercent:g.stats.yieldPercent})),f=a.map(({waferIndex:i,summary:g})=>g.stats.perTestStats?.length?{waferIndex:i,tests:g.stats.perTestStats}:null).filter(i=>i!==null);return{level:"lot",hasNotableFindings:d.some(i=>i.severity!=="info")||a.some(i=>i.summary.hasNotableFindings),findings:d,lot:Object.keys(w).length>0?w:void 0,...y.length>0?{mixedIdentityFields:y}:{},analysisOptions:ue(o),stats:{waferCount:e.length,...He(s,a.map(i=>i.summary)),...Ue(be(a.map(i=>i.summary)))},lotYieldSeries:l,perWafer:a,...f.length>0?{perWaferTestStats:f}:{}}}function He(e,o){const s={...ze(o)},t=Se(o,Ie(e).defs);t&&(s.capability=t);const a=ve(o,e.map(u=>u.ringCount));return a&&(s.regionYield=a),s}const Ue=e=>e?{testValueAnalysis:e}:{},ae=()=>new Promise(e=>setTimeout(e,0));export async function analyzeWaferLotAsync(e,o={}){const{onProgress:s,signal:t,...a}=o,u=e.map(ee),r=se(u,a),c=[];let p=Date.now();for(let h=0;h<u.length;h++)t?.throwIfAborted(),c.push(a.perWaferSummaries?.[h]??F(u[h],a,r)),s?.(h+1,u.length),Date.now()-p>100&&(await ae(),p=Date.now());return await ae(),t?.throwIfAborted(),analyzeWaferLot(u,{...a,perWaferSummaries:c})}export function remapLotWaferIndices(e,o){const s=t=>o[t]??t;return{...e,perWafer:e.perWafer.map(t=>({...t,waferIndex:s(t.waferIndex)})),lotYieldSeries:e.lotYieldSeries.map(t=>({...t,waferIndex:s(t.waferIndex)})),...e.perWaferTestStats?{perWaferTestStats:e.perWaferTestStats.map(t=>({...t,waferIndex:s(t.waferIndex)}))}:{},findings:e.findings.map(t=>{const a=t.highlight;if(!a||a.kind!=="wafer")return t;const u=a.dieKeysByWafer?Object.fromEntries(Object.entries(a.dieKeysByWafer).map(([r,c])=>[s(Number(r)),c])):void 0;return{...t,highlight:{...a,waferIndices:a.waferIndices.map(s),...u?{dieKeysByWafer:u}:{}}}})}}
@@ -33,6 +33,14 @@ export declare function resolveOptions(options: AnalyzeWaferMapOptions): {
33
33
  resolved: ResolvedOptions;
34
34
  warnings: WaferWarning[];
35
35
  };
36
+ /**
37
+ * Lists under each cluster of one bin (`relatedIds`) the region findings of that bin it explains: a rise in the
38
+ * bin in a ring, quadrant or sector that the cluster's dies make up at least half of, and no more severe than the
39
+ * cluster. Those findings are the same spot seen through a coarser region, and read below it rather than ahead of
40
+ * it; like the rows a pattern claims, they are marked info. A region row more severe than the cluster carries the
41
+ * stronger evidence, so it stands on its own.
42
+ */
43
+ export declare function claimForBinClusters(findings: StatsFinding[]): void;
36
44
  /**
37
45
  * Per-test pass rate for functional (`testType: 'F'`) tests — the functional
38
46
  * counterpart of `computeTestSpecYield`. Same population convention: partial and