AMA-Labs / cal-notebooks

CEOS Analytics Laboratory notebooks and tools
0 stars 1 forks source link

Automatically update notebook headers #13

Closed jdh-ama closed 7 months ago

jdh-ama commented 8 months ago

Summary

Defines a standard header template, custom notebook metadata for providing header values, a tag for marking a cell as a header, and a script to automate the update process.

Details

Custom metadata

"cal": {
    "category": "Introduction and Overview",
    "title": "The Open Data Cube and Available Products"
}

The cal key identifies the notebook as a CAL notebook subject to automatic header updates and defines a namespace for sub-keys. The keys in the cal namespace define the values of the variables defined by the header template. Other notebooks are ignored.

Header template

The header template is a standalone HTML document which defines jinja2 template variables. The jinja2 package is part of the standard CAL environment.

Update script

The update script recursively searches the entire repository for CAL notebooks and updates (or adds) the CAL header to the notebook using the supplied template variable values. Existing header cells are identified by the presence of the cal.header tag. The script makes no assumptions about the template variables, so the template and metadata schema can be updated without modifying the script.

Environment setup

chmod +x ~/cal-notebooks/bin/updateheaders.py

# .bashrc
alias updateheaders=~/cal-notebooks/bin/updateheaders.py