Skip to content

Instantly share code, notes, and snippets.

View sunt05's full-sized avatar

Ting Sun sunt05

View GitHub Profile
@sunt05
sunt05 / fix_env.sh
Last active February 21, 2024 12:39
fix conda/mamba env with explicit versions
#!/usr/bin/env zsh
# This script fixes the environment.yml file for a conda environment.
# Dr Ting Sun (ting.sun@ucl.ac.uk) + GitHub Copilot
# 09 Nov 2023: Initial version
# 11 Feb 2024:
# - Better handling of the pip section
# - Add "-f" flag to force overwrite the original env.yml file
@sunt05
sunt05 / multi-grid-supy-run-loop.py
Created June 15, 2022 14:01
workaround for resolving memory limit issue when running supy for a large number of grids
import supy as sp
import pandas as pd
# using a short period of forcing for example
df_forcing_test = df_forcing.loc["2021-7-1"]
# create an empty list to store dataframes
list_res = []
for grid in df_state_init.index:
df_out, df_state_fina = sp.run_supy(df_forcing_test, df_state_init.loc[[grid]])
generate metric wedge plot; inspired by https://www.nature.com/articles/s41597-021-01079-3/figures/3
@sunt05
sunt05 / egis_env.yml
Created June 15, 2021 16:41
python-QGIS3 related snippets
name: qgis_env
channels:
- conda-forge
- defaults
dependencies:
- python=3.8
- pandas
- xarray
- geopandas
- georasters
@sunt05
sunt05 / plot-SUEWS-stab.py
Last active August 10, 2019 16:56
Plot stability correction functions used in SUEWS 2019a
import pandas as pd
import numpy as np
# working for SUEWS v2019a: supy_driver >= 2019a2
from supy_driver import atmmoiststab_module as atm
# create z/L range
ser_zl = pd.Series(np.arange(-5, 2, .2))
# base DataFrame with z/L and scheme columns
df_zl_psi = pd.DataFrame({i: ser_zl
"""
Standalone python script for QGIS3 on OSX.
"""
import os
import sys
# Define plugin locations from QGIS3
sys.path.append('/Applications/QGIS3.app/Contents/Resources/python/')
sys.path.append('/Applications/QGIS3.app/Contents/Resources/python/plugins')
# Define Qt5 plugin path since Qt5 can't find it
@sunt05
sunt05 / QuickStart-Docker-mingw-python3-macOS.md
Created October 3, 2018 19:27
Quickstart for Windows-targeted development on macOS with `mingw`+`python3`

Quickstart for Windows-targeted development on macOS with mingw+python3

1. install Homebrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2. install Virtual Box (free):

brew cask install virtualbox
@sunt05
sunt05 / example_explicit.f95
Last active August 10, 2017 05:01
SUEWS interface improvement
calPotEvap(& ! compared with the above subroutine, you may find we put all input and output variables explicitly here
TSurf, Qair, SoilMoist, Res, PET)
! below are pseudo-code and comments:
implict none
real, intent(in):: TSurf, Qair, SoilMoist, Res
real, intent(out):: PET
real:: Rho,Lv ! these are constant values: Rho (air density), Lv (latent heat of vaporization)
PET= soilMoist*Rho*Lv/Res*(qsat(Tsurf)-Qair) ! this is the final result we want
@sunt05
sunt05 / gist:1cdc72c2bfe2cabdd33e1528eb82dc1d
Created July 30, 2017 09:54 — forked from agathe/gist:2956101
VBA Excel - Convert each sheet to CSV - For MAC
Function SaveAllSheetsAsCSV(outputPath As String)
On Error GoTo Heaven
' each sheet reference
Dim Sheet As Worksheet
' path to output to
'Dim outputPath As String
' name of each csv
Dim OutputFile As String