{"id":23449118,"url":"https://github.com/oeway/hypha-microscope-demo","last_synced_at":"2025-04-10T02:37:50.240Z","repository":{"id":266166364,"uuid":"897158426","full_name":"oeway/hypha-microscope-demo","owner":"oeway","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-02T22:41:48.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-15T18:32:49.407Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oeway.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-02T06:15:15.000Z","updated_at":"2024-12-02T22:41:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"99b73317-0cd4-44c0-9a80-ba9b9fd516a2","html_url":"https://github.com/oeway/hypha-microscope-demo","commit_stats":null,"previous_names":["oeway/hypha-microscope-demo"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oeway%2Fhypha-microscope-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oeway%2Fhypha-microscope-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oeway%2Fhypha-microscope-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oeway%2Fhypha-microscope-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oeway","download_url":"https://codeload.github.com/oeway/hypha-microscope-demo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248144653,"owners_count":21054965,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-23T22:20:06.658Z","updated_at":"2025-04-10T02:37:50.230Z","avatar_url":"https://github.com/oeway.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"### Tutorial: Building a Distributed Microscope Control Application with Hypha\n\nThis tutorial explains how to create a distributed application for controlling a microscope and snapping images using Hypha. It consists of two components: **Microscope Control** and a **User Interface**.\n\n---\n\n### Components Overview\n\n#### 1. Microscope Control (`microscope.py`)\n\nThe microscope control component handles operations for moving the microscope stage and capturing images.\n\n- **Key Features**:\n  - **Move Stage**: Moves the microscope stage to specified X and Y offsets.\n  - **Snap Image**: Simulates capturing an image, returning either a shared memory object (`SharedImage`) or a numpy array.\n\n- **Implementation Highlights**:\n  - **SharedImage**:\n    - A custom class to transfer large image data efficiently via shared memory.\n    - Includes methods to create, encode, decode, and restore images from shared memory.\n  - **Schema Functions**:\n    - `move_stage`: Moves the microscope stage based on user input.\n    - `snap_image`: Captures a simulated image and optionally returns it via shared memory.\n  - **Hypha Server Integration**:\n    - Registers schema functions with the Hypha server, enabling access via the Hypha RPC framework.\n\n---\n\n#### 2. User Interface (`ui.py`)\n\nThe user interface allows users to interact with the microscope system, move the stage, and snap images.\n\n- **Key Features**:\n  - **Move Stage UI**: Provides input fields to move the stage to specified X and Y positions.\n  - **Snap Image UI**: Captures and displays images in real-time, with customizable exposure times.\n\n- **Implementation Highlights**:\n  - **Built with PyQt5**:\n    - Provides a responsive and user-friendly interface.\n    - Displays captured images using a `QLabel`.\n  - **Integration with Microscope Control**:\n    - Connects to the Hypha server to invoke `move_stage` and `snap_image` functions.\n  - **Timer-Based Image Updates**:\n    - Uses a `QTimer` to update snapped images at regular intervals.\n\n---\n\n### Workflow Overview\nBefore start, make sure you have installed the required packages:\n```bash\nconda install pyqt\npip install hypha-rpc hypha pydantic\n```\n\n1. **Set Up the Hypha Server**:\n   Start the Hypha server on your machine:\n   ```bash\n   export JWT_SECRET=19b2e4b3 # Set a secret key for JWT token, change it to your own secret key\n   python3 -m hypha.server --host=0.0.0.0 --port=9527\n   ```\n\n2. **Deploy Microscope Control**:\n   - Run `microscope.py` to register the microscope control service.\n   - The service enables controlling the microscope stage and capturing images.\n\n3. **Launch the User Interface**:\n   - Run `ui.py` to open the GUI.\n   - The GUI connects to the microscope control service, allowing users to:\n     - Move the microscope stage.\n     - Snap images and view them in real-time.\n\n---\n\n### Interaction Between Components\n\n1. The **Hypha Server** serves as the communication hub between the microscope control component and the UI.\n2. The **Microscope Control Service** handles backend operations for stage movement and image capture.\n3. The **User Interface** sends commands to the microscope service and displays the results (e.g., snapped images).\n\n---\n\n### How It Works Together\n\n1. **Starting the Server**:\n   The Hypha server is started to enable communication between components.\n\n2. **Microscope Control Service**:\n   - Registers two schema functions:\n     - `move_stage`: Moves the microscope stage based on user input.\n     - `snap_image`: Captures a simulated image, optionally using shared memory.\n\n3. **User Interface**:\n   - Allows users to interact with the microscope control service via input fields and buttons.\n   - Captured images are displayed in real-time in the UI.\n\n---\n\n### Future Extensions\n\n- Add more microscope operations, such as focusing or changing magnification.\n- Integrate real microscope hardware into the system.\n- Extend the UI to include advanced visualization and analysis tools.\n\nThis streamlined setup demonstrates the power of Hypha in building distributed, modular scientific applications with efficient data handling.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foeway%2Fhypha-microscope-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foeway%2Fhypha-microscope-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foeway%2Fhypha-microscope-demo/lists"}