Public
Edited
Jan 21
Paused
3 forks
30 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
monthly_data = raw_monthly_data.map((d) => ({
...d,
anomaly_1850_1900: round(
monthly_baseline_1951_1980[d.month - 1] +
d.anomaly_1951_1980 -
monthly_baseline_1850_1900[d.month - 1].mean,
4
)
}))
Insert cell
Insert cell
Insert cell
paris_targets = [
{ target: 1.5, text: "+1,5°C (from 1850-1900)" },
{ target: 2, text: "+2°C (from 1850-1900)" }
]
Insert cell
Insert cell
Insert cell
/**
* Parse berkeley text file and returns an array of objects.
* @param {string} text - The text to parse.
* @param {number} start - The line number to start parsing from.
* @param {number} [end] - The line number to stop parsing at. If not specified, all lines after `start` will be parsed.
* @param {string[]} columns - An array of column names to use for the resulting objects.
* @returns {Object[]} An array of objects, where each object represents a row in the parsed data. The keys of each object are the column names specified in the `columns` parameter, and the values are the corresponding values from the parsed data.
*/
function parse_file(text, start, end = undefined, columns) {
const data = text.split("\n").slice(start, end);

return data.map((d) => {
const values = d
.split(" ")
.filter((value) => value !== "")
.slice(0, columns.length + 1);

const row = {};
columns.forEach((c, i) => (row[c] = +values[i]));

return row;
});
}
Insert cell
/**
* Rounds a value to a given number of significant digits
* Based on https://stackoverflow.com/a/75954111
*
* @param value - The number to round
* @param significant_digits - The number of significant digits
* @returns The value rounded to the given number of significant digits
*/
function round(value, significant_digits) {
if (value === 0) return 0;
const exponent = Math.floor(Math.log10(Math.abs(value)));
const nIntegers = exponent + 1;
const precision = 10 ** -(nIntegers - significant_digits);
return Math.round(value * precision) / precision;
}
Insert cell
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