Skip to content

Instantly share code, notes, and snippets.

View tlambert03's full-sized avatar

Talley Lambert tlambert03

View GitHub Profile
@tlambert03
tlambert03 / ome.json
Last active August 17, 2021 13:53
OME json schema
{
"title": "OME",
"description": "The OME element is a container for all information objects accessible by OME.\n\nThese information objects include descriptions of the imaging experiments and\nthe people who perform them, descriptions of the microscope, the resulting\nimages and how they were acquired, the analyses performed on those images, and\nthe analysis results themselves. An OME file may contain any or all of this\ninformation.\n\nWith the creation of the Metadata Only Companion OME-XML and Binary Only OME-\nTIFF files the top level OME node has changed slightly. It can EITHER: Contain\nall the previously expected elements OR: Contain a single BinaryOnly element\nthat points at its Metadata Only Companion OME-XML file.\n\nParameters\n----------\nbinary_only : BinaryOnly, optional\n Pointer to an external metadata file. If this element is\n present, then no other metadata may be present in this\n file, i.e. this file is a place-holder.\ncreator : str, optional\n This is the
@tlambert03
tlambert03 / example.py
Created August 17, 2021 18:34
Using loci_tools to create ome-types OME
"""
This requires jpype: `pip install jpype1`
You will also need to have java accessible (`conda install openjdk` works)
Lastly, download the loci_tools.jar from:
https://downloads.openmicroscopy.org/bio-formats/latest/artifacts/
and set the path in the `LOCI` variable below
"""
from ome_types import from_xml
@tlambert03
tlambert03 / mgui_compositions.py
Last active January 18, 2022 21:05
magicgui and qt gui layout patterns
from typing import Container
from magicgui import magicgui, widgets
from qtpy.QtWidgets import QWidget, QVBoxLayout
@magicgui
def my_widget(x: int): ...
# in pseudocode the above is similar to
@tlambert03
tlambert03 / find_layers.py
Created January 18, 2022 13:34
filtering layer list in magicgui
from napari.layers import Image, Layer
from magicgui import magicgui
def custom_get_layers(combo_widget):
from napari.utils._magicgui import find_viewer_ancestor
viewer = find_viewer_ancestor(combo_widget.native)
if not viewer:
return []
@tlambert03
tlambert03 / typed_decorator.py
Created February 15, 2022 01:06
Typing a decorator with optional params
from typing import Callable, Optional, TypeVar, overload, Union
from typing_extensions import ParamSpec, Literal
from functools import wraps
P = ParamSpec("P")
R = TypeVar("R")
@overload
def decorator(func: Callable[P, R], param: int = ...) -> Callable[P, R]:
@tlambert03
tlambert03 / pamba.py
Last active June 5, 2022 01:15
Install deps from pyproject or setup.cfg using mamba
import re
import shutil
import sys
from pathlib import Path
from subprocess import check_call
from typing import Any, Dict, Sequence, Union
from grayskull.strategy.pypi import (
PYPI_CONFIG,
Configuration,
@tlambert03
tlambert03 / imwrite_bench.py
Last active September 12, 2022 15:38
Image writing benchmarks
# modified from https://github.com/adamkglaser/io_benchmarks
import threading
import multiprocessing
import zarr
import numpy as np
import z5py
import h5py
import tifffile
import dask.array as da
@tlambert03
tlambert03 / drawdot.py
Created September 20, 2022 14:42
vispy scenegraph visualizer
from graphviz import Digraph
from vispy import scene
def trace(root):
nodes, edges = set(), set()
def build(v):
if v not in nodes:
nodes.add(v)
for child in v.children:
edges.add((child, v))
@tlambert03
tlambert03 / pyperf.ipynb
Last active February 20, 2023 21:47
pyperf.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tlambert03
tlambert03 / image_conv.ipynb
Created February 28, 2023 01:18
image convolution
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.