Skip to content

Instantly share code, notes, and snippets.

import numpy as np
import pandas as pd
import geopandas as gpd
from shapely.geometry import Point, Polygon
zwally = np.loadtxt('grndrainagesystems_ekholm.txt',skiprows=7)
regions = np.unique(zwally[:,0])
for region in regions:
z = zwally[np.abs(zwally[:,0]-region)<0.001,1:]
@grinsted
grinsted / bedmachine2geotiff.py
Last active June 9, 2023 07:15
bedmachine5 to geotiff
import rioxarray as rio
from rasterio.enums import Resampling
import xarray as xr
import numpy as np
ds = rio.open_rasterio('BedMachineGreenland-v5.nc')
props_to_save = ["thickness", "surface", "bed", "errbed"]
ds.thickness.rio.write_nodata(0, inplace=True)
@grinsted
grinsted / aslak.mplstyle
Last active October 25, 2022 13:20
a custom matplotlib style
figure.facecolor: white
figure.dpi: 200
savefig.dpi: 600
figure.figsize: 3.3,2.2
axes.facecolor: white
figure.subplot.bottom: 0.01
figure.subplot.left: 0.01
figure.subplot.right: 0.99
figure.subplot.wspace: 0.2
#
# Snippet to empirically determine credible intervals for return period plots
#
# aslak grinsted 2021
#
import numpy as np
from scipy.stats import beta
@grinsted
grinsted / interpgrid.py
Created January 29, 2021 11:39
A reasonably fast interp2 for python.
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 6 15:01:40 2020
@author: aslak grinsted
"""
import numpy as np
import matplotlib.pyplot as plt
from numpy import nan
@grinsted
grinsted / balanceflux.py
Last active December 23, 2020 10:06
Some code to calculate balance fluxes.
import numpy as np
import heapq
import scipy.ndimage
# lebrocq et al.
# https://www.sciencedirect.com/science/article/pii/S0098300406000781?via%3Dihub
def balanceflux(Z, P, n=1):
"""
@grinsted
grinsted / drumkit_split64.py
Last active April 18, 2021 22:14
Tool for quickly making drumkits for the novation circuit
# This file contains code to save 64 samples as a syx file for Novation Circuit
#
# * It reads a single long wave file.
# * splits it into 64 equal chunks
# * crops the sound
# * adds a super fast fadein and "an appropriate fadeout". To remove clicks
# * normalizes every sample
# * Saves the whole thing as a syx file.
#
import subprocess
import os
import glob
for filename in glob.iglob(os.path.join(".", "**", "*.nc"), recursive=True):
if os.stat(filename).st_size < 50:
continue
result = subprocess.run(["gdalinfo.exe", filename], stdout=subprocess.PIPE)
if result.stdout.rfind(b"COMPRESSION=") > 0:
@grinsted
grinsted / ulln.py
Last active December 19, 2017 09:27
from sympy import *
init_printing(use_unicode=False, wrap_line=False, no_global=True)
x = Symbol('x', positive=True)
xmax = Symbol('xmax', positive=True)
sigma = Symbol('sigma', positive=True)
mu = Symbol('mu')
lx = log(x)-log(xmax-x)