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

Logging fix #155

Merged
merged 7 commits into from
Jan 9, 2025
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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,15 @@ Open this link in the browser, navigate to the exact dataset, right-click on the

### ii) Open `inTRACKtive` using a Jupyter Notebook

To make the previous two proccesses (conversion + hosting data) easiest, we compiled them into a single python function, which is demonstration in a [Jupyter Notebook (`/napari/src/intracktive/examples`)](/python/src/intracktive/examples/notebook1_inTRACKtive_from_notebook.ipynb).
To make the previous two proccesses (conversion + hosting data) easier, we compiled them into a single python function, which is demonstration in a [Jupyter Notebook (`/napari/src/intracktive/examples`)](/python/src/intracktive/examples/notebook1_inTRACKtive_from_notebook.ipynb).

```
dataframe_to_browser(data, zarr_dir)
```

where `data` is a `pandas.dataFrame` containing the tracking data, and `zarr_dir` to directory on your computer to save the Zarr file. The `dataframe_to_browser` function, under the hood, sequentially: 1) converts pd.dataFrame to Zarr, 2) saves the Zarr in the specified location, 3) spins up a localhost at that location, and 4) launches a browser window of `inTRACKtive` with as dataUrl the zarr in the localhost. All in a function call.

> ⚠️ Currently `dataframe_to_browser` only works for Chrome and Firefox

### iii) Open `inTRACKtive` using the napari widget

Using the same capabilities of the `dataframe_to_browser`, we made a [napari](https://napari.org/stable/) widget. The widget (`intracktiveWidget`) is part of the python package after `pip install`, and automatically shows up in the napari widget list (`plugins>inTRACKtive`). To keep the `inTRACKtive` python package light-weight, napari is not listed as one of it's dependecies. To make use of the napari widget, please `pip install napari[all]` in the same conda environment as `inTRACKtive`. The widget takes the tracking data from a [`tracks`](https://napari.org/dev/howtos/layers/tracks.html) layer in napari and opens an `inTRACKtive` browser window with the data. We provide an example of how to use the widget in a [Jupyter Notebook (`/napari/src/intracktive/examples`)](/python/src/intracktive/examples/notebook2_inTRACKtive_from_napari.ipynb).
Expand Down
11 changes: 7 additions & 4 deletions python/src/intracktive/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ def dataframe_to_browser(df: pd.DataFrame, zarr_dir: Path) -> None:
if str(zarr_dir) in (".", None):
with tempfile.TemporaryDirectory() as temp_dir:
zarr_dir = Path(temp_dir)
logging.info("Temporary directory used for localhost:", zarr_dir)
logging.info("Temporary directory used for localhost: %s", zarr_dir)
else:
logging.info("Provided directory used used for localhost:", zarr_dir)
logging.info("Provided directory used used for localhost: %s", zarr_dir)

extra_cols = []
zarr_path = (
Expand All @@ -324,14 +324,17 @@ def dataframe_to_browser(df: pd.DataFrame, zarr_dir: Path) -> None:
threaded=True,
)

logging.info("localhost successfully launched, serving:", zarr_dir_with_storename)
logging.info(
"localhost successfully launched, serving: %s", zarr_dir_with_storename
)

baseUrl = "https://intracktive.sf.czbiohub.org" # inTRACKtive application
dataUrl = hostURL + "/zarr_bundle.zarr/" # exact path of the data (on localhost)
fullUrl = baseUrl + generate_viewer_state_hash(
data_url=str(dataUrl)
) # full hash that encodes viewerState
logging.info("full URL", fullUrl)
logging.info("Copy the following URL into the Google Chrome browser:")
logging.info("full URL: %s", fullUrl)
webbrowser.open(fullUrl)


Expand Down
2 changes: 2 additions & 0 deletions python/src/intracktive/createHash.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def generate_viewer_state_hash(data_url: str) -> str:
"showTrackHighlights": True,
"cameraPosition": [-4, 0, 0],
"cameraTarget": [0, 0, 0],
"pointSize": 0.1,
"trackWidthFactor": 1,
}

# Step 1: Serialize the viewer state to a JSON string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -52,7 +52,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand Down
Loading