Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* Support in-notebook configuration of workflow ID, environment file,
and container image tag (#30, #33)
* Support writing of stage-out STAC by notebook (#32)
* Make viewer work on non-default ports (#21)
* Improve dynamic example notebook

## Changes in 0.1.0

Expand Down
103 changes: 76 additions & 27 deletions examples/dynamic/dynamic.ipynb

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion xcengine/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,15 @@ def run(
command = (
["python", "execute.py"]
+ (["--batch"] if run_batch else [])
+ (["--server"] if host_port is not None else [])
+ (
[
"--server",
"--xcube-viewer-api-url",
f"http://localhost:{host_port}",
]
if host_port is not None
else []
)
+ (["--from-saved"] if from_saved else [])
)
run_args = dict(
Expand Down
24 changes: 22 additions & 2 deletions xcengine/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
# https://opensource.org/licenses/MIT.


import json
import logging
import os
import pathlib
import sys
import util


print("CWD", os.getcwd())

import parameters
Expand Down Expand Up @@ -45,6 +47,7 @@ def __xce_set_params():
from xcube.server.framework import get_framework_class
import xcube.util.plugin
import xcube.core.new
import xcube.webapi.viewer


def main():
Expand All @@ -55,6 +58,9 @@ def main():
parser.add_argument("--server", action="store_true")
parser.add_argument("--from-saved", action="store_true")
parser.add_argument("--eoap", action="store_true")
parser.add_argument(
"--xcube-viewer-api-url", type=str, default="http://localhost:8080"
)
parser.add_argument("-v", "--verbose", action="count", default=0)
args, _ = parser.parse_known_args()
if args.verbose > 0:
Expand All @@ -77,15 +83,29 @@ def main():
if args.server:
xcube.util.plugin.init_plugins()
server = Server(framework=get_framework_class("tornado")(), config={})
context = server.ctx.get_api_ctx("datasets")
dataset_context = server.ctx.get_api_ctx("datasets")
for name in datasets:
dataset = (
xr.open_zarr(saved_datasets[name])
if args.batch and args.from_saved
else datasets[name]
)
context.add_dataset(dataset, name, style="bar")
dataset_context.add_dataset(dataset, name, style="bar")
LOGGER.info("Added " + name)
logo_data = (
pathlib.Path(xcube.webapi.viewer.__file__).parent
/ "dist"
/ "images"
/ "logo.png"
).read_bytes()

viewer_context = server.ctx.get_api_ctx("viewer")
viewer_context.config_items = {
"config.json": json.dumps(
{"server": {"url": args.xcube_viewer_api_url}, "branding": {}}
),
"images/logo.png": logo_data,
}
LOGGER.info(f"Starting server on port {server.ctx.config['port']}...")
server.start()

Expand Down