Published
Edited
Sep 26, 2021
Importers
Insert cell
Insert cell
Insert cell
ECSVmeta = (ecsv)=>Inputs.table(ecsv.datatype, {layout:"auto"})
Insert cell
Insert cell
ECSVdata = (ecsv,cols=ecsv.datatype)=>Inputs.table(ecsv.data, {columns:cols.map(({name})=>name)})
Insert cell
async function parseECSV(source) {
// The ECSV format is defined at https://github.com/astropy/astropy-APEs/blob/main/APE6.rst
return source.text()
.then(txt=>{
const lines=txt.split("\n");
let comments=lines.filter(line=>line.startsWith("# ")).map(line=>line.slice(2));
if(!comments[0].trim().startsWith("%ECSV")) throw new Error("Missing %ECSV header");
const version=Number(comments[0].trim().slice(6));
comments=comments.slice(1).join("\n");
const body=lines.filter(line=>line[0]!="#").join("\n");
return {version,comments,body};
})
.then(({version,comments,body})=>{
const header=yaml.load(comments);
if(!header?.datatype) throw new Error("Header is missing required datatype");
const delimiter=header?.delimiter ?? " ";
const data=d3.dsvFormat(delimiter).parse(body, d3.autoType);
return Object.assign({version,data},header);
});
}
Insert cell
yaml=require('https://cdn.jsdelivr.net/npm/js-yaml@4.1.0/dist/js-yaml.min.js')
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more