Spaces:
Sleeping
Sleeping
Alex Liberzon commited on
Commit ·
2015bc1
1
Parent(s): dbdf005
added tests and demo
Browse files- demo/test1/exp1_001_a.tiff +3 -0
- demo/test1/exp1_001_b.tiff +3 -0
- tests/test_client.py +29 -0
- tests/test_piv_compute.py +45 -0
- tests/test_quiver.py +38 -0
demo/test1/exp1_001_a.tiff
ADDED
|
|
Git LFS Details
|
demo/test1/exp1_001_b.tiff
ADDED
|
|
Git LFS Details
|
tests/test_client.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Test client for the OpenPIV MCP server."""
|
| 3 |
+
|
| 4 |
+
import asyncio
|
| 5 |
+
import json
|
| 6 |
+
from mcp.client.stdio import stdio_client, StdioServerParameters
|
| 7 |
+
from mcp import ClientSession
|
| 8 |
+
|
| 9 |
+
async def test_piv_server():
|
| 10 |
+
server_params = StdioServerParameters(
|
| 11 |
+
command="python",
|
| 12 |
+
args=["src/openpiv_mcp.py"],
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
async with stdio_client(server_params) as (read, write):
|
| 16 |
+
async with ClientSession(read, write) as session:
|
| 17 |
+
# Initialize
|
| 18 |
+
await session.initialize()
|
| 19 |
+
|
| 20 |
+
# List available tools
|
| 21 |
+
tools = await session.list_tools()
|
| 22 |
+
print("Available tools:")
|
| 23 |
+
for tool in tools.tools:
|
| 24 |
+
print(f" - {tool.name}: {tool.description}")
|
| 25 |
+
|
| 26 |
+
print("\nServer is working correctly!")
|
| 27 |
+
|
| 28 |
+
if __name__ == "__main__":
|
| 29 |
+
asyncio.run(test_piv_server())
|
tests/test_piv_compute.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Test the compute_piv tool with sample images."""
|
| 3 |
+
|
| 4 |
+
import asyncio
|
| 5 |
+
import os
|
| 6 |
+
from mcp.client.stdio import stdio_client, StdioServerParameters
|
| 7 |
+
from mcp import ClientSession
|
| 8 |
+
|
| 9 |
+
async def test_compute_piv():
|
| 10 |
+
server_params = StdioServerParameters(
|
| 11 |
+
command="python",
|
| 12 |
+
args=["src/openpiv_mcp.py"],
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
async with stdio_client(server_params) as (read, write):
|
| 16 |
+
async with ClientSession(read, write) as session:
|
| 17 |
+
await session.initialize()
|
| 18 |
+
|
| 19 |
+
# Get test images from openpiv package
|
| 20 |
+
import importlib.resources as pkg
|
| 21 |
+
im1 = str(pkg.files("openpiv").joinpath("data/test1/exp1_001_a.bmp"))
|
| 22 |
+
im2 = str(pkg.files("openpiv").joinpath("data/test1/exp1_001_b.bmp"))
|
| 23 |
+
|
| 24 |
+
print(f"Using test images:")
|
| 25 |
+
print(f" Image A: {im1}")
|
| 26 |
+
print(f" Image B: {im2}")
|
| 27 |
+
print()
|
| 28 |
+
|
| 29 |
+
# Call compute_piv tool
|
| 30 |
+
result = await session.call_tool(
|
| 31 |
+
"compute_piv",
|
| 32 |
+
arguments={
|
| 33 |
+
"image_a_path": im1,
|
| 34 |
+
"image_b_path": im2,
|
| 35 |
+
"window_size": 32,
|
| 36 |
+
"overlap": 16,
|
| 37 |
+
"dt": 1.0
|
| 38 |
+
}
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
print("Result:")
|
| 42 |
+
print(result.content[0].text)
|
| 43 |
+
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
asyncio.run(test_compute_piv())
|
tests/test_quiver.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Test the create_quiver_plot tool."""
|
| 3 |
+
|
| 4 |
+
import asyncio
|
| 5 |
+
from mcp.client.stdio import stdio_client, StdioServerParameters
|
| 6 |
+
from mcp import ClientSession
|
| 7 |
+
|
| 8 |
+
async def test_quiver():
|
| 9 |
+
server_params = StdioServerParameters(
|
| 10 |
+
command="python",
|
| 11 |
+
args=["src/openpiv_mcp.py"],
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
async with stdio_client(server_params) as (read, write):
|
| 15 |
+
async with ClientSession(read, write) as session:
|
| 16 |
+
await session.initialize()
|
| 17 |
+
|
| 18 |
+
# List tools
|
| 19 |
+
tools = await session.list_tools()
|
| 20 |
+
print("Available tools:")
|
| 21 |
+
for tool in tools.tools:
|
| 22 |
+
print(f" - {tool.name}")
|
| 23 |
+
print()
|
| 24 |
+
|
| 25 |
+
# Call create_quiver_plot tool
|
| 26 |
+
result = await session.call_tool(
|
| 27 |
+
"create_quiver_plot",
|
| 28 |
+
arguments={
|
| 29 |
+
"csv_path": "/tmp/piv_results.csv",
|
| 30 |
+
"title": "Test PIV Flow Field"
|
| 31 |
+
}
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
print("Result:")
|
| 35 |
+
print(result.content[0].text)
|
| 36 |
+
|
| 37 |
+
if __name__ == "__main__":
|
| 38 |
+
asyncio.run(test_quiver())
|