337.1 / 777.4 nm photometer

Physicist verification companion · source release r4 · mathematical checks and unresolved limits

Review index · Download raw source

modules/common.py

1"""Common SI constants, portable data access and bounded display tables."""2from pathlib import Path3import json,html4ROOT=Path(__file__).resolve().parents[1]5H=6.62607015e-346C=299792458.07PHOTON_ENERGY_337=H*C/(337.1e-9)8PHOTON_ENERGY_777=H*C/(777.4e-9)9R_PHOTONS_PER_R_M2_SR_S=1e10/(4*3.141592653589793)10def load_data(name):11    return json.loads((ROOT/'data'/name).read_text(encoding='utf-8-sig'))12def table(rows,columns=None,max_rows=12):13    from IPython.display import HTML,display14    rows=list(rows);cols=columns or (list(rows[0]) if rows else [])15    def fmt(v):16        if isinstance(v,float):return f'{v:.8g}'17        if isinstance(v,(dict,list,tuple)):return json.dumps(v,ensure_ascii=False)18        return str(v)19    head='<tr>'+''.join('<th>'+html.escape(k)+'</th>' for k in cols)+'</tr>'20    body=''.join('<tr>'+''.join('<td>'+html.escape(fmt(row.get(k,'')))+'</td>' for k in cols)+'</tr>' for row in rows[:max_rows])21    display(HTML('<div style="overflow:auto"><table>'+head+body+'</table></div><p>'+str(len(rows))+' rows total; '+str(min(len(rows),max_rows))+' shown.</p>'))22