"""Read the saved observation, actually fit six starts, then profile/common-geometry scenarios.""" import argparse,hashlib,json,math,signal,time from pathlib import Path import numpy as np from conditional_fit import analyze_record def load_saved(path): body=path.read_bytes();record=json.loads(body);rows=np.asarray(record.get('rows',[]),dtype=float) if record.get('schema')!='rotation-curve-observation-v1' or rows.ndim!=2 or rows.shape[1]!=8 or len(rows) not in [48,73]:raise ValueError('Unsupported saved observation schema') if not np.isfinite(rows).all() or np.any(rows[:,0]<=0) or np.any(np.diff(rows[:,0])<=0) or np.any(rows[:,1:3]<=0) or np.any(rows[:,5]!=0) or np.any(rows[:,7]!=0):raise ValueError('Invalid saved no-bulge data') if len(rows)==73 and (record.get('galaxy')!='NGC2403' or hashlib.sha256(body).hexdigest()!='ffcaeb60d85c809793dbea27ef54da6091fd8773b868f87119666c1e77eea547'):raise ValueError('Only the exact saved named real observation is supported; do not alter source data') return record def main(): parser=argparse.ArgumentParser();parser.add_argument('--input',type=Path,required=True);parser.add_argument('--output',type=Path,required=True);args=parser.parse_args();started=time.monotonic() def cap(signum,frame):raise TimeoutError('120s numerical-run cap exceeded') signal.signal(signal.SIGALRM,cap);signal.setitimer(signal.ITIMER_REAL,120);args.output.mkdir(parents=True,exist_ok=False) record=load_saved(args.input);result=analyze_record(record,profiles=True,nuisance=True) result.update({'inputSha256':hashlib.sha256(args.input.read_bytes()).hexdigest(),'inputSamples':len(record['rows']),'scriptReadsInjectedTruth':False,'profileMeaning':'Fixed-M/L conditional likelihood profile, not calibrated confidence or posterior','commonGeometryScenarios':'3x3 deterministic D/i offsets, not independent points or posterior samples'}) (args.output/'analysis.json').write_text(json.dumps(result,indent=2,allow_nan=False)+'\n') summary={'status':'COMPUTED','inputSha256':result['inputSha256'],'samples':len(record['rows']),'fits':{kind:{key:value for key,value in fit.items() if key not in ['predictedRecord','attempts']} for kind,fit in result['fits'].items()},'allSixStarts':{kind:fit['attempts'] for kind,fit in result['fits'].items()},'profilePointsPerHalo':len(result['profileMassToLight']['nfw']),'geometryScenariosPerHalo':len(result['sharedNuisanceSensitivity']['nfw']),'generatedBytes':sum(path.stat().st_size for path in args.output.rglob('*') if path.is_file()),'wallSeconds':time.monotonic()-started} (args.output/'receipt.json').write_text(json.dumps(summary,indent=2,allow_nan=False)+'\n');signal.setitimer(signal.ITIMER_REAL,0);print(json.dumps(summary,indent=2)) if __name__=='__main__':main()