-
Notifications
You must be signed in to change notification settings - Fork 0
DM-54580: Add skymap viewer for the plan #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
0d284e4
Update requirements for skymap addition
a213536
Update requirements for skymap addition
1f1f256
Update requirements for skymap addition
a7a67ef
Add skymap dashboard jinja template
e23e67a
Run black
cc67926
Add jinja2 template
7c8019f
Update test fixture for skymap
e3eeceb
Add SkyMapTest
8fb6b87
Update README.md
leannep ed593a1
Update code doc
bddedb6
Fix string format
c9af916
Remove # noqa: E702
e532b72
Add button to switch to map view
5013957
Clean up imports and comments
2096ba6
Clean up imports and comments
debfade
Add skymap endpoint to external.py
76636d1
Add the PROJ development headers needed by skyproj
37c26d5
Add r-band values for em_min/em_max values to to the mock so that the…
c3f63f5
Add message to runlocal to print the full endpoint for convenience
e3f09db
Add the PROJ development headers needed by skyproj to Dockerfile.co…
1b721db
Move import to top of file
59e5c09
Address wom comments -- move service url to config
a867878
Refactor js code out of python files
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -31,3 +31,6 @@ scikit-learn | |
| rubin_sim>=2.6.0 | ||
| psycopg2-binary | ||
| types-requests | ||
| bokeh>=3.9.0 | ||
| jinja2>=3.1.6 | ||
|
|
||
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,155 @@ | ||
| """Render the obsloctap skymap to a local HTML file and open it in a browser. | ||
|
|
||
| Loads a local fixture by default; use --live or --refresh-live to hit the | ||
| deployed service. | ||
|
|
||
| Usage (from the repo root): | ||
| python3.13 scripts/render_skymap.py | ||
| python3.13 scripts/render_skymap.py --live [--time 48] [--start now] | ||
| python3.13 scripts/render_skymap.py --refresh-live | ||
| [--time 48] [--start now] | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import json | ||
| import os | ||
| import pathlib | ||
| import sys | ||
| import tempfile | ||
| import webbrowser | ||
| from typing import Any | ||
|
|
||
| import requests | ||
|
|
||
| from obsloctap.models import Obsplan | ||
| from obsloctap.skymap import make_sky_html | ||
|
|
||
| _REPO_ROOT = pathlib.Path(__file__).parent.parent | ||
| sys.path.insert(0, str(_REPO_ROOT / "src")) | ||
|
|
||
| LIVE_URL = "https://usdf-rsp.slac.stanford.edu/obsloctap/schedule" | ||
| LIVE_PREFIX = "https://usdf-rsp.slac.stanford.edu/obsloctap" | ||
| _FIXTURE = _REPO_ROOT / "tests" / "fixtures" / "schedule_48h.json" | ||
|
|
||
|
|
||
| def _should_open_browser(no_open: bool) -> bool: | ||
| if no_open: | ||
| return False | ||
| return os.environ.get("CI", "").lower() not in {"1", "true", "yes"} | ||
|
|
||
|
|
||
| def _fetch_live_data(start: str, time: int) -> list[dict[str, Any]] | None: | ||
| params: dict[str, Any] = {"time": time} | ||
| if start.lower() != "now": | ||
| params["start"] = start | ||
|
|
||
| print( | ||
| f"Checking live service at {LIVE_URL} with params {params} …", | ||
| flush=True, | ||
| ) | ||
| try: | ||
| resp = requests.get(LIVE_URL, params=params, timeout=30) | ||
| resp.raise_for_status() | ||
| raw = resp.json() | ||
| except requests.RequestException as exc: | ||
| print(f"Live service is down or not returning data: {exc}") | ||
| return None | ||
| except ValueError as exc: | ||
| print(f"Live service returned invalid JSON: {exc}") | ||
| return None | ||
|
|
||
| if not raw: | ||
| print("Live service is up but returned no schedule data.") | ||
| return None | ||
|
|
||
| print(f" → {len(raw)} observations received") | ||
| return raw | ||
|
|
||
|
|
||
| def main() -> None: | ||
| parser = argparse.ArgumentParser( | ||
| description=__doc__, | ||
| formatter_class=argparse.RawDescriptionHelpFormatter, | ||
| ) | ||
| parser.add_argument( | ||
| "--time", | ||
| type=int, | ||
| default=48, | ||
| help="Lookahead window in hours (default: 48)", | ||
| ) | ||
| parser.add_argument( | ||
| "--start", | ||
| default="now", | ||
| help="Start time: 'now', ISO, or MJD (default: now)", | ||
| ) | ||
| parser.add_argument( | ||
| "--no-open", | ||
| action="store_true", | ||
| help="Write the HTML file but do not open a browser", | ||
| ) | ||
| parser.add_argument( | ||
| "--live", | ||
| action="store_true", | ||
| help="Render using the live service, but do not refresh the fixture", | ||
| ) | ||
| parser.add_argument( | ||
| "--refresh-live", | ||
| action="store_true", | ||
| help=( | ||
| f"Fetch the live service and overwrite " | ||
| f"{_FIXTURE.relative_to(_REPO_ROOT)}." | ||
| ), | ||
| ) | ||
| args = parser.parse_args() | ||
|
|
||
| if args.live and args.refresh_live: | ||
| print("Choose only one of --live or --refresh-live.") | ||
| sys.exit(2) | ||
|
|
||
| if args.live or args.refresh_live: | ||
| raw = _fetch_live_data(args.start, args.time) | ||
| if raw is None: | ||
| sys.exit(0) | ||
| if args.refresh_live: | ||
| _FIXTURE.parent.mkdir(parents=True, exist_ok=True) | ||
| _FIXTURE.write_text(json.dumps(raw)) | ||
| print(f" → Fixture updated: {_FIXTURE.relative_to(_REPO_ROOT)}") | ||
| else: | ||
| if not _FIXTURE.exists(): | ||
| print(f"Fixture not found: {_FIXTURE}") | ||
| print( | ||
| "Refresh it explicitly with " | ||
| "'python scripts/render_skymap.py --refresh-live'." | ||
| ) | ||
| sys.exit(1) | ||
| print(f"Loading fixture {_FIXTURE} …", flush=True) | ||
| raw = json.loads(_FIXTURE.read_text()) | ||
| print(f" → {len(raw)} observations loaded from fixture") | ||
|
|
||
| schedule = [Obsplan(**obs) for obs in raw] | ||
|
|
||
| html = make_sky_html( | ||
| schedule, | ||
| start_val=args.start, | ||
| time_val=args.time, | ||
| path_prefix=LIVE_PREFIX, | ||
| ) | ||
|
|
||
| with tempfile.NamedTemporaryFile( | ||
| mode="w", suffix=".html", prefix="skymap_", delete=False | ||
| ) as fh: | ||
| fh.write(html) | ||
| path = fh.name | ||
|
|
||
| print(f" -- Wrote {path}") | ||
| if _should_open_browser(args.no_open): | ||
| webbrowser.open(f"file://{path}") | ||
| print(" -- Opened in browser") | ||
| else: | ||
| print(f" → Open manually: file://{path}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.