Skip to content

Instantly share code, notes, and snippets.

View kanglcn's full-sized avatar

Kang Liang kanglcn

View GitHub Profile
@kanglcn
kanglcn / parallel_bash_from_python.py
Last active June 8, 2023 21:37 — forked from davidgardenier/parallel_bash_from_python.py
Run parallel bash scripts from python
max_processes = 10
template = 'bash'
# Run commands in parallel
processes = set()
for run_file in run_files:
command = 'bash ' + str(run_file)
process = subprocess.Popen(command.split(' '))
processes.add(process)
if len(processes) >= max_processes:
os.wait()
@kanglcn
kanglcn / posdef.py
Created January 2, 2023 09:17 — forked from fasiha/posdef.py
Python/Numpy port of John D’Errico’s implementation (https://www.mathworks.com/matlabcentral/fileexchange/42885-nearestspd) of Higham’s 1988 paper (https://doi.org/10.1016/0024-3795(88)90223-6), including a built-in unit test. License: whatever D’Errico’s license, since this is a port of that.
from numpy import linalg as la
import numpy as np
def nearestPD(A):
"""Find the nearest positive-definite matrix to input
A Python/Numpy port of John D'Errico's `nearestSPD` MATLAB code [1], which
credits [2].
@kanglcn
kanglcn / GoogleMapDownloader.py
Created November 17, 2022 18:51 — forked from farhadinima75/GoogleMapDownloader.py
A python script to download high resolution Google map images given a longitude, latitude and zoom level (Works with Python 3).
#!/usr/bin/python
# GoogleMapDownloader.py
# Created by Hayden Eskriett [http://eskriett.com]
# Edited by Nima Farhadi
#
# A script which when given a longitude, latitude and zoom level downloads a
# high resolution google map
# Find the associated blog post at: http://blog.eskriett.com/2013/07/19/downloading-google-maps/
from PIL import Image
@kanglcn
kanglcn / Tiles.md
Created November 17, 2022 07:21 — forked from xantiagoma/Tiles.md
Map tiles
@kanglcn
kanglcn / rastermerege-rasterio,py
Created August 16, 2021 06:32 — forked from nishadhka/rastermerege-rasterio,py
Raster merge using rasterio
import rasterio.merge
bounds=None
res=None
nodata=None
precision=7
def merge(input1,bounds, res, nodata, precision):
import warnings
warnings.warn("Deprecated; Use rasterio.merge instead", DeprecationWarning)