"""Recompute fixed paper Table2 aggregates; do not refit spectra or claim MP absence.""" from pathlib import Path from html.parser import HTMLParser import argparse import hashlib import json import numpy as np from scipy.stats import binom class Table(HTMLParser): def __init__(self): super().__init__();self.active=False;self.cell=None;self.rows=[];self.row=None def handle_starttag(self,tag,attrs): attributes=dict(attrs) if tag=='table' and attributes.get('id')=='S3.T2.2':self.active=True if not self.active:return if tag=='tr':self.row=[] if tag in ['td','th']:self.cell=[] def handle_data(self,text): if self.active and self.cell is not None:self.cell.append(text) def handle_endtag(self,tag): if not self.active:return if tag in ['td','th'] and self.cell is not None: self.row.append(' '.join(''.join(self.cell).split()));self.cell=None if tag=='tr' and self.row is not None:self.rows.append(self.row);self.row=None if tag=='table':self.active=False def compute(path): body=path.read_bytes();digest=hashlib.sha256(body).hexdigest() if digest!='971ed5b241edcd43bc447ba5349c843d7cbaf0ea8e84dc27d6c3333832d2c28c':raise ValueError('Fixed Huang2024v1 changed') parser=Table();parser.feed(body.decode()) if len(parser.rows)!=9 or parser.rows[0]!=['name','[C/Fe]','[C/Fe]err','[N/Fe]','[N/Fe]err']:raise ValueError('Original abundance table structure changed') numbers=np.array([[float(value.replace('–','-')) for value in row[1:]] for row in parser.rows[1:]]) carbon,nitrogen=numbers[:,0],numbers[:,2] probability=[] for fraction in [.2,.4,.6,.8]: either=fraction**8+(1-fraction)**8 reference=binom.pmf(0,8,fraction)+binom.pmf(8,8,fraction) assert abs(either-reference)<1e-15 probability.append({'assumedFirstPopulationFraction':fraction,'eightAllFirst':fraction**8,'eightAllEitherPopulation':either}) return {'status':'Actual fixed Table2 parsed and aggregate/conditional probability arithmetic recomputed', 'source':'https://arxiv.org/html/2401.17584v1','sourceSha256':digest,'table':'S3.T2.2','stars':len(carbon), 'carbonStdDDoF0Dex':float(np.std(carbon)),'carbonStdDDoF1Dex':float(np.std(carbon,ddof=1)), 'nitrogenStdDDoF0Dex':float(np.std(nitrogen)),'nitrogenStdDDoF1Dex':float(np.std(nitrogen,ddof=1)), 'meanCarbonReportedErrorDex':float(np.mean(numbers[:,1])),'meanNitrogenReportedErrorDex':float(np.mean(numbers[:,3])), 'conditionalSimpleDraws':probability, 'boundary':'Original table is already inferred stellar abundances. No CN/CH spectral extraction, atmosphere calculation, selection model or intrinsic-scatter posterior. A small table scatter relative to reported errors is a conditional nondetection, not proof that chemical multiple populations are absent. All-first and all-either events differ; independent unbiased draws and known population fraction are additional hypotheses.'} if __name__=='__main__': parser=argparse.ArgumentParser(description=__doc__);parser.add_argument('--inputs',type=Path,default=Path('inputs')) parser.add_argument('--report',type=Path,default=Path('results/frontier-reading.json')) args=parser.parse_args();result=compute(args.inputs/'huang2024-v1.html');args.report.parent.mkdir(parents=True,exist_ok=True);args.report.write_text(json.dumps(result,indent=2)+'\n');print(json.dumps(result,indent=2))