Skip to content

Instantly share code, notes, and snippets.

@denis-bz
denis-bz / 0-Poisson-matrices.md
Last active Jun 25, 2022
Poisson2 - 4 I: nice test matrices for linear solvers and eigensolvers 25 Jun 2022
View 0-Poisson-matrices.md

Poisson2 - 4 I: nice test matrices for linear solvers and eigensolvers

Purpose: a simple generator of test matrices for linear solvers and eigensolvers

Keywords: sparse-matrix, linear-solver, eigensolver, arpack, nullspace, python

poisson2( n ) below generates sparse $n^2 \ x \ n^2$ matrices $A$ with $A$ symmetric (aka Hermitian) and positive-definite; solving $A \ x = b$ is then relatively easy. $A_4 = A - 4 I$ is more interesting: there are $n$ vectors $z_i$

@denis-bz
denis-bz / ssquery.py
Created Jun 21, 2022
One-line queries of the SuiteSparse matrix collection 21 Jun 2022
View ssquery.py
#!/usr/bin/env python3
""" Usage:
python3 ssquery.py '(posdef == 1) & (1000 <= rows <= 20000)' posdef.csv
reads http://sparse.tamu.edu/files/ssstats.csv
queries it
writes "posdef.csv" like
# SuiteSparse posdef & (1000 <= rows <= 20000)
id,group,name,rows,cols,nnz,real,bool,is2d3d,posdef,symm,nsymm,kind
29156,Boeing,msc01050,1050,1050,26198,1,0,1,1,1.0,1.0,structural
@denis-bz
denis-bz / 0-HUSL-lch-is-not-CIELCh.md
Last active Mar 26, 2022
HUSL rgb_to_lch is not CIELCh
View 0-HUSL-lch-is-not-CIELCh.md

HUSL rgb_to_lch is for CIELuv, not CIELab

Keywords: color-space HUSL HSLuv CIELCh CIELuv CIELab max-chroma everyone-knows

Whenever something can be done in two ways, someone will be confused.

22mar-husl-wall-imshow2

There are two quite different color spaces: \

@denis-bz
denis-bz / 0-globalwindatlas-linear.md
Last active Feb 28, 2022
Are windspeeds and capacity factors from https://globalwindatlas.info linearly related ? 24 Dec 2021
View 0-globalwindatlas-linear.md

Are windspeeds and capacity factors from https://globalwindatlas.info linearly related ?

Keywords: wind power, Germany, python, globalwindatlas

24dec-regress-wind

I'd appreciate hearing from anyone who knows how globalwindatlas calculates its data.

@denis-bz
denis-bz / 0-Windpower-Weibullmodel.md
Created Nov 30, 2021
How does wind power vary with wind speed, Weibull model ? 30 Nov 2021
View 0-Windpower-Weibullmodel.md

How does wind power vary with wind speed, Weibull model ?

Keywords: wind power, wind energy, model, Weibull, python

Purpose: a simple model of wind power, power curve × Weibull wind curves.

Look at the map of windspeeds in Germany under globalwindatlas.info: set the height to 150m and windspeeds to say 6 to 9 m/s in the sidebars. (I'd show it here, but it's copyrighted.)

@denis-bz
denis-bz / 0-Windfarms-in-Germany.md
Last active Feb 28, 2022
Windfarms in Germany, from de.wikipedia 14 Nov 2021
View 0-Windfarms-in-Germany.md

Windfarms in Germany from de.wikipedia

Keywords: wind power, Germany, python, globalwindatlas

Purpose: collect data on wind farms in Germany in a single .csv file, from https://de.wikipedia.org/wiki/Liste_von_Windkraftanlagen_in_Bayern etc.

The file windfarms-in-Germany.csv looks like this:

MW MW/Rad Nrad Year N E Land Lkr Typ Ort

@denis-bz
denis-bz / 0-warp.md
Created Nov 7, 2021
Basic image warping or map reproject in python 7 Nov 2021
View 0-warp.md

Warping maps or images

Keywords: image raster resize rescale reproject Manhattan-grid regular-grid

We have a picture (image, raster) A, an array of colored pixels, and want to warp it to a new picture O of a different size or shape. Examples: Map projection, flat maps <-> globe; Image scaling.
There are hundreds of cases of these, and zillions of programs

@denis-bz
denis-bz / 0-warp_raster_test.md
Last active Sep 13, 2021
rioxarray reproject UTM -> 4326 widens NaNs at the sides 13 Sep 2021
View 0-warp_raster_test.md

rioxarray reproject UTM -> 4326 widens NaNs at the sides

Keywords: rioxarray, rasterio, reproject, geotiff, testcase

This plot shows that rioxarray reproject UTM -> 4326, middle -> right, widens NaNs at the sides:

13sep-warp_raster_test_riox

@denis-bz
denis-bz / 0-German-energy.md
Last active Jul 12, 2021
Electricity in Germany from coal, wind etc.
View 0-German-energy.md

Electricity in Germany from coal, wind etc.

Keywords: electricity, Germany, renewable, wind, python, pandas

Purpose: summarize data on electricity sources in Germany from the electricity market site smard.de:

total 502489 GWh  365 days, 2020-07-01 .. 2021-06-30:
                 GWh    %   GW

Braunkohle 96253.2 19.2 11.0

@denis-bz
denis-bz / rki_excel.py
Created Jun 10, 2021
Read German Corona data rki.de/.../Fallzahlen_Kum_Tab.xlsx in python pandas
View rki_excel.py
#!/usr/bin/env python3
""" https://www.rki.de/DE/Content/InfAZ/N/Neuartiges_Coronavirus/Daten/Fallzahlen_Kum_Tab.html .xlsx
-> python pandas read_excel
"""
# sheets, from openpyxl --
# 0 Erlaeuterungen 20 rows 1 cols
# 1 Fälle-Todesfälle-gesamt 509 rows 16384 cols ?!
# 2 BL_7-Tage-Fallzahlen (fixiert) 39 rows 396 cols
# 3 BL_7-Tage-Inzidenz (fixiert) 21 rows 396 cols
# 4 LK_7-Tage-Fallzahlen (fixiert) 419 rows 207 cols