Skip to content

Instantly share code, notes, and snippets.

View tommylees112's full-sized avatar
🐘

Tommy Lees tommylees112

🐘
  • University of Oxford
  • Oxford
View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import calplot
cfg_date_ranges = { "test_date_ranges": [
[
"2011-01-01",
"2011-12-31"
],
[
"2020-01-01",
"2020-12-31"
@tommylees112
tommylees112 / pystan2_env.sh
Last active February 17, 2022 11:14
Pystan2 environment for linux machines
conda create -n stan2 python=3.7 --yes
conda activate stan2
conda install -c anaconda gcc_linux-64 gxx_linux-64 --yes
## FOR MAC:
# conda install -c anaconda clang_osx-64 clangxx_osx-64 --yes
conda install -c conda-forge numpy pandas scipy cython ipython jupyterlab matplotlib freetype --yes
python -m pip install --upgrade pip
pip install pystan==2.19.0.0
conda install -c conda-forge arviz --yes
@tommylees112
tommylees112 / pystan_env.sh
Last active April 12, 2022 13:04
New Pystan Environment that works on M1 Mac
conda create -n stan --yes
conda activate stan
conda install pip --yes
# Install httpstan from source (this will take a while).
pip install -v git+https://github.com/tillahoffmann/httpstan@pip
# Install pystan.
pip install 'pystan>=3'
# Try a dummy program (this should report build and sampling progress).
python -c 'import stan; stan.build("parameters { real x; } model { x ~ normal(0, 1); }").sample()'

# For Macbook Air 2020 (M1 Chip)

First you need to install xcode from the app store

Then you can run:

xcode-select --install

See Here for why

conda create -n h2ox --yes
conda activate h2ox
conda install pytorch torchvision cudatoolkit -c pytorch --yes
conda install -c conda-forge jupyterlab seaborn loguru --yes
conda install -c conda-forge netcdf4 numba tqdm tensorboard ipython pip ruamel.yaml xarray descartes scikit-learn black mypy xskillscore cdsapi cftime --yes
# conda install -c alex-marty sacred
pip install sacred
pip install geopandas
@tommylees112
tommylees112 / viridis_color_sequence.py
Last active January 27, 2022 11:39
Create a list of viridis colors as arrays of `rgba` values
from matplotlib import cm
from matplotlib.colors import ListedColormap, LinearSegmentedColormap
import seaborn as sns
n_unique_vals = 5
colors = cm.get_cmap('viridis', n_unique_vals)(np.linspace(0, 1, n_unique_vals))
sns.palplot(colors)
# create colormap and mappable for colorbar construction
cmap = LinearSegmentedColormap.from_list("RANDOM", colors, N=n_pcs)
@tommylees112
tommylees112 / gdal_env.sh
Created January 26, 2022 09:12
GDAL Environment
conda create -n gdal --yes
conda activate gdal
conda install -c conda-forge gdal --yes
conda install -c conda-forge rioxarray geopandas --yes
conda install -c conda-forge netcdf4 xarray ipython six scipy scikit-learn seaborn matplotlib jupyterlab --yes
@tommylees112
tommylees112 / kouji_code.py
Last active January 15, 2022 15:21
Code to read csv files and combine them all together
import pandas as pd
from pathlib import Path
import numpy as np
from datetime import datetime
# CHANGE THIS >>>>>>>>>
DATA_DIR = "/Users/tommylees/Downloads"
USER = "kouji"
FIRST_ROW_TO_READ = 13 # remember it is 0-based indexing
from pathlib import Path
from cmdstanpy import cmdstan_path, CmdStanModel, CmdStanMCMC
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from typing import Dict
import arviz as az
model_dir = Path("stan_code")