Skip to content

Instantly share code, notes, and snippets.

@roomrys
roomrys / image_intensity.py
Last active October 20, 2023 18:03
Image Intensity: Collect and Compare
# %%
import random
import cv2
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
# %%
def read_intensities(video_path: str):
# Open the video file
@roomrys
roomrys / compare_dependencies.py
Last active October 6, 2023 19:41
Compare dependencies of two different conda environments. `mamba list > env1.txt` for as many files/environments as you like then enter the path to the files here.
import csv
import sys
from pathlib import Path
from typing import List
try:
from tqdm import tqdm
except ImportError:
print("Cannot import tqdm. Progress bar will not be displayed.")
tqdm = lambda x: x
@roomrys
roomrys / interactive_track_replacement.py
Created October 19, 2023 17:40
sleap: track replacer
import logging
import os
from typing import Optional
import sleap
from sleap.gui.app import main as sleap_label
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
@roomrys
roomrys / convert_package_to_slp.py
Created October 20, 2023 15:14
sleap: convert `.pkg.slp` to `.slp`
import logging
import sleap
from sleap.io.video import MediaVideo
logger = logging.getLogger(__name__)
def main(path_pkg_slp, paths_to_videos, output_slp_path="slp_from_package.slp"):
"""Replace HDF5 backend with MediaVideo backend for videos in package.
@roomrys
roomrys / log_git_branch.py
Created October 20, 2023 18:00
Log current git branch of code being executed
import logging
import subprocess
from pathlib import Path
logger = logging.getLogger(__name__)
file_path = Path(__file__).resolve()
git_dir = Path(
subprocess.check_output(
["git", "rev-parse", "--git-dir"], cwd=file_path.parent.as_posix()
@roomrys
roomrys / find_missing_predicted_instances.py
Created November 3, 2023 18:31
sleap: find which frames have missing predicted instances
from pathlib import Path
import pandas as pd
import sleap
from sleap import Labels
def main(
ds: str, num_instances_expected: int = 8, output_csv: str = "missing_instances.csv"
) -> None:
@roomrys
roomrys / plot_reprojection.py
Last active December 7, 2023 07:42
Plot labels and reprojections across views
import colorsys
import matplotlib
import matplotlib.colors as mcolors
import matplotlib.patches as mpatches
import matplotlib.pyplot as plt
import numpy as np
from itertools import permutations
from typing import Callable, Dict, Iterator, List, Optional, Tuple, Union
@roomrys
roomrys / plot_exponential_suface.py
Last active January 2, 2024 20:12
Plot an exponential surface and 2D slices in the x and y directions.
import logging
import math
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import numpy as np
from typing import List, Tuple
# Set up logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
@roomrys
roomrys / sleap_metrics_per_video.py
Last active February 8, 2024 17:36
SLEAP: Calculate metrics on a per video basis.
"""This module defines functions to evaluate metrics on a per video basis."""
from pathlib import Path
from typing import Optional
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
@roomrys
roomrys / gcloud_create_delete_instance.py
Last active February 2, 2024 20:19
Create and delete an instance from a machine images programmatically in Google Cloud Compute Engine.
"""This module requires having gcloud authenticated and the google-cloud-compute library."""
from __future__ import annotations
import re
import sys
from typing import Any
import warnings
from google.api_core.extended_operation import ExtendedOperation