Skip to content

Instantly share code, notes, and snippets.

View cbpygit's full-sized avatar

Carlo Barth cbpygit

View GitHub Profile
import pandas as pd
import gzip
from typing import List
from concurrent.futures import ThreadPoolExecutor
from google.cloud import bigquery, storage
import gcsfs
import logging
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@cbpygit
cbpygit / split_image_into_tiles.sh
Created June 3, 2024 17:23
Split image into multiple tiles to display full screen images crisp on Google Slides:
# This is a work-around around Google Slides' limitation to 1600x1600 pixel images which make full-screen graphics look pixelated
# See this thread: https://support.google.com/docs/thread/9031600/how-can-i-stop-google-slides-applying-their-extreme-image-compression-and-resampling?hl=en
# requires ImageMagick
# Run on image of e.g. 3840x2160 size for 16:9 4K
convert YOUR-IMAGE-NAME.png -crop 3x2-0-0@ +repage +adjoin YOUR-IMAGE-NAME-tile-%d.png
# This create 2x3 = 6 tiles that can be pasted into Google Slides. They can be grouped and act as one single image which renders sharply.
from functools import wraps
def allow_simulate_exception(exception_class=Exception):
def _allow_simulate_exception(method):
"""Decorator that allows to raise an exception """
@wraps(method)
def _raise_exception_if_method_name_fits(self, *method_args,
**method_kwargs):
from cachetools import cached, LRUCache, Cache
from cachetools.keys import hashkey
from time import sleep
class LRUCacheEnsemble:
def __init__(self, maxsize_ensemble, maxsize_caches):
self.maxsize_ensemble = maxsize_ensemble
self.maxsize_caches = maxsize_caches
self.caches = LRUCache(maxsize=maxsize_ensemble)
@cbpygit
cbpygit / find_nearest.py
Created April 8, 2020 08:03
Find nearest value in numpy array
import numpy as np
def find_nearest(array, value):
array = np.asarray(array)
idx = (np.abs(array - value)).argmin()
return idx, array[idx]
@cbpygit
cbpygit / clean_simuset_workaround.py
Created March 22, 2018 07:27
Implementation of a `SimulationSet` that uses a yet undocumented feature that causes the H5-store to be deleted on each initialization. Usually this does not make much sense, but it can be useful in a workflow where the project (or processing function) is still revised regarding the keys.
import pypmj as jpy
class SimulationSetClean(jpy.SimulationSet):
""" Extends `SimulationSet` and simply forces to start with an empty
H5-store each time it is initialized.
"""
def __init__(self, *args, **kwargs):
self._start_withclean_H5_store = True