Public
Edited
Apr 11, 2024
Insert cell
Insert cell
Insert cell
Insert cell
// 0.7.2
h5 = import("https://cdn.observableusercontent.com/npm/h5wasm@0.4.9/+esm").then(
(h5) => h5.ready.then(() => h5)
)
Insert cell
Insert cell
// helcom = FileAttachment("100-HELCOM-MORS-2018@1.nc")
// .arrayBuffer()
// .then(
// (d) => (
// h5.FS.writeFile("helcom4.h5", new Uint8Array(d)),
// new h5.File("helcom4.h5", "r")
// )
// )
Insert cell
files = [FileAttachment("100-HELCOM-MORS-2018@1.nc")]
Insert cell
function loadNetcdf(file) {
const fname = `${file.name.split(".")[0]}.h5`;
console.log(fname);
return file
.arrayBuffer()
.then(
(d) => (
h5.FS.writeFile(fname, new Uint8Array(d)), new h5.File(fname, "r")
)
);
}
Insert cell
helcom = loadNetcdf(files[0])
Insert cell
helcom.keys()
Insert cell
Insert cell
wellknown = require("https://bundle.run/wellknown@0.5.0")
Insert cell
turf = require("@turf/turf@6.5")
Insert cell
helcom.attrs
Insert cell
// Geojson winding rules: https://observablehq.com/@d3/winding-order
bbox_netcdf = turf.rewind(wellknown(helcom.attrs.geospatial_bounds.value), {
reverse: true,
mutate: true
})
Insert cell
world = (
await fetch("https://cdn.jsdelivr.net/npm/world-atlas@2/land-50m.json")
).json()
Insert cell
land = topojson.feature(world, world.objects.land)
Insert cell
Insert cell
helcom.attrs
Insert cell
Insert cell
{
for (const property in helcom.attrs) {
console.log(`${property}: ${helcom.attrs[property].value}`);
}
}
Insert cell
str_sanitized = "**MORS Environment database** has been used to collate data resulting from monitoring of environmental radioactivity in the Baltic Sea based on HELCOM Recommendation 26/3. The database is structured according to [HELCOM Guidelines on Monitoring of Radioactive Substances](https://www.helcom.fi/wp-content/uploads/2019/08/Guidelines-for-Monitoring-of-Radioactive-Substances.pdf), which specifies reporting format, database structure, data types and obligatory parameters used for reporting data under Recommendation 26/3. The database is updated and quality assured annually by HELCOM MORS EG."
Insert cell
sanitized_logs = "*Remap to MARIS radionuclide names *Renaming variables to MARIS standard names., Drop variable containing only NaN or 'Not available' (id=0 in MARIS lookup tables)., Assign Detection Limit name to its id based on MARIS nomenclature., Convert data from long to wide with renamed columns., Encode time as int representing seconds since xxx, Drop row when both longitude & latitude equal 0."
Insert cell
function metadata(attrs) {
let table = [];
// "| Heading 1 | # Title |"
for (const property in attrs) {
table.push(`|${property} | ${attrs[property].value} |`);
// console.log(`${property}: ${attrs[property].value}`);
}
console.log(table);

return md`### Metadata

| Name | Value(s) |
| -------------- | ---------------------------------- |
| Title | **${attrs.title.value}** |
| Summary | ${str_sanitized}|
| Keywords | ${attrs.keywords.value} |
| Postprocessing logs | ${attrs.publisher_postprocess_logs.value} |
| Publisher name | ${attrs.publisher_name.value} |

`;
}
Insert cell
Insert cell
// {
// const data = {
// key1: "value1",
// key2: "value2",
// key3: "value3",
// key4: "value4"
// };

// let html = `<table>
// <tr>
// <th>Key</th>
// <th>Value</th>
// </tr>
// ${Object.keys(data)
// .map(
// (key) => `
// <tr>
// <td>${key}</td>
// <td>${data[key]}</td>
// </tr>
// `
// )
// .join("")}
// </table>`;
// }
Insert cell
metadata(helcom.attrs)
Insert cell
helcom.attrs.title.value

// .attrs.long_name.value
Insert cell
helcom.get("biota").keys()
Insert cell
// biota, seawater, sediment
helcom.keys()
Insert cell
helcom.get("biota/sample").value.length
Insert cell
helcom.get("seawater/sample").value.length
Insert cell
helcom.get("sediment/sample").value.length
Insert cell
helcom.get("species_t")
Insert cell
Insert cell
lon = helcom.get("biota/lon")
Insert cell
lon.shape
Insert cell
lon.attrs
Insert cell
helcom.get("biota/lon").metadata
Insert cell
helcom.get("biota").get("depth").value
Insert cell
helcom.get("biota").get("area").value[0]
Insert cell
// Global individual attr
// helcom.get_attribute("description")
Insert cell
// Or all
Object.keys(helcom.attrs).map((d) => `${d}: ${helcom.get_attribute(d)}`)
Insert cell
// groups
helcom.keys()
Insert cell
helcom.get("species_t")
Insert cell
// Available variables in group
helcom.get("biota").keys()
Insert cell
helcom.get("biota").get("cs137").value
Insert cell
// Variable attributes name
helcom.get("sediment").get("cs137").attrs.long_name.value
Insert cell
// Variable attribute value
helcom.get("sediment").get("cs137").get_attribute("long_name")
Insert cell
helcom.get("biota").keys()
Insert cell
helcom.get("biota").get("species").metadata["enum_type"].members
Insert cell
Insert cell
Insert cell
clouds.keys()
Insert cell
clouds.get("primary_cloud").value
Insert cell
clouds.get("primary_cloud").metadata["enum_type"].members
Insert cell
clouds
Insert cell
// fileArrayBuffer = FileAttachment("clouds.nc").arrayBuffer()

// netcdfFile = h5wasm.open(await fileArrayBuffer)
Insert cell
// clouds
// .get("clouds.nc")
// .arrayBuffer()
// .then((buffer) => {
// const h5 = new H5(buffer);
// // const variable = h5.open("cloud_t");

// return variable;
// })
Insert cell
// clouds.get("cloud_t")
Insert cell
Insert cell
Insert cell
// 0.4.9
// h5 = import("https://cdn.observableusercontent.com/npm/h5wasm@0.7.2/+esm").then(
// (h5) => h5.ready.then(() => h5)
// )
Insert cell
// clouds2 = FileAttachment("clouds.nc")
// .arrayBuffer()
// .then((buffer) => h5.open(buffer))
Insert cell
// import { H5 } from "https://cdn.skypack.dev/h5wasm"
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