Skip to content

Commit

Permalink
Merge pull request #44 from lkluft/daily-reports
Browse files Browse the repository at this point in the history
Add infrastructure for flight reports
  • Loading branch information
yu71ng authored Jul 22, 2024
2 parents 4ba5e77 + 2160a58 commit 30fc494
Show file tree
Hide file tree
Showing 10 changed files with 280 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ _build
__pycache__/
*.py[cod]
.ipynb_checkpoints

# Auto-generated files
orcestra_book/operation.md
2 changes: 2 additions & 0 deletions orcestra_book/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
title: ORCESTRA
author: The ORCESTRA Community
logo: logos/orcestra.png
exclude_patterns: ["_templates/*"]

# Force re-execution of notebooks on each build.
# See https://jupyterbook.org/content/execute.html
Expand All @@ -30,6 +31,7 @@ sphinx:
local_extensions:
apastyle: _ext/
bracket_citation_style: _ext/
flight_reports: _ext/
config:
bibtex_default_style: myapastyle
bibtex_reference_style: author_year_round
Expand Down
106 changes: 106 additions & 0 deletions orcestra_book/_ext/flight_reports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/usr/bin/env python3
import os
import pathlib
import subprocess
from datetime import datetime
from docutils import nodes
from functools import lru_cache, partial

import yaml
from jinja2 import Template
from sphinx.util.docutils import SphinxRole


@lru_cache
def load_frontmatter(path, derive_flight=False):
with open(path, "r") as fp:
frontmatter = next(yaml.safe_load_all(fp))

if derive_flight:
takeoff = frontmatter["takeoff"]
landing = frontmatter["landing"]

frontmatter["expr_date"] = takeoff.strftime("%d %B %Y")
frontmatter["expr_takeoff"] = takeoff.strftime("%X")
frontmatter["expr_landing"] = landing.strftime("%X")
frontmatter["expr_categories"] = map(
lambda s: f"{{cat}}`{s}`", frontmatter.get("categories", [])
)

return frontmatter


@lru_cache
def create_badge(cat_id):
"""Return an HTML node based on a category id."""
with open("orcestra_book/flight_reports/categories.yaml", "r") as fp:
cat_tier = {
key: attrs["tier"]
for key, attrs in yaml.safe_load(fp)["categories"].items()
}.get(cat_id, "unknown")

span = f'<span class="badge cat-{cat_tier} cat-{cat_id}">{cat_id}</span>'
href = f'<a href="https://orcestra-campaign.org/search.html?q={cat_id}">{span}</a>'
node = nodes.raw(
text=href,
format="html",
)

return node


class CategoryRole(SphinxRole):
def run(self):
node = create_badge(self.text)

return [node], []


class BadgesRole(SphinxRole):
def run(self):
fm = load_frontmatter(self.env.doc2path(self.env.docname))
categories = fm.get("categories", [])

nodes = [create_badge(cat_id) for cat_id in categories]

return nodes, []


class FrontmatterRole(SphinxRole):
def run(self):
"""Access variables defined in document front matter."""
fm = load_frontmatter(self.env.doc2path(self.env.docname))

return nodes.raw(text=fm[self.text]), []


def collect_fronmatter():
flights = pathlib.Path("orcestra_book/flight_reports/").glob("*[0-9]*[a-z].md")
func = partial(load_frontmatter, derive_flight=True)

return {fm["flight_id"]: fm for fm in map(func, sorted(flights))}


def write_flight_table(app):
frontmatters = collect_fronmatter()

with open("orcestra_book/_templates/operation.md", "r") as fp:
templ = fp.read()

with open("orcestra_book/operation.md", "w") as fp:
t = Template(templ)
fp.write(t.render(flights=frontmatters))


def setup(app):
app.connect("builder-inited", write_flight_table)

app.add_role("cat", CategoryRole())
app.add_role("badges", BadgesRole())
app.add_role("front", FrontmatterRole())

return {
"version": "0.1",
"parallel_read_safe": True,
"parallel_write_safe": True,
}
37 changes: 37 additions & 0 deletions orcestra_book/_static/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,40 @@ html {
--pst-font-family-heading: Aileron, var(--pst-font-family-base-system);
--pst-font-family-base: Aileron, var(--pst-font-family-base-system);
}

.badge {
display: inline-block;
padding: 0.25em 0.5em;
font-size: tiny;
font-weight: 400;
text-align: center;
white-space: nowrap;
vertical-align: baseline;
border-radius: 0.25em;
}

/* HACK: Fix spacing between span elements in "row view". */
a:has(> span.badge) + a:has(> span.badge) {
margin-left: 0.25em;
}

.cat-a {
background-color: #33691E;
color: #fff;
}

.cat-b {
background-color: #8BC34A;
color: #333;
}

.cat-c {
background-color: #C5E1A5;
color: #333;
}

.cat-unknown {
background-color: #fff;
color: red;
font-style: italic;
}
8 changes: 8 additions & 0 deletions orcestra_book/_templates/operation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!-- This file was created automatically -->
# Operation

Flight-ID | Date | Takeoff | Landing | PI | Nickname | Categories
--- | --- | --- | --- | --- | --- | ---
{% for k, v in flights.items() -%}
[](flight_reports/{{ k }}) | {{ v["expr_date"] }} | {{ v["expr_takeoff"] }} | {{ v["expr_landing"] }} | {{ v["pi"] }} | {{ v["nickname"] }} | {{ v["expr_categories"]|join(' ') }}
{% endfor -%}
2 changes: 1 addition & 1 deletion orcestra_book/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ chapters:
sections:
- file: virtual_campaign
- file: water_vapour_overview
#- file: operation
- file: operation
- file: data
sections:
- file: data_policy
Expand Down
46 changes: 46 additions & 0 deletions orcestra_book/flight_reports/HALO-20240810a.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
mission: ORCESTRA
platform: HALO
flight_id: HALO-20240810a
nickname: Example
pi: "Lukas Kluft"
takeoff: 2024-08-10 09:13:00
landing: 2024-08-10 15:46:00
categories: [ec_under, ec_track, atr_over, radar, cirrus]
orphan: true
---

# {front}`flight_id`

{badges}`_`

## Summary

This flight took place on 2024-08-10. Everything went fine besides the "Oh no!" at 08:00h.

```{note}
Something noteworthy happened!
```

## Overview

During our flight we observed deep convection. Obviously, we didn't fly throught it because everyone was concerned we could die.

```{figure} https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExOWl2Zzh3ZWxnY3J2ZTVramlkMDMxdjdvcnoxOXloaXF0NHdjcDIzaCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/3o6EhOYMhOTANYgHMk/giphy.gif
:alt: Deep convection.
Development of deep-convective clouds.
```

## Remarks

* The second circle was a square

## Events

Time | Comment
--- | ---
07:00 | All good.
08:00 | Oh no!
14:00 | Yada yada.
18:00 | Feierabend!
30 changes: 30 additions & 0 deletions orcestra_book/flight_reports/HALO-20240812a.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
mission: ORCESTRA
platform: HALO
flight_id: HALO-20240812a
nickname: Yippie!
pi: "Yuting Wu"
takeoff: 2024-08-12 09:03:00
landing: 2024-08-12 16:00:00
categories: [ec_under, ec_track]
orphan: true
---

# {front}`flight_id`

{badges}`_`

## Summary

I am lazy.

## Remarks

* Nothing special.

## Events

Time | Comment
--- | ---
07:00 | All good.
18:00 | Feierabend!
46 changes: 46 additions & 0 deletions orcestra_book/flight_reports/categories.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
categories:
ec_under:
long_name: "EarthCARE underpass"
tier: "a"
ec_track:
long_name: "Fly along EarthCARE track"
tier: "a"
two_circ:
long_name: "Two circles at 48mm"
tier: "a"
itcz_circ:
long_name: "Once circle inside the ITCZ"
tier: "a"
south:
long_name: "Southern extension (100km)"
tier: "b"
atr_circ:
long_name: "Circle around ATR"
tier: "b"
atr_over:
long_name: "ATR overpass"
tier: "b"
sar:
long_name: "SAR overpass"
tier: "b"
pace:
long_name: "PACE overpass"
tier: "b"
gpm:
long_name: "GPM/Radar satellite"
tier: "b"
mindelo:
long_name: "Mindelo overpass"
tier: "b"
cloud_circ:
long_name: "Circle a cloud"
tier: "b"
curtain:
long_name: "Dropsonde curtain thought the ITCZ"
tier: "b"
radar:
long_name: "Radar calibration"
tier: "b"
cirrus:
long_name: "Cirrus transmissivity"
tier: "c"
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ pybtex-apa-style
docutils==0.17.1 # see https://github.com/executablebooks/jupyter-book/issues/1997
easygems>=0.0.3
cmocean
jinja2

0 comments on commit 30fc494

Please sign in to comment.