This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, []) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]]) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -------------------------------------------------------------------------------------------------# | |
# # | |
# _ _ _ _ __ ___ _____ _ _ __ _ # | |
# | | | |_ _ __ _ _ _ _ __| |_(_)/ _|_ _ / __| / / __|| |_ _| |_ __ ___ _ _ / _(_)__ _ # | |
# | |_| | ' \/ _| '_| || (_-< _| | _| || | | (__ / / (_|_ _|_ _| / _/ _ \ ' \| _| / _` | # | |
# \___/|_||_\__|_| \_,_/__/\__|_|_| \_, | \___/_/ \___||_| |_| \__\___/_||_|_| |_\__, | # | |
# |__/ |___/ # | |
# # | |
# -------------------------------------------------------------------------------------------------# | |
# # |