-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from lkluft/daily-reports
Add infrastructure for flight reports
- Loading branch information
Showing
10 changed files
with
280 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,6 @@ _build | |
__pycache__/ | ||
*.py[cod] | ||
.ipynb_checkpoints | ||
|
||
# Auto-generated files | ||
orcestra_book/operation.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 -%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters