Skip to content

Instantly share code, notes, and snippets.

@grinsted
grinsted / test_northbound.py
Created September 16, 2025 06:57
minimal test of Northbound login, and fetching of station list
import requests
_host= 'https://eu5.fusionsolar.huawei.com'
_username = 'test'
_password = 'test'
url = _host + '/thirdData/login'
headers = {
'accept': 'application/json',
}
@grinsted
grinsted / compress_video.ipynb
Created March 28, 2025 09:16
compress phone videos to make space
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@grinsted
grinsted / SIA-solution2025.ipynb
Created March 26, 2025 11:53
shallow ice approximation
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@grinsted
grinsted / color_fun.py
Created February 26, 2025 13:38
nice colorgradients using SR2Lab (or OKLab)
import numpy as np
from matplotlib import colors
import matplotlib.pyplot as plt
def lch_to_lab(LCh):
a = np.cos(LCh[2] * np.pi / 180) * LCh[1]
b = np.sin(LCh[2] * np.pi / 180) * LCh[1]
return np.array((LCh[0], a, b))
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