Skip to content

Instantly share code, notes, and snippets.

View simleo's full-sized avatar

Simone Leo simleo

  • Researcher @crs4
  • Cagliari, Italy
View GitHub Profile
@simleo
simleo / gpu_alloc.py
Last active January 14, 2022 14:42
List docker containers for each GPU
#!/usr/bin/env python
import re
import subprocess as sp
from operator import itemgetter
import docker
def map_gpu_ids():
@simleo
simleo / find_dep_img.py
Created March 15, 2019 11:23
Find dependent images for a given Docker image ID
"""\
Find dependent images for a given Docker image ID.
"""
import argparse
import docker
def find_img(img_idx, id):
try:
@simleo
simleo / try_decorators_args.py
Created July 15, 2017 09:12
Python decorator with arguments
from functools import wraps
def admin_only(*fargs):
def _admin_only(func):
@wraps(func)
def _check_admin(*args, **kwargs):
self = args[0]
if not self.user.isAdmin:
raise RuntimeError("ERROR: admin only")
@simleo
simleo / CreateCompanion.java
Last active June 16, 2017 15:58
Create a companion XML file associated to a plain TIFF file
import java.util.UUID;
import java.io.PrintWriter;
import loci.formats.ImageReader;
import loci.formats.FormatTools;
import loci.formats.ome.OMEXMLMetadata;
import loci.formats.services.OMEXMLService;
import loci.common.Constants;
import loci.common.Location;
import loci.common.xml.XMLTools;
@simleo
simleo / data_packages.py
Last active March 20, 2017 16:25
ome-files-py, map annotations and data packages
# Based on https://github.com/CellMigStandOrg/CMSO-Samples/pull/10
import ome_files
import ome_files.metadata as ofmd
reader = ome_files.OMETIFFReader()
reader.set_id("links/ome_links_1/multifile.companion.ome")
meta = ofmd.OMEXMLMetadata(reader.get_ome_xml())
reader.close()
@simleo
simleo / cellmorph-calc.sh
Last active September 2, 2016 15:39
Generate celery task commands for serializing IDR images to avro
#!/bin/bash
set -eu
shopt -s nullglob
AVRO_PARENTDIR=/uod/idr/homes/szleo/features/idr0012-fuchs-cellmorph/screenA/input
IDR_WRITEABLE=/home/idr-scratch/szleo
RUNAS_USER=13500
ADD_TASK="../venv/bin/python tasks.py"
TASKID_LOG=taskid-calc.log
@simleo
simleo / try_metamorph.py
Created May 5, 2016 14:11
quick hack for reading MetaMorph STK data
"""
From-scratch MetaMorph Stack (STK) reader.
Currently just a quick hack. Dumps the TIFF tags to stdout and each
plane to its own single-image TIFF file.
"""
import sys
import struct
from contextlib import closing
@simleo
simleo / track_mem_linux.py
Created June 5, 2015 09:19
A very non-portable way of tracking memory consumption in Python
import os
PAGESIZE = os.sysconf("SC_PAGE_SIZE") # BYTES
STATM_FIELDS = ["size", "resident", "share", "text", "lib", "data", "dt"]
def meminfo(pid=None):
if pid is None:
pid = os.getpid()
pid = str(pid)