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 / clinton_environment.sh
Last active May 25, 2021 14:47
Environment for Clinton with Spyder
# environment_rioxarray.sh
conda create -n rioxarray --yes
conda activate rioxarray
conda install -c conda-forge geopandas --yes
conda install -c conda-forge rioxarray rasterio --yes
conda install -c conda-forge matplotlib tqdm jupyterlab ipython pip ruamel.yaml xarray descartes black mypy --yes
conda install -c anaconda spyder
# test it has worked
ipython -c "import geopandas; import rioxarray; import xarray"
@tommylees112
tommylees112 / antonia_plot_code.py
Created April 3, 2021 14:01
initial plotting code for antonia
import xarray as xr
import matplotlib.pyplot as plt
import seaborn as sns
preds = xr.open_dataset("test_predictions_E030.nc")
preds = preds.drop(["horizon", "easting", "northing"])
f, ax = plt.subplots(figsize=(12, 4))
preds.isel(pixel=0).sel(time="2007").obs.plot(ax=ax, color="k")
preds.isel(pixel=0).sel(time="2007").sim.plot(ax=ax)
@tommylees112
tommylees112 / run_camera.py
Created April 4, 2021 12:50
Take camera image
"""
append to bottom of `/home/pi/.bashrc`
nohup python3 /home/pi/REACH_tjx/scripts/run_camera.py
"""
from datetime import datetime
from time import sleep
from picamera import PiCamera
@tommylees112
tommylees112 / metpy_env.sh
Created April 5, 2021 08:50
working metpy conda environment
# metpy_env.sh
conda create -n metpy --yes
conda activate metpy
conda install -c conda-forge metpy --yes
conda install -c conda-forge matplotlib tqdm jupyterlab ipython pip ruamel.yaml xarray descartes black mypy --yes
# NOTE: can only install geopandas with conda if python=3.7
# conda install -c conda-forge geopandas --yes
# pip install geopandas
@tommylees112
tommylees112 / environment_xarray.sh
Last active April 6, 2021 12:38
Simple xarray python environment
conda create -n py
conda activate py
conda install -c conda-forge matplotlib tqdm jupyterlab ipython pip ruamel.yaml xarray black mypy pandas --yes
# test
ipython -c "import xarray; import numpy; import pandas; import matplotlib; print('Everything Worked!')"
@tommylees112
tommylees112 / demo_sonde_data.py
Last active April 6, 2021 17:01
example script for loading in pandas csv file and a very basic SkewT plot
import pandas as pd
import matplotlib.pyplot as plt
from pathlib import Path
# make sure the data is loaded
data_dir = Path("/Users/tommylees/Downloads")
df = pd.read_csv(data_dir / "demo_sonde.csv", index_col=0)
# initialise plot
f, ax = plt.subplots()
@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()
@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 / 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
package main
import (
"fmt"
"time"
)
func main() {
today := time.Now().Weekday()
fmt.Printf("Today is: %v\n", today)