Skip to content

Instantly share code, notes, and snippets.

@edobez
edobez / flatten_list.py
Created February 7, 2020 15:19
How to flatten a nested list
l = [ [1, 2], [3, 4, 5] ]
# Option 1
# Nice because it works not only with lists but all kinds of iterators
flattened1 = list(itertools.chain(*l))
# Option 2
flattened2 = sum(l, [])
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
from netCDF4 import Dataset
import netCDF4 as nc4
import os
import gdal
TILE_PARAMS = {
@edobez
edobez / hyst.py
Created October 26, 2018 13:58
Time-level hysteresis
def hyst(x, thr1, thr2, thr1_time = 0, thr2_time = 0, initial = False):
def level_hysteresis(sig, thr):
when_over = sig > thr
when_under = 1-when_over
where_under = np.where(when_over == 0)[0]
over_cumsum = np.cumsum(when_over)
under_cumsum = np.cumsum(when_under)
return np.maximum(0, over_cumsum - over_cumsum[where_under[under_cumsum-1]])
@edobez
edobez / bytes2hexstring.py
Created March 13, 2018 16:37
Python: bytes to hex string
def byte2hexstring(b, spacing=" ", upper_case=True):
"""
Converts bytes into hex string.
Args:
b (bytes): Bytes to be converted
spacing (string): Spacing between each couple of hex charachters. Defaults to single space
upper_case: If True, uses upper-case letters for the digits above 9
Returns:
@edobez
edobez / uncrustify-c-cpp.cfg
Created October 28, 2016 08:26 — forked from rindeal/uncrustify-c-cpp.cfg
Uncrustify C/C++ config
# -------------------------------------------------------------------------------------------------#
# #
# _ _ _ _ __ ___ _____ _ _ __ _ #
# | | | |_ _ __ _ _ _ _ __| |_(_)/ _|_ _ / __| / / __|| |_ _| |_ __ ___ _ _ / _(_)__ _ #
# | |_| | ' \/ _| '_| || (_-< _| | _| || | | (__ / / (_|_ _|_ _| / _/ _ \ ' \| _| / _` | #
# \___/|_||_\__|_| \_,_/__/\__|_|_| \_, | \___/_/ \___||_| |_| \__\___/_||_|_| |_\__, | #
# |__/ |___/ #
# #
# -------------------------------------------------------------------------------------------------#
# #