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
@tommylees112
tommylees112 / create_vertigo_environment.sh
Last active June 28, 2021 13:15
Create working environment on virtual machine
conda create -n ml python=3.8
source activate ml
conda install pytorch torchvision torchaudio cudatoolkit=11.2 -c pytorch -c nvidia --yes
conda install -c conda-forge seaborn=0.11 --yes
conda install -c conda-forge netcdf4 numba tqdm jupyterlab tensorboard ipython pip ruamel.yaml xarray descartes statsmodels scikit-learn black mypy --yes
pip install geopandas
ipython --pdb -c "import torch; assert torch.cuda.is_available(); print(torch.backends.cudnn.version()); print(torch.cuda.device_count());"
@tommylees112
tommylees112 / ml_env.sh
Last active February 8, 2022 11:14
Create PT env with geopandas, pytorch and libraries for spatio_temporal `ml`
# python=3.8
conda create -n ml --yes
conda activate ml
conda install pytorch torchvision cudatoolkit -c pytorch --yes
#ย conda install -c conda-forge seaborn=0.11 --yes3
#ย conda install -c conda-forge jupyterlab=3.0.16 --yes
conda install -c conda-forge jupyterlab seaborn --yes
conda install -c conda-forge netcdf4 numba tqdm tensorboard ipython pip ruamel.yaml xarray descartes statsmodels scikit-learn black mypy eofs xskillscore cdsapi cftime seaborn gcsfs zarr loguru google-cloud-bigquery --yes
conda install -c conda-forge cartopy pyflwdir --yes
conda install -c conda-forge pytest pytest-cov --yes
@tommylees112
tommylees112 / antonia_initial.py
Last active May 21, 2021 12:55
Plotting the predictions from LSTM
import xarray as xr
import matplotlib.pyplot as plt
import seaborn as sns
from pathlib import Path
data_dir = Path("C:\\Users\\anton\\Downloads")
preds = xr.open_dataset(data_dir / "preds.nc")
f, ax = plt.subplots(figsize=(12, 4))
preds.isel(pixel=0).sel(time="2007").obs.plot(ax=ax, color="k")
@tommylees112
tommylees112 / antonia_environment.sh
Last active May 21, 2021 12:27
Conda environment for Antonia
conda create -n ml --yes python=3.7
conda activate ml
conda install tensorflow -c anaconda --yes
conda install pytorch torchvision -c pytorch --yes
conda install -c conda-forge seaborn=0.11 --yes
conda install -c conda-forge netcdf4 numba tqdm jupyterlab tensorboard ipython pip ruamel.yaml xarray descartes statsmodels scikit-learn black mypy --yes
conda install -c anaconda spyder
python -c "import torch; import xarray"
@tommylees112
tommylees112 / exercise_maps.go
Created April 19, 2021 17:14
Maps exercise from ["A Tour of Go"](https://tour.golang.org/welcome/1)
package main
import (
"fmt"
"golang.org/x/tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
// create a slice of strings with each of the inputs
@tommylees112
tommylees112 / picture_demo_slices.go
Last active April 19, 2021 16:32
Slice exercises from the Go Tutorial
package main
import "golang.org/x/tour/pic"
func Formula(x int, y int) uint8 {
// return uint8((x + y) / 2)
return uint8(x * y)
// return uint8(x ^ y)
}
package main
import (
"fmt"
"time"
)
func main() {
today := time.Now().Weekday()
fmt.Printf("Today is: %v\n", today)
@tommylees112
tommylees112 / sqrt_newton_method.go
Last active April 19, 2021 10:16
Playing around with go following the tutorials here: https://tour.golang.org/welcome/3
package main
import (
"fmt"
)
const INITIAL_Z = 1
const DELTA = 1e-7
@tommylees112
tommylees112 / schedule_shifts_in_pulp.py
Created April 9, 2021 10:16
Use the Linear Programming Package PuLP to solve an Integer Programming Problem, subject to certain constraints
"""[summary]
My Question Described:
https://stackoverflow.com/questions/67004787/pulp-linear-programming-scheduling-optimisation-constraint-on-consecutive-nigh
https://or.stackexchange.com/questions/6070/pulp-scheduling-optimisation-constraint-on-consecutive-shifts-consecutive-ni
Minimise:
The maximum difference in the numbers of shifts per person...?
The cost function defined by hand-coded weights in a data table...?
Objective Function
@tommylees112
tommylees112 / demo_xarray_to_pandas.py
Created April 8, 2021 12:33
example xarray to pandas conversion
import xarray as xr
from pathlib import Path
if __name__ == "__main__":
data_dir = Path("/Users/tommylees/github/spatio_temporal/data")
# list(data_dir.glob("*.nc"))
ds = xr.open_dataset(data_dir / "camels_static.nc")
df = ds.to_dataframe()