Skip to content
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

Agave test #123

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ types/

.npmrc
.pnpm-store
.env

# temp transpiled TS files that don't always get cleaned up
vite.config.ts.timestamp-*.mjs
vite.config.ts.timestamp-*.mts
vite.config.ts.timestamp-*.mts
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"lint": "pnpm prettier --check . && pnpm eslint .",
"lint:fix": "pnpm prettier --write . && pnpm eslint --fix .",
"setup-micromamba": "setup-micromamba --micromamba-binary-path ./micromamba/micromamba --micromamba-root-path ./micromamba --init-shell none --create-environment true --environment-file environment.yml --log-level info --run-command \"clean -fya\"",
"start-hypha": "pnpm setup-micromamba && ./micromamba/micromamba run -r micromamba -n itk-viewer hypha --host=127.0.0.1 --port=37580",
"start-hypha": "pnpm setup-micromamba && ./micromamba/micromamba run -r micromamba -n itk-viewer hypha --host=127.0.0.1 --port=9000 --startup-functions ./test/agave-startup.py:hypha_startup ./test/ome-zarr-startup.py:hypha_startup",
"test": "pnpm test:downloadData && concurrently -n \"hypha,cypress\" --success first -k \"pnpm start-hypha\" \"pnpm cy:component\"",
"test:downloadData": "node test/downloadData.mjs",
"cy:watch": "cypress open --component -b chrome",
Expand Down
15 changes: 4 additions & 11 deletions packages/agave-renderer/itk_viewer_agave_renderer/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async def recv(self):

frame = VideoFrame.from_image(img)

frame.pts = self.count
frame.pts = self.count
self.count+=1
frame.time_base = fractions.Fraction(1, 1000)
return frame
Expand Down Expand Up @@ -118,7 +118,7 @@ async def draw_frame(self):
img = r.memory_redraw()
self.render_time = time.time() - start_time
return img

def get_render_time(self):
return self.render_time

Expand Down Expand Up @@ -187,21 +187,14 @@ async def on_ended():

async def connect(
self,
hypha_server_url,
server,
load_image_into_agave_fn,
visibility="public",
identifier="agave-renderer-rtc",
identifier=f"{RENDERER_SERVICE_ID}-rtc",
):
self.load_image = functools.partial(load_image_into_agave_fn, self)

service_id = identifier
client_id = service_id + "-client"
server = await connect_to_server(
{
"client_id": client_id,
"server_url": hypha_server_url,
}
)

await server.register_service(
{
Expand Down
4 changes: 2 additions & 2 deletions packages/agave-renderer/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ authors = [
classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
Expand Down Expand Up @@ -59,7 +59,7 @@ cov = [
]

[[tool.hatch.envs.all.matrix]]
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
python = ["3.8", "3.9", "3.10", "3.11", "3.12"]

[tool.hatch.envs.lint]
detached = true
Expand Down
2 changes: 1 addition & 1 deletion packages/element/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VITE_HYPHA_URL=http://127.0.0.1:9000
VITE_HYPHA_RENDER_SERVICE_ID=agave-renderer-rtc
VITE_HYPHA_REMOTE_ZARR_SERVICE_ID=remote-zarr
VITE_IMAGE=data/aneurism.ome.tif
VITE_IMAGE=input/ome-ngff-prototypes/single_image/v0.4/zyx.ome.zarr
14 changes: 5 additions & 9 deletions packages/remote-image/itk_viewer_remote_image/remote_zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from pathlib import Path

from imjoy_rpc.hypha import connect_to_server
import zarr
from ngff_zarr import (
detect_cli_io_backend,
Expand Down Expand Up @@ -47,37 +46,34 @@ def __init__(self):
pass

async def get_store(self, image_path):
print(f"get_store: {image_path}", flush=True)
print(f"image_path: {image_path}", flush=True)

mapped_path = self.map_path(image_path)
print(f"mapped_path: {mapped_path}", flush=True)

if mapped_path.find("://") == -1 and not Path(mapped_path).exists():
print(f"File not found: {mapped_path}\n", flush=True)
raise Exception(f"File not found: {mapped_path}\n")

backend = detect_cli_io_backend([mapped_path])
if backend is ConversionBackend.NGFF_ZARR:
return zarr.storage.DirectoryStore(mapped_path)
return zarr.storage.DirectoryStore(mapped_path, dimension_separator="/")

# TODO: code below does not work yet
image = cli_input_to_ngff_image(backend, [mapped_path])
multiscales = to_multiscales(image, method=Methods.DASK_IMAGE_GAUSSIAN)
multiscales = to_multiscales(image, method=Methods.ITKWASM_GAUSSIAN)
store, chunk_store = _make_multiscale_store()
to_ngff_zarr(store, multiscales, chunk_store=chunk_store)

return store

async def connect(
self,
hypha_server_url,
server,
map_path=lambda p: p,
visibility="public",
identifier="remote-zarr",
):
server = await connect_to_server(
{"name": "remote-zarr", "server_url": hypha_server_url}
)

self.map_path = map_path

await server.register_service(
Expand Down
8 changes: 4 additions & 4 deletions packages/remote-image/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "itk-viewer-remote-image"
dynamic = ["version"]
description = ''
readme = "README.md"
requires-python = ">=3.7"
requires-python = ">=3.8"
license = "Apache-2.0"
keywords = []
authors = [
Expand All @@ -17,16 +17,16 @@ authors = [
classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = [
"ngff-zarr[dask-image]",
"ngff-zarr",
"zarr",
"hypha",
"numpy",
Expand Down Expand Up @@ -59,7 +59,7 @@ cov = [
]

[[tool.hatch.envs.all.matrix]]
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
python = ["3.8", "3.9", "3.10", "3.11", "3.12"]

[tool.hatch.envs.lint]
detached = true
Expand Down
7 changes: 4 additions & 3 deletions packages/remote-image/tests/get_store.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import os
import asyncio
from imjoy_rpc.hypha import connect_to_server

HYPHA_SERVER_URL = "https://hypha.website"

from dotenv import load_dotenv

async def main():
server = await connect_to_server({"server_url": HYPHA_SERVER_URL})
hypha_server_url = os.environ.get("HYPHA_SERVER_URL", "https://hypha.website")
server = await connect_to_server({"server_url": hypha_server_url})

svc = await server.get_service("remote-zarr")

Expand Down
24 changes: 18 additions & 6 deletions packages/remote-image/tests/service.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import os
import asyncio
from pathlib import Path

from itk_viewer_remote_image import RemoteZarr

HYPHA_SERVER_URL = "https://hypha.website"
from imjoy_rpc.hypha import connect_to_server

remoteZarr = RemoteZarr()
from dotenv import load_dotenv

from itk_viewer_remote_image import RemoteZarr

def map_path(image_path) -> str:
return f"../../../test/data/input/{image_path}"
script_dir = os.path.dirname(os.path.realpath(__file__))
image_path_mapped = Path(script_dir) / '..' / '..' / '..' / 'test' / 'data' / 'input' / image_path
return str(image_path_mapped)

async def hypha_startup():
hypha_server_url = os.environ.get("HYPHA_SERVER_URL", "https://hypha.website")
server = await connect_to_server(
{"name": "remote-zarr-client", "server_url": hypha_server_url}
)

remote_zarr = RemoteZarr()
await remote_zarr.connect(server, map_path)


if __name__ == "__main__":
loop = asyncio.new_event_loop()
task = loop.create_task(remoteZarr.connect(HYPHA_SERVER_URL, map_path))
task = loop.create_task(hypha_startup())
loop.run_forever()
37 changes: 37 additions & 0 deletions test/agave-startup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
import websockets

from dotenv import load_dotenv

from itk_viewer_agave_renderer import Renderer

load_dotenv()

async def check_websocket_server():
try:
async with websockets.connect('ws://localhost:1235') as ws:
return True
except Exception as e:
print(f"Failed to connect: {e}")
return False

async def load_image(renderer, image_path="", multiresolution_level=0, channels=[], region=[]):
agave_renderer = renderer.agave

script_dir = os.path.dirname(os.path.realpath(__file__))
image_path_mapped = os.path.join(script_dir, f"data/{image_path}")

agave_renderer.load_data(
image_path_mapped, 0, multiresolution_level, 0, channels, region
)

async def hypha_startup(server):
renderer = Renderer()

server_is_listening = await check_websocket_server()
if not server_is_listening:
print("Server is not listening, start with `agave --server`")
print("Skipping tests...")
return

await renderer.connect(server, load_image)
18 changes: 18 additions & 0 deletions test/ome-zarr-startup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os
from pathlib import PosixPath

from dotenv import load_dotenv

from itk_viewer_remote_image import RemoteZarr

load_dotenv()

def map_path(image_path) -> str:
script_dir = os.path.dirname(os.path.realpath(__file__))
image_path_mapped = PosixPath(script_dir) / "data" / image_path
return str(image_path_mapped.resolve())

async def hypha_startup(server):
remote_zarr = RemoteZarr()

await remote_zarr.connect(server, map_path)
Loading